fast-cocos 1.1.3 → 1.1.4
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 +26 -26
- package/package.json +1 -1
package/dist/xor/src/xor.js
CHANGED
|
@@ -11,6 +11,7 @@ exports.batchProcess = batchProcess;
|
|
|
11
11
|
exports.runXorCommand = runXorCommand;
|
|
12
12
|
const fs_1 = __importDefault(require("fs"));
|
|
13
13
|
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const utils_1 = require("../../utils");
|
|
14
15
|
/** 默认签名(4 字节) */
|
|
15
16
|
exports.DEFAULT_SIGN = "CrP3";
|
|
16
17
|
/** 默认密钥(16 字节) */
|
|
@@ -56,7 +57,7 @@ function encryptFile(opts) {
|
|
|
56
57
|
const signature = Buffer.from(finalSign, "utf-8");
|
|
57
58
|
const output = Buffer.concat([signature, encrypted]);
|
|
58
59
|
fs_1.default.writeFileSync(destPath, output);
|
|
59
|
-
console.
|
|
60
|
+
console.info("\x1b[32m%s\x1b[0m", `加密: ${path_1.default.basename(opts.inputPath)} -> ${path_1.default.basename(destPath)} [sign:${finalSign}, key:${finalKey.substring(0, 4)}...]`);
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
62
63
|
* 解密文件(校验签名头 + XOR)
|
|
@@ -94,45 +95,44 @@ function decryptFile(opts) {
|
|
|
94
95
|
return true;
|
|
95
96
|
}
|
|
96
97
|
/**
|
|
97
|
-
*
|
|
98
|
+
* 递归批量处理目录(输出与源文件同名;有 outputDir 时保持相对子目录结构)
|
|
98
99
|
*/
|
|
99
100
|
function batchProcess(opts) {
|
|
100
101
|
var _a;
|
|
101
102
|
const { dirPath, mode, outputDir = null, sign = null, key = null } = opts;
|
|
102
103
|
const extensions = (_a = opts.extensions) !== null && _a !== void 0 ? _a : defaultExtensionsForMode(mode);
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
const rootDir = path_1.default.resolve(dirPath);
|
|
105
|
+
if (!fs_1.default.existsSync(rootDir)) {
|
|
106
|
+
console.error("\x1b[31m%s\x1b[0m", `目录不存在: ${rootDir}`);
|
|
105
107
|
return;
|
|
106
108
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
const outRoot = outputDir ? path_1.default.resolve(outputDir) : null;
|
|
110
|
+
if (outRoot) {
|
|
111
|
+
utils_1.utils.mkdir(outRoot);
|
|
109
112
|
}
|
|
110
|
-
const
|
|
113
|
+
const allFiles = utils_1.utils.findFiles(rootDir, extensions);
|
|
111
114
|
let processedCount = 0;
|
|
112
|
-
for (const
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
if (
|
|
116
|
-
const
|
|
117
|
-
|
|
115
|
+
for (const fullPath of allFiles) {
|
|
116
|
+
const absIn = path_1.default.resolve(fullPath);
|
|
117
|
+
let outputFile;
|
|
118
|
+
if (outRoot) {
|
|
119
|
+
const rel = path_1.default.relative(rootDir, absIn);
|
|
120
|
+
outputFile = path_1.default.join(outRoot, rel);
|
|
121
|
+
utils_1.utils.mkdir(path_1.default.dirname(outputFile));
|
|
118
122
|
}
|
|
119
123
|
else {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
else if (decryptFile({ inputPath: fullPath, outputPath: outputFile, sign, key })) {
|
|
130
|
-
processedCount++;
|
|
131
|
-
}
|
|
124
|
+
outputFile = absIn;
|
|
125
|
+
}
|
|
126
|
+
if (mode === "encrypt") {
|
|
127
|
+
encryptFile({ inputPath: absIn, outputPath: outputFile, sign, key });
|
|
128
|
+
processedCount++;
|
|
129
|
+
}
|
|
130
|
+
else if (decryptFile({ inputPath: absIn, outputPath: outputFile, sign, key })) {
|
|
131
|
+
processedCount++;
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
if (processedCount > 0) {
|
|
135
|
-
console.
|
|
135
|
+
console.info("\x1b[32m%s\x1b[0m", `\n${mode === "encrypt" ? "加密" : "解密"} 完成,共处理 ${processedCount} 个文件`);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
/**
|