@nodesecure/js-x-ray 9.0.0 → 9.2.0

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.
Files changed (180) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +9 -209
  3. package/dist/AstAnalyser.d.ts +64 -0
  4. package/dist/AstAnalyser.d.ts.map +1 -0
  5. package/dist/AstAnalyser.js +165 -0
  6. package/dist/AstAnalyser.js.map +1 -0
  7. package/dist/Deobfuscator.d.ts +36 -0
  8. package/dist/Deobfuscator.d.ts.map +1 -0
  9. package/dist/Deobfuscator.js +154 -0
  10. package/dist/Deobfuscator.js.map +1 -0
  11. package/dist/EntryFilesAnalyser.d.ts +20 -0
  12. package/dist/EntryFilesAnalyser.d.ts.map +1 -0
  13. package/dist/EntryFilesAnalyser.js +121 -0
  14. package/dist/EntryFilesAnalyser.js.map +1 -0
  15. package/dist/JsSourceParser.d.ts +18 -0
  16. package/dist/JsSourceParser.d.ts.map +1 -0
  17. package/dist/JsSourceParser.js +38 -0
  18. package/dist/JsSourceParser.js.map +1 -0
  19. package/dist/NodeCounter.d.ts +24 -0
  20. package/dist/NodeCounter.d.ts.map +1 -0
  21. package/dist/NodeCounter.js +62 -0
  22. package/dist/NodeCounter.js.map +1 -0
  23. package/dist/ProbeRunner.d.ts +40 -0
  24. package/dist/ProbeRunner.d.ts.map +1 -0
  25. package/dist/ProbeRunner.js +106 -0
  26. package/dist/ProbeRunner.js.map +1 -0
  27. package/dist/SourceFile.d.ts +43 -0
  28. package/dist/SourceFile.d.ts.map +1 -0
  29. package/dist/SourceFile.js +137 -0
  30. package/dist/SourceFile.js.map +1 -0
  31. package/dist/index.d.ts +6 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +6 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/obfuscators/freejsobfuscator.d.ts +3 -0
  36. package/dist/obfuscators/freejsobfuscator.d.ts.map +1 -0
  37. package/dist/obfuscators/freejsobfuscator.js +10 -0
  38. package/dist/obfuscators/freejsobfuscator.js.map +1 -0
  39. package/dist/obfuscators/jjencode.d.ts +3 -0
  40. package/dist/obfuscators/jjencode.d.ts.map +1 -0
  41. package/dist/obfuscators/jjencode.js +24 -0
  42. package/dist/obfuscators/jjencode.js.map +1 -0
  43. package/dist/obfuscators/jsfuck.d.ts +3 -0
  44. package/dist/obfuscators/jsfuck.d.ts.map +1 -0
  45. package/dist/obfuscators/jsfuck.js +13 -0
  46. package/dist/obfuscators/jsfuck.js.map +1 -0
  47. package/dist/obfuscators/obfuscator-io.d.ts +3 -0
  48. package/dist/obfuscators/obfuscator-io.d.ts.map +1 -0
  49. package/dist/obfuscators/obfuscator-io.js +15 -0
  50. package/dist/obfuscators/obfuscator-io.js.map +1 -0
  51. package/dist/obfuscators/trojan-source.d.ts +2 -0
  52. package/dist/obfuscators/trojan-source.d.ts.map +1 -0
  53. package/dist/obfuscators/trojan-source.js +27 -0
  54. package/dist/obfuscators/trojan-source.js.map +1 -0
  55. package/dist/probes/isArrayExpression.d.ts +21 -0
  56. package/dist/probes/isArrayExpression.d.ts.map +1 -0
  57. package/{src → dist}/probes/isArrayExpression.js +10 -15
  58. package/dist/probes/isArrayExpression.js.map +1 -0
  59. package/dist/probes/isBinaryExpression.d.ts +21 -0
  60. package/dist/probes/isBinaryExpression.d.ts.map +1 -0
  61. package/dist/probes/isBinaryExpression.js +54 -0
  62. package/dist/probes/isBinaryExpression.js.map +1 -0
  63. package/dist/probes/isESMExport.d.ts +24 -0
  64. package/dist/probes/isESMExport.d.ts.map +1 -0
  65. package/dist/probes/isESMExport.js +30 -0
  66. package/dist/probes/isESMExport.js.map +1 -0
  67. package/dist/probes/isFetch.d.ts +14 -0
  68. package/dist/probes/isFetch.d.ts.map +1 -0
  69. package/dist/probes/isFetch.js +18 -0
  70. package/dist/probes/isFetch.js.map +1 -0
  71. package/dist/probes/isImportDeclaration.d.ts +26 -0
  72. package/dist/probes/isImportDeclaration.d.ts.map +1 -0
  73. package/dist/probes/isImportDeclaration.js +38 -0
  74. package/dist/probes/isImportDeclaration.js.map +1 -0
  75. package/dist/probes/isLiteral.d.ts +21 -0
  76. package/dist/probes/isLiteral.d.ts.map +1 -0
  77. package/dist/probes/isLiteral.js +66 -0
  78. package/dist/probes/isLiteral.js.map +1 -0
  79. package/dist/probes/isLiteralRegex.d.ts +20 -0
  80. package/dist/probes/isLiteralRegex.d.ts.map +1 -0
  81. package/dist/probes/isLiteralRegex.js +30 -0
  82. package/dist/probes/isLiteralRegex.js.map +1 -0
  83. package/dist/probes/isRegexObject.d.ts +22 -0
  84. package/dist/probes/isRegexObject.d.ts.map +1 -0
  85. package/dist/probes/isRegexObject.js +50 -0
  86. package/dist/probes/isRegexObject.js.map +1 -0
  87. package/dist/probes/isRequire/RequireCallExpressionWalker.d.ts +15 -0
  88. package/dist/probes/isRequire/RequireCallExpressionWalker.d.ts.map +1 -0
  89. package/dist/probes/isRequire/RequireCallExpressionWalker.js +95 -0
  90. package/dist/probes/isRequire/RequireCallExpressionWalker.js.map +1 -0
  91. package/dist/probes/isRequire/isRequire.d.ts +20 -0
  92. package/dist/probes/isRequire/isRequire.d.ts.map +1 -0
  93. package/dist/probes/isRequire/isRequire.js +138 -0
  94. package/dist/probes/isRequire/isRequire.js.map +1 -0
  95. package/dist/probes/isSerializeEnv.d.ts +24 -0
  96. package/dist/probes/isSerializeEnv.d.ts.map +1 -0
  97. package/dist/probes/isSerializeEnv.js +66 -0
  98. package/dist/probes/isSerializeEnv.js.map +1 -0
  99. package/dist/probes/isSyncIO.d.ts +16 -0
  100. package/dist/probes/isSyncIO.d.ts.map +1 -0
  101. package/dist/probes/isSyncIO.js +74 -0
  102. package/dist/probes/isSyncIO.js.map +1 -0
  103. package/dist/probes/isUnsafeCallee.d.ts +22 -0
  104. package/dist/probes/isUnsafeCallee.d.ts.map +1 -0
  105. package/dist/probes/isUnsafeCallee.js +60 -0
  106. package/dist/probes/isUnsafeCallee.js.map +1 -0
  107. package/dist/probes/isUnsafeCommand.d.ts +24 -0
  108. package/dist/probes/isUnsafeCommand.d.ts.map +1 -0
  109. package/dist/probes/isUnsafeCommand.js +100 -0
  110. package/dist/probes/isUnsafeCommand.js.map +1 -0
  111. package/dist/probes/isWeakCrypto.d.ts +16 -0
  112. package/dist/probes/isWeakCrypto.d.ts.map +1 -0
  113. package/dist/probes/isWeakCrypto.js +46 -0
  114. package/dist/probes/isWeakCrypto.js.map +1 -0
  115. package/dist/types/estree.d.ts +11 -0
  116. package/dist/types/estree.d.ts.map +1 -0
  117. package/dist/types/estree.js +15 -0
  118. package/dist/types/estree.js.map +1 -0
  119. package/dist/utils/extractNode.d.ts +5 -0
  120. package/dist/utils/extractNode.d.ts.map +1 -0
  121. package/dist/utils/extractNode.js +13 -0
  122. package/dist/utils/extractNode.js.map +1 -0
  123. package/dist/utils/index.d.ts +5 -0
  124. package/dist/utils/index.d.ts.map +1 -0
  125. package/dist/utils/index.js +5 -0
  126. package/dist/utils/index.js.map +1 -0
  127. package/dist/utils/isOneLineExpressionExport.d.ts +3 -0
  128. package/dist/utils/isOneLineExpressionExport.d.ts.map +1 -0
  129. package/dist/utils/isOneLineExpressionExport.js +49 -0
  130. package/dist/utils/isOneLineExpressionExport.js.map +1 -0
  131. package/dist/utils/notNullOrUndefined.d.ts +2 -0
  132. package/dist/utils/notNullOrUndefined.d.ts.map +1 -0
  133. package/dist/utils/notNullOrUndefined.js +4 -0
  134. package/dist/utils/notNullOrUndefined.js.map +1 -0
  135. package/dist/utils/toArrayLocation.d.ts +5 -0
  136. package/dist/utils/toArrayLocation.d.ts.map +1 -0
  137. package/dist/utils/toArrayLocation.js +14 -0
  138. package/dist/utils/toArrayLocation.js.map +1 -0
  139. package/dist/warnings.d.ts +88 -0
  140. package/dist/warnings.d.ts.map +1 -0
  141. package/dist/warnings.js +91 -0
  142. package/dist/warnings.js.map +1 -0
  143. package/package.json +59 -77
  144. package/index.d.ts +0 -46
  145. package/index.js +0 -4
  146. package/src/AstAnalyser.js +0 -222
  147. package/src/Deobfuscator.js +0 -195
  148. package/src/EntryFilesAnalyser.js +0 -167
  149. package/src/JsSourceParser.js +0 -57
  150. package/src/NodeCounter.js +0 -76
  151. package/src/ProbeRunner.js +0 -144
  152. package/src/SourceFile.js +0 -147
  153. package/src/obfuscators/freejsobfuscator.js +0 -9
  154. package/src/obfuscators/jjencode.js +0 -27
  155. package/src/obfuscators/jsfuck.js +0 -11
  156. package/src/obfuscators/obfuscator-io.js +0 -13
  157. package/src/obfuscators/trojan-source.js +0 -28
  158. package/src/probes/isBinaryExpression.js +0 -55
  159. package/src/probes/isESMExport.js +0 -31
  160. package/src/probes/isFetch.js +0 -19
  161. package/src/probes/isImportDeclaration.js +0 -33
  162. package/src/probes/isLiteral.js +0 -70
  163. package/src/probes/isLiteralRegex.js +0 -31
  164. package/src/probes/isRegexObject.js +0 -49
  165. package/src/probes/isRequire/RequireCallExpressionWalker.js +0 -93
  166. package/src/probes/isRequire/isRequire.js +0 -148
  167. package/src/probes/isUnsafeCallee.js +0 -35
  168. package/src/probes/isWeakCrypto.js +0 -37
  169. package/src/utils/exportAssignmentHasRequireLeave.js +0 -40
  170. package/src/utils/extractNode.js +0 -14
  171. package/src/utils/index.js +0 -8
  172. package/src/utils/isNode.js +0 -5
  173. package/src/utils/isOneLineExpressionExport.js +0 -24
  174. package/src/utils/isUnsafeCallee.js +0 -28
  175. package/src/utils/notNullOrUndefined.js +0 -3
  176. package/src/utils/rootLocation.js +0 -3
  177. package/src/utils/toArrayLocation.js +0 -11
  178. package/src/warnings.js +0 -77
  179. package/types/api.d.ts +0 -177
  180. package/types/warnings.d.ts +0 -36
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2021-2025 NodeSecure
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2021-2025 NodeSecure
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,209 +1,9 @@
1
- <p align="center">
2
- <img src="https://user-images.githubusercontent.com/4438263/213887379-c873eb89-8786-4b5c-8a59-dcca49e01cb8.jpg" alt="@nodesecure/js-x-ray">
3
- </p>
4
-
5
- <p align="center">
6
- <a href="https://github.com/NodeSecure/js-x-ray">
7
- <img src="https://img.shields.io/badge/dynamic/json.svg?style=for-the-badge&url=https://raw.githubusercontent.com/NodeSecure/js-x-ray/master/package.json&query=$.version&label=Version" alt="npm version">
8
- </a>
9
- <a href="https://github.com/NodeSecure/js-x-ray/blob/master/LICENSE">
10
- <img src="https://img.shields.io/github/license/NodeSecure/js-x-ray.svg?style=for-the-badge" alt="license">
11
- </a>
12
- <a href="https://api.securityscorecards.dev/projects/github.com/NodeSecure/js-x-ray">
13
- <img src="https://api.securityscorecards.dev/projects/github.com/NodeSecure/js-x-ray/badge?style=for-the-badge" alt="ossf scorecard">
14
- </a>
15
- <a href="https://github.com/NodeSecure/js-x-ray/actions?query=workflow%3A%22Node.js+CI%22">
16
- <img src="https://img.shields.io/github/actions/workflow/status/NodeSecure/js-x-ray/node.js.yml?style=for-the-badge" alt="github ci workflow">
17
- </a>
18
- <a href="https://codecov.io/github/NodeSecure/js-xray">
19
- <img src="https://img.shields.io/codecov/c/github/NodeSecure/js-x-ray?style=for-the-badge" alt="codecov">
20
- </a>
21
- </p>
22
-
23
- JavaScript AST analysis. This package has been created to export the [NodeSecure](https://github.com/NodeSecure/cli) AST Analysis to enable better code evolution and allow better access to developers and researchers.
24
-
25
- The goal is to quickly identify dangerous code and patterns for developers and Security researchers. Interpreting the results of this tool will still require you to have a set of security notions.
26
-
27
- ## Goals
28
- The objective of the project is to successfully detect all potentially suspicious JavaScript codes.. The target is obviously codes that are added or injected for malicious purposes..
29
-
30
- Most of the time these hackers will try to hide the behaviour of their codes as much as possible to avoid being spotted or easily understood... The work of the library is to understand and analyze these patterns that will allow us to detect malicious code..
31
-
32
- ## Features Highlight
33
- - Retrieve required dependencies and files for Node.js.
34
- - Detect unsafe RegEx.
35
- - Get warnings when the AST Analysis as a problem or when not able to follow a statement.
36
- - Highlight common attack patterns and API usages.
37
- - Capable to follow the usage of dangerous Node.js globals.
38
- - Detect obfuscated code and when possible the tool that has been used.
39
-
40
- ## Getting Started
41
-
42
- This package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).
43
-
44
- ```bash
45
- $ npm i @nodesecure/js-x-ray
46
- # or
47
- $ yarn add @nodesecure/js-x-ray
48
- ```
49
-
50
- ## Usage example
51
-
52
- Create a local `.js` file with the following content:
53
- ```js
54
- try {
55
- require("http");
56
- }
57
- catch (err) {
58
- // do nothing
59
- }
60
- const lib = "crypto";
61
- require(lib);
62
- require("util");
63
- require(Buffer.from("6673", "hex").toString());
64
- ```
65
-
66
- ---
67
-
68
- Then use `js-x-ray` to run an analysis of the JavaScript code:
69
- ```js
70
- import { AstAnalyser } from "@nodesecure/js-x-ray";
71
- import { readFileSync } from "node:fs";
72
-
73
- const scanner = new AstAnalyser();
74
-
75
- const { warnings, dependencies } = await scanner.analyseFile(
76
- "./file.js"
77
- );
78
-
79
- console.log(dependencies);
80
- console.dir(warnings, { depth: null });
81
- ```
82
-
83
- The analysis will return: `http` (in try), `crypto`, `util` and `fs`.
84
-
85
- > [!TIP]
86
- > There is also a lot of suspicious code example in the `./examples` cases directory. Feel free to try the tool on these files.
87
-
88
- ## API
89
-
90
- - [AstAnalyser](./docs/api/AstAnalyser.md)
91
- - [EntryFilesAnalyser](./docs/api/EntryFilesAnalyser.md)
92
-
93
- ## Warnings
94
-
95
- This section describes how use `warnings` export.
96
-
97
- ```ts
98
- type WarningName = "parsing-error"
99
- | "encoded-literal"
100
- | "unsafe-regex"
101
- | "unsafe-stmt"
102
- | "short-identifiers"
103
- | "suspicious-literal"
104
- | "suspicious-file"
105
- | "obfuscated-code"
106
- | "weak-crypto"
107
- | "unsafe-import"
108
- | "shady-link";
109
-
110
- declare const warnings: Record<WarningName, {
111
- i18n: string;
112
- severity: "Information" | "Warning" | "Critical";
113
- experimental?: boolean;
114
- }>;
115
- ```
116
-
117
- We make a call to `i18n` through the package `NodeSecure/i18n` to get the translation.
118
-
119
- ```js
120
- import * as jsxray from "@nodesecure/js-x-ray";
121
- import * as i18n from "@nodesecure/i18n";
122
-
123
- console.log(i18n.getTokenSync(jsxray.warnings["parsing-error"].i18n));
124
- ```
125
-
126
- ### Legends
127
-
128
- This section describe all the possible warnings returned by JSXRay. Click on the warning **name** for additional information and examples.
129
-
130
- | name | experimental | description |
131
- | --- | :-: | --- |
132
- | [parsing-error](./docs/parsing-error.md) | ❌ | The AST parser throw an error |
133
- | [unsafe-import](./docs/unsafe-import.md) | ❌ | Unable to follow an import (require, require.resolve) statement/expr. |
134
- | [unsafe-regex](./docs/unsafe-regex.md) | ❌ | A RegEx as been detected as unsafe and may be used for a ReDoS Attack. |
135
- | [unsafe-stmt](./docs//unsafe-stmt.md) | ❌ | Usage of dangerous statement like `eval()` or `Function("")`. |
136
- | [encoded-literal](./docs/encoded-literal.md) | ❌ | An encoded literal has been detected (it can be an hexa value, unicode sequence or a base64 string) |
137
- | [short-identifiers](./docs/short-identifiers.md) | ❌ | This mean that all identifiers has an average length below 1.5. |
138
- | [suspicious-literal](./docs/suspicious-literal.md) | ❌ | A suspicious literal has been found in the source code. |
139
- | [suspicious-file](./docs/suspicious-file.md) | ❌ | A suspicious file with more than ten encoded-literal in it |
140
- | [obfuscated-code](./docs/obfuscated-code.md) | ✔️ | There's a very high probability that the code is obfuscated. |
141
- | [weak-crypto](./docs/weak-crypto.md) | ❌ | The code probably contains a weak crypto algorithm (md5, sha1...) |
142
- | [shady-link](./docs/shady-link.md) | ❌ | The code contains shady/unsafe link |
143
-
144
- ## Workspaces
145
-
146
- Click on one of the links to access the documentation of the workspace:
147
-
148
- | name | package and link |
149
- | --- | --- |
150
- | estree-ast-utils | [@nodesecure/estree-ast-utils](./workspaces/estree-ast-utils) |
151
- | sec-literal | [@nodesecure/sec-literal ](./workspaces/sec-literal) |
152
- | ts-source-parser | [@nodesecure/ts-source-parser ](./workspaces/ts-source-parser) |
153
-
154
- These packages are available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).
155
- ```bash
156
- $ npm i @nodesecure/estree-ast-util
157
- # or
158
- $ yarn add @nodesecure/estree-ast-util
159
- ```
160
-
161
- ## Contributors ✨
162
-
163
- <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
164
- [![All Contributors](https://img.shields.io/badge/all_contributors-20-orange.svg?style=flat-square)](#contributors-)
165
- <!-- ALL-CONTRIBUTORS-BADGE:END -->
166
-
167
- Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
168
-
169
- <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
170
- <!-- prettier-ignore-start -->
171
- <!-- markdownlint-disable -->
172
- <table>
173
- <tbody>
174
- <tr>
175
- <td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/thomas-gentilhomme/"><img src="https://avatars.githubusercontent.com/u/4438263?v=4?s=100" width="100px;" alt="Gentilhomme"/><br /><sub><b>Gentilhomme</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=fraxken" title="Code">💻</a> <a href="https://github.com/NodeSecure/js-x-ray/commits?author=fraxken" title="Documentation">📖</a> <a href="https://github.com/NodeSecure/js-x-ray/pulls?q=is%3Apr+reviewed-by%3Afraxken" title="Reviewed Pull Requests">👀</a> <a href="#security-fraxken" title="Security">🛡️</a> <a href="https://github.com/NodeSecure/js-x-ray/issues?q=author%3Afraxken" title="Bug reports">🐛</a></td>
176
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/Rossb0b"><img src="https://avatars.githubusercontent.com/u/39910164?v=4?s=100" width="100px;" alt="Nicolas Hallaert"/><br /><sub><b>Nicolas Hallaert</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=Rossb0b" title="Documentation">📖</a></td>
177
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/antoine-coulon"><img src="https://avatars.githubusercontent.com/u/43391199?v=4?s=100" width="100px;" alt="Antoine"/><br /><sub><b>Antoine</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=antoine-coulon" title="Code">💻</a></td>
178
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/Mathieuka"><img src="https://avatars.githubusercontent.com/u/34446722?v=4?s=100" width="100px;" alt="Mathieu"/><br /><sub><b>Mathieu</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=Mathieuka" title="Code">💻</a></td>
179
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/Kawacrepe"><img src="https://avatars.githubusercontent.com/u/40260517?v=4?s=100" width="100px;" alt="Vincent Dhennin"/><br /><sub><b>Vincent Dhennin</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=Kawacrepe" title="Code">💻</a> <a href="https://github.com/NodeSecure/js-x-ray/commits?author=Kawacrepe" title="Tests">⚠️</a></td>
180
- <td align="center" valign="top" width="14.28%"><a href="http://tonygo.dev"><img src="https://avatars.githubusercontent.com/u/22824417?v=4?s=100" width="100px;" alt="Tony Gorez"/><br /><sub><b>Tony Gorez</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=tony-go" title="Code">💻</a> <a href="https://github.com/NodeSecure/js-x-ray/commits?author=tony-go" title="Documentation">📖</a> <a href="https://github.com/NodeSecure/js-x-ray/commits?author=tony-go" title="Tests">⚠️</a></td>
181
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/PierreDemailly"><img src="https://avatars.githubusercontent.com/u/39910767?v=4?s=100" width="100px;" alt="PierreD"/><br /><sub><b>PierreD</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=PierreDemailly" title="Tests">⚠️</a> <a href="https://github.com/NodeSecure/js-x-ray/commits?author=PierreDemailly" title="Code">💻</a></td>
182
- </tr>
183
- <tr>
184
- <td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/franck-hallaert/"><img src="https://avatars.githubusercontent.com/u/110826655?v=4?s=100" width="100px;" alt="Franck Hallaert"/><br /><sub><b>Franck Hallaert</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=Aekk0" title="Code">💻</a></td>
185
- <td align="center" valign="top" width="14.28%"><a href="https://maji.kiwi"><img src="https://avatars.githubusercontent.com/u/33150916?v=4?s=100" width="100px;" alt="Maji"/><br /><sub><b>Maji</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=M4gie" title="Code">💻</a></td>
186
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/targos"><img src="https://avatars.githubusercontent.com/u/2352663?v=4?s=100" width="100px;" alt="Michaël Zasso"/><br /><sub><b>Michaël Zasso</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=targos" title="Code">💻</a> <a href="https://github.com/NodeSecure/js-x-ray/issues?q=author%3Atargos" title="Bug reports">🐛</a></td>
187
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/fabnguess"><img src="https://avatars.githubusercontent.com/u/72697416?v=4?s=100" width="100px;" alt="Kouadio Fabrice Nguessan"/><br /><sub><b>Kouadio Fabrice Nguessan</b></sub></a><br /><a href="#maintenance-fabnguess" title="Maintenance">🚧</a> <a href="https://github.com/NodeSecure/js-x-ray/commits?author=fabnguess" title="Code">💻</a></td>
188
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/jean-michelet"><img src="https://avatars.githubusercontent.com/u/110341611?v=4?s=100" width="100px;" alt="Jean"/><br /><sub><b>Jean</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=jean-michelet" title="Tests">⚠️</a> <a href="https://github.com/NodeSecure/js-x-ray/commits?author=jean-michelet" title="Code">💻</a> <a href="https://github.com/NodeSecure/js-x-ray/commits?author=jean-michelet" title="Documentation">📖</a></td>
189
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/tchapacan"><img src="https://avatars.githubusercontent.com/u/28821702?v=4?s=100" width="100px;" alt="tchapacan"/><br /><sub><b>tchapacan</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=tchapacan" title="Code">💻</a> <a href="https://github.com/NodeSecure/js-x-ray/commits?author=tchapacan" title="Tests">⚠️</a></td>
190
- <td align="center" valign="top" width="14.28%"><a href="http://miikkak.dev"><img src="https://avatars.githubusercontent.com/u/65869801?v=4?s=100" width="100px;" alt="mkarkkainen"/><br /><sub><b>mkarkkainen</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=mkarkkainen" title="Code">💻</a></td>
191
- </tr>
192
- <tr>
193
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/FredGuiou"><img src="https://avatars.githubusercontent.com/u/99122562?v=4?s=100" width="100px;" alt="FredGuiou"/><br /><sub><b>FredGuiou</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=FredGuiou" title="Documentation">📖</a> <a href="https://github.com/NodeSecure/js-x-ray/commits?author=FredGuiou" title="Code">💻</a></td>
194
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/madina0801"><img src="https://avatars.githubusercontent.com/u/101329759?v=4?s=100" width="100px;" alt="Madina"/><br /><sub><b>Madina</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=madina0801" title="Code">💻</a></td>
195
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/sairuss7"><img src="https://avatars.githubusercontent.com/u/87803528?v=4?s=100" width="100px;" alt="SairussDev"/><br /><sub><b>SairussDev</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=sairuss7" title="Code">💻</a></td>
196
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/fless-lab"><img src="https://avatars.githubusercontent.com/u/71844440?v=4?s=100" width="100px;" alt="Abdou-Raouf ATARMLA"/><br /><sub><b>Abdou-Raouf ATARMLA</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=fless-lab" title="Code">💻</a></td>
197
- <td align="center" valign="top" width="14.28%"><a href="https://clementgombauld.netlify.app/"><img src="https://avatars.githubusercontent.com/u/91478082?v=4?s=100" width="100px;" alt="Clement Gombauld"/><br /><sub><b>Clement Gombauld</b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=clemgbld" title="Code">💻</a> <a href="https://github.com/NodeSecure/js-x-ray/commits?author=clemgbld" title="Tests">⚠️</a></td>
198
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/intincrab"><img src="https://avatars.githubusercontent.com/u/93028153?v=4?s=100" width="100px;" alt="Ajāy "/><br /><sub><b>Ajāy </b></sub></a><br /><a href="https://github.com/NodeSecure/js-x-ray/commits?author=intincrab" title="Code">💻</a></td>
199
- </tr>
200
- </tbody>
201
- </table>
202
-
203
- <!-- markdownlint-restore -->
204
- <!-- prettier-ignore-end -->
205
-
206
- <!-- ALL-CONTRIBUTORS-LIST:END -->
207
-
208
- ## License
209
- MIT
1
+ <p align="center">
2
+ <h1 align="center">
3
+ @nodesecure/js-x-ray
4
+ </h1>
5
+ </p>
6
+
7
+ <p align="center">
8
+ <a href="../../README.md">The documentation of this project is in the root README</a>
9
+ </p>
@@ -0,0 +1,64 @@
1
+ import type { ESTree } from "meriyah";
2
+ import { type Warning } from "./warnings.js";
3
+ import { SourceFile, type ProbesOptions, type SourceFlags } from "./SourceFile.js";
4
+ import { type SourceParser } from "./JsSourceParser.js";
5
+ export interface Dependency {
6
+ unsafe: boolean;
7
+ inTry: boolean;
8
+ location?: null | ESTree.SourceLocation;
9
+ }
10
+ export interface RuntimeOptions {
11
+ /**
12
+ * @default true
13
+ */
14
+ module?: boolean;
15
+ /**
16
+ * @default false
17
+ */
18
+ removeHTMLComments?: boolean;
19
+ /**
20
+ * @default false
21
+ */
22
+ isMinified?: boolean;
23
+ initialize?: (sourceFile: SourceFile) => void;
24
+ finalize?: (sourceFile: SourceFile) => void;
25
+ }
26
+ export interface RuntimeFileOptions extends Omit<RuntimeOptions, "isMinified"> {
27
+ packageName?: string;
28
+ }
29
+ export interface Report {
30
+ dependencies: Map<string, Dependency>;
31
+ warnings: Warning[];
32
+ flags: Set<SourceFlags>;
33
+ idsLengthAvg: number;
34
+ stringScore: number;
35
+ }
36
+ export type ReportOnFile = {
37
+ ok: true;
38
+ warnings: Warning[];
39
+ dependencies: Map<string, Dependency>;
40
+ flags: Set<SourceFlags>;
41
+ } | {
42
+ ok: false;
43
+ warnings: Warning[];
44
+ };
45
+ export interface AstAnalyserOptions extends ProbesOptions {
46
+ /**
47
+ * @default JsSourceParser
48
+ */
49
+ customParser?: SourceParser;
50
+ }
51
+ export interface PrepareSourceOptions {
52
+ removeHTMLComments?: boolean;
53
+ }
54
+ export declare class AstAnalyser {
55
+ #private;
56
+ parser: SourceParser;
57
+ probesOptions: ProbesOptions;
58
+ constructor(options?: AstAnalyserOptions);
59
+ analyse(str: string, options?: RuntimeOptions): Report;
60
+ analyseFile(pathToFile: string | URL, options?: RuntimeFileOptions): Promise<ReportOnFile>;
61
+ analyseFileSync(pathToFile: string | URL, options?: RuntimeFileOptions): ReportOnFile;
62
+ prepareSource(source: string, options?: PrepareSourceOptions): string;
63
+ }
64
+ //# sourceMappingURL=AstAnalyser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AstAnalyser.d.ts","sourceRoot":"","sources":["../src/AstAnalyser.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAItC,OAAO,EAAmB,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EACL,UAAU,EACV,KAAK,aAAa,EAClB,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExE,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,OAAO,CAAC;IA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IACtB,MAAM,EAAE,YAAY,CAAC;IACrB,aAAa,EAAE,aAAa,CAAC;gBAEjB,OAAO,GAAE,kBAAuB;IAS5C,OAAO,CACL,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,cAAmB,GAC3B,MAAM;IA4DH,WAAW,CACf,UAAU,EAAE,MAAM,GAAG,GAAG,EACxB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,YAAY,CAAC;IAkDxB,eAAe,CACb,UAAU,EAAE,MAAM,GAAG,GAAG,EACxB,OAAO,GAAE,kBAAuB,GAC/B,YAAY;IAkDf,aAAa,CACX,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,oBAAyB,GACjC,MAAM;CAqBV"}
@@ -0,0 +1,165 @@
1
+ // Import Node.js Dependencies
2
+ import fs from "node:fs/promises";
3
+ import fsSync from "node:fs";
4
+ import path from "node:path";
5
+ // Import Third-party Dependencies
6
+ import { walk } from "estree-walker";
7
+ import isMinified from "is-minified-code";
8
+ // Import Internal Dependencies
9
+ import { generateWarning } from "./warnings.js";
10
+ import { SourceFile } from "./SourceFile.js";
11
+ import { isOneLineExpressionExport } from "./utils/index.js";
12
+ import { JsSourceParser } from "./JsSourceParser.js";
13
+ export class AstAnalyser {
14
+ parser;
15
+ probesOptions;
16
+ constructor(options = {}) {
17
+ this.parser = options.customParser ?? new JsSourceParser();
18
+ this.probesOptions = {
19
+ customProbes: options.customProbes ?? [],
20
+ skipDefaultProbes: options.skipDefaultProbes ?? false,
21
+ optionalWarnings: options.optionalWarnings ?? false
22
+ };
23
+ }
24
+ analyse(str, options = {}) {
25
+ const { isMinified = false, module = true, removeHTMLComments = false, initialize, finalize } = options;
26
+ const body = this.parser.parse(this.prepareSource(str, { removeHTMLComments }), {
27
+ isEcmaScriptModule: Boolean(module)
28
+ });
29
+ const source = new SourceFile(str, this.probesOptions);
30
+ // TODO: this check should be factorized in a way that we reuse it
31
+ // on analyze and anlyseFile
32
+ if (initialize) {
33
+ if (typeof initialize !== "function") {
34
+ throw new TypeError("options.initialize must be a function");
35
+ }
36
+ initialize(source);
37
+ }
38
+ // we walk each AST Nodes, this is a purely synchronous I/O
39
+ // @ts-expect-error
40
+ walk(body, {
41
+ enter(node) {
42
+ // Skip the root of the AST.
43
+ if (Array.isArray(node)) {
44
+ return;
45
+ }
46
+ const action = source.walk(node);
47
+ if (action === "skip") {
48
+ this.skip();
49
+ }
50
+ }
51
+ });
52
+ // TODO: this check should be factorized in a way that we reuse it
53
+ // on analyze and anlyseFile
54
+ if (finalize) {
55
+ if (typeof finalize !== "function") {
56
+ throw new TypeError("options.finalize must be a function");
57
+ }
58
+ finalize(source);
59
+ }
60
+ // Add oneline-require flag if this is a one-line require expression
61
+ if (isOneLineExpressionExport(body)) {
62
+ source.flags.add("oneline-require");
63
+ }
64
+ return {
65
+ ...source.getResult(isMinified),
66
+ dependencies: source.dependencies,
67
+ flags: source.flags
68
+ };
69
+ }
70
+ async analyseFile(pathToFile, options = {}) {
71
+ try {
72
+ const { packageName = null, module = true, removeHTMLComments = false, initialize, finalize } = options;
73
+ const str = await fs.readFile(pathToFile, "utf-8");
74
+ const filePathString = pathToFile instanceof URL ? pathToFile.href : pathToFile;
75
+ const isMin = filePathString.includes(".min") || isMinified(str);
76
+ const data = this.analyse(str, {
77
+ isMinified: isMin,
78
+ module: path.extname(filePathString) === ".mjs" ? true : module,
79
+ removeHTMLComments,
80
+ initialize,
81
+ finalize
82
+ });
83
+ if (packageName !== null) {
84
+ data.dependencies.delete(packageName);
85
+ }
86
+ // Add is-minified flag if the file is minified and not a one-line require
87
+ if (!data.flags.has("oneline-require") && isMin) {
88
+ data.flags.add("is-minified");
89
+ }
90
+ return {
91
+ ok: true,
92
+ dependencies: data.dependencies,
93
+ warnings: data.warnings,
94
+ flags: data.flags
95
+ };
96
+ }
97
+ catch (error) {
98
+ return {
99
+ ok: false,
100
+ warnings: [
101
+ generateWarning("parsing-error", {
102
+ value: error.message
103
+ })
104
+ ]
105
+ };
106
+ }
107
+ }
108
+ analyseFileSync(pathToFile, options = {}) {
109
+ try {
110
+ const { packageName = null, module = true, removeHTMLComments = false, initialize, finalize } = options;
111
+ const str = fsSync.readFileSync(pathToFile, "utf-8");
112
+ const filePathString = pathToFile instanceof URL ? pathToFile.href : pathToFile;
113
+ const isMin = filePathString.includes(".min") || isMinified(str);
114
+ const data = this.analyse(str, {
115
+ isMinified: isMin,
116
+ module: path.extname(filePathString) === ".mjs" ? true : module,
117
+ removeHTMLComments,
118
+ initialize,
119
+ finalize
120
+ });
121
+ if (packageName !== null) {
122
+ data.dependencies.delete(packageName);
123
+ }
124
+ // Add is-minified flag if the file is minified and not a one-line require
125
+ if (!data.flags.has("oneline-require") && isMin) {
126
+ data.flags.add("is-minified");
127
+ }
128
+ return {
129
+ ok: true,
130
+ dependencies: data.dependencies,
131
+ warnings: data.warnings,
132
+ flags: data.flags
133
+ };
134
+ }
135
+ catch (error) {
136
+ return {
137
+ ok: false,
138
+ warnings: [
139
+ generateWarning("parsing-error", {
140
+ value: error.message
141
+ })
142
+ ]
143
+ };
144
+ }
145
+ }
146
+ prepareSource(source, options = {}) {
147
+ if (typeof source !== "string") {
148
+ throw new TypeError("source must be a string");
149
+ }
150
+ const { removeHTMLComments = false } = options;
151
+ /**
152
+ * if the file start with a shebang then we remove it because meriyah.parseScript fail to parse it.
153
+ * @example
154
+ * #!/usr/bin/env node
155
+ */
156
+ const rawNoShebang = source.startsWith("#") ?
157
+ source.slice(source.indexOf("\n") + 1) : source;
158
+ return removeHTMLComments ?
159
+ this.#removeHTMLComment(rawNoShebang) : rawNoShebang;
160
+ }
161
+ #removeHTMLComment(str) {
162
+ return str.replaceAll(/<!--[\s\S]*?(?:-->)/g, "");
163
+ }
164
+ }
165
+ //# sourceMappingURL=AstAnalyser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AstAnalyser.js","sourceRoot":"","sources":["../src/AstAnalyser.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,OAAO,EAAE,MAAM,kBA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AAQ;gBACvB,KAAK,EAAE,IAAI,CAAC,KAAK;aAClB,CAAC;QACJ,CAAC;QACD,OAAO,KAAU,EAAE,CAAC;YAClB,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,QAAQ,EAAE;oBACR,eAAe,CAAC,eAAe,EAAE;wBAC/B,KAAK,EAAE,KAAK,CAAC,OAAO;qBACrB,CAAC;iBACH;aACF,CAAC;QACJ,CAAC;IACH,CAAC;IAED,aAAa,CACX,MAAc,EACd,UAAgC,EAAE;QAElC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,MAAM,IAAI,SAAS,CAAC,yBAAyB,CAAC,CAAC;QACjD,CAAC;QACD,MAAM,EAAE,kBAAkB,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;QAE/C;;;;WAIG;QACH,MAAM,YAAY,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;YAC3C,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAElD,OAAO,kBAAkB,CAAC,CAAC;YACzB,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC;IACzD,CAAC;IAED,kBAAkB,CAAC,GAAW;QAC5B,OAAO,GAAG,CAAC,UAAU,CAAC,sBAAsB,EAAE,EAAE,CAAC,CAAC;IACpD,CAAC;CACF"}
@@ -0,0 +1,36 @@
1
+ import type { ESTree } from "meriyah";
2
+ export type ObfuscatedEngine = "jsfuck" | "jjencode" | "morse" | "freejsobfuscator" | "obfuscator.io" | "unknown";
3
+ export interface ObfuscatedIdentifier {
4
+ name: string;
5
+ type: string;
6
+ }
7
+ export interface ObfuscatedCounters {
8
+ Identifiers: number;
9
+ VariableDeclaration?: {
10
+ const?: number;
11
+ let?: number;
12
+ var?: number;
13
+ };
14
+ VariableDeclarator?: number;
15
+ AssignmentExpression?: number;
16
+ FunctionDeclaration?: number;
17
+ MemberExpression?: Record<string, number>;
18
+ Property?: number;
19
+ UnaryExpression?: number;
20
+ DoubleUnaryExpression?: number;
21
+ }
22
+ export declare class Deobfuscator {
23
+ #private;
24
+ deepBinaryExpression: number;
25
+ encodedArrayValue: number;
26
+ hasDictionaryString: boolean;
27
+ hasPrefixedIdentifiers: boolean;
28
+ morseLiterals: Set<string>;
29
+ literalScores: number[];
30
+ identifiers: ObfuscatedIdentifier[];
31
+ analyzeString(str: string): void;
32
+ walk(node: ESTree.Node): void;
33
+ aggregateCounters(): ObfuscatedCounters;
34
+ assertObfuscation(): ObfuscatedEngine | null;
35
+ }
36
+ //# sourceMappingURL=Deobfuscator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Deobfuscator.d.ts","sourceRoot":"","sources":["../src/Deobfuscator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAoBtC,MAAM,MAAM,gBAAgB,GACxB,QAAQ,GACR,UAAU,GACV,OAAO,GACP,kBAAkB,GAClB,eAAe,GACf,SAAS,CAAC;AAEd,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,CAAC,EAAE;QACpB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;IACF,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,e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