@futpib/parser 1.0.2 → 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.
Files changed (284) hide show
  1. package/.github/copilot-instructions.md +149 -0
  2. package/.github/workflows/copilot-setup-steps.yml +18 -0
  3. package/.github/workflows/main.yml +29 -8
  4. package/.yarn/releases/yarn-4.9.4.cjs +942 -0
  5. package/.yarnrc.yml +1 -1
  6. package/build/allSettledStream.js +1 -1
  7. package/build/allSettledStream.test.js +2 -2
  8. package/build/androidPackageParser.d.ts +1 -1
  9. package/build/androidPackageParser.js +5 -3
  10. package/build/androidPackageParser.test.js +7 -7
  11. package/build/androidPackageUnparser.d.ts +2 -2
  12. package/build/androidPackageUnparser.js +18 -14
  13. package/build/androidPackageUnparser.test.js +7 -7
  14. package/build/arbitrarilySlicedAsyncInterator.js +2 -1
  15. package/build/arbitraryDalvikBytecode.d.ts +4 -0
  16. package/build/arbitraryDalvikBytecode.js +640 -0
  17. package/build/arbitraryDalvikExecutable.d.ts +3 -0
  18. package/build/arbitraryDalvikExecutable.js +282 -0
  19. package/build/arbitraryDosDateTime.js +1 -0
  20. package/build/arbitraryZipStream.js +1 -1
  21. package/build/arrayParser.js +2 -2
  22. package/build/arrayUnparser.d.ts +1 -1
  23. package/build/backsmali.d.ts +3 -1
  24. package/build/backsmali.js +31 -3
  25. package/build/customInvariant.d.ts +2 -1
  26. package/build/customInvariant.js +4 -6
  27. package/build/dalvikBytecodeParser/formatParsers.d.ts +76 -2
  28. package/build/dalvikBytecodeParser/formatParsers.js +146 -11
  29. package/build/dalvikBytecodeParser/formatSizes.d.ts +34 -0
  30. package/build/dalvikBytecodeParser/formatSizes.js +34 -0
  31. package/build/dalvikBytecodeParser/operationFormats.d.ts +225 -0
  32. package/build/dalvikBytecodeParser/operationFormats.js +225 -0
  33. package/build/dalvikBytecodeParser.d.ts +1105 -5
  34. package/build/dalvikBytecodeParser.js +658 -205
  35. package/build/dalvikBytecodeUnparser/formatUnparsers.d.ts +152 -0
  36. package/build/dalvikBytecodeUnparser/formatUnparsers.js +225 -0
  37. package/build/dalvikBytecodeUnparser.d.ts +3 -0
  38. package/build/dalvikBytecodeUnparser.js +642 -0
  39. package/build/dalvikBytecodeUnparser.test.d.ts +1 -0
  40. package/build/dalvikBytecodeUnparser.test.js +25 -0
  41. package/build/dalvikExecutable.d.ts +65 -8
  42. package/build/dalvikExecutable.js +36 -0
  43. package/build/dalvikExecutableParser/stringSyntaxParser.d.ts +1 -1
  44. package/build/dalvikExecutableParser/stringSyntaxParser.js +17 -17
  45. package/build/dalvikExecutableParser/typeParsers.d.ts +2 -1
  46. package/build/dalvikExecutableParser/typeParsers.js +16 -11
  47. package/build/dalvikExecutableParser/typedNumbers.d.ts +85 -69
  48. package/build/dalvikExecutableParser/typedNumbers.js +0 -1
  49. package/build/dalvikExecutableParser.d.ts +2 -2
  50. package/build/dalvikExecutableParser.js +655 -337
  51. package/build/dalvikExecutableParser.test.js +24 -22
  52. package/build/dalvikExecutableParserAgainstSmaliParser.test.js +223 -246
  53. package/build/dalvikExecutableUnparser/annotationUnparsers.d.ts +14 -0
  54. package/build/dalvikExecutableUnparser/annotationUnparsers.js +97 -0
  55. package/build/dalvikExecutableUnparser/poolBuilders.d.ts +49 -0
  56. package/build/dalvikExecutableUnparser/poolBuilders.js +140 -0
  57. package/build/dalvikExecutableUnparser/poolScanners.d.ts +4 -0
  58. package/build/dalvikExecutableUnparser/poolScanners.js +220 -0
  59. package/build/dalvikExecutableUnparser/sectionUnparsers.d.ts +25 -0
  60. package/build/dalvikExecutableUnparser/sectionUnparsers.js +581 -0
  61. package/build/dalvikExecutableUnparser/utils.d.ts +10 -0
  62. package/build/dalvikExecutableUnparser/utils.js +108 -0
  63. package/build/dalvikExecutableUnparser.d.ts +4 -0
  64. package/build/dalvikExecutableUnparser.js +406 -0
  65. package/build/dalvikExecutableUnparser.test.d.ts +1 -0
  66. package/build/dalvikExecutableUnparser.test.js +31 -0
  67. package/build/debugLogInputParser.js +1 -1
  68. package/build/disjunctionParser.d.ts +2 -2
  69. package/build/disjunctionParser.js +2 -2
  70. package/build/elementTerminatedArrayParser.d.ts +2 -2
  71. package/build/elementTerminatedArrayParser.js +1 -1
  72. package/build/elementTerminatedArrayParser.test.js +5 -5
  73. package/build/elementTerminatedSequenceArrayParser.d.ts +2 -2
  74. package/build/elementTerminatedSequenceArrayParser.js +1 -1
  75. package/build/elementTerminatedSequenceArrayParser.test.js +2 -2
  76. package/build/elementTerminatedSequenceParser.d.ts +2 -2
  77. package/build/elementTerminatedSequenceParser.js +1 -1
  78. package/build/elementTerminatedSequenceParser.test.js +2 -2
  79. package/build/endOfInputParser.d.ts +1 -1
  80. package/build/exactElementSwitchParser.d.ts +3 -0
  81. package/build/exactElementSwitchParser.js +22 -0
  82. package/build/fetchCid.js +2 -6
  83. package/build/fetchCid.test.d.ts +1 -0
  84. package/build/fetchCid.test.js +16 -0
  85. package/build/fixedLengthSequenceParser.test.js +2 -2
  86. package/build/hasExecutable.js +2 -2
  87. package/build/highResolutionTimer.js +1 -1
  88. package/build/inputReader.d.ts +1 -1
  89. package/build/inputReader.test.js +33 -45
  90. package/build/javaKeyStoreParser.test.js +6 -6
  91. package/build/jsonParser.js +8 -8
  92. package/build/lazyMessageError.d.ts +48 -0
  93. package/build/lazyMessageError.js +53 -0
  94. package/build/lazyMessageError.test.d.ts +1 -0
  95. package/build/lazyMessageError.test.js +15 -0
  96. package/build/leb128Parser.d.ts +1 -1
  97. package/build/leb128Parser.js +10 -10
  98. package/build/leb128Parser.test.js +7 -7
  99. package/build/negativeLookaheadParser.js +2 -2
  100. package/build/negativeLookaheadParser.test.js +4 -4
  101. package/build/noStackCaptureOverheadError.d.ts +4 -0
  102. package/build/noStackCaptureOverheadError.js +9 -0
  103. package/build/noStackCaptureOverheadError.test.d.ts +1 -0
  104. package/build/noStackCaptureOverheadError.test.js +15 -0
  105. package/build/nonEmptyArrayParser.js +2 -2
  106. package/build/nonEmptyArrayParser.test.js +2 -1
  107. package/build/optionalParser.js +2 -2
  108. package/build/parser.d.ts +2 -1
  109. package/build/parser.js +23 -8
  110. package/build/parser.test.js +78 -29
  111. package/build/parserConsumedSequenceParser.d.ts +1 -1
  112. package/build/parserConsumedSequenceParser.js +2 -2
  113. package/build/parserContext.d.ts +8 -6
  114. package/build/parserContext.js +60 -33
  115. package/build/parserContext.test.js +7 -3
  116. package/build/parserError.d.ts +603 -44
  117. package/build/parserError.js +98 -53
  118. package/build/parserImplementationInvariant.d.ts +1 -1
  119. package/build/parserImplementationInvariant.js +2 -2
  120. package/build/parserInputCompanion.js +2 -2
  121. package/build/promiseCompose.js +1 -2
  122. package/build/separatedArrayParser.js +2 -2
  123. package/build/separatedNonEmptyArrayParser.d.ts +2 -0
  124. package/build/separatedNonEmptyArrayParser.js +40 -0
  125. package/build/separatedNonEmptyArrayParser.test.d.ts +1 -0
  126. package/build/separatedNonEmptyArrayParser.test.js +66 -0
  127. package/build/sequenceBuffer.js +1 -1
  128. package/build/sequenceTerminatedSequenceParser.d.ts +2 -2
  129. package/build/sequenceTerminatedSequenceParser.js +3 -3
  130. package/build/sequenceTerminatedSequenceParser.test.js +1 -1
  131. package/build/sequenceUnparser.d.ts +1 -1
  132. package/build/skipToParser.d.ts +1 -1
  133. package/build/skipToParser.js +2 -2
  134. package/build/sliceBoundedParser.test.js +4 -9
  135. package/build/smali.d.ts +1 -1
  136. package/build/smali.js +6 -2
  137. package/build/smaliParser.d.ts +62 -6
  138. package/build/smaliParser.js +1721 -296
  139. package/build/smaliParser.test.js +338 -43
  140. package/build/stringFromAsyncIterable.d.ts +1 -0
  141. package/build/stringFromAsyncIterable.js +7 -0
  142. package/build/terminatedArrayParser.js +4 -4
  143. package/build/terminatedArrayParser.test.js +7 -7
  144. package/build/toAsyncIterator.js +4 -4
  145. package/build/unionParser.d.ts +1 -1
  146. package/build/unionParser.js +2 -2
  147. package/build/unionParser.test.js +3 -3
  148. package/build/unparser.d.ts +3 -3
  149. package/build/unparser.js +6 -4
  150. package/build/unparser.test.js +7 -19
  151. package/build/unparserContext.d.ts +2 -2
  152. package/build/unparserContext.js +2 -3
  153. package/build/unparserError.d.ts +2 -1
  154. package/build/unparserError.js +2 -1
  155. package/build/unparserImplementationInvariant.d.ts +1 -1
  156. package/build/unparserOutputCompanion.d.ts +1 -1
  157. package/build/unparserOutputCompanion.js +1 -1
  158. package/build/zipParser.js +1 -1
  159. package/build/zipUnparser.d.ts +3 -3
  160. package/build/zipUnparser.js +9 -19
  161. package/build/zipUnparser.test.js +1 -1
  162. package/package.json +19 -26
  163. package/src/allSettledStream.test.ts +2 -2
  164. package/src/allSettledStream.ts +3 -3
  165. package/src/androidPackageParser.test.ts +17 -19
  166. package/src/androidPackageParser.ts +129 -171
  167. package/src/androidPackageUnparser.test.ts +19 -21
  168. package/src/androidPackageUnparser.ts +23 -17
  169. package/src/arbitrarilySlicedAsyncInterable.ts +1 -1
  170. package/src/arbitrarilySlicedAsyncInterator.ts +4 -4
  171. package/src/arbitraryDalvikBytecode.ts +992 -0
  172. package/src/arbitraryDalvikExecutable.ts +434 -0
  173. package/src/arbitraryDosDateTime.ts +1 -0
  174. package/src/arbitraryZipStream.ts +1 -1
  175. package/src/arrayParser.ts +2 -2
  176. package/src/arrayUnparser.ts +2 -2
  177. package/src/backsmali.ts +48 -4
  178. package/src/bsonParser.test.ts +12 -14
  179. package/src/customInvariant.ts +8 -12
  180. package/src/dalvikBytecodeParser/formatParsers.ts +376 -17
  181. package/src/dalvikBytecodeParser/formatSizes.ts +35 -0
  182. package/src/dalvikBytecodeParser/operationFormats.ts +226 -0
  183. package/src/dalvikBytecodeParser.ts +1042 -243
  184. package/src/dalvikBytecodeUnparser/formatUnparsers.ts +442 -0
  185. package/src/dalvikBytecodeUnparser.test.ts +44 -0
  186. package/src/dalvikBytecodeUnparser.ts +758 -0
  187. package/src/dalvikExecutable.ts +110 -48
  188. package/src/dalvikExecutableParser/stringSyntaxParser.ts +33 -33
  189. package/src/dalvikExecutableParser/typeParsers.ts +23 -14
  190. package/src/dalvikExecutableParser/typedNumbers.ts +19 -19
  191. package/src/dalvikExecutableParser.test.ts +60 -60
  192. package/src/dalvikExecutableParser.test.ts.md +6 -6
  193. package/src/dalvikExecutableParser.test.ts.snap +0 -0
  194. package/src/dalvikExecutableParser.ts +911 -434
  195. package/src/dalvikExecutableParserAgainstSmaliParser.test.ts +256 -239
  196. package/src/dalvikExecutableUnparser/annotationUnparsers.ts +135 -0
  197. package/src/dalvikExecutableUnparser/poolBuilders.ts +189 -0
  198. package/src/dalvikExecutableUnparser/poolScanners.ts +297 -0
  199. package/src/dalvikExecutableUnparser/sectionUnparsers.ts +683 -0
  200. package/src/dalvikExecutableUnparser/utils.ts +149 -0
  201. package/src/dalvikExecutableUnparser.test.ts +57 -0
  202. package/src/dalvikExecutableUnparser.ts +581 -0
  203. package/src/debugLogInputParser.ts +1 -1
  204. package/src/disjunctionParser.ts +5 -5
  205. package/src/elementTerminatedArrayParser.test.ts +8 -8
  206. package/src/elementTerminatedArrayParser.ts +2 -2
  207. package/src/elementTerminatedSequenceArrayParser.test.ts +4 -6
  208. package/src/elementTerminatedSequenceArrayParser.ts +2 -2
  209. package/src/elementTerminatedSequenceParser.test.ts +4 -6
  210. package/src/elementTerminatedSequenceParser.ts +2 -2
  211. package/src/endOfInputParser.ts +1 -1
  212. package/src/exactElementSwitchParser.ts +41 -0
  213. package/src/fetchCid.test.ts +20 -0
  214. package/src/fetchCid.ts +3 -7
  215. package/src/fixedLengthSequenceParser.test.ts +10 -12
  216. package/src/hasExecutable.ts +2 -2
  217. package/src/highResolutionTimer.ts +1 -1
  218. package/src/inputReader.test.ts +39 -52
  219. package/src/inputReader.ts +2 -4
  220. package/src/inputReaderState.ts +1 -1
  221. package/src/inspect.ts +1 -1
  222. package/src/javaKeyStoreParser.test.ts +12 -14
  223. package/src/javaKeyStoreParser.ts +2 -6
  224. package/src/jsonParser.test.ts +2 -4
  225. package/src/jsonParser.ts +34 -38
  226. package/src/lazyMessageError.test.ts +21 -0
  227. package/src/lazyMessageError.ts +88 -0
  228. package/src/leb128Parser.test.ts +25 -23
  229. package/src/leb128Parser.ts +19 -19
  230. package/src/negativeLookaheadParser.test.ts +7 -11
  231. package/src/negativeLookaheadParser.ts +2 -2
  232. package/src/noStackCaptureOverheadError.test.ts +17 -0
  233. package/src/noStackCaptureOverheadError.ts +12 -0
  234. package/src/nonEmptyArrayParser.test.ts +3 -2
  235. package/src/nonEmptyArrayParser.ts +2 -2
  236. package/src/optionalParser.ts +2 -2
  237. package/src/parser.test.ts +96 -43
  238. package/src/parser.test.ts.md +13 -6
  239. package/src/parser.test.ts.snap +0 -0
  240. package/src/parser.ts +35 -12
  241. package/src/parserAccessorParser.ts +1 -1
  242. package/src/parserConsumedSequenceParser.ts +3 -3
  243. package/src/parserContext.test.ts +7 -3
  244. package/src/parserContext.ts +82 -48
  245. package/src/parserError.ts +143 -63
  246. package/src/parserImplementationInvariant.ts +3 -3
  247. package/src/parserInputCompanion.ts +2 -2
  248. package/src/promiseCompose.ts +2 -2
  249. package/src/separatedArrayParser.ts +3 -3
  250. package/src/separatedNonEmptyArrayParser.test.ts +117 -0
  251. package/src/separatedNonEmptyArrayParser.ts +61 -0
  252. package/src/sequenceBuffer.test.ts +9 -9
  253. package/src/sequenceBuffer.ts +4 -4
  254. package/src/sequenceTerminatedSequenceParser.test.ts +3 -5
  255. package/src/sequenceTerminatedSequenceParser.ts +4 -4
  256. package/src/sequenceUnparser.ts +2 -2
  257. package/src/skipToParser.ts +2 -2
  258. package/src/sliceBoundedParser.test.ts +4 -12
  259. package/src/sliceBoundedParser.ts +2 -2
  260. package/src/smali.ts +8 -3
  261. package/src/smaliParser.test.ts +377 -66
  262. package/src/smaliParser.test.ts.md +1635 -48
  263. package/src/smaliParser.test.ts.snap +0 -0
  264. package/src/smaliParser.ts +2751 -569
  265. package/src/stringFromAsyncIterable.ts +9 -0
  266. package/src/terminatedArrayParser.test.ts +11 -11
  267. package/src/terminatedArrayParser.ts +5 -7
  268. package/src/toAsyncIterator.ts +8 -8
  269. package/src/uint8Array.ts +2 -3
  270. package/src/unionParser.test.ts +22 -23
  271. package/src/unionParser.ts +6 -8
  272. package/src/unparser.test.ts +18 -34
  273. package/src/unparser.ts +13 -9
  274. package/src/unparserContext.ts +9 -13
  275. package/src/unparserError.ts +2 -1
  276. package/src/unparserImplementationInvariant.ts +1 -1
  277. package/src/unparserOutputCompanion.ts +1 -1
  278. package/src/zip.ts +2 -6
  279. package/src/zipParser.ts +10 -18
  280. package/src/zipUnparser.test.ts +1 -1
  281. package/src/zipUnparser.ts +52 -64
  282. package/tsconfig.json +7 -1
  283. package/xo.config.ts +15 -0
  284. package/.yarn/releases/yarn-4.5.3.cjs +0 -934
