lua-obfuscator 1.0.1 → 1.0.3
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/index.js +17 -5
- package/package.json +1 -1
- package/src/index.ts +19 -5
package/dist/index.js
CHANGED
|
@@ -5,21 +5,31 @@ import { fileURLToPath } from 'url';
|
|
|
5
5
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
6
|
const prometheusPath = path.join(__dirname, '../dist/prometheus');
|
|
7
7
|
const factory = new LuaFactory();
|
|
8
|
-
|
|
8
|
+
let mountPromise = null;
|
|
9
|
+
async function mountDirectory(dir, prefix = '') {
|
|
9
10
|
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
10
11
|
for (const entry of entries) {
|
|
11
12
|
const fullPath = path.join(dir, entry.name);
|
|
12
13
|
const luaPath = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
13
14
|
if (entry.isDirectory()) {
|
|
14
|
-
mountDirectory(fullPath, luaPath);
|
|
15
|
+
await mountDirectory(fullPath, luaPath);
|
|
15
16
|
}
|
|
16
17
|
else if (entry.name.endsWith('.lua')) {
|
|
17
|
-
factory.mountFile(luaPath, fs.readFileSync(fullPath));
|
|
18
|
+
await factory.mountFile(luaPath, fs.readFileSync(fullPath));
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
+
function ensureMounted() {
|
|
23
|
+
if (!mountPromise) {
|
|
24
|
+
mountPromise = mountDirectory(prometheusPath).catch(err => {
|
|
25
|
+
mountPromise = null;
|
|
26
|
+
throw err;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return mountPromise;
|
|
30
|
+
}
|
|
22
31
|
export async function obfuscate(text, config = 'Strong', luaVersion) {
|
|
32
|
+
await ensureMounted();
|
|
23
33
|
const lua = await factory.createEngine();
|
|
24
34
|
try {
|
|
25
35
|
await lua.doString(`arg = {}`);
|
|
@@ -33,7 +43,9 @@ export async function obfuscate(text, config = 'Strong', luaVersion) {
|
|
|
33
43
|
lua.global.set('__custom_config', config);
|
|
34
44
|
configExpr = '__custom_config';
|
|
35
45
|
}
|
|
36
|
-
|
|
46
|
+
if (luaVersion !== undefined) {
|
|
47
|
+
await lua.global.set('__lua_version', luaVersion);
|
|
48
|
+
}
|
|
37
49
|
const obfuscated = await lua.doString(`
|
|
38
50
|
local Prometheus = require("src.prometheus")
|
|
39
51
|
Prometheus.Logger.logLevel = Prometheus.Logger.LogLevel.Error
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -8,20 +8,30 @@ const prometheusPath = path.join(__dirname, '../dist/prometheus')
|
|
|
8
8
|
|
|
9
9
|
const factory = new LuaFactory()
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
let mountPromise: Promise<void> | null = null
|
|
12
|
+
|
|
13
|
+
async function mountDirectory(dir: string, prefix: string = ''): Promise<void> {
|
|
12
14
|
const entries = fs.readdirSync(dir, { withFileTypes: true })
|
|
13
15
|
for (const entry of entries) {
|
|
14
16
|
const fullPath = path.join(dir, entry.name)
|
|
15
17
|
const luaPath = prefix ? `${prefix}/${entry.name}` : entry.name
|
|
16
18
|
if (entry.isDirectory()) {
|
|
17
|
-
mountDirectory(fullPath, luaPath)
|
|
19
|
+
await mountDirectory(fullPath, luaPath)
|
|
18
20
|
} else if (entry.name.endsWith('.lua')) {
|
|
19
|
-
factory.mountFile(luaPath, fs.readFileSync(fullPath))
|
|
21
|
+
await factory.mountFile(luaPath, fs.readFileSync(fullPath))
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
function ensureMounted(): Promise<void> {
|
|
27
|
+
if (!mountPromise) {
|
|
28
|
+
mountPromise = mountDirectory(prometheusPath).catch(err => {
|
|
29
|
+
mountPromise = null
|
|
30
|
+
throw err
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
return mountPromise
|
|
34
|
+
}
|
|
25
35
|
|
|
26
36
|
type PrometheusPreset = 'Minify' | 'Weak' | 'Medium' | 'Strong'
|
|
27
37
|
|
|
@@ -39,6 +49,8 @@ export async function obfuscate(
|
|
|
39
49
|
config: PrometheusPreset | PrometheusConfig = 'Strong',
|
|
40
50
|
luaVersion?: 'Lua51' | 'LuaU'
|
|
41
51
|
): Promise<string> {
|
|
52
|
+
await ensureMounted()
|
|
53
|
+
|
|
42
54
|
const lua = await factory.createEngine()
|
|
43
55
|
try {
|
|
44
56
|
await lua.doString(`arg = {}`)
|
|
@@ -53,7 +65,9 @@ export async function obfuscate(
|
|
|
53
65
|
configExpr = '__custom_config'
|
|
54
66
|
}
|
|
55
67
|
|
|
56
|
-
|
|
68
|
+
if (luaVersion !== undefined) {
|
|
69
|
+
await lua.global.set('__lua_version', luaVersion)
|
|
70
|
+
}
|
|
57
71
|
|
|
58
72
|
const obfuscated = await lua.doString(`
|
|
59
73
|
local Prometheus = require("src.prometheus")
|