本人写POST经常会遇到用JS来加密的一些网站,然后又不想用C#重写。
在百度和论坛里找的JS执行不是64位不支持就是要带个DLL神马的。很讨厌。
然后自己就写了个不需要带DLL的。而且支持所有系统哟(64位也一样)(服务器2003多线程POST1个月没崩溃过)
先来一个取13位时间戳的 相信玩POST的都比较常见 比如:1410106357535
[C#] 纯文本查看 复制代码 Type obj = Type.GetTypeFromProgID("ScriptControl");
if (obj == null) return; //单身? 找不到对象啊,
object ScriptControl = Activator.CreateInstance(obj);
obj.InvokeMember("Language", BindingFlags.SetProperty, null, ScriptControl, new object[] { "JScript" });
string js = "function time(){return new Date().getTime()}";
obj.InvokeMember("AddCode", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { js });
string str = obj.InvokeMember("Eval", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { "time()" }).ToString();
textBox1.Text = str;
继续 取随机数 比如:0.0117551307930485
[C#] 纯文本查看 复制代码 Type obj = Type.GetTypeFromProgID("ScriptControl");
if (obj == null) return; //单身? 找不到对象啊,
object ScriptControl = Activator.CreateInstance(obj);
obj.InvokeMember("Language", BindingFlags.SetProperty, null, ScriptControl, new object[] { "JScript" });
string js = "function random(){return Math.random()}";
obj.InvokeMember("AddCode", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { js });
string str = obj.InvokeMember("Eval", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { "random()" }).ToString();
textBox1.Text = str;
继续 计算表达式 比如:表达式:(5*10-2*10)/2 结果为 15
[C#] 纯文本查看 复制代码 Type obj = Type.GetTypeFromProgID("ScriptControl");
if (obj == null) return; //单身? 找不到对象啊,
object ScriptControl = Activator.CreateInstance(obj);
obj.InvokeMember("Language", BindingFlags.SetProperty, null, ScriptControl, new object[] { "JScript" });
string str = obj.InvokeMember("Eval", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { "(5*10-2*10)/2" }).ToString();
textBox1.Text = "(5*10-2*10)/2=" + str;
继续 QQ空间的GTK 比如:193432059
[C#] 纯文本查看 复制代码 StringBuilder sb = new StringBuilder();
sb.Append("function getGtk(str) {");
sb.Append("var hash = 5381;");
sb.Append("for (var i = 0,");
sb.Append("len = str.length; i < len; ++i) {");
sb.Append(" hash += (hash << 5) + str.charAt(i).charCodeAt();");
sb.Append("}");
sb.Append("return hash & 0x7fffffff;");
sb.Append("}");
Type obj = Type.GetTypeFromProgID("ScriptControl");
if (obj == null) return; //单身? 找不到对象啊,
object ScriptControl = Activator.CreateInstance(obj);
obj.InvokeMember("Language", BindingFlags.SetProperty, null, ScriptControl, new object[] { "JScript" });
obj.InvokeMember("AddCode", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { sb.ToString() });
string str = obj.InvokeMember("Eval", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { "getGtk(\"123\")" }).ToString();
textBox1.Text = str;
有这几个例子应该都看懂了吧。下面是DEMO。
|