@futpib/parser 1.0.1 → 1.0.2

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 (304) hide show
  1. package/build/allSettledStream.js +32 -14
  2. package/build/allSettledStream.test.js +32 -0
  3. package/build/androidPackage.d.ts +39 -0
  4. package/build/androidPackageParser.d.ts +17 -0
  5. package/build/androidPackageParser.js +183 -0
  6. package/build/{apkParser.test.js → androidPackageParser.test.js} +6 -6
  7. package/build/androidPackageUnparser.d.ts +4 -0
  8. package/build/{apkUnparser.js → androidPackageUnparser.js} +23 -23
  9. package/build/androidPackageUnparser.test.js +26 -0
  10. package/build/arbitrarilySlicedAsyncInterable.d.ts +3 -1
  11. package/build/arbitrarilySlicedAsyncInterable.js +3 -3
  12. package/build/arrayParser.test.js +3 -3
  13. package/build/backsmali.d.ts +1 -0
  14. package/build/backsmali.js +22 -0
  15. package/build/bsonParser.js +6 -2
  16. package/build/customInvariant.d.ts +1 -1
  17. package/build/dalvikBytecodeParser/formatParsers.d.ts +97 -0
  18. package/build/dalvikBytecodeParser/formatParsers.js +169 -0
  19. package/build/dalvikBytecodeParser.d.ts +107 -0
  20. package/build/dalvikBytecodeParser.js +836 -0
  21. package/build/dalvikExecutable.d.ts +158 -0
  22. package/build/dalvikExecutable.js +20 -0
  23. package/build/dalvikExecutableParser/stringSyntaxParser.d.ts +4 -0
  24. package/build/dalvikExecutableParser/stringSyntaxParser.js +76 -0
  25. package/build/dalvikExecutableParser/typeParsers.d.ts +10 -0
  26. package/build/dalvikExecutableParser/typeParsers.js +34 -0
  27. package/build/dalvikExecutableParser/typedNumbers.d.ts +90 -0
  28. package/build/dalvikExecutableParser/typedNumbers.js +19 -0
  29. package/build/dalvikExecutableParser.d.ts +5 -0
  30. package/build/dalvikExecutableParser.js +1439 -0
  31. package/build/dalvikExecutableParser.test.js +70 -0
  32. package/build/dalvikExecutableParserAgainstSmaliParser.test.js +298 -0
  33. package/build/debugLogInputParser.d.ts +4 -0
  34. package/build/debugLogInputParser.js +16 -0
  35. package/build/debugLogParser.js +14 -3
  36. package/build/disjunctionParser.d.ts +2 -1
  37. package/build/disjunctionParser.js +4 -2
  38. package/build/elementTerminatedArrayParser.d.ts +3 -0
  39. package/build/elementTerminatedArrayParser.js +18 -0
  40. package/build/elementTerminatedArrayParser.test.js +52 -0
  41. package/build/elementTerminatedSequenceArrayParser.d.ts +3 -0
  42. package/build/elementTerminatedSequenceArrayParser.js +32 -0
  43. package/build/elementTerminatedSequenceArrayParser.test.js +34 -0
  44. package/build/elementTerminatedSequenceParser.d.ts +3 -0
  45. package/build/elementTerminatedSequenceParser.js +27 -0
  46. package/build/elementTerminatedSequenceParser.test.js +34 -0
  47. package/build/exactElementParser.js +10 -5
  48. package/build/exactSequenceParser.d.ts +2 -1
  49. package/build/exactSequenceParser.js +12 -2
  50. package/build/fetchCid.d.ts +1 -0
  51. package/build/fetchCid.js +107 -0
  52. package/build/fixedLengthSequenceParser.d.ts +1 -0
  53. package/build/fixedLengthSequenceParser.js +18 -1
  54. package/build/fixedLengthSequenceParser.test.js +41 -0
  55. package/build/hasExecutable.d.ts +1 -0
  56. package/build/hasExecutable.js +8 -0
  57. package/build/highResolutionTimer.d.ts +16 -0
  58. package/build/highResolutionTimer.js +42 -0
  59. package/build/inputReader.d.ts +11 -0
  60. package/build/inputReader.js +37 -0
  61. package/build/inputReader.test.js +165 -0
  62. package/build/inputReaderState.d.ts +10 -0
  63. package/build/inputReaderState.js +16 -0
  64. package/build/inspect.d.ts +1 -0
  65. package/build/inspect.js +7 -0
  66. package/build/javaKeyStoreParser.test.js +2 -2
  67. package/build/jsonParser.d.ts +2 -0
  68. package/build/jsonParser.js +11 -14
  69. package/build/leb128Parser.d.ts +7 -0
  70. package/build/leb128Parser.js +82 -0
  71. package/build/leb128Parser.test.js +107 -0
  72. package/build/lookaheadParser.d.ts +2 -0
  73. package/build/lookaheadParser.js +14 -0
  74. package/build/negativeLookaheadParser.js +21 -15
  75. package/build/negativeLookaheadParser.test.js +30 -0
  76. package/build/nonEmptyArrayParser.d.ts +2 -0
  77. package/build/nonEmptyArrayParser.js +32 -0
  78. package/build/nonEmptyArrayParser.test.js +16 -0
  79. package/build/parser.d.ts +10 -1
  80. package/build/parser.js +66 -31
  81. package/build/parser.test.js +79 -12
  82. package/build/parserAccessorParser.js +9 -1
  83. package/build/parserConsumedSequenceParser.js +20 -15
  84. package/build/parserContext.d.ts +14 -0
  85. package/build/parserContext.js +56 -27
  86. package/build/parserContext.test.js +27 -0
  87. package/build/parserCreatorCompose.d.ts +1 -0
  88. package/build/parserCreatorCompose.js +8 -2
  89. package/build/parserError.d.ts +6 -0
  90. package/build/parserError.js +6 -6
  91. package/build/parserInputCompanion.d.ts +15 -0
  92. package/build/parserInputCompanion.js +38 -0
  93. package/build/promiseCompose.d.ts +1 -1
  94. package/build/promiseCompose.js +12 -1
  95. package/build/promiseSettled.d.ts +1 -0
  96. package/build/promiseSettled.js +4 -0
  97. package/build/separatedArrayParser.d.ts +2 -0
  98. package/build/separatedArrayParser.js +39 -0
  99. package/build/separatedArrayParser.test.d.ts +1 -0
  100. package/build/separatedArrayParser.test.js +21 -0
  101. package/build/sequenceBuffer.d.ts +10 -0
  102. package/build/sequenceBuffer.js +54 -2
  103. package/build/sequenceBuffer.test.js +57 -0
  104. package/build/sequenceTerminatedSequenceParser.d.ts +5 -0
  105. package/build/sequenceTerminatedSequenceParser.js +32 -0
  106. package/build/sequenceTerminatedSequenceParser.test.d.ts +1 -0
  107. package/build/sequenceTerminatedSequenceParser.test.js +37 -0
  108. package/build/skipParser.d.ts +1 -1
  109. package/build/skipParser.js +4 -2
  110. package/build/skipToParser.d.ts +2 -0
  111. package/build/skipToParser.js +11 -0
  112. package/build/sliceBoundedParser.d.ts +1 -1
  113. package/build/sliceBoundedParser.js +7 -2
  114. package/build/sliceBoundedParser.test.js +35 -1
  115. package/build/smali.d.ts +1 -0
  116. package/build/smali.js +17 -0
  117. package/build/smaliParser.d.ts +12 -0
  118. package/build/smaliParser.js +656 -0
  119. package/build/smaliParser.test.d.ts +1 -0
  120. package/build/smaliParser.test.js +115 -0
  121. package/build/terminatedArrayParser.d.ts +3 -1
  122. package/build/terminatedArrayParser.js +79 -2
  123. package/build/terminatedArrayParser.test.d.ts +1 -0
  124. package/build/terminatedArrayParser.test.js +131 -0
  125. package/build/toAsyncIterable.d.ts +1 -0
  126. package/build/toAsyncIterable.js +7 -0
  127. package/build/toAsyncIterator.d.ts +1 -0
  128. package/build/toAsyncIterator.js +33 -0
  129. package/build/tupleParser.d.ts +4 -0
  130. package/build/tupleParser.js +1 -5
  131. package/build/unionParser.d.ts +2 -1
  132. package/build/unionParser.js +27 -12
  133. package/build/unionParser.test.d.ts +1 -0
  134. package/build/unionParser.test.js +60 -0
  135. package/build/zipParser.d.ts +7 -2
  136. package/build/zipParser.js +36 -12
  137. package/build/zipUnparser.d.ts +4 -1
  138. package/build/zipUnparser.js +55 -26
  139. package/build/zipUnparser.test.js +14 -14
  140. package/package.json +23 -7
  141. package/src/allSettledStream.test.ts +40 -0
  142. package/src/allSettledStream.ts +47 -15
  143. package/src/androidPackage.ts +48 -0
  144. package/src/{apkParser.test.ts → androidPackageParser.test.ts} +6 -7
  145. package/src/{apkParser.test.ts.md → androidPackageParser.test.ts.md} +4 -4
  146. package/src/androidPackageParser.test.ts.snap +0 -0
  147. package/src/androidPackageParser.ts +440 -0
  148. package/src/androidPackageUnparser.test.ts +36 -0
  149. package/src/androidPackageUnparser.ts +120 -0
  150. package/src/arbitrarilySlicedAsyncInterable.ts +7 -2
  151. package/src/arrayParser.test.ts +3 -3
  152. package/src/backsmali.ts +30 -0
  153. package/src/bsonParser.ts +13 -2
  154. package/src/customInvariant.ts +1 -1
  155. package/src/dalvikBytecodeParser/formatParsers.ts +421 -0
  156. package/src/dalvikBytecodeParser.ts +2074 -0
  157. package/src/dalvikExecutable.ts +220 -0
  158. package/src/dalvikExecutableParser/stringSyntaxParser.ts +145 -0
  159. package/src/dalvikExecutableParser/typeParsers.ts +65 -0
  160. package/src/dalvikExecutableParser/typedNumbers.ts +57 -0
  161. package/src/dalvikExecutableParser.test.ts +89 -0
  162. package/src/dalvikExecutableParser.test.ts.md +634 -0
  163. package/src/dalvikExecutableParser.test.ts.snap +0 -0
  164. package/src/dalvikExecutableParser.ts +2768 -0
  165. package/src/dalvikExecutableParserAgainstSmaliParser.test.ts +346 -0
  166. package/src/debugLogInputParser.ts +28 -0
  167. package/src/debugLogParser.ts +19 -3
  168. package/src/disjunctionParser.ts +10 -5
  169. package/src/elementTerminatedArrayParser.test.ts +99 -0
  170. package/src/elementTerminatedArrayParser.ts +31 -0
  171. package/src/elementTerminatedSequenceArrayParser.test.ts +54 -0
  172. package/src/elementTerminatedSequenceArrayParser.ts +52 -0
  173. package/src/elementTerminatedSequenceParser.test.ts +54 -0
  174. package/src/elementTerminatedSequenceParser.ts +43 -0
  175. package/src/exactElementParser.ts +17 -11
  176. package/src/exactSequenceParser.ts +23 -2
  177. package/src/fetchCid.ts +125 -0
  178. package/src/fixedLengthSequenceParser.test.ts +77 -0
  179. package/src/fixedLengthSequenceParser.ts +28 -1
  180. package/src/hasExecutable.ts +11 -0
  181. package/src/highResolutionTimer.ts +49 -0
  182. package/src/inputReader.test.ts +209 -0
  183. package/src/inputReader.ts +75 -0
  184. package/src/inputReaderState.ts +33 -0
  185. package/src/inspect.ts +9 -0
  186. package/src/javaKeyStoreParser.test.ts +2 -3
  187. package/src/jsonParser.ts +13 -25
  188. package/src/leb128Parser.test.ts +171 -0
  189. package/src/leb128Parser.ts +125 -0
  190. package/src/lookaheadParser.ts +19 -0
  191. package/src/negativeLookaheadParser.test.ts +53 -0
  192. package/src/negativeLookaheadParser.ts +26 -14
  193. package/src/nonEmptyArrayParser.test.ts +20 -0
  194. package/src/nonEmptyArrayParser.ts +44 -0
  195. package/src/optionalParser.ts +1 -0
  196. package/src/parser.test.ts +131 -12
  197. package/src/parser.test.ts.md +21 -21
  198. package/src/parser.test.ts.snap +0 -0
  199. package/src/parser.ts +149 -45
  200. package/src/parserAccessorParser.ts +12 -2
  201. package/src/parserConsumedSequenceParser.ts +25 -16
  202. package/src/parserContext.test.ts +31 -0
  203. package/src/parserContext.ts +109 -37
  204. package/src/parserCreatorCompose.ts +20 -2
  205. package/src/parserError.ts +9 -6
  206. package/src/parserInputCompanion.ts +55 -0
  207. package/src/promiseCompose.ts +17 -3
  208. package/src/promiseSettled.ts +6 -0
  209. package/src/separatedArrayParser.test.ts +34 -0
  210. package/src/separatedArrayParser.ts +55 -0
  211. package/src/sequenceBuffer.test.ts +70 -0
  212. package/src/sequenceBuffer.ts +88 -2
  213. package/src/sequenceTerminatedSequenceParser.test.ts +60 -0
  214. package/src/sequenceTerminatedSequenceParser.ts +62 -0
  215. package/src/skipParser.ts +7 -5
  216. package/src/skipToParser.ts +16 -0
  217. package/src/sliceBoundedParser.test.ts +43 -1
  218. package/src/sliceBoundedParser.ts +19 -1
  219. package/src/smali.ts +24 -0
  220. package/src/smaliParser.test.ts +132 -0
  221. package/src/smaliParser.test.ts.md +2320 -0
  222. package/src/smaliParser.test.ts.snap +0 -0
  223. package/src/smaliParser.ts +1166 -0
  224. package/src/terminatedArrayParser.test.ts +258 -0
  225. package/src/terminatedArrayParser.ts +108 -3
  226. package/src/toAsyncIterable.ts +7 -0
  227. package/src/toAsyncIterator.ts +48 -0
  228. package/src/tupleParser.ts +8 -5
  229. package/src/unionParser.test.ts +79 -0
  230. package/src/unionParser.ts +44 -16
  231. package/src/zipParser.ts +77 -18
  232. package/src/zipUnparser.test.ts +18 -18
  233. package/src/zipUnparser.ts +88 -27
  234. package/build/apk.d.ts +0 -39
  235. package/build/apkParser.d.ts +0 -16
  236. package/build/apkParser.js +0 -164
  237. package/build/apkUnparser.d.ts +0 -4
  238. package/build/apkUnparser.test.js +0 -26
  239. package/build/arbitraryDosDate.d.ts +0 -2
  240. package/build/arbitraryDosDate.js +0 -8
  241. package/build/arbitraryZipEntry.d.ts +0 -3
  242. package/build/arbitraryZipEntry.js +0 -26
  243. package/build/createDisjunctionParser.d.ts +0 -2
  244. package/build/createDisjunctionParser.js +0 -47
  245. package/build/createExactParser.d.ts +0 -2
  246. package/build/createExactParser.js +0 -12
  247. package/build/createSequentialUnionParser.d.ts +0 -2
  248. package/build/createSequentialUnionParser.js +0 -69
  249. package/build/fixedLengthChunkParser.d.ts +0 -2
  250. package/build/fixedLengthChunkParser.js +0 -12
  251. package/build/fixedLengthParser.d.ts +0 -2
  252. package/build/fixedLengthParser.js +0 -12
  253. package/build/inputChunkBuffer.d.ts +0 -15
  254. package/build/inputChunkBuffer.js +0 -40
  255. package/build/inputChunkBuffer.test.js +0 -34
  256. package/build/inputCompanion.d.ts +0 -18
  257. package/build/inputCompanion.js +0 -28
  258. package/build/invariantDefined.d.ts +0 -1
  259. package/build/invariantDefined.js +0 -5
  260. package/build/invariantIdentity.d.ts +0 -3
  261. package/build/invariantIdentity.js +0 -5
  262. package/build/javaKeystoreParser.d.ts +0 -2
  263. package/build/javaKeystoreParser.js +0 -7
  264. package/build/jsonParser2.d.ts +0 -3
  265. package/build/jsonParser2.js +0 -52
  266. package/build/jsonParser2.test.js +0 -22
  267. package/build/negativeLookahead.d.ts +0 -2
  268. package/build/negativeLookahead.js +0 -18
  269. package/build/parserCompose.d.ts +0 -3
  270. package/build/parserCompose.js +0 -7
  271. package/build/parserImplementationInvariantInvariant.d.ts +0 -3
  272. package/build/parserImplementationInvariantInvariant.js +0 -15
  273. package/build/parserInvariant.d.ts +0 -4
  274. package/build/parserInvariant.js +0 -11
  275. package/build/promiseFish.d.ts +0 -1
  276. package/build/promiseFish.js +0 -3
  277. package/build/sequenceParser.d.ts +0 -3
  278. package/build/sequenceParser.js +0 -10
  279. package/build/terminatedSequenceParser.d.ts +0 -2
  280. package/build/terminatedSequenceParser.js +0 -24
  281. package/build/unparserInputCompanion.d.ts +0 -15
  282. package/build/unparserInputCompanion.js +0 -13
  283. package/build/zipEntry.d.ts +0 -28
  284. package/build/zipFile.d.ts +0 -32
  285. package/build/zipFileEntry.d.ts +0 -6
  286. package/src/apk.ts +0 -48
  287. package/src/apkParser.test.ts.snap +0 -0
  288. package/src/apkParser.ts +0 -392
  289. package/src/apkUnparser.test.ts +0 -37
  290. package/src/apkUnparser.ts +0 -120
  291. package/src/invariantDefined.ts +0 -6
  292. package/src/invariantIdentity.ts +0 -8
  293. /package/build/{apk.js → androidPackage.js} +0 -0
  294. /package/build/{apkParser.test.d.ts → androidPackageParser.test.d.ts} +0 -0
  295. /package/build/{apkUnparser.test.d.ts → androidPackageUnparser.test.d.ts} +0 -0
  296. /package/build/{arbitraryDosPermissions.d.ts → dalvikExecutableParser.test.d.ts} +0 -0
  297. /package/build/{arbitraryDosPermissions.js → dalvikExecutableParserAgainstSmaliParser.test.d.ts} +0 -0
  298. /package/build/{inputChunkBuffer.test.d.ts → elementTerminatedArrayParser.test.d.ts} +0 -0
  299. /package/build/{jsonParser2.test.d.ts → elementTerminatedSequenceArrayParser.test.d.ts} +0 -0
  300. /package/build/{parserParsingInvariant.d.ts → elementTerminatedSequenceParser.test.d.ts} +0 -0
  301. /package/build/{parserParsingInvariant.js → fixedLengthSequenceParser.test.d.ts} +0 -0
  302. /package/build/{zipEntry.js → leb128Parser.test.d.ts} +0 -0
  303. /package/build/{zipFile.js → negativeLookaheadParser.test.d.ts} +0 -0
  304. /package/build/{zipFileEntry.js → nonEmptyArrayParser.test.d.ts} +0 -0
