是否有任何 Objective-C/Swift 库可以解压这样的 JavaScript“数据包”代码?
eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r [c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c --)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p} ('(0(){4 1="5 6 7 8";0 2(3){9(3)}2(1)})();',10,10,'函数|b|东西| a|var|some|sample|packed|code|alert'.split('|'),0,{}))
我找到了像http://matthewfl.com/unPacker.html这样的在线工具但对于 iOS 没有任何帮助。
谢谢!
测试 1
let function = "eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(0(){4 1=\"5 6 7 8\";0 2(3){9(3)}2(1)})();',10,10,'function|b|something|a|var|some|sample|packed|code|alert'.split('|'),0,{}))"
let toTest = NSString(format: "document.write('<textarea id=\"output\" cols=\"120\" rows=\"10\">');document.write(%@);document.write('</textarea>');document.getElementById(\"output\").value;", NSString(string: function).substringWithRange(NSRange(location: 5, length: count(function) - 6)))
此代码返回:
(0(){4 1="5 6 7 8";0 2(3){9(3)}2(1)})();
但这是错误的...
最佳答案
你可以使用
- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
在这样的 UIWebView 上:
NSString *packedFunction = @"......";
[webview stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.write('<textarea id="output" cols="120" rows="10">');document.write(%@);document.write('</textarea>');document.getElementById("output").value;",[packedFunction subStringWithRange:NSMakeRange(5,packedFunction-1)]]];
关于适用于 iOS 的 JavaScript 解包库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30990100/