ASP/VBSCRIPT/解密/JAVASCRIPT代码-转集

  1. <% @Language="JavaScript" %>
  2. <%
  3. /*
  4.  *--------------- decode.asp -----------------
  5.  * 功能:遍历某个目录下的所有文件,对加密过的.asp文件
  6.  *      进行解密,并写入源文件中.
  7.  * 实例:单个文件解密
  8.  * Response.Write(DncodeFile(Server.MapPath("conn.asp")));
  9.  * 实例:目录下所有文件解密.
  10.  * DncodeFolderFiles(Server.MapPath("xml"))
  11.  * author:wanghr100(灰豆宝宝.net)
  12.  * update:2004-5-17 11:31
  13.  *--------------- decode.asp -----------------
  14.  */
  15. function DncodeFile(sFilePath)
  16. {
  17. /*
  18.  *--------------- DncodeFile(sFilePath) -----------------
  19.  * DncodeFile(sFilePath) 
  20.  * 功能:打开文件sFilePath,Encode解密,重写该文件.
  21.  * 参数:sFilePath,字符串,文件的路径.
  22.  * 返回:sFilePath,文件的路径.
  23.  * 实例:Response.Write(DncodeFile(Server.MapPath("conn.asp")));
  24.  * author:wanghr100(灰豆宝宝.net)
  25.  * update:2004-5-17 0:58
  26.  *--------------- DncodeFile(sFilePath) -----------------
  27.  */
  28.     var ForReading = 1, ForWriting =2, ForAppending =8;
  29.     var fso = Server.CreateObject("Scripting.FileSystemObject");
  30.     var f = fso.OpenTextFile(sFilePath,ForReading,true);
  31.     sFileText = f.ReadAll();
  32.     f.Close();
  33.     sDncodeText = strdec(sFileText)
  34.     var f = fso.OpenTextFile(sFilePath,ForWriting,true);
  35.     f.Write(sDncodeText);
  36.     f.Close();
  37.     //return sDncodeText;
  38.     return sFilePath;
  39. }
  40. function GetFilesPath(sFolderPath)
  41. {
  42. /*
  43.  *--------------- GetFilesPath(sFolderPath) -----------------
  44.  * GetFilesPath(sFolderPath) 
  45.  * 功能:遍历sFolderPath目录下的所有文件.返回数组.存储文件路径.
  46.  * 参数:sFolderPath,字符串,目录绝对路径.
  47.  * 实例:Response.Write(GetFilesPath(Server.MapPath("xml")))
  48.  * update:2004-5-12 8:33
  49.  * author:wanghr100(灰豆宝宝.net)
  50.  *--------------- GetFilesPath(sFolderPath) -----------------
  51.  */
  52.     var sFilePath = new Array();
  53.     var fso = Server.CreateObject("Scripting.FileSystemObject");
  54.     var oFolder = fso.GetFolder(sFolderPath);
  55.     var oSubFolders = oFolder.SubFolders;
  56.     var oFiles = oFolder.Files;
  57.     icount = oFiles.Count;
  58.     var enmFiles = new Enumerator(oFiles);
  59.     for(;!enmFiles.atEnd();enmFiles.moveNext())
  60.     {
  61.         sFilePath[sFilePath.length] = enmFiles.item().Path
  62.     }
  63.     var enmFolders = new Enumerator(oSubFolders);
  64.     for(;!enmFolders.atEnd();enmFolders.moveNext())
  65.     {
  66.         /* Old 数组成了多维. */
  67.         //sFilePath[sFilePath.length]=GetFilesPath(enmFolders.item().Path);
  68.         /* Add 2004-5-17 11:09 只为一维数组 */
  69.         sFilePath=sFilePath.concat(GetFilesPath(enmFolders.item().Path));
  70.     }
  71.     return sFilePath;
  72. }
  73. function GetFileType(sFileName)
  74. {
  75. /*
  76.  *--------------- GetFileType(sFileName) -----------------
  77.  * GetFileType(sFileName) 
  78.  * 功能:通过后缀,取得sFileName的文件类型.
  79.  * 参数:sFileName,字符串,文件名.
  80.  * 实例:Response.Write(GetFileType("decode.asp"))
  81.  * update:2004-5-13 8:33
  82.  * author:wanghr100(灰豆宝宝.net)
  83.  *--------------- GetFileType(sFileName) -----------------
  84.  */
  85.     sFileName = String(sFileName);
  86.     return sFileName.split(".")[sFileName.split(".").length-1];
  87. }
  88. /* Start 解密实现:李辉煌 Start*/
  89. function screncode(s,l)
  90. {enc=new ActiveXObject("Scripting.Encoder");
  91. return enc.EncodeScriptFile("."+l,s,0,l+"cript");
  92. }
  93.     var STATE_COPY_INPUT        = 100
  94.     var STATE_READLEN       = 101
  95.     var STATE_DECODE        = 102
  96.     var STATE_UNESCAPE      = 103
  97.     var pick_encoding = new Array(
  98.         1, 2, 0, 1, 2, 0, 2, 0, 0, 2, 0, 2, 1, 0, 2, 0,
  99.         1, 0, 2, 0, 1, 1, 2, 0, 0, 2, 1, 0, 2, 0, 0, 2,
  100.         1, 1, 0, 2, 0, 2, 0, 1, 0, 1, 1, 2, 0, 1, 0, 2,
  101.         1, 0, 2, 0, 1, 1, 2, 0, 0, 1, 1, 2, 0, 1, 0, 2
  102.     )
  103.     var rawData = new Array(
  104.         0x64,0x37,0x69, 0x50,0x7E,0x2C, 0x22,0x5A,0x65, 0x4A,0x45,0x72,
  105.         0x61,0x3A,0x5B, 0x5E,0x79,0x66, 0x5D,0x59,0x75, 0x5B,0x27,0x4C,
  106.         0x42,0x76,0x45, 0x60,0x63,0x76, 0x23,0x62,0x2A, 0x65,0x4D,0x43,
  107.         0x5F,0x51,0x33, 0x7E,0x53,0x42, 0x4F,0x52,0x20, 0x52,0x20,0x63,
  108.         0x7A,0x26,0x4A, 0x21,0x54,0x5A, 0x46,0x71,0x38, 0x20,0x2B,0x79,
  109.         0x26,0x66,0x32, 0x63,0x2A,0x57, 0x2A,0x58,0x6C, 0x76,0x7F,0x2B,
  110.         0x47,0x7B,0x46, 0x25,0x30,0x52, 0x2C,0x31,0x4F, 0x29,0x6C,0x3D,
  111.         0x69,0x49,0x70, 0x3F,0x3F,0x3F, 0x27,0x78,0x7B, 0x3F,0x3F,0x3F,
  112.         0x67,0x5F,0x51, 0x3F,0x3F,0x3F, 0x62,0x29,0x7A, 0x41,0x24,0x7E,
  113.         0x5A,0x2F,0x3B, 0x66,0x39,0x47, 0x32,0x33,0x41, 0x73,0x6F,0x77,
  114.         0x4D,0x21,0x56, 0x43,0x75,0x5F, 0x71,0x28,0x26, 0x39,0x42,0x78,
  115.         0x7C,0x46,0x6E, 0x53,0x4A,0x64, 0x48,0x5C,0x74, 0x31,0x48,0x67,
  116.         0x72,0x36,0x7D, 0x6E,0x4B,0x68, 0x70,0x7D,0x35, 0x49,0x5D,0x22,
  117.         0x3F,0x6A,0x55, 0x4B,0x50,0x3A, 0x6A,0x69,0x60, 0x2E,0x23,0x6A,
  118.         0x7F,0x09,0x71, 0x28,0x70,0x6F, 0x35,0x65,0x49, 0x7D,0x74,0x5C,
  119.         0x24,0x2C,0x5D, 0x2D,0x77,0x27, 0x54,0x44,0x59, 0x37,0x3F,0x25,
  120.         0x7B,0x6D,0x7C, 0x3D,0x7C,0x23, 0x6C,0x43,0x6D, 0x34,0x38,0x28,
  121.         0x6D,0x5E,0x31, 0x4E,0x5B,0x39, 0x2B,0x6E,0x7F, 0x30,0x57,0x36,
  122.         0x6F,0x4C,0x54, 0x74,0x34,0x34, 0x6B,0x72,0x62, 0x4C,0x25,0x4E,
  123.         0x33,0x56,0x30, 0x56,0x73,0x5E, 0x3A,0x68,0x73, 0x78,0x55,0x09,
  124.         0x57,0x47,0x4B, 0x77,0x32,0x61, 0x3B,0x35,0x24, 0x44,0x2E,0x4D,
  125.         0x2F,0x64,0x6B, 0x59,0x4F,0x44, 0x45,0x3B,0x21, 0x5C,0x2D,0x37,
  126.         0x68,0x41,0x53, 0x36,0x61,0x58, 0x58,0x7A,0x48, 0x79,0x22,0x2E,
  127.         0x09,0x60,0x50, 0x75,0x6B,0x2D, 0x38,0x4E,0x29, 0x55,0x3D,0x3F
  128.     )
  129.     var transformed = new Array()
  130.     for (var i=0; i<3; i++) transformed[i] = new Array()
  131.     for (var i=31; i<=126; i++) for (var j=0; j<3; j++) transformed[j][rawData[(i-31) * 3 + j]] = (i==31) ? 9 : i
  132.     
  133.     var digits = new Array()
  134.     for (var i=0; i<26; i++)
  135.     {
  136.         digits["A".charCodeAt(0)+i] = i
  137.         digits["a".charCodeAt(0)+i] = i+26
  138.     }
  139.     for (var i=0; i<10; i++)    digits["0".charCodeAt(0)+i] = i+52
  140.     digits[0x2b] = 62
  141.     digits[0x2f] = 63
  142.     function unescape(char)
  143.     {
  144.         var escapes = "#&!*$"
  145.         var escaped = "/r/n<>@"
  146.         if (char.charCodeAt(0) > 126)   return char
  147.         if (escapes.indexOf(char) != -1)    return escaped.substr(escapes.indexOf(char), 1)
  148.         return "?"
  149.     }
  150.     
  151.     function decodeBase64(string)
  152.     {
  153.         var val = 0
  154.         val +=  (digits[string.substr(0,1).charCodeAt(0)] << 2)
  155.         val +=  (digits[string.substr(1,1).charCodeAt(0)] >> 4)
  156.         val +=  (digits[string.substr(1,1).charCodeAt(0)] & 0xf) << 12
  157.         val += ((digits[string.substr(2,1).charCodeAt(0)] >> 2) << 8)
  158.         val += ((digits[string.substr(2,1).charCodeAt(0)] & 0x3) << 22)
  159.         val +=  (digits[string.substr(3,1).charCodeAt(0)] << 16)
  160.         return val
  161.     }
  162.     function strdec(encodingString)
  163.     {
  164.         
  165.         var marker = "#@~^"
  166.         var stringIndex = 0
  167.         var scriptIndex = -1
  168.         var unEncodingIndex = 0
  169.         var char = null
  170.         var encodingLength = unEncodinglength = 0
  171.         var state = STATE_COPY_INPUT
  172.         var unEncodingString = ""
  173.         var re, arr
  174.         
  175.         while(state)
  176.         {
  177.             switch (state)
  178.             {
  179.                 case (STATE_COPY_INPUT) :
  180.                     scriptIndex = encodingString.indexOf(marker, stringIndex)
  181.                     if (scriptIndex != -1)
  182.                     {
  183.                         unEncodingString += encodingString.substring(stringIndex, scriptIndex)
  184.                         scriptIndex += marker.length
  185.                         state = STATE_READLEN
  186.                     }
  187.                     else
  188.                     {
  189.                         stringIndex = stringIndex==0 ? 0 : stringIndex
  190.                         unEncodingString += encodingString.substr(stringIndex, encodingString.length)
  191.                         state = 0
  192.                     }
  193.                     break
  194.                 
  195.                 case (STATE_READLEN)    :
  196.                     encodingLength = encodingString.substr(scriptIndex, 6)
  197.                     unEncodinglength = decodeBase64(encodingLength)
  198.                     scriptIndex += (6 + "==".length)
  199.                     state = STATE_DECODE
  200.                     break
  201.                     
  202.                 case (STATE_DECODE) :
  203.                     if (!unEncodinglength)
  204.                     {
  205.                         stringIndex = scriptIndex + "DQgAAA==^#~@".length
  206.                         unEncodingIndex = 0
  207.                         state = STATE_COPY_INPUT
  208.                         break
  209.                     }
  210.                     char = encodingString.substr(scriptIndex, 1)
  211.                     if (char == "@")    state = STATE_UNESCAPE
  212.                     else
  213.                     {
  214.                         if (char.charCodeAt(0) < 0xFF)
  215.                         {
  216.                             unEncodingString += String.fromCharCode(transformed[pick_encoding[unEncodingIndex%64]][char.charCodeAt(0)])
  217.                             unEncodingIndex++
  218.                         }
  219.                         else
  220.                         {
  221.                             unEncodingString += char
  222.                         }                       
  223.                         scriptIndex++
  224.                         unEncodinglength--
  225.                         break
  226.                     }
  227.                     
  228.                 case STATE_UNESCAPE:
  229.                     unEncodingString += unescape(encodingString.substr(++scriptIndex, 1))
  230.                     scriptIndex++;  unEncodinglength -=2
  231.                     unEncodingIndex++
  232.                     state = STATE_DECODE
  233.                     break
  234.             }
  235.         }
  236.         
  237.         re  = new RegExp("(JScript|VBscript).encode""gmi")
  238.         while(arr = re.exec(unEncodingString))  unEncodingString = RegExp.leftContext + RegExp.$1 + RegExp.rightContext
  239.         return unEncodingString
  240.     }
  241. /* End 解密实现:李辉煌 End*/
  242. function DncodeFolderFiles(sFolderPath)
  243. {
  244. /*
  245.  *--------------- DncodeFolderFiles(sFolderPath) -----------------
  246.  * DncodeFolderFiles(sFolderPath)
  247.  * 功能:遍历sFolderPath目录下的所有文件,对加密过的.asp文件
  248.  *      进行解密,并写入源文件中.
  249.  * 实例:DncodeFolderFiles(Server.MapPath("xml"));
  250.  * author:wanghr100(灰豆宝宝.net)
  251.  * update:2004-5-17 8:07
  252.  *--------------- DncodeFolderFiles(sFolderPath) -----------------
  253.  */
  254.     var arrFiles = GetFilesPath(sFolderPath)
  255.     for(var i=0;i<arrFiles.length;i++)
  256.     {
  257.         if(GetFileType(arrFiles[i])=="asp")
  258.         {
  259.             Response.Write(DncodeFile(arrFiles[i]))
  260.             Response.Write("OK.<br>")
  261.         }
  262.     }
  263. }
  264. //取得xml目录下的所有文件.解密.
  265. //DncodeFolderFiles(Server.MapPath("xml"))
  266. //取得t.asp.解密.
  267. //Response.Write(DncodeFile(Server.MapPath("t.asp")))
  268. var fpath="" + Request.Form("aspFile")//.toLowerCase()
  269. if (fpath.length==0 || fpath=="undefined") {
  270. //仅适用于本机调试
  271. }else{
  272. Response.Write("<script Language=javascript>")
  273. Response.Write("alert('"+DncodeFile(fpath)+"反编译完成!');")
  274. Response.Write("location.href='?';")
  275. Response.Write("</script>")
  276. }
  277. %>
  278. <form action="" method="post" enctype="application/x-www-form-urlencoded" name="form1">
  279.   <table width="98%"  border="1">
  280.     <tr>
  281.       <td> </td>
  282.       <td> </td>
  283.       <td> </td>
  284.       <td> </td>
  285.       <td> </td>
  286.       <td> </td>
  287.       <td> </td>
  288.     </tr>
  289.     <tr>
  290.       <td> </td>
  291.       <td><input type="file" name="aspFile"></td>
  292.       <td> </td>
  293.       <td> </td>
  294.       <td> </td>
  295.       <td> </td>
  296.       <td> </td>
  297.     </tr>
  298.     <tr>
  299.       <td> </td>
  300.       <td><input type="submit" name="Submit" value="提交"></td>
  301.       <td> </td>
  302.       <td> </td>
  303.       <td> </td>
  304.       <td> </td>
  305.       <td> </td>
  306.     </tr>
  307.   </table>
  308. </form>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值