@@ -3,8 +3,19 @@ import { createArrayParser } from './arrayParser.js';
3
3
  import { createElementParser } from './elementParser.js';
4
4
  import { createTupleParser } from './tupleParser.js';
5
5
  import { createSliceBoundedParser } from './sliceBoundedParser.js';
6
- import { runParser } from './parser.js';
6
+ import { runParser, runParserWithRemainingInput } from './parser.js';
7
7
  import { stringParserInputCompanion } from './parserInputCompanion.js';
8
+ import { createExactElementParser } from './exactElementParser.js';
9
+
10
+ async function stringFromAsyncIterable(asyncIterable: AsyncIterable<string>) {
11
+ let string = '';
12
+
13
+ for await (const chunk of asyncIterable) {
14
+ string += chunk;
15
+ }
16
+
17
+ return string;
18
+ }
8
19
 
9
20
  const anythingParser = createArrayParser(createElementParser<string>());
10
21
 
@@ -26,3 +37,34 @@ test('sliceBoundedParser', async t => {
26
37
  'a',
27
38
  ]);
28
39
  });
40
+
41
+ test('sliceBoundedParser mustConsumeAll: true fail to cosume all', async t => {
42
+ const parser = createTupleParser([
43
+ createElementParser<string>(),
44
+ createSliceBoundedParser(createArrayParser(createExactElementParser('b' as string)), 2),
45
+ createElementParser(),
46
+ ]);
47
+
48
+ await t.throwsAsync(() => runParser(parser, 'abcd', stringParserInputCompanion), {
49
+ message: /child parser must consume all input in the slice/,
50
+ });
51
+ });
52
+
53
+ test('sliceBoundedParser mustConsumeAll: false', async t => {
54
+ const parser = createTupleParser([
55
+ createElementParser<string>(),
56
+ createSliceBoundedParser(createArrayParser(createExactElementParser('b' as string)), 2, false),
57
+ createElementParser(),
58
+ ]);
59
+
60
+ const { output, remainingInput } = await runParserWithRemainingInput(parser, 'abcd', stringParserInputCompanion);
61
+
62
+ t.deepEqual(output, [
63
+ 'a',
64
+ [
65
+ 'b',
66
+ ],
67
+ 'c',
68
+ ]);
69
+ t.deepEqual(await stringFromAsyncIterable(remainingInput!), 'd');
70
+ });
@@ -3,14 +3,30 @@ import { getParserName, type Parser, setParserName } from './parser.js';
3
3
  export const createSliceBoundedParser = <Output, Sequence>(
4
4
  childParser: Parser<Output, Sequence>,
5
5
  sliceEnd: number,
6
+ mustConsumeAll: boolean = true,
6
7
  ): Parser<Output, Sequence> => {
7
8
  const sliceBoundedParser: typeof childParser = async parserContext => {
9
+ const absoluteSliceEnd = parserContext.position + sliceEnd;
10
+
8
11
  const childParserContext = parserContext.lookahead({
9
- sliceEnd: parserContext.position + sliceEnd,
12
+ sliceEnd: absoluteSliceEnd,
10
13
  });
11
14
 
12
15
  try {
13
16
  const value = await childParser(childParserContext);
17
+
18
+ childParserContext.invariant(
19
+ (
20
+ !mustConsumeAll
21
+ || childParserContext.position === absoluteSliceEnd
22
+ ),
23
+ 'child parser must consume all input in the slice (%s in total, up to position %s), instead consumed %s up to position %s',
24
+ sliceEnd,
25
+ absoluteSliceEnd,
26
+ childParserContext.position - parserContext.position,
27
+ childParserContext.position,
28
+ );
29
+
14
30
  childParserContext.unlookahead();
15
31
  return value;
16
32
  } finally {
@@ -23,6 +39,8 @@ export const createSliceBoundedParser = <Output, Sequence>(
23
39
  getParserName(childParser, 'anonymousSliceBoundedChild'),
24
40
  ',',
25
41
  sliceEnd,
42
+ ',',
43
+ mustConsumeAll,
26
44
  ')',
27
45
  ].join(''));
28
46
 
package/src/smali.ts ADDED
@@ -0,0 +1,24 @@
1
+ import fs from 'node:fs/promises';
2
+ import { execa } from 'execa';
3
+ import { temporaryFile } from 'tempy';
4
+
5
+ export async function smaliClass(smaliStream: AsyncIterable<string>) {
6
+ const inputFilePath = temporaryFile();
7
+ const outputFilePath = temporaryFile();
8
+
9
+ await fs.writeFile(inputFilePath, smaliStream);
10
+
11
+ await execa('smali', [
12
+ 'assemble',
13
+ '--output', outputFilePath,
14
+ inputFilePath,
15
+ ]);
16
+
17
+ await fs.unlink(inputFilePath);
18
+
19
+ const dex = await fs.readFile(outputFilePath);
20
+
21
+ await fs.unlink(outputFilePath);
22
+
23
+ return dex;
24
+ }
@@ -0,0 +1,132 @@
1
+ import test from 'ava';
2
+ import { stringParserInputCompanion } from './parserInputCompanion.js';
3
+ import { getParserName, Parser, runParser } from './parser.js';
4
+ import { fetchCid } from './fetchCid.js';
5
+ import { smaliAnnotationParser, smaliCodeParameterParser, smaliFieldParser, smaliParser } from './smaliParser.js';
6
+ import { hasExecutable } from './hasExecutable.js';
7
+ import { baksmaliClass } from './backsmali.js';
8
+
9
+ const hasBaksmaliPromise = hasExecutable('baksmali');
10
+
11
+ function stringParserTest<Output>(parser: Parser<Output, string>, examples: [ string, Output ][]) {
12
+ const parserName = getParserName(parser);
13
+
14
+ for (const [ input, expected ] of examples) {
15
+ test(parserName + ' ' + JSON.stringify(input), async t => {
16
+ const actual = await runParser(parser, input, stringParserInputCompanion, {
17
+ errorJoinMode: 'all',
18
+ });
19
+
20
+ t.deepEqual(actual, expected as any);
21
+ });
22
+ }
23
+ }
24
+
25
+ stringParserTest(smaliCodeParameterParser, [
26
+ [
27
+ ' .param p1\n',
28
+ {
29
+ index: 1,
30
+ prefix: 'p',
31
+ },
32
+ ],
33
+ [
34
+ ' .param p1, "savedInstanceState" # Landroid/os/Bundle;\n',
35
+ {
36
+ index: 1,
37
+ prefix: 'p',
38
+ },
39
+ ],
40
+ ]);
41
+
42
+ stringParserTest(smaliFieldParser, [
43
+ [
44
+ '.field private barcodeScannerView:Lcom/journeyapps/barcodescanner/DecoratedBarcodeView;\n',
45
+ {
46
+ accessFlags: {
47
+ abstract: false,
48
+ annotation: false,
49
+ bridge: false,
50
+ constructor: false,
51
+ declaredSynchronized: false,
52
+ enum: false,
53
+ final: false,
54
+ interface: false,
55
+ native: false,
56
+ private: true,
57
+ protected: false,
58
+ public: false,
59
+ static: false,
60
+ strict: false,
61
+ synchronized: false,
62
+ synthetic: false,
63
+ transient: false,
64
+ varargs: false,
65
+ volatile: false,
66
+ },
67
+ field: {
68
+ class: 'FILLED_LATER',
69
+ name: 'barcodeScannerView',
70
+ type: 'Lcom/journeyapps/barcodescanner/DecoratedBarcodeView;',
71
+ },
72
+ },
73
+ ],
74
+ ]);
75
+
76
+ stringParserTest(smaliAnnotationParser, [
77
+ [
78
+ ` .annotation system Ldalvik/annotation/Signature;
79
+ value = {
80
+ "<T:",
81
+ "Landroid/view/View;",
82
+ ">(I)TT;"
83
+ }
84
+ .end annotation
85
+ `,
86
+ {
87
+ type: 'Ldalvik/annotation/Signature;',
88
+ value: [
89
+ '<T:',
90
+ 'Landroid/view/View;',
91
+ '>(I)TT;',
92
+ ],
93
+ },
94
+ ],
95
+ ]);
96
+
97
+ for (const [ dexCid, smaliFilePath, shouldSnapshot ] of [
98
+ [ 'bafkreibb4gsprc3fvmnyqx6obswvm7e7wngnfj64gz65ey72r7xgyzymt4', 'pl/czak/minimal/MainActivity', true ],
99
+ [ 'bafybeiebe27ylo53trgitu6fqfbmba43c4ivxj3nt4kumsilkucpbdxtqq', 'd/m', true ],
100
+ // [ 'bafybeibbupm7uzhuq4pa674rb2amxsenbdaoijigmaf4onaodaql4mh7yy', 'com/journeyapps/barcodescanner/CaptureActivity', true ],
101
+ // [ 'bafybeicb3qajmwy6li7hche2nkucvytaxcyxhwhphmi73tgydjzmyoqoda', false ],
102
+ ] as const) {
103
+ test.serial(
104
+ 'smali from dex ' + dexCid + ' ' + smaliFilePath,
105
+ async t => {
106
+ const hasBaksmali = await hasBaksmaliPromise;
107
+
108
+ if (!hasBaksmali) {
109
+ t.pass('skipping test because baksmali is not available');
110
+
111
+ return;
112
+ }
113
+
114
+ const dexStream = await fetchCid(dexCid);
115
+
116
+ const smali = await baksmaliClass(dexStream, smaliFilePath);
117
+
118
+ const actual = await runParser(smaliParser, smali, stringParserInputCompanion, {
119
+ errorJoinMode: 'all',
120
+ });
121
+
122
+ // console.dir(actual, { depth: null });
123
+
124
+ if (shouldSnapshot) {
125
+ t.snapshot(actual);
126
+ } else {
127
+ //console.dir(actual, { depth: null });
128
+ t.pass();
129
+ }
130
+ },
131
+ );
132
+ }