@reverse-craft/smart-fs 1.0.7 → 2.0.1
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/README.md +114 -100
- package/README.zh-CN.md +181 -0
- package/dist/analyzer.d.ts +91 -0
- package/dist/analyzer.d.ts.map +1 -0
- package/dist/beautifier.d.ts +120 -0
- package/dist/beautifier.d.ts.map +1 -0
- package/dist/index.d.ts +102 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1270 -0
- package/dist/index.js.map +7 -0
- package/dist/languageDetector.d.ts +74 -0
- package/dist/languageDetector.d.ts.map +1 -0
- package/dist/llmConfig.d.ts +34 -0
- package/dist/llmConfig.d.ts.map +1 -0
- package/dist/searcher.d.ts +113 -0
- package/dist/searcher.d.ts.map +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +537 -41
- package/dist/server.js.map +4 -4
- package/dist/tools/ToolDefinition.d.ts +24 -0
- package/dist/tools/ToolDefinition.d.ts.map +1 -0
- package/dist/tools/aiFindJsvmpDispatcher.d.ts +79 -0
- package/dist/tools/aiFindJsvmpDispatcher.d.ts.map +1 -0
- package/dist/tools/applyCustomTransform.d.ts +14 -0
- package/dist/tools/applyCustomTransform.d.ts.map +1 -0
- package/dist/tools/findUsageSmart.d.ts +16 -0
- package/dist/tools/findUsageSmart.d.ts.map +1 -0
- package/dist/tools/index.d.ts +43 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/readCodeSmart.d.ts +13 -0
- package/dist/tools/readCodeSmart.d.ts.map +1 -0
- package/dist/tools/searchCodeSmart.d.ts +18 -0
- package/dist/tools/searchCodeSmart.d.ts.map +1 -0
- package/dist/transformer.d.ts +119 -0
- package/dist/transformer.d.ts.map +1 -0
- package/dist/truncator.d.ts +69 -0
- package/dist/truncator.d.ts.map +1 -0
- package/dist/types.d.ts +61 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +16 -16
package/README.md
CHANGED
|
@@ -1,133 +1,138 @@
|
|
|
1
1
|
# @reverse-craft/smart-fs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Smart code processing library with beautification, truncation, search, analysis, and transformation. Multi-language support with source map generation.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- **Code Beautification** - Format minified/obfuscated code with source maps (set breakpoints in Chrome DevTools)
|
|
8
|
+
- **Smart Truncation** - Truncate long strings while preserving line numbers and structure
|
|
9
|
+
- **Code Search** - Search in beautified code, returns original file positions
|
|
10
|
+
- **Variable Analysis** - AST-based scope analysis to find definitions and references
|
|
11
|
+
- **Code Transform** - Apply custom Babel plugins for transformation
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
2. **Long strings overflow context** - Base64 blobs, encrypted data, and huge arrays waste precious tokens
|
|
13
|
+
## Supported Languages
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
| Language | Beautify | AST Truncation | Source Map |
|
|
16
|
+
|----------|----------|----------------|------------|
|
|
17
|
+
| JavaScript/TypeScript | ✓ | ✓ | ✓ |
|
|
18
|
+
| JSON | ✓ | - | - |
|
|
19
|
+
| HTML/XML | ✓ | - | - |
|
|
20
|
+
| CSS | ✓ | - | - |
|
|
21
|
+
| Others | Fallback | Fallback | - |
|
|
15
22
|
|
|
16
23
|
## Installation
|
|
17
24
|
|
|
18
25
|
```bash
|
|
19
|
-
npm install
|
|
26
|
+
npm install @reverse-craft/smart-fs
|
|
20
27
|
```
|
|
21
28
|
|
|
22
|
-
##
|
|
29
|
+
## Quick Start
|
|
23
30
|
|
|
24
|
-
|
|
31
|
+
```typescript
|
|
32
|
+
import { smartRead, smartSearch, findUsage } from '@reverse-craft/smart-fs';
|
|
25
33
|
|
|
26
|
-
|
|
27
|
-
{
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
```
|
|
34
|
+
// Read and process file
|
|
35
|
+
const result = await smartRead('./dist/app.min.js', {
|
|
36
|
+
charLimit: 300, // String truncation length
|
|
37
|
+
maxLineChars: 500, // Max characters per line
|
|
38
|
+
});
|
|
39
|
+
console.log(result.code);
|
|
36
40
|
|
|
37
|
-
|
|
41
|
+
// Search code
|
|
42
|
+
const searchResult = await smartSearch('./dist/app.min.js', 'function', {
|
|
43
|
+
contextLines: 2,
|
|
44
|
+
caseSensitive: false,
|
|
45
|
+
});
|
|
46
|
+
console.log(searchResult.formatted);
|
|
38
47
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"smart-fs": {
|
|
43
|
-
"command": "smart-fs"
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
48
|
+
// Find variable usage
|
|
49
|
+
const usageResult = await findUsage('./dist/app.min.js', 'myFunction');
|
|
50
|
+
console.log(usageResult.formatted);
|
|
47
51
|
```
|
|
48
52
|
|
|
49
|
-
##
|
|
53
|
+
## API
|
|
50
54
|
|
|
51
|
-
|
|
55
|
+
### Convenience Functions
|
|
52
56
|
|
|
53
|
-
|
|
57
|
+
#### `smartRead(filePath, options?)`
|
|
54
58
|
|
|
55
|
-
Read
|
|
59
|
+
Read file with beautification and truncation.
|
|
56
60
|
|
|
57
|
-
|
|
61
|
+
```typescript
|
|
62
|
+
const result = await smartRead('./app.min.js', {
|
|
63
|
+
startLine: 1, // Start line (optional)
|
|
64
|
+
endLine: 100, // End line (optional)
|
|
65
|
+
charLimit: 300, // String truncation length
|
|
66
|
+
maxLineChars: 500, // Max characters per line
|
|
67
|
+
saveLocal: false, // Save beautified file locally
|
|
68
|
+
});
|
|
69
|
+
```
|
|
58
70
|
|
|
59
|
-
|
|
60
|
-
|-----------|------|----------|---------|-------------|
|
|
61
|
-
| `file_path` | string | ✓ | - | Path to JavaScript file |
|
|
62
|
-
| `start_line` | number | ✓ | - | Start line (1-based) |
|
|
63
|
-
| `end_line` | number | ✓ | - | End line (1-based) |
|
|
64
|
-
| `char_limit` | number | | 300 | Max string length before truncation |
|
|
65
|
-
| `max_line_chars` | number | | 500 | Maximum characters per line |
|
|
66
|
-
| `save_local` | boolean | | false | Save beautified file locally |
|
|
71
|
+
#### `smartSearch(filePath, query, options?)`
|
|
67
72
|
|
|
68
|
-
|
|
73
|
+
Search in beautified code, returns original file positions.
|
|
69
74
|
|
|
75
|
+
```typescript
|
|
76
|
+
const result = await smartSearch('./app.min.js', 'decrypt', {
|
|
77
|
+
isRegex: false,
|
|
78
|
+
caseSensitive: false,
|
|
79
|
+
contextLines: 2,
|
|
80
|
+
maxMatches: 50,
|
|
81
|
+
});
|
|
70
82
|
```
|
|
71
|
-
/path/to/obfuscated.js (1-20/5000)
|
|
72
|
-
Src=original position for breakpoints
|
|
73
|
-
1 L1:0 var _0x1234 = function() {
|
|
74
|
-
2 L1:25 var data = "SGVsbG8gV29ybGQ=...[TRUNCATED 50000 CHARS]...base64==";
|
|
75
|
-
3 L1:50078 return decode(data);
|
|
76
|
-
4 L1:50100 };
|
|
77
83
|
|
|
78
|
-
|
|
84
|
+
#### `findUsage(filePath, identifier, options?)`
|
|
85
|
+
|
|
86
|
+
Find all definitions and references of a variable/function.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
const result = await findUsage('./app.min.js', '_0x1234', {
|
|
90
|
+
targetLine: 42, // Target line for precise binding
|
|
91
|
+
maxReferences: 10,
|
|
92
|
+
});
|
|
79
93
|
```
|
|
80
94
|
|
|
81
|
-
###
|
|
95
|
+
### Module Exports
|
|
82
96
|
|
|
83
|
-
|
|
97
|
+
The library exports the following modules:
|
|
84
98
|
|
|
85
|
-
|
|
99
|
+
```typescript
|
|
100
|
+
// Language detection
|
|
101
|
+
import { detectLanguage, getLanguageInfo, isFullySupportedLanguage } from '@reverse-craft/smart-fs';
|
|
86
102
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
| `file_path` | string | ✓ | - | Path to JavaScript file |
|
|
90
|
-
| `identifier` | string | ✓ | - | Variable or function name to find |
|
|
91
|
-
| `line` | number | | - | Line number for precise binding (recommended for obfuscated code) |
|
|
92
|
-
| `char_limit` | number | | 300 | Max string length before truncation |
|
|
93
|
-
| `max_line_chars` | number | | 500 | Maximum characters per line |
|
|
103
|
+
// Code beautification
|
|
104
|
+
import { beautifyCode, ensureBeautified } from '@reverse-craft/smart-fs';
|
|
94
105
|
|
|
95
|
-
|
|
106
|
+
// Code truncation
|
|
107
|
+
import { truncateCode, truncateCodeFromFile, truncateFallback } from '@reverse-craft/smart-fs';
|
|
96
108
|
|
|
97
|
-
|
|
98
|
-
/
|
|
99
|
-
Identifier="_0x1234"
|
|
100
|
-
Src=original position for breakpoints
|
|
101
|
-
Bindings: 1 (Targeted at line 10)
|
|
102
|
-
--- Targeted Scope (const) ---
|
|
103
|
-
📍 Definition:
|
|
104
|
-
5 L1:100 const _0x1234 = function() {
|
|
105
|
-
🔎 References (3):
|
|
106
|
-
10 L1:200 return _0x1234(); ◀── hit
|
|
107
|
-
15 L1:300 _0x1234.call(this);
|
|
108
|
-
20 L1:400 console.log(_0x1234);
|
|
109
|
-
```
|
|
109
|
+
// Code search
|
|
110
|
+
import { searchInCode, formatSearchResult } from '@reverse-craft/smart-fs';
|
|
110
111
|
|
|
111
|
-
|
|
112
|
+
// Variable analysis
|
|
113
|
+
import { analyzeBindings, formatAnalysisResult } from '@reverse-craft/smart-fs';
|
|
112
114
|
|
|
113
|
-
|
|
115
|
+
// Code transformation
|
|
116
|
+
import { applyCustomTransform, loadBabelPlugin } from '@reverse-craft/smart-fs';
|
|
117
|
+
```
|
|
114
118
|
|
|
115
|
-
|
|
119
|
+
## Output Examples
|
|
116
120
|
|
|
117
|
-
|
|
118
|
-
|-----------|------|----------|---------|-------------|
|
|
119
|
-
| `file_path` | string | ✓ | - | Path to JavaScript file |
|
|
120
|
-
| `query` | string | ✓ | - | Text or regex pattern to search |
|
|
121
|
-
| `context_lines` | number | | 2 | Number of context lines |
|
|
122
|
-
| `case_sensitive` | boolean | | false | Case sensitive search |
|
|
123
|
-
| `is_regex` | boolean | | false | Treat query as regex pattern |
|
|
124
|
-
| `char_limit` | number | | 300 | Max string length before truncation |
|
|
125
|
-
| `max_line_chars` | number | | 500 | Maximum characters per line |
|
|
121
|
+
### smartRead Output
|
|
126
122
|
|
|
127
|
-
|
|
123
|
+
```
|
|
124
|
+
/path/to/app.min.js (1-20/5000)
|
|
125
|
+
Src=original position for breakpoints
|
|
126
|
+
1 L1:0 var _0x1234 = function() {
|
|
127
|
+
2 L1:25 var data = "SGVsbG8gV29ybGQ=...[TRUNCATED 50000 CHARS]...base64==";
|
|
128
|
+
3 L1:50078 return decode(data);
|
|
129
|
+
4 L1:50100 };
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### smartSearch Output
|
|
128
133
|
|
|
129
134
|
```
|
|
130
|
-
/path/to/
|
|
135
|
+
/path/to/app.min.js
|
|
131
136
|
Query="decrypt" (literal, case-insensitive)
|
|
132
137
|
Src=original position for breakpoints
|
|
133
138
|
Matches: 3
|
|
@@ -136,29 +141,38 @@ Matches: 3
|
|
|
136
141
|
41 L1:1020 var key = getKey();
|
|
137
142
|
>>42 L1:1050 return decrypt(data, key);
|
|
138
143
|
43 L1:1080 }
|
|
139
|
-
44 L1:1100
|
|
140
144
|
```
|
|
141
145
|
|
|
142
|
-
|
|
146
|
+
### findUsage Output
|
|
143
147
|
|
|
144
|
-
|
|
148
|
+
```
|
|
149
|
+
/path/to/app.min.js
|
|
150
|
+
Identifier="_0x1234"
|
|
151
|
+
Src=original position for breakpoints
|
|
152
|
+
Bindings: 1 (Targeted at line 10)
|
|
153
|
+
--- Targeted Scope (const) ---
|
|
154
|
+
📍 Definition:
|
|
155
|
+
5 L1:100 const _0x1234 = function() {
|
|
156
|
+
� Referetnces (3):
|
|
157
|
+
10 L1:200 return _0x1234(); ◀── hit
|
|
158
|
+
15 L1:300 _0x1234.call(this);
|
|
159
|
+
20 L1:400 console.log(_0x1234);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Related Packages
|
|
145
163
|
|
|
146
|
-
- **
|
|
147
|
-
- **
|
|
148
|
-
- **Smart truncation**: Preserves line count when truncating strings
|
|
149
|
-
- **Caching**: Beautified files are cached based on file modification time
|
|
150
|
-
- **Pagination**: Large files can be read in chunks
|
|
164
|
+
- **[@reverse-craft/smart-fs-mcp](https://github.com/reverse-craft/smart-fs-mcp)** - MCP server exposing smart-fs as MCP tools
|
|
165
|
+
- **[@reverse-craft/ai-tools](https://github.com/reverse-craft/ai-tools)** - AI-powered tools like JSVMP dispatcher detection
|
|
151
166
|
|
|
152
167
|
## How It Works
|
|
153
168
|
|
|
154
169
|
1. **Beautification**: Uses esbuild to format minified code and generate source maps
|
|
155
|
-
2. **Truncation**: Parses AST with meriyah, truncates long
|
|
156
|
-
3. **Mapping**: Uses source-map-js to map
|
|
170
|
+
2. **Truncation**: Parses AST with meriyah, truncates long strings while preserving newlines
|
|
171
|
+
3. **Mapping**: Uses source-map-js to map beautified lines back to original positions
|
|
157
172
|
|
|
158
173
|
## Use Cases
|
|
159
174
|
|
|
160
175
|
- Reverse engineering obfuscated/minified JavaScript
|
|
161
|
-
- Analyzing obfuscated JavaScript
|
|
162
176
|
- Understanding minified third-party libraries
|
|
163
177
|
- Setting breakpoints in beautified code while debugging original
|
|
164
178
|
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# @reverse-craft/smart-fs
|
|
2
|
+
|
|
3
|
+
智能代码处理库,提供代码美化、截断、搜索、分析和转换功能,支持多语言和 Source Map 生成。
|
|
4
|
+
|
|
5
|
+
## 功能特性
|
|
6
|
+
|
|
7
|
+
- **代码美化** - 格式化压缩/混淆代码,生成 Source Map(可在 Chrome DevTools 中设置断点)
|
|
8
|
+
- **智能截断** - 截断超长字符串,保留行号和代码结构
|
|
9
|
+
- **代码搜索** - 在美化后的代码中搜索,返回原始文件位置
|
|
10
|
+
- **变量分析** - 基于 AST 作用域分析,查找变量/函数的定义和引用
|
|
11
|
+
- **代码转换** - 应用自定义 Babel 插件进行代码转换
|
|
12
|
+
|
|
13
|
+
## 支持的语言
|
|
14
|
+
|
|
15
|
+
| 语言 | 美化 | AST 截断 | Source Map |
|
|
16
|
+
|------|------|----------|------------|
|
|
17
|
+
| JavaScript/TypeScript | ✓ | ✓ | ✓ |
|
|
18
|
+
| JSON | ✓ | - | - |
|
|
19
|
+
| HTML/XML | ✓ | - | - |
|
|
20
|
+
| CSS | ✓ | - | - |
|
|
21
|
+
| 其他 | 回退模式 | 回退模式 | - |
|
|
22
|
+
|
|
23
|
+
## 安装
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @reverse-craft/smart-fs
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 快速开始
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { smartRead, smartSearch, findUsage } from '@reverse-craft/smart-fs';
|
|
33
|
+
|
|
34
|
+
// 读取并处理文件
|
|
35
|
+
const result = await smartRead('./dist/app.min.js', {
|
|
36
|
+
charLimit: 300, // 字符串截断长度
|
|
37
|
+
maxLineChars: 500, // 每行最大字符数
|
|
38
|
+
});
|
|
39
|
+
console.log(result.code);
|
|
40
|
+
|
|
41
|
+
// 搜索代码
|
|
42
|
+
const searchResult = await smartSearch('./dist/app.min.js', 'function', {
|
|
43
|
+
contextLines: 2,
|
|
44
|
+
caseSensitive: false,
|
|
45
|
+
});
|
|
46
|
+
console.log(searchResult.formatted);
|
|
47
|
+
|
|
48
|
+
// 查找变量用法
|
|
49
|
+
const usageResult = await findUsage('./dist/app.min.js', 'myFunction');
|
|
50
|
+
console.log(usageResult.formatted);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## API
|
|
54
|
+
|
|
55
|
+
### 便捷函数
|
|
56
|
+
|
|
57
|
+
#### `smartRead(filePath, options?)`
|
|
58
|
+
|
|
59
|
+
读取文件并进行美化和截断处理。
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
const result = await smartRead('./app.min.js', {
|
|
63
|
+
startLine: 1, // 起始行(可选)
|
|
64
|
+
endLine: 100, // 结束行(可选)
|
|
65
|
+
charLimit: 300, // 字符串截断长度
|
|
66
|
+
maxLineChars: 500, // 每行最大字符数
|
|
67
|
+
saveLocal: false, // 是否保存美化后的文件
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### `smartSearch(filePath, query, options?)`
|
|
72
|
+
|
|
73
|
+
在美化后的代码中搜索,返回原始文件位置。
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
const result = await smartSearch('./app.min.js', 'decrypt', {
|
|
77
|
+
isRegex: false,
|
|
78
|
+
caseSensitive: false,
|
|
79
|
+
contextLines: 2,
|
|
80
|
+
maxMatches: 50,
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### `findUsage(filePath, identifier, options?)`
|
|
85
|
+
|
|
86
|
+
查找变量/函数的所有定义和引用。
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
const result = await findUsage('./app.min.js', '_0x1234', {
|
|
90
|
+
targetLine: 42, // 指定行号精确定位
|
|
91
|
+
maxReferences: 10,
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 模块导出
|
|
96
|
+
|
|
97
|
+
库导出以下模块,可按需使用:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
// 语言检测
|
|
101
|
+
import { detectLanguage, getLanguageInfo, isFullySupportedLanguage } from '@reverse-craft/smart-fs';
|
|
102
|
+
|
|
103
|
+
// 代码美化
|
|
104
|
+
import { beautifyCode, ensureBeautified } from '@reverse-craft/smart-fs';
|
|
105
|
+
|
|
106
|
+
// 代码截断
|
|
107
|
+
import { truncateCode, truncateCodeFromFile, truncateFallback } from '@reverse-craft/smart-fs';
|
|
108
|
+
|
|
109
|
+
// 代码搜索
|
|
110
|
+
import { searchInCode, formatSearchResult } from '@reverse-craft/smart-fs';
|
|
111
|
+
|
|
112
|
+
// 变量分析
|
|
113
|
+
import { analyzeBindings, formatAnalysisResult } from '@reverse-craft/smart-fs';
|
|
114
|
+
|
|
115
|
+
// 代码转换
|
|
116
|
+
import { applyCustomTransform, loadBabelPlugin } from '@reverse-craft/smart-fs';
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## 输出示例
|
|
120
|
+
|
|
121
|
+
### smartRead 输出
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
/path/to/app.min.js (1-20/5000)
|
|
125
|
+
Src=原始位置(用于设置断点)
|
|
126
|
+
1 L1:0 var _0x1234 = function() {
|
|
127
|
+
2 L1:25 var data = "SGVsbG8gV29ybGQ=...[TRUNCATED 50000 CHARS]...base64==";
|
|
128
|
+
3 L1:50078 return decode(data);
|
|
129
|
+
4 L1:50100 };
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### smartSearch 输出
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
/path/to/app.min.js
|
|
136
|
+
Query="decrypt" (literal, case-insensitive)
|
|
137
|
+
Src=原始位置(用于设置断点)
|
|
138
|
+
Matches: 3
|
|
139
|
+
--- Line 42 ---
|
|
140
|
+
40 L1:1000 function process(data) {
|
|
141
|
+
41 L1:1020 var key = getKey();
|
|
142
|
+
>>42 L1:1050 return decrypt(data, key);
|
|
143
|
+
43 L1:1080 }
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### findUsage 输出
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
/path/to/app.min.js
|
|
150
|
+
Identifier="_0x1234"
|
|
151
|
+
Src=原始位置(用于设置断点)
|
|
152
|
+
Bindings: 1 (Targeted at line 10)
|
|
153
|
+
--- Targeted Scope (const) ---
|
|
154
|
+
📍 Definition:
|
|
155
|
+
5 L1:100 const _0x1234 = function() {
|
|
156
|
+
🔎 References (3):
|
|
157
|
+
10 L1:200 return _0x1234(); ◀── hit
|
|
158
|
+
15 L1:300 _0x1234.call(this);
|
|
159
|
+
20 L1:400 console.log(_0x1234);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## 相关包
|
|
163
|
+
|
|
164
|
+
- **[@reverse-craft/smart-fs-mcp](https://github.com/reverse-craft/smart-fs-mcp)** - MCP 服务器,将 smart-fs 功能暴露为 MCP 工具
|
|
165
|
+
- **[@reverse-craft/ai-tools](https://github.com/reverse-craft/ai-tools)** - AI 辅助工具,如 JSVMP 分发器检测
|
|
166
|
+
|
|
167
|
+
## 工作原理
|
|
168
|
+
|
|
169
|
+
1. **美化**: 使用 esbuild 格式化压缩代码并生成 Source Map
|
|
170
|
+
2. **截断**: 使用 meriyah 解析 AST,截断长字符串同时保留换行符
|
|
171
|
+
3. **映射**: 使用 source-map-js 将美化后的行映射回原始位置
|
|
172
|
+
|
|
173
|
+
## 使用场景
|
|
174
|
+
|
|
175
|
+
- 逆向分析混淆/压缩的 JavaScript
|
|
176
|
+
- 理解第三方压缩库
|
|
177
|
+
- 在美化代码中设置断点调试原始代码
|
|
178
|
+
|
|
179
|
+
## License
|
|
180
|
+
|
|
181
|
+
MIT
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { SourceMap } from './beautifier.js';
|
|
2
|
+
/**
|
|
3
|
+
* Original position from source map
|
|
4
|
+
*/
|
|
5
|
+
export interface OriginalPosition {
|
|
6
|
+
line: number | null;
|
|
7
|
+
column: number | null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Location information for a definition or reference
|
|
11
|
+
*/
|
|
12
|
+
export interface LocationInfo {
|
|
13
|
+
/** Line number in beautified code (1-based) */
|
|
14
|
+
line: number;
|
|
15
|
+
/** Column number in beautified code (0-based) */
|
|
16
|
+
column: number;
|
|
17
|
+
/** Original file coordinates from source map */
|
|
18
|
+
originalPosition: OriginalPosition;
|
|
19
|
+
/** Content of the line containing this location */
|
|
20
|
+
lineContent: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Binding information for a variable/function
|
|
24
|
+
*/
|
|
25
|
+
export interface BindingInfo {
|
|
26
|
+
/** Unique scope identifier */
|
|
27
|
+
scopeUid: number;
|
|
28
|
+
/** Binding kind (var, let, const, param, etc.) */
|
|
29
|
+
kind: string;
|
|
30
|
+
/** Definition location */
|
|
31
|
+
definition: LocationInfo;
|
|
32
|
+
/** All reference locations */
|
|
33
|
+
references: LocationInfo[];
|
|
34
|
+
/** Total reference count (before limiting) */
|
|
35
|
+
totalReferences: number;
|
|
36
|
+
/** The location that matched the target line (if targeted search) */
|
|
37
|
+
hitLocation?: LocationInfo;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Analysis result containing all bindings for an identifier
|
|
41
|
+
*/
|
|
42
|
+
export interface AnalysisResult {
|
|
43
|
+
/** All bindings found for the identifier */
|
|
44
|
+
bindings: BindingInfo[];
|
|
45
|
+
/** The identifier that was searched */
|
|
46
|
+
identifier: string;
|
|
47
|
+
/** Whether this was a targeted (line-specific) search */
|
|
48
|
+
isTargeted: boolean;
|
|
49
|
+
/** The target line if specified */
|
|
50
|
+
targetLine?: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Parse JavaScript/TypeScript code into an AST
|
|
54
|
+
* @param code - Source code to parse
|
|
55
|
+
* @returns Parsed AST
|
|
56
|
+
* @throws Error if parsing fails
|
|
57
|
+
*/
|
|
58
|
+
export declare function parseCode(code: string): import("@babel/parser").ParseResult<import("@babel/types").File>;
|
|
59
|
+
/**
|
|
60
|
+
* Options for binding analysis
|
|
61
|
+
*/
|
|
62
|
+
export interface AnalyzeOptions {
|
|
63
|
+
/** Maximum references to return per binding (default 10) */
|
|
64
|
+
maxReferences?: number;
|
|
65
|
+
/** Target line number for precise binding identification (1-based) */
|
|
66
|
+
targetLine?: number;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Analyze bindings for a specific identifier in the code
|
|
70
|
+
* Uses Babel traverse to find all bindings and their references
|
|
71
|
+
*
|
|
72
|
+
* @param code - Beautified code to analyze
|
|
73
|
+
* @param rawMap - Source map for coordinate mapping
|
|
74
|
+
* @param identifier - Variable/function name to find
|
|
75
|
+
* @param options - Analysis options
|
|
76
|
+
* @returns Analysis result with all bindings
|
|
77
|
+
*/
|
|
78
|
+
export declare function analyzeBindings(code: string, rawMap: SourceMap, identifier: string, options?: AnalyzeOptions): Promise<AnalysisResult>;
|
|
79
|
+
/**
|
|
80
|
+
* Format source position as "L{line}:{column}" or placeholder
|
|
81
|
+
*/
|
|
82
|
+
export declare function formatSourcePosition(line: number | null, column: number | null): string;
|
|
83
|
+
/**
|
|
84
|
+
* Format analysis result for output
|
|
85
|
+
* @param filePath - Path to the file
|
|
86
|
+
* @param result - Analysis result
|
|
87
|
+
* @param maxReferences - Maximum references shown per binding
|
|
88
|
+
* @returns Formatted output string
|
|
89
|
+
*/
|
|
90
|
+
export declare function formatAnalysisResult(filePath: string, result: AnalysisResult, maxReferences?: number): string;
|
|
91
|
+
//# sourceMappingURL=analyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAsBjD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,mDAAmD;IACnD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,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from './languageDetector.js';
|
|
2
|
+
export interface SourceMap {
|
|
3
|
+
version: number;
|
|
4
|
+
sources: string[];
|
|
5
|
+
names: string[];
|
|
6
|
+
mappings: string;
|
|
7
|
+
file?: string;
|
|
8
|
+
sourceRoot?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface BeautifyOptions {
|
|
11
|
+
/** Override auto-detected language */
|
|
12
|
+
language?: SupportedLanguage;
|
|
13
|
+
/** Save beautified file locally (default: true for JS/TS) */
|
|
14
|
+
saveLocal?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface BeautifyResult {
|
|
17
|
+
code: string;
|
|
18
|
+
/** Source map (null for languages that don't support it) */
|
|
19
|
+
rawMap: SourceMap | null;
|
|
20
|
+
/** 本地保存的美化文件路径 */
|
|
21
|
+
localPath: string;
|
|
22
|
+
/** 本地保存的 source map 路径 */
|
|
23
|
+
localMapPath: string;
|
|
24
|
+
/** 本地保存失败时的错误信息 */
|
|
25
|
+
localSaveError?: string;
|
|
26
|
+
/** Whether fallback mode was used */
|
|
27
|
+
usedFallback: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Local paths result interface
|
|
31
|
+
*/
|
|
32
|
+
export interface LocalPaths {
|
|
33
|
+
/** Path to the beautified file in the same directory as the original */
|
|
34
|
+
beautifiedPath: string;
|
|
35
|
+
/** Path to the source map file in the same directory as the original */
|
|
36
|
+
mapPath: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get local file paths for beautified output
|
|
40
|
+
* Given an original file path, returns the paths where the beautified file
|
|
41
|
+
* and source map should be saved in the same directory.
|
|
42
|
+
*
|
|
43
|
+
* Naming convention:
|
|
44
|
+
* - Original: {filename}.js -> Beautified: {filename}.beautified.js
|
|
45
|
+
* - Source map: {filename}.beautified.js.map
|
|
46
|
+
*
|
|
47
|
+
* @param originalPath - Path to the original JavaScript file
|
|
48
|
+
* @returns Object containing beautifiedPath and mapPath
|
|
49
|
+
*/
|
|
50
|
+
export declare function getLocalPaths(originalPath: string): LocalPaths;
|
|
51
|
+
/**
|
|
52
|
+
* Local cache validation result interface
|
|
53
|
+
*/
|
|
54
|
+
export interface LocalCacheCheck {
|
|
55
|
+
/** Original file modification time in milliseconds */
|
|
56
|
+
originalMtime: number;
|
|
57
|
+
/** Whether the beautified file exists */
|
|
58
|
+
beautifiedExists: boolean;
|
|
59
|
+
/** Beautified file modification time in milliseconds (0 if not exists) */
|
|
60
|
+
beautifiedMtime: number;
|
|
61
|
+
/** Whether the cache is valid (beautifiedMtime >= originalMtime) */
|
|
62
|
+
isValid: boolean;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Check if local beautified cache is valid
|
|
66
|
+
*
|
|
67
|
+
* A local cache is considered valid when:
|
|
68
|
+
* 1. The beautified file exists
|
|
69
|
+
* 2. The beautified file's modification time is >= the original file's modification time
|
|
70
|
+
*
|
|
71
|
+
* @param originalPath - Path to the original JavaScript file
|
|
72
|
+
* @returns LocalCacheCheck object with validation details
|
|
73
|
+
*/
|
|
74
|
+
export declare function isLocalCacheValid(originalPath: string): Promise<LocalCacheCheck>;
|
|
75
|
+
/**
|
|
76
|
+
* Beautify JSON content with proper indentation
|
|
77
|
+
* @param content - JSON string to beautify
|
|
78
|
+
* @returns Object with beautified JSON string and error flag
|
|
79
|
+
*/
|
|
80
|
+
export declare function beautifyJson(content: string): {
|
|
81
|
+
code: string;
|
|
82
|
+
parseFailed: boolean;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Simple HTML/XML beautification with indentation
|
|
86
|
+
* This is a basic formatter that handles common cases
|
|
87
|
+
* @param content - HTML/XML string to beautify
|
|
88
|
+
* @returns Beautified HTML/XML string, or original content if formatting fails
|
|
89
|
+
*/
|
|
90
|
+
export declare function beautifyHtml(content: string): string;
|
|
91
|
+
/**
|
|
92
|
+
* Simple CSS beautification with indentation
|
|
93
|
+
* @param content - CSS string to beautify
|
|
94
|
+
* @returns Beautified CSS string, or original content if formatting fails
|
|
95
|
+
*/
|
|
96
|
+
export declare function beautifyCss(content: string): string;
|
|
97
|
+
/**
|
|
98
|
+
* Beautify code string directly based on language
|
|
99
|
+
* @param code - Source code to beautify
|
|
100
|
+
* @param language - Language type
|
|
101
|
+
* @returns Beautified code (or original if fallback mode)
|
|
102
|
+
*/
|
|
103
|
+
export declare function beautifyCode(code: string, language: SupportedLanguage): {
|
|
104
|
+
code: string;
|
|
105
|
+
usedFallback: boolean;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Beautify file based on detected or specified language
|
|
109
|
+
* - JS/TS: Use esbuild for formatting with source map
|
|
110
|
+
* - JSON: Use JSON.stringify with indentation
|
|
111
|
+
* - HTML/XML: Use simple indentation-based formatting
|
|
112
|
+
* - CSS: Use simple formatting
|
|
113
|
+
* - Unknown: Return original (fallback mode)
|
|
114
|
+
*
|
|
115
|
+
* @param originalPath - Original file path
|
|
116
|
+
* @param options - Optional beautify options (language, saveLocal, etc.)
|
|
117
|
+
* @returns Beautified code and Source Map (null for non-JS/TS)
|
|
118
|
+
*/
|
|
119
|
+
export declare function ensureBeautified(originalPath: string, options?: BeautifyOptions): Promise<BeautifyResult>;
|
|
120
|
+
//# sourceMappingURL=beautifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"beautifier.d.ts","sourceRoot":"","sources":["../src/beautifier.ts"],"names":[],"mappings":"AAKA,OAAO,EAAmC,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAIhG,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,sCAAsC;IACtC,QAAQ,CAAC,EA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