将base64解码为ActiveX JavaScript中的Windows可执行文件
我正在尝试使用WSH JavaScript来解码包含可执行文件的base64字符串,然后将EXE写入文件。这是我对解码的功能:
decodeBase64 = function(s) {
var e={},i,b=0,c,x,l=0,a,r='',w=String.fromCharCode,L=s.length;
var A="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
for(i=0;i<64;i++){e[A.charAt(i)]=i;}
for(x=0;x<L;x++){
c=e[s.charAt(x)];b=(b<<6)+c;l+=6;
while(l>=8){((a=(b>>>(l-=8))&0xff)||(x<(L-2)))&&(r+=w(a));}
}
return r;
};
它适用于解码,但是当我尝试将解码字符串写入文件时,我会遇到一个错误,说“无效的过程调用或参数”。我怀疑这是由于编码是错误的。这是该代码:
var FSO = new ActiveXObject("Scripting.FileSystemObject");
var f = FSO.CreateTextFile(Path, true, false);
f.Write(decodeBase64(data));
f.Close();
现在,我知道您可以使用ISO-8859-1编码进行ADODB.Stream进行编码,并将其读取为Windows-1252编码,但是我在我所处的环境中没有它。还有另一种方法可以解码base64字符串,该字符串包含JavaScript中的EXE,在Windows ANSI编码中,然后将其保存到文件中?可能是一种将DecodeBase64函数结果编码转换为可以作为有效EXE编写的编码的方法?
I'm trying to, with WSH JavaScript, decode a base64 string containing an executable file, and write the EXE to a file. This is the function I have for decoding:
decodeBase64 = function(s) {
var e={},i,b=0,c,x,l=0,a,r='',w=String.fromCharCode,L=s.length;
var A="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
for(i=0;i<64;i++){e[A.charAt(i)]=i;}
for(x=0;x<L;x++){
c=e[s.charAt(x)];b=(b<<6)+c;l+=6;
while(l>=8){((a=(b>>>(l-=8))&0xff)||(x<(L-2)))&&(r+=w(a));}
}
return r;
};
It works for the decoding but when I try to write the decoded string to a file, I get an error saying "Invalid procedure call or argument". I suspect that's due to the encoding being wrong. Here's that code:
var FSO = new ActiveXObject("Scripting.FileSystemObject");
var f = FSO.CreateTextFile(Path, true, false);
f.Write(decodeBase64(data));
f.Close();
Now, I know you can make a ADODB.Stream with ISO-8859-1 encoding and read it out as Windows-1252 encoding, but I don't have that in the environment I'm in. Is it possible that there is another way to decode a Base64 string, containing an EXE in JavaScript, in the Windows ANSI encoding then save that to a file? Possibly a way to convert the encoding of the result of the decodeBase64 function to an encoding that I could write as a valid EXE?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论