@@ -0,0 +1,282 @@
1
+ import * as fc from 'fast-check';
2
+ // String generators for valid Dalvik identifiers and type descriptors
3
+ const arbitraryJavaIdentifier = fc.stringMatching(/^[a-zA-Z_][a-zA-Z0-9_]*$/);
4
+ const arbitraryPrimitiveType = fc.oneof(fc.constant('V'), // void
5
+ fc.constant('Z'), // boolean
6
+ fc.constant('B'), // byte
7
+ fc.constant('S'), // short
8
+ fc.constant('C'), // char
9
+ fc.constant('I'), // int
10
+ fc.constant('J'), // long
11
+ fc.constant('F'), // float
12
+ fc.constant('D'));
13
+ const arbitraryDalvikClassName = fc.tuple(fc.array(arbitraryJavaIdentifier, { minLength: 1, maxLength: 3 }), arbitraryJavaIdentifier).map(([packages, className]) => `L${packages.join('/')}/${className};`);
14
+ const arbitraryDalvikTypeName = fc.oneof(arbitraryPrimitiveType, arbitraryDalvikClassName, arbitraryPrimitiveType.map(p => `[${p}`), // array of primitive
15
+ arbitraryDalvikClassName.map(c => `[${c}`));
16
+ const arbitraryDalvikMethodName = fc.oneof(arbitraryJavaIdentifier, fc.constant('<init>'), fc.constant('<clinit>'));
17
+ const arbitraryDalvikFieldName = arbitraryJavaIdentifier;
18
+ // Access flags generator - common flags for all contexts
19
+ const arbitraryDalvikExecutableAccessFlagsCommon = fc.record({
20
+ public: fc.boolean(),
21
+ private: fc.boolean(),
22
+ protected: fc.boolean(),
23
+ static: fc.boolean(),
24
+ final: fc.boolean(),
25
+ synchronized: fc.boolean(),
26
+ volatile: fc.constant(false),
27
+ bridge: fc.constant(false),
28
+ transient: fc.constant(false),
29
+ varargs: fc.constant(false),
30
+ native: fc.boolean(),
31
+ interface: fc.boolean(),
32
+ abstract: fc.boolean(),
33
+ strict: fc.boolean(),
34
+ synthetic: fc.boolean(),
35
+ annotation: fc.boolean(),
36
+ enum: fc.boolean(),
37
+ constructor: fc.boolean(),
38
+ declaredSynchronized: fc.boolean(),
39
+ });
40
+ // Access flags for fields - volatile and transient are valid (0x40 and 0x80)
41
+ const arbitraryDalvikExecutableFieldAccessFlags = fc.record({
42
+ public: fc.boolean(),
43
+ private: fc.boolean(),
44
+ protected: fc.boolean(),
45
+ static: fc.boolean(),
46
+ final: fc.boolean(),
47
+ synchronized: fc.boolean(),
48
+ volatile: fc.boolean(),
49
+ bridge: fc.constant(false),
50
+ transient: fc.boolean(),
51
+ varargs: fc.constant(false),
52
+ native: fc.boolean(),
53
+ interface: fc.boolean(),
54
+ abstract: fc.boolean(),
55
+ strict: fc.boolean(),
56
+ synthetic: fc.boolean(),
57
+ annotation: fc.boolean(),
58
+ enum: fc.boolean(),
59
+ constructor: fc.boolean(),
60
+ declaredSynchronized: fc.boolean(),
61
+ });
62
+ // Access flags for methods - bridge and varargs are valid (0x40 and 0x80)
63
+ const arbitraryDalvikExecutableMethodAccessFlags = fc.record({
64
+ public: fc.boolean(),
65
+ private: fc.boolean(),
66
+ protected: fc.boolean(),
67
+ static: fc.boolean(),
68
+ final: fc.boolean(),
69
+ synchronized: fc.boolean(),
70
+ volatile: fc.constant(false),
71
+ bridge: fc.boolean(),
72
+ transient: fc.constant(false),
73
+ varargs: fc.boolean(),
74
+ native: fc.boolean(),
75
+ interface: fc.boolean(),
76
+ abstract: fc.boolean(),
77
+ strict: fc.boolean(),
78
+ synthetic: fc.boolean(),
79
+ annotation: fc.boolean(),
80
+ enum: fc.boolean(),
81
+ constructor: fc.boolean(),
82
+ declaredSynchronized: fc.boolean(),
83
+ });
84
+ // Generic access flags for class-level (uses common)
85
+ const arbitraryDalvikExecutableAccessFlags = arbitraryDalvikExecutableAccessFlagsCommon;
86
+ // Field generator
87
+ const arbitraryDalvikExecutableField = fc.record({
88
+ class: arbitraryDalvikClassName,
89
+ type: arbitraryDalvikTypeName,
90
+ name: arbitraryDalvikFieldName,
91
+ });
92
+ const arbitraryDalvikExecutableFieldWithAccess = fc.record({
93
+ field: arbitraryDalvikExecutableField,
94
+ accessFlags: arbitraryDalvikExecutableFieldAccessFlags,
95
+ });
96
+ // Prototype generator
97
+ const arbitraryShorty = fc.tuple(arbitraryPrimitiveType, // return type
98
+ fc.array(fc.oneof(fc.constant('L'), arbitraryPrimitiveType), { maxLength: 5 })).map(([returnType, params]) => returnType + params.join(''));
99
+ const arbitraryDalvikExecutablePrototype = arbitraryShorty.chain(shorty => {
100
+ const returnTypeChar = shorty[0];
101
+ const paramChars = shorty.slice(1).split('');
102
+ const returnType = returnTypeChar === 'L' ? arbitraryDalvikClassName : fc.constant(returnTypeChar);
103
+ const parameters = fc.tuple(...paramChars.map(char => char === 'L' ? arbitraryDalvikClassName : fc.constant(char)));
104
+ return fc.record({
105
+ shorty: fc.constant(shorty),
106
+ returnType,
107
+ parameters,
108
+ });
109
+ });
110
+ // Method generator
111
+ const arbitraryDalvikExecutableMethod = fc.record({
112
+ class: arbitraryDalvikClassName,
113
+ prototype: arbitraryDalvikExecutablePrototype,
114
+ name: arbitraryDalvikMethodName,
115
+ });
116
+ // Encoded value generator (recursive)
117
+ // DalvikExecutableEncodedValue is now a tagged union with type information
118
+ const arbitraryDalvikExecutableEncodedValue = fc.letrec(tie => ({
119
+ value: fc.oneof(fc.record({ type: fc.constant('byte'), value: fc.integer({ min: -128, max: 127 }) }), fc.record({ type: fc.constant('short'), value: fc.integer({ min: -32768, max: 32767 }) }), fc.record({ type: fc.constant('char'), value: fc.integer({ min: 0, max: 65535 }) }), fc.record({ type: fc.constant('int'), value: fc.integer({ min: -2147483648, max: 2147483647 }) }), fc.record({ type: fc.constant('long'), value: fc.bigInt({ min: -9223372036854775808n, max: 9223372036854775807n }) }), fc.record({ type: fc.constant('float'), value: fc.float() }), fc.record({ type: fc.constant('double'), value: fc.double() }), fc.record({ type: fc.constant('methodType'), value: arbitraryDalvikExecutablePrototype }), fc.record({ type: fc.constant('methodHandle'), value: fc.nat(255) }), fc.record({ type: fc.constant('string'), value: fc.string() }), fc.record({ type: fc.constant('type'), value: arbitraryDalvikClassName }), fc.record({ type: fc.constant('field'), value: arbitraryDalvikExecutableField }), fc.record({ type: fc.constant('method'), value: arbitraryDalvikExecutableMethod }), fc.record({ type: fc.constant('enum'), value: arbitraryDalvikExecutableField }), fc.record({ type: fc.constant('array'), value: fc.array(tie('value'), { maxLength: 3 }) }),
120
+ // Note: We skip 'annotation' type here to avoid deep recursion complexity
121
+ fc.record({ type: fc.constant('null'), value: fc.constant(null) }), fc.record({ type: fc.constant('boolean'), value: fc.boolean() })),
122
+ })).value;
123
+ // Annotation generators
124
+ const arbitraryAnnotationVisibility = fc.oneof(fc.constant('build'), fc.constant('runtime'), fc.constant('system'));
125
+ const arbitraryDalvikExecutableAnnotationElement = fc.record({
126
+ name: arbitraryJavaIdentifier,
127
+ value: arbitraryDalvikExecutableEncodedValue,
128
+ });
129
+ const arbitraryDalvikExecutableAnnotation = fc.record({
130
+ visibility: arbitraryAnnotationVisibility,
131
+ type: arbitraryDalvikClassName,
132
+ elements: fc.array(arbitraryDalvikExecutableAnnotationElement, { maxLength: 3 }),
133
+ });
134
+ // Debug info generators
135
+ const arbitraryDalvikExecutableDebugByteCodeValue = fc.oneof(fc.record({
136
+ type: fc.constant('advancePc'),
137
+ addressDiff: fc.nat({ max: 255 }),
138
+ }), fc.record({
139
+ type: fc.constant('advanceLine'),
140
+ lineDiff: fc.integer({ min: -128, max: 127 }),
141
+ }), fc.record({
142
+ type: fc.constant('startLocal'),
143
+ registerNum: fc.nat({ max: 255 }),
144
+ name: fc.option(arbitraryJavaIdentifier, { nil: undefined }),
145
+ type_: fc.option(arbitraryDalvikTypeName, { nil: undefined }),
146
+ }), fc.record({
147
+ type: fc.constant('startLocalExtended'),
148
+ registerNum: fc.nat({ max: 255 }),
149
+ name: fc.option(arbitraryJavaIdentifier, { nil: undefined }),
150
+ type_: fc.option(arbitraryDalvikTypeName, { nil: undefined }),
151
+ signature: fc.option(fc.string(), { nil: undefined }),
152
+ }), fc.record({
153
+ type: fc.constant('endLocal'),
154
+ registerNum: fc.nat({ max: 255 }),
155
+ }), fc.record({
156
+ type: fc.constant('restartLocal'),
157
+ registerNum: fc.nat({ max: 255 }),
158
+ }), fc.record({
159
+ type: fc.constant('setPrologueEnd'),
160
+ }), fc.record({
161
+ type: fc.constant('setEpilogueBegin'),
162
+ }), fc.record({
163
+ type: fc.constant('setFile'),
164
+ name: fc.option(fc.string(), { nil: undefined }),
165
+ }), fc.record({
166
+ type: fc.constant('special'),
167
+ // Special opcodes must be >= 0x0A (values 0x00-0x09 are specific debug opcodes)
168
+ value: fc.integer({ min: 0x0A, max: 255 }),
169
+ }));
170
+ const arbitraryDalvikExecutableDebugInfo = fc.record({
171
+ lineStart: fc.nat({ max: 65535 }),
172
+ parameterNames: fc.array(fc.option(arbitraryJavaIdentifier, { nil: undefined }), { maxLength: 5 }),
173
+ bytecode: fc.array(arbitraryDalvikExecutableDebugByteCodeValue, { maxLength: 10 }),
174
+ });
175
+ const arbitraryDalvikExecutableEncodedTypeAddressPair = fc.record({
176
+ type: arbitraryDalvikClassName,
177
+ address: fc.nat({ max: 65535 }),
178
+ });
179
+ const arbitraryDalvikExecutableEncodedCatchHandler = fc.record({
180
+ handlers: fc.array(arbitraryDalvikExecutableEncodedTypeAddressPair, { maxLength: 3 }),
181
+ catchAllAddress: fc.option(fc.nat({ max: 65535 }), { nil: undefined }),
182
+ }).filter(handler => {
183
+ // A handler must have at least one typed handler OR a catch-all address
184
+ return handler.handlers.length > 0 || handler.catchAllAddress !== undefined;
185
+ });
186
+ const arbitraryDalvikExecutableTry = fc.record({
187
+ startAddress: fc.nat({ max: 65535 }),
188
+ instructionCount: fc.nat({ max: 255 }),
189
+ handler: arbitraryDalvikExecutableEncodedCatchHandler,
190
+ });
191
+ // Generic factory function for DalvikExecutable
192
+ export const createArbitraryDalvikExecutable = (arbitraryInstructions) => {
193
+ // Code generator using provided instructions arbitrary
194
+ const arbitraryDalvikExecutableCode = fc.record({
195
+ registersSize: fc.nat({ max: 65535 }),
196
+ insSize: fc.nat({ max: 255 }),
197
+ outsSize: fc.nat({ max: 255 }),
198
+ debugInfo: fc.option(arbitraryDalvikExecutableDebugInfo, { nil: undefined }),
199
+ instructions: arbitraryInstructions,
200
+ tries: fc.array(arbitraryDalvikExecutableTry, { maxLength: 2 }),
201
+ });
202
+ // Method with access and code
203
+ const arbitraryDalvikExecutableMethodWithAccess = fc.record({
204
+ method: arbitraryDalvikExecutableMethod,
205
+ accessFlags: arbitraryDalvikExecutableMethodAccessFlags,
206
+ code: fc.option(arbitraryDalvikExecutableCode, { nil: undefined }),
207
+ });
208
+ // Annotation collections
209
+ const arbitraryDalvikExecutableClassFieldAnnotation = fc.record({
210
+ field: arbitraryDalvikExecutableField,
211
+ annotations: fc.option(fc.array(arbitraryDalvikExecutableAnnotation, { maxLength: 2 }), { nil: undefined }),
212
+ });
213
+ const arbitraryDalvikExecutableClassMethodAnnotation = fc.record({
214
+ method: arbitraryDalvikExecutableMethod,
215
+ annotations: fc.array(arbitraryDalvikExecutableAnnotation, { maxLength: 2 }),
216
+ });
217
+ const arbitraryDalvikExecutableClassParameterAnnotation = fc.record({
218
+ method: arbitraryDalvikExecutableMethod,
219
+ annotations: fc.array(fc.array(arbitraryDalvikExecutableAnnotation, { maxLength: 2 }), { maxLength: 3 }),
220
+ });
221
+ const arbitraryDalvikExecutableClassAnnotations = fc.record({
222
+ classAnnotations: fc.array(arbitraryDalvikExecutableAnnotation, { maxLength: 2 }),
223
+ fieldAnnotations: fc.array(arbitraryDalvikExecutableClassFieldAnnotation, { maxLength: 2 }),
224
+ methodAnnotations: fc.array(arbitraryDalvikExecutableClassMethodAnnotation, { maxLength: 2 }),
225
+ parameterAnnotations: fc.array(arbitraryDalvikExecutableClassParameterAnnotation, { maxLength: 2 }),
226
+ }).map(annotations => ({
227
+ ...annotations,
228
+ // Filter out field/method/parameter annotations with undefined or empty annotations array
229
+ // In DEX format, fields/methods/parameters with no annotations should not appear in the annotations directory at all
230
+ fieldAnnotations: annotations.fieldAnnotations.filter(fa => fa.annotations !== undefined && fa.annotations.length > 0),
231
+ methodAnnotations: annotations.methodAnnotations.filter(ma => ma.annotations.length > 0),
232
+ parameterAnnotations: annotations.parameterAnnotations.filter(pa => pa.annotations.length > 0 && pa.annotations.some(paramAnnots => paramAnnots.length > 0)),
233
+ }));
234
+ // Class data
235
+ const arbitraryDalvikExecutableClassData = fc.record({
236
+ staticFields: fc.array(arbitraryDalvikExecutableFieldWithAccess, { maxLength: 3 }),
237
+ instanceFields: fc.array(arbitraryDalvikExecutableFieldWithAccess, { maxLength: 3 }),
238
+ directMethods: fc.array(arbitraryDalvikExecutableMethodWithAccess, { maxLength: 3 }),
239
+ virtualMethods: fc.array(arbitraryDalvikExecutableMethodWithAccess, { maxLength: 3 }),
240
+ }).filter(classData =>
241
+ // Filter out empty classData (all arrays empty) as it's semantically equivalent to undefined
242
+ classData.staticFields.length > 0 ||
243
+ classData.instanceFields.length > 0 ||
244
+ classData.directMethods.length > 0 ||
245
+ classData.virtualMethods.length > 0);
246
+ // Class definition
247
+ const arbitraryDalvikExecutableClassDefinition = fc.record({
248
+ class: arbitraryDalvikClassName,
249
+ accessFlags: arbitraryDalvikExecutableAccessFlags,
250
+ superclass: arbitraryDalvikClassName,
251
+ interfaces: fc.array(arbitraryDalvikClassName, { maxLength: 3 }),
252
+ sourceFile: fc.option(fc.stringMatching(/^[a-zA-Z0-9_]+\.java$/), { nil: undefined }),
253
+ annotations: fc.option(arbitraryDalvikExecutableClassAnnotations, { nil: undefined }),
254
+ staticValues: fc.array(arbitraryDalvikExecutableEncodedValue, { maxLength: 3 }),
255
+ classData: fc.option(arbitraryDalvikExecutableClassData, { nil: undefined }),
256
+ }).map(classDef => {
257
+ // Match parser logic: if all members are synthetic, set class synthetic to true
258
+ const allMembers = [
259
+ ...classDef.classData?.staticFields ?? [],
260
+ ...classDef.classData?.instanceFields ?? [],
261
+ ...classDef.classData?.directMethods ?? [],
262
+ // Note: virtualMethods are not included to match parser behavior
263
+ ];
264
+ const allMembersAreSynthetic = (allMembers.every(member => member.accessFlags.synthetic)
265
+ && allMembers.length > 0);
266
+ if (allMembersAreSynthetic) {
267
+ return {
268
+ ...classDef,
269
+ accessFlags: {
270
+ ...classDef.accessFlags,
271
+ synthetic: true,
272
+ },
273
+ };
274
+ }
275
+ return classDef;
276
+ });
277
+ // Root DalvikExecutable
278
+ return fc.record({
279
+ classDefinitions: fc.array(arbitraryDalvikExecutableClassDefinition, { minLength: 1, maxLength: 3 }),
280
+ link: fc.option(fc.uint8Array({ minLength: 1, maxLength: 10 }), { nil: undefined }),
281
+ });
282
+ };
@@ -2,6 +2,7 @@ import * as fc from 'fast-check';
2
2
  export const arbitraryDosDateTime = fc.date({
3
3
  min: new Date(Date.UTC(1980, 0, 1)),
4
4
  max: new Date(Date.UTC(2099, 11, 31)),
5
+ noInvalidDate: true,
5
6
  }).map(date => {
6
7
  date.setSeconds(0);
7
8
  date.setMilliseconds(0);
@@ -4,7 +4,7 @@ function addZipEntryToZip(zip, zipEntry) {
4
4
  const options = {
5
5
  comment: zipEntry.comment,
6
6
  date: zipEntry.date,
7
- // unixPermissions: zipEntry.permissions.type === 'unix' ? zipEntry.permissions.unixPermissions : undefined,
7
+ // UnixPermissions: zipEntry.permissions.type === 'unix' ? zipEntry.permissions.unixPermissions : undefined,
8
8
  // dosPermissions: zipEntry.permissions.type === 'dos' ? zipEntry.permissions.dosPermissions : undefined,
9
9
  };
10
10
  if (zipEntry.type === 'file') {
@@ -1,5 +1,5 @@
1
1
  import { getParserName, setParserName } from './parser.js';
2
- import { ParserParsingFailedError } from './parserError.js';
2
+ import { isParserParsingFailedError } from './parserError.js';
3
3
  export const createArrayParser = (elementParser) => {
4
4
  const arrayParser = async (parserContext) => {
5
5
  const elements = [];
@@ -15,7 +15,7 @@ export const createArrayParser = (elementParser) => {
15
15
  elementParserContext.unlookahead();
16
16
  }
17
17
  catch (error) {
18
- if (error instanceof ParserParsingFailedError) {
18
+ if (isParserParsingFailedError(error)) {
19
19
  return elements;
20
20
  }
21
21
  throw error;
@@ -1,2 +1,2 @@
1
- import { Unparser } from "./unparser.js";
1
+ import { type Unparser } from './unparser.js';
2
2
  export declare const createArrayUnparser: <ElementInput, Sequence>(elementUnparser: Unparser<ElementInput, Sequence>) => Unparser<ElementInput[], Sequence>;
@@ -1 +1,3 @@
1
- export declare function baksmaliClass(dexStream: AsyncIterable<Uint8Array>, smaliFilePath: string): Promise<string>;
1
+ export declare function baksmaliClass(dexStream: Uint8Array | AsyncIterable<Uint8Array>, smaliFilePath: string): Promise<string>;
2
+ export declare function backsmaliSmaliIsolateClass(dexStream: Uint8Array | AsyncIterable<Uint8Array>, smaliFilePath: string): Promise<Uint8Array>;
3
+ export declare function baksmaliListClasses(dexStream: Uint8Array | AsyncIterable<Uint8Array>): Promise<string[]>;
@@ -1,15 +1,18 @@
1
1
  import fs from 'node:fs/promises';
2
+ import path from 'node:path';
2
3
  import { execa } from 'execa';
3
4
  import { temporaryDirectory, temporaryFile } from 'tempy';
4
- import path from 'node:path';
5
+ import { smaliClass } from './smali.js';
5
6
  export async function baksmaliClass(dexStream, smaliFilePath) {
6
7
  const inputFilePath = temporaryFile();
7
8
  const outputDirectoryPath = temporaryDirectory();
8
9
  await fs.writeFile(inputFilePath, dexStream);
9
10
  await execa('baksmali', [
10
11
  'disassemble',
11
- '--classes', 'L' + smaliFilePath + ';',
12
- '--output', outputDirectoryPath,
12
+ '--classes',
13
+ 'L' + smaliFilePath + ';',
14
+ '--output',
15
+ outputDirectoryPath,
13
16
  inputFilePath,
14
17
  ]);
15
18
  await fs.unlink(inputFilePath);
@@ -20,3 +23,28 @@ export async function baksmaliClass(dexStream, smaliFilePath) {
20
23
  });
21
24
  return smali;
22
25
  }
26
+ export async function backsmaliSmaliIsolateClass(dexStream, smaliFilePath) {
27
+ const smali = await baksmaliClass(dexStream, smaliFilePath);
28
+ return smaliClass(smali);
29
+ }
30
+ export async function baksmaliListClasses(dexStream) {
31
+ const inputFilePath = temporaryFile();
32
+ await fs.writeFile(inputFilePath, dexStream);
33
+ const result = await execa('baksmali', [
34
+ 'list',
35
+ 'classes',
36
+ inputFilePath,
37
+ ]);
38
+ await fs.unlink(inputFilePath);
39
+ if (result.stderr) {
40
+ throw new Error(`baksmali error: ${result.stderr}`);
41
+ }
42
+ const classes = result.stdout
43
+ .split('\n')
44
+ .filter(line => line.trim())
45
+ .map(line => line.trim())
46
+ .map(class_ => (class_
47
+ .replace(/^L/, '')
48
+ .replace(/;$/, '')));
49
+ return classes;
50
+ }
@@ -1,4 +1,5 @@
1
1
  import { type Constructor } from 'type-fest';
2
+ import { LazyMessage, LazyMessageError } from './lazyMessageError.js';
2
3
  export type Falsy = '' | 0 | false | undefined;
3
4
  export type ValueOrAccessor<T> = T | (() => T);
4
- export declare function customInvariant<T>(ErrorConstructor: Constructor<Error, [message: string]> | ((message: string) => Error), value: T, formatOrFormatLines: ValueOrAccessor<string | string[]>, ...formatArguments: (unknown | (() => unknown))[]): Exclude<T, Falsy>;
5
+ export declare function customInvariant<T>(ErrorConstructor: Constructor<LazyMessageError, [LazyMessage]> | ((lazyMessage: LazyMessage) => LazyMessageError), value: T, formatOrFormatLines: ValueOrAccessor<string | string[]>, ...formatArguments: Array<unknown | (() => unknown)>): Exclude<T, Falsy>;
@@ -2,10 +2,8 @@ export function customInvariant(ErrorConstructor, value, formatOrFormatLines, ..
2
2
  if (value) {
3
3
  return value;
4
4
  }
5
- let format = typeof formatOrFormatLines === 'function' ? formatOrFormatLines() : formatOrFormatLines;
6
- format = Array.isArray(format) ? format.join('\n') : format;
7
- throw new ErrorConstructor(format.replaceAll('%s', () => {
8
- const argumentOrAccessor = formatArguments.shift();
9
- return typeof argumentOrAccessor === 'function' ? argumentOrAccessor() : argumentOrAccessor;
10
- }));
5
+ throw new ErrorConstructor([
6
+ formatOrFormatLines,
7
+ ...formatArguments,
8
+ ]);
11
9
  }
@@ -1,5 +1,5 @@
1
- import { Iso } from "monocle-ts";
2
- import { Parser } from "../parser.js";
1
+ import { type Iso } from 'monocle-ts';
2
+ import { type Parser } from '../parser.js';
3
3
  export declare const nibblesParser: Parser<[number, number], Uint8Array>;
4
4
  type DalvikBytecodeFormat10t = {
5
5
  branchOffset: number;
@@ -11,6 +11,11 @@ type DalvikBytecodeFormat11x = {
11
11
  registers: number[];
12
12
  };
13
13
  export declare const dalvikBytecodeFormat11xParser: Parser<DalvikBytecodeFormat11x, Uint8Array>;
14
+ type DalvikBytecodeFormat11n = {
15
+ value: number;
16
+ registers: number[];
17
+ };
18
+ export declare const dalvikBytecodeFormat11nParser: Parser<DalvikBytecodeFormat11n, Uint8Array>;
14
19
  type DalvikBytecodeFormat12x = {
15
20
  registers: number[];
16
21
  };
@@ -71,11 +76,27 @@ type DalvikBytecodeFormat23x = {
71
76
  registers: number[];
72
77
  };
73
78
  export declare const dalvikBytecodeFormat23xParser: Parser<DalvikBytecodeFormat23x, Uint8Array>;
79
+ type DalvikBytecodeFormat30t = {
80
+ branchOffset: number;
81
+ };
82
+ export declare const dalvikBytecodeFormat30tParser: Parser<DalvikBytecodeFormat30t, Uint8Array>;
74
83
  type DalvikBytecodeFormat31i = {
75
84
  value: number;
76
85
  registers: number[];
77
86
  };
78
87
  export declare const dalvikBytecodeFormat31iParser: Parser<DalvikBytecodeFormat31i, Uint8Array>;
88
+ type DalvikBytecodeFormat31c<Index> = {
89
+ index: Index;
90
+ registers: number[];
91
+ };
92
+ export declare const createDalvikBytecodeFormat31cParser: <Index>({ isoIndex, }: {
93
+ isoIndex: Iso<Index, number>;
94
+ }) => Parser<DalvikBytecodeFormat31c<Index>, Uint8Array>;
95
+ type DalvikBytecodeFormat31t = {
96
+ branchOffset: number;
97
+ registers: number[];
98
+ };
99
+ export declare const dalvikBytecodeFormat31tParser: Parser<DalvikBytecodeFormat31t, Uint8Array>;
79
100
  type DalvikBytecodeFormat32x = {
80
101
  registers: number[];
81
102
  };
@@ -94,4 +115,57 @@ type DalvikBytecodeFormat3rc<Index> = {
94
115
  export declare const createDalvikBytecodeFormat3rcParser: <Index>({ isoIndex, }: {
95
116
  isoIndex: Iso<Index, number>;
96
117
  }) => Parser<DalvikBytecodeFormat3rc<Index>, Uint8Array>;
118
+ type DalvikBytecodeFormat51l = {
119
+ value: bigint;
120
+ registers: number[];
121
+ };
122
+ export declare const dalvikBytecodeFormat51lParser: Parser<DalvikBytecodeFormat51l, Uint8Array>;
123
+ type DalvikBytecodeFormat20bc = {
124
+ kind: number;
125
+ index: number;
126
+ };
127
+ export declare const dalvikBytecodeFormat20bcParser: Parser<DalvikBytecodeFormat20bc, Uint8Array>;
128
+ type DalvikBytecodeFormat22cs = {
129
+ registers: number[];
130
+ fieldOffset: number;
131
+ };
132
+ export declare const dalvikBytecodeFormat22csParser: Parser<DalvikBytecodeFormat22cs, Uint8Array>;
133
+ type DalvikBytecodeFormat35mi = {
134
+ inlineIndex: number;
135
+ registers: number[];
136
+ };
137
+ export declare const dalvikBytecodeFormat35miParser: Parser<DalvikBytecodeFormat35mi, Uint8Array>;
138
+ type DalvikBytecodeFormat35ms = {
139
+ vtableOffset: number;
140
+ registers: number[];
141
+ };
142
+ export declare const dalvikBytecodeFormat35msParser: Parser<DalvikBytecodeFormat35ms, Uint8Array>;
143
+ type DalvikBytecodeFormat3rmi = {
144
+ inlineIndex: number;
145
+ registers: number[];
146
+ };
147
+ export declare const dalvikBytecodeFormat3rmiParser: Parser<DalvikBytecodeFormat3rmi, Uint8Array>;
148
+ type DalvikBytecodeFormat3rms = {
149
+ vtableOffset: number;
150
+ registers: number[];
151
+ };
152
+ export declare const dalvikBytecodeFormat3rmsParser: Parser<DalvikBytecodeFormat3rms, Uint8Array>;
153
+ type DalvikBytecodeFormat45cc<MethodIndex, ProtoIndex> = {
154
+ methodIndex: MethodIndex;
155
+ protoIndex: ProtoIndex;
156
+ registers: number[];
157
+ };
158
+ export declare const createDalvikBytecodeFormat45ccParser: <MethodIndex, ProtoIndex>({ isoMethodIndex, isoProtoIndex, }: {
159
+ isoMethodIndex: Iso<MethodIndex, number>;
160
+ isoProtoIndex: Iso<ProtoIndex, number>;
161
+ }) => Parser<DalvikBytecodeFormat45cc<MethodIndex, ProtoIndex>, Uint8Array>;
162
+ type DalvikBytecodeFormat4rcc<MethodIndex, ProtoIndex> = {
163
+ methodIndex: MethodIndex;
164
+ protoIndex: ProtoIndex;
165
+ registers: number[];
166
+ };
167
+ export declare const createDalvikBytecodeFormat4rccParser: <MethodIndex, ProtoIndex>({ isoMethodIndex, isoProtoIndex, }: {
168
+ isoMethodIndex: Iso<MethodIndex, number>;
169
+ isoProtoIndex: Iso<ProtoIndex, number>;
170
+ }) => Parser<DalvikBytecodeFormat4rcc<MethodIndex, ProtoIndex>, Uint8Array>;
97
171
  export {};