使用 xor Jscript WSH 加密二进制文件
Encrypt binary file with xor Jscript WSH
当使用异或加密法加密字符串时,一切正常。但是在处理字节时,它不起作用。它在 k.charCodeAt(0)
处抛出错误请问可能是什么问题?这是我的完整代码。
function Main() {
var key;
key = "thisistheencryptionkey";
WScript.Echo("Encryption started . . .");
Crypt( "C:\xxx\xxx\file.exe", "C:\xxx\xxx\fileenc.txt", key );
WScript.Echo("Decryption started . . .");
Crypt( "C:\xxx\xxx\fileenc.txt", "C:\xxx\xxx\file.exe", key );
WScript.Echo("Finished!");}
function Crypt(fileIn, fileOut, key) {
var fileInRead, objFSOFile;
objFSOFile = new ActiveXObject( "Scripting.FileSystemObject" );
var e = objFSOFile.getFile(fileIn);
var fileSize = e.size;
key = key;
while (key.length < fileSize) {
key += key;
}
var adTypeBinaryWrite = 1;
var adSaveCreateOverWrite = 2;
var BinaryStreamWrite;
BinaryStreamWrite = new ActiveXObject("ADODB.Stream");
BinaryStreamWrite.Type = adTypeBinaryWrite;
BinaryStreamWrite.Open();
var adTypeBinary = 1;
var BinaryStream;
BinaryStream = new ActiveXObject("ADODB.Stream");
BinaryStream.Type = adTypeBinary;
BinaryStream.Open();
BinaryStream.LoadFromFile(fileIn);
var k, ss, q;
i = 0;
do {
q = key.substr(i, 1);
k = BinaryStream.Read(1);
ss = q.charCodeAt(0);
BinaryStreamWrite.Write(String.fromCharCode(k.charCodeAt(0) ^ ss));
i = i + 1;
} while (!BinaryStream.EOS);
BinaryStream.close();
BinaryStreamWrite.SaveToFile(fileOut, adSaveCreateOverWrite);
BinaryStreamWrite.close();}
编辑:
错误说:预期对象
错误代码:800A138F
在测试了很多没有用的东西之后,这就是对我有用的,它正在实施。
当使用异或加密法加密字符串时,一切正常。但是在处理字节时,它不起作用。它在 k.charCodeAt(0)
处抛出错误请问可能是什么问题?这是我的完整代码。
function Main() {
var key;
key = "thisistheencryptionkey";
WScript.Echo("Encryption started . . .");
Crypt( "C:\xxx\xxx\file.exe", "C:\xxx\xxx\fileenc.txt", key );
WScript.Echo("Decryption started . . .");
Crypt( "C:\xxx\xxx\fileenc.txt", "C:\xxx\xxx\file.exe", key );
WScript.Echo("Finished!");}
function Crypt(fileIn, fileOut, key) {
var fileInRead, objFSOFile;
objFSOFile = new ActiveXObject( "Scripting.FileSystemObject" );
var e = objFSOFile.getFile(fileIn);
var fileSize = e.size;
key = key;
while (key.length < fileSize) {
key += key;
}
var adTypeBinaryWrite = 1;
var adSaveCreateOverWrite = 2;
var BinaryStreamWrite;
BinaryStreamWrite = new ActiveXObject("ADODB.Stream");
BinaryStreamWrite.Type = adTypeBinaryWrite;
BinaryStreamWrite.Open();
var adTypeBinary = 1;
var BinaryStream;
BinaryStream = new ActiveXObject("ADODB.Stream");
BinaryStream.Type = adTypeBinary;
BinaryStream.Open();
BinaryStream.LoadFromFile(fileIn);
var k, ss, q;
i = 0;
do {
q = key.substr(i, 1);
k = BinaryStream.Read(1);
ss = q.charCodeAt(0);
BinaryStreamWrite.Write(String.fromCharCode(k.charCodeAt(0) ^ ss));
i = i + 1;
} while (!BinaryStream.EOS);
BinaryStream.close();
BinaryStreamWrite.SaveToFile(fileOut, adSaveCreateOverWrite);
BinaryStreamWrite.close();}
编辑: 错误说:预期对象 错误代码:800A138F
在测试了很多没有用的东西之后,这就是对我有用的,它正在实施。