fast-cocos 1.1.5 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/xor/src/xor.js +23 -14
- package/package.json +1 -1
package/dist/xor/src/xor.js
CHANGED
|
@@ -31,6 +31,13 @@ function xorTransform(opts) {
|
|
|
31
31
|
}
|
|
32
32
|
return result;
|
|
33
33
|
}
|
|
34
|
+
function xor(data, key) {
|
|
35
|
+
let result = "";
|
|
36
|
+
for (let i = 0; i < data.length; i++) {
|
|
37
|
+
result += String.fromCharCode(data.charCodeAt(i) ^ key.charCodeAt(i % key.length));
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
34
41
|
/**
|
|
35
42
|
* 加密文件(签名头 + XOR),输出文件名与源文件 basename 相同(通常配合输出目录使用)
|
|
36
43
|
*/
|
|
@@ -52,11 +59,14 @@ function encryptFile(opts) {
|
|
|
52
59
|
throw new Error("输出路径解析失败");
|
|
53
60
|
}
|
|
54
61
|
const destPath = out;
|
|
55
|
-
const rawData = fs_1.default.readFileSync(opts.inputPath);
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
const rawData = fs_1.default.readFileSync(opts.inputPath, { encoding: "binary" });
|
|
63
|
+
const fileSign = rawData.slice(0, finalSign.length);
|
|
64
|
+
if (fileSign == finalSign) {
|
|
65
|
+
console.log(`跳过(签名已匹配): ${opts.inputPath}`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const encrypted = fileSign + xor(rawData, finalKey);
|
|
69
|
+
fs_1.default.writeFileSync(destPath, encrypted, { encoding: "binary" });
|
|
60
70
|
console.info("\x1b[32m%s\x1b[0m", `加密: ${opts.inputPath} -> ${destPath} [sign:${finalSign}, key:${finalKey.substring(0, 4)}...]`);
|
|
61
71
|
}
|
|
62
72
|
/**
|
|
@@ -81,17 +91,16 @@ function decryptFile(opts) {
|
|
|
81
91
|
throw new Error("输出路径解析失败");
|
|
82
92
|
}
|
|
83
93
|
const destPath = out;
|
|
84
|
-
const encryptedData = fs_1.default.readFileSync(opts.inputPath);
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
console.log(`跳过(签名不匹配): ${path_1.default.basename(opts.inputPath)}`);
|
|
94
|
+
const encryptedData = fs_1.default.readFileSync(opts.inputPath, { encoding: "binary" });
|
|
95
|
+
const fileSign = encryptedData.slice(0, finalSign.length);
|
|
96
|
+
if (fileSign != finalSign) {
|
|
97
|
+
console.info("\x1b[31m%s\x1b[0m", `跳过(签名不匹配): ${opts.inputPath}`);
|
|
89
98
|
return false;
|
|
90
99
|
}
|
|
91
|
-
const
|
|
92
|
-
const decrypted =
|
|
93
|
-
fs_1.default.writeFileSync(destPath, decrypted);
|
|
94
|
-
console.
|
|
100
|
+
const encrypted = encryptedData.slice(finalSign.length);
|
|
101
|
+
const decrypted = xor(encrypted, finalKey);
|
|
102
|
+
fs_1.default.writeFileSync(destPath, decrypted, { encoding: "binary" });
|
|
103
|
+
console.info("\x1b[32m%s\x1b[0m", `解密: ${opts.inputPath} -> ${destPath} [sign:${finalSign}, key:${finalKey.substring(0, 4)}...]`);
|
|
95
104
|
return true;
|
|
96
105
|
}
|
|
97
106
|
/**
|