fast-cocos 1.1.6 → 1.1.8

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.
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.XOR_VERSION = exports.DEFAULT_IMAGE_EXTS = exports.DEFAULT_KEY = exports.DEFAULT_SIGN = void 0;
7
- exports.xorTransform = xorTransform;
8
7
  exports.encryptFile = encryptFile;
9
8
  exports.decryptFile = decryptFile;
10
9
  exports.batchProcess = batchProcess;
@@ -19,18 +18,6 @@ exports.DEFAULT_KEY = "Xk9#mQ2$vL5@nR8w";
19
18
  /** 默认参与批量处理的图片扩展名 */
20
19
  exports.DEFAULT_IMAGE_EXTS = [".png", ".jpg", ".jpeg", ".webp", ".bmp"];
21
20
  exports.XOR_VERSION = "1.0.0";
22
- /**
23
- * XOR 加密/解密(对称)
24
- */
25
- function xorTransform(opts) {
26
- const { data, key } = opts;
27
- const result = Buffer.alloc(data.length);
28
- const keyLen = key.length;
29
- for (let i = 0; i < data.length; i++) {
30
- result[i] = data[i] ^ key.charCodeAt(i % keyLen);
31
- }
32
- return result;
33
- }
34
21
  function xor(data, key) {
35
22
  let result = "";
36
23
  for (let i = 0; i < data.length; i++) {
@@ -62,10 +49,10 @@ function encryptFile(opts) {
62
49
  const rawData = fs_1.default.readFileSync(opts.inputPath, { encoding: "binary" });
63
50
  const fileSign = rawData.slice(0, finalSign.length);
64
51
  if (fileSign == finalSign) {
65
- console.log(`跳过(签名已匹配): ${opts.inputPath}`);
52
+ console.log(`跳过(已加密): ${opts.inputPath}`);
66
53
  return;
67
54
  }
68
- const encrypted = fileSign + xor(rawData, finalKey);
55
+ const encrypted = finalSign + xor(rawData, finalKey);
69
56
  fs_1.default.writeFileSync(destPath, encrypted, { encoding: "binary" });
70
57
  console.info("\x1b[32m%s\x1b[0m", `加密: ${opts.inputPath} -> ${destPath} [sign:${finalSign}, key:${finalKey.substring(0, 4)}...]`);
71
58
  }
@@ -93,11 +80,12 @@ function decryptFile(opts) {
93
80
  const destPath = out;
94
81
  const encryptedData = fs_1.default.readFileSync(opts.inputPath, { encoding: "binary" });
95
82
  const fileSign = encryptedData.slice(0, finalSign.length);
83
+ console.log("文件签名:", fileSign);
96
84
  if (fileSign != finalSign) {
97
85
  console.info("\x1b[31m%s\x1b[0m", `跳过(签名不匹配): ${opts.inputPath}`);
98
86
  return false;
99
87
  }
100
- const encrypted = encryptedData.slice(finalSign.length);
88
+ const encrypted = encryptedData.slice(finalSign.length, encryptedData.length);
101
89
  const decrypted = xor(encrypted, finalKey);
102
90
  fs_1.default.writeFileSync(destPath, decrypted, { encoding: "binary" });
103
91
  console.info("\x1b[32m%s\x1b[0m", `解密: ${opts.inputPath} -> ${destPath} [sign:${finalSign}, key:${finalKey.substring(0, 4)}...]`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-cocos",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "scripts": {
5
5
  "clean": "rm -rf dist",
6
6
  "start": "node ./dist/index.js",