@futpib/parser 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +24 -0
- package/.github/workflows/main.yml +1 -0
- package/build/androidPackageParser.js +30 -32
- package/build/arbitraryDalvikBytecode.d.ts +3 -3
- package/build/arbitraryDalvikBytecode.js +33 -27
- package/build/arbitraryDalvikExecutable.js +55 -17
- package/build/arbitraryJava.d.ts +31 -0
- package/build/arbitraryJava.js +532 -0
- package/build/arbitraryJavaScript.d.ts +3 -0
- package/build/arbitraryJavaScript.js +263 -0
- package/build/arbitraryJavascript.d.ts +3 -0
- package/build/arbitraryJavascript.js +263 -0
- package/build/arbitraryZig.d.ts +3 -0
- package/build/arbitraryZig.js +240 -0
- package/build/arbitraryZipStream.d.ts +1 -1
- package/build/arrayParser.js +72 -13
- package/build/backsmali.d.ts +4 -3
- package/build/backsmali.js +26 -6
- package/build/bash.d.ts +6 -1
- package/build/bashParser.js +131 -90
- package/build/bashParser.test.js +162 -0
- package/build/bashParserEdgeCases.test.d.ts +1 -0
- package/build/bashParserEdgeCases.test.js +117 -0
- package/build/dalvikBytecodeParser/addressConversion.d.ts +110 -0
- package/build/dalvikBytecodeParser/addressConversion.js +334 -0
- package/build/dalvikBytecodeParser/formatParsers.d.ts +7 -6
- package/build/dalvikBytecodeParser/formatParsers.js +13 -14
- package/build/dalvikBytecodeParser.d.ts +60 -31
- package/build/dalvikBytecodeParser.js +92 -35
- package/build/dalvikBytecodeParser.test-d.d.ts +1 -0
- package/build/dalvikBytecodeParser.test-d.js +268 -0
- package/build/dalvikBytecodeUnparser/formatUnparsers.d.ts +9 -8
- package/build/dalvikBytecodeUnparser/formatUnparsers.js +13 -12
- package/build/dalvikBytecodeUnparser.d.ts +2 -2
- package/build/dalvikBytecodeUnparser.js +23 -23
- package/build/dalvikBytecodeUnparser.test.js +7 -7
- package/build/dalvikExecutable.d.ts +3 -3
- package/build/dalvikExecutable.test-d.d.ts +1 -0
- package/build/dalvikExecutable.test-d.js +59 -0
- package/build/dalvikExecutableParser/typedNumbers.d.ts +18 -0
- package/build/dalvikExecutableParser/typedNumbers.js +3 -0
- package/build/dalvikExecutableParser.d.ts +2 -1
- package/build/dalvikExecutableParser.js +96 -77
- package/build/dalvikExecutableParser.test.js +24 -3
- package/build/dalvikExecutableParserAgainstSmaliParser.test.js +3 -0
- package/build/dalvikExecutableUnparser/poolScanners.d.ts +2 -2
- package/build/dalvikExecutableUnparser/sectionUnparsers.d.ts +3 -3
- package/build/dalvikExecutableUnparser/sectionUnparsers.js +26 -11
- package/build/dalvikExecutableUnparser.d.ts +2 -2
- package/build/dalvikExecutableUnparser.test.js +2 -1
- package/build/disjunctionParser.d.ts +5 -3
- package/build/disjunctionParser.js +79 -17
- package/build/disjunctionParser.test-d.d.ts +1 -0
- package/build/disjunctionParser.test-d.js +72 -0
- package/build/elementSwitchParser.d.ts +4 -0
- package/build/{exactElementSwitchParser.js → elementSwitchParser.js} +3 -4
- package/build/elementSwitchParser.test-d.d.ts +1 -0
- package/build/elementSwitchParser.test-d.js +44 -0
- package/build/exactSequenceParser.d.ts +4 -2
- package/build/exactSequenceParser.test-d.d.ts +1 -0
- package/build/exactSequenceParser.test-d.js +36 -0
- package/build/fetchCid.js +2 -66
- package/build/index.d.ts +3 -2
- package/build/index.js +2 -1
- package/build/index.test.js +16 -1
- package/build/inputReader.d.ts +10 -0
- package/build/inputReader.js +36 -0
- package/build/java.d.ts +502 -0
- package/build/java.js +2 -0
- package/build/javaKeyStoreParser.js +14 -17
- package/build/javaParser.d.ts +51 -0
- package/build/javaParser.js +1538 -0
- package/build/javaParser.test.d.ts +1 -0
- package/build/javaParser.test.js +1287 -0
- package/build/javaScript.d.ts +35 -0
- package/build/javaScript.js +1 -0
- package/build/javaScriptParser.d.ts +9 -0
- package/build/javaScriptParser.js +34 -0
- package/build/javaScriptUnparser.d.ts +3 -0
- package/build/javaScriptUnparser.js +4 -0
- package/build/javaScriptUnparser.test.d.ts +1 -0
- package/build/javaScriptUnparser.test.js +24 -0
- package/build/javaUnparser.d.ts +2 -0
- package/build/javaUnparser.js +519 -0
- package/build/javaUnparser.test.d.ts +1 -0
- package/build/javaUnparser.test.js +24 -0
- package/build/javascript.d.ts +35 -0
- package/build/javascript.js +1 -0
- package/build/javascriptParser.d.ts +9 -0
- package/build/javascriptParser.js +34 -0
- package/build/javascriptUnparser.d.ts +3 -0
- package/build/javascriptUnparser.js +4 -0
- package/build/javascriptUnparser.test.d.ts +1 -0
- package/build/javascriptUnparser.test.js +24 -0
- package/build/jsonParser.js +2 -12
- package/build/lazyMessageError.d.ts +3 -0
- package/build/lookaheadParser.js +60 -3
- package/build/negativeLookaheadParser.js +70 -11
- package/build/nonEmptyArrayParser.js +72 -13
- package/build/objectParser.d.ts +12 -0
- package/build/objectParser.js +31 -0
- package/build/objectParser.test-d.d.ts +1 -0
- package/build/objectParser.test-d.js +112 -0
- package/build/objectParser.test.d.ts +1 -0
- package/build/objectParser.test.js +55 -0
- package/build/optionalParser.js +69 -10
- package/build/parser.d.ts +4 -0
- package/build/parser.js +3 -1
- package/build/parser.test.js +114 -1
- package/build/parserConsumedSequenceParser.js +66 -7
- package/build/parserContext.d.ts +6 -0
- package/build/parserContext.js +20 -11
- package/build/parserError.d.ts +119 -27
- package/build/parserError.js +16 -8
- package/build/regexpParser.js +33 -3
- package/build/regexpParser.test.js +31 -0
- package/build/regularExpressionParser.js +35 -15
- package/build/separatedArrayParser.js +73 -14
- package/build/separatedNonEmptyArrayParser.js +73 -14
- package/build/sliceBoundedParser.js +62 -5
- package/build/smaliParser.d.ts +7 -7
- package/build/smaliParser.js +185 -268
- package/build/smaliParser.test.js +58 -0
- package/build/stringEscapes.d.ts +5 -0
- package/build/stringEscapes.js +244 -0
- package/build/symbolicExpression.d.ts +29 -0
- package/build/symbolicExpression.js +1 -0
- package/build/symbolicExpressionParser.d.ts +4 -0
- package/build/symbolicExpressionParser.js +123 -0
- package/build/symbolicExpressionParser.test.d.ts +1 -0
- package/build/symbolicExpressionParser.test.js +289 -0
- package/build/terminatedArrayParser.js +113 -38
- package/build/terminatedArrayParser.test.js +4 -2
- package/build/tupleParser.d.ts +7 -15
- package/build/tupleParser.js +1 -0
- package/build/unionParser.d.ts +5 -3
- package/build/unionParser.js +7 -2
- package/build/unionParser.test-d.d.ts +1 -0
- package/build/unionParser.test-d.js +72 -0
- package/build/unionParser.test.js +10 -11
- package/build/zig.d.ts +280 -0
- package/build/zig.js +2 -0
- package/build/zigParser.d.ts +3 -0
- package/build/zigParser.js +1119 -0
- package/build/zigParser.test.d.ts +1 -0
- package/build/zigParser.test.js +1590 -0
- package/build/zigUnparser.d.ts +2 -0
- package/build/zigUnparser.js +460 -0
- package/build/zigUnparser.test.d.ts +1 -0
- package/build/zigUnparser.test.js +24 -0
- package/build/zipParser.js +19 -32
- package/build/zipUnparser.js +19 -7
- package/build/zipUnparser.test.js +1 -1
- package/node_modules-@types/s-expression/index.d.ts +5 -0
- package/package.json +24 -6
- package/src/androidPackageParser.ts +33 -60
- package/src/arbitraryDalvikBytecode.ts +39 -31
- package/src/arbitraryDalvikExecutable.ts +65 -20
- package/src/arbitraryJava.ts +804 -0
- package/src/arbitraryJavaScript.ts +410 -0
- package/src/arbitraryZig.ts +380 -0
- package/src/arrayParser.ts +1 -3
- package/src/backsmali.ts +35 -4
- package/src/bash.ts +8 -1
- package/src/bashParser.test.ts +258 -0
- package/src/bashParser.ts +180 -143
- package/src/dalvikBytecodeParser/addressConversion.ts +496 -0
- package/src/dalvikBytecodeParser/formatParsers.ts +19 -29
- package/src/dalvikBytecodeParser.test-d.ts +310 -0
- package/src/dalvikBytecodeParser.ts +194 -69
- package/src/dalvikBytecodeUnparser/formatUnparsers.ts +27 -26
- package/src/dalvikBytecodeUnparser.test.ts +7 -7
- package/src/dalvikBytecodeUnparser.ts +31 -30
- package/src/dalvikExecutable.test-d.ts +132 -0
- package/src/dalvikExecutable.ts +3 -3
- package/src/dalvikExecutableParser/typedNumbers.ts +11 -0
- package/src/dalvikExecutableParser.test.ts +37 -3
- package/src/dalvikExecutableParser.test.ts.md +163 -2
- package/src/dalvikExecutableParser.test.ts.snap +0 -0
- package/src/dalvikExecutableParser.ts +121 -139
- package/src/dalvikExecutableParserAgainstSmaliParser.test.ts +4 -0
- package/src/dalvikExecutableUnparser/poolScanners.ts +6 -6
- package/src/dalvikExecutableUnparser/sectionUnparsers.ts +38 -14
- package/src/dalvikExecutableUnparser.test.ts +3 -2
- package/src/dalvikExecutableUnparser.ts +4 -4
- package/src/disjunctionParser.test-d.ts +105 -0
- package/src/disjunctionParser.ts +18 -15
- package/src/elementSwitchParser.test-d.ts +74 -0
- package/src/elementSwitchParser.ts +51 -0
- package/src/exactSequenceParser.test-d.ts +43 -0
- package/src/exactSequenceParser.ts +13 -8
- package/src/fetchCid.ts +2 -76
- package/src/index.test.ts +22 -1
- package/src/index.ts +7 -1
- package/src/inputReader.ts +53 -0
- package/src/java.ts +708 -0
- package/src/javaKeyStoreParser.ts +18 -32
- package/src/javaParser.test.ts +1592 -0
- package/src/javaParser.ts +2640 -0
- package/src/javaScript.ts +36 -0
- package/src/javaScriptParser.ts +57 -0
- package/src/javaScriptUnparser.test.ts +37 -0
- package/src/javaScriptUnparser.ts +7 -0
- package/src/javaUnparser.test.ts +37 -0
- package/src/javaUnparser.ts +640 -0
- package/src/jsonParser.ts +6 -27
- package/src/lookaheadParser.ts +2 -6
- package/src/negativeLookaheadParser.ts +1 -3
- package/src/nonEmptyArrayParser.ts +1 -3
- package/src/objectParser.test-d.ts +152 -0
- package/src/objectParser.test.ts +71 -0
- package/src/objectParser.ts +69 -0
- package/src/optionalParser.ts +1 -3
- package/src/parser.test.ts +151 -4
- package/src/parser.ts +11 -1
- package/src/parserConsumedSequenceParser.ts +2 -4
- package/src/parserContext.ts +26 -11
- package/src/parserError.ts +17 -3
- package/src/regexpParser.test.ts +78 -0
- package/src/regexpParser.ts +35 -3
- package/src/regularExpressionParser.ts +36 -37
- package/src/separatedArrayParser.ts +1 -3
- package/src/separatedNonEmptyArrayParser.ts +1 -3
- package/src/sliceBoundedParser.test.ts +2 -2
- package/src/sliceBoundedParser.ts +15 -19
- package/src/smaliParser.test.ts +64 -0
- package/src/smaliParser.test.ts.md +12 -12
- package/src/smaliParser.test.ts.snap +0 -0
- package/src/smaliParser.ts +246 -534
- package/src/stringEscapes.ts +253 -0
- package/src/symbolicExpression.ts +17 -0
- package/src/symbolicExpressionParser.test.ts +466 -0
- package/src/symbolicExpressionParser.ts +190 -0
- package/src/terminatedArrayParser.test.ts +9 -6
- package/src/terminatedArrayParser.ts +25 -29
- package/src/tupleParser.ts +21 -18
- package/src/unionParser.test-d.ts +105 -0
- package/src/unionParser.test.ts +18 -17
- package/src/unionParser.ts +28 -16
- package/src/zig.ts +411 -0
- package/src/zigParser.test.ts +1693 -0
- package/src/zigParser.ts +1745 -0
- package/src/zigUnparser.test.ts +37 -0
- package/src/zigUnparser.ts +615 -0
- package/src/zipParser.ts +20 -56
- package/src/zipUnparser.test.ts +1 -1
- package/src/zipUnparser.ts +22 -7
- package/tsconfig.json +2 -2
- package/build/exactElementSwitchParser.d.ts +0 -3
- package/src/exactElementSwitchParser.ts +0 -41
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import * as fc from 'fast-check';
|
|
2
|
+
const zigKeywords = new Set([
|
|
3
|
+
'addrspace', 'align', 'allowzero', 'and', 'anyframe', 'anytype',
|
|
4
|
+
'asm', 'async', 'await', 'break', 'callconv', 'catch', 'comptime',
|
|
5
|
+
'const', 'continue', 'defer', 'else', 'enum', 'errdefer', 'error',
|
|
6
|
+
'export', 'extern', 'false', 'fn', 'for', 'if', 'inline',
|
|
7
|
+
'linksection', 'noalias', 'nosuspend', 'null', 'opaque', 'or',
|
|
8
|
+
'orelse', 'packed', 'pub', 'resume', 'return', 'struct',
|
|
9
|
+
'suspend', 'switch', 'test', 'threadlocal', 'true', 'try',
|
|
10
|
+
'undefined', 'union', 'unreachable', 'var', 'volatile', 'while',
|
|
11
|
+
]);
|
|
12
|
+
const arbitraryZigIdentifier = fc.stringMatching(/^[a-zA-Z_][a-zA-Z0-9_]*$/).filter(id => !zigKeywords.has(id));
|
|
13
|
+
// Leaf expressions - safe to use as operands without precedence issues
|
|
14
|
+
const arbitraryIdentifier = fc.record({
|
|
15
|
+
type: fc.constant('Identifier'),
|
|
16
|
+
name: arbitraryZigIdentifier,
|
|
17
|
+
});
|
|
18
|
+
const arbitraryIntegerLiteral = fc.record({
|
|
19
|
+
type: fc.constant('IntegerLiteral'),
|
|
20
|
+
value: fc.nat({ max: 999 }).map(n => String(n)),
|
|
21
|
+
});
|
|
22
|
+
const arbitraryStringLiteral = fc.record({
|
|
23
|
+
type: fc.constant('StringLiteral'),
|
|
24
|
+
value: fc.oneof(fc.stringMatching(/^[a-zA-Z0-9 ]*$/), fc.constantFrom('hello\nworld', 'tab\there', 'back\\slash', 'quote\ttab\nnewline')),
|
|
25
|
+
});
|
|
26
|
+
const arbitraryCharLiteral = fc.record({
|
|
27
|
+
type: fc.constant('CharLiteral'),
|
|
28
|
+
value: fc.stringMatching(/^[a-zA-Z0-9]$/),
|
|
29
|
+
});
|
|
30
|
+
const arbitraryEnumLiteral = fc.record({
|
|
31
|
+
type: fc.constant('EnumLiteral'),
|
|
32
|
+
name: arbitraryZigIdentifier,
|
|
33
|
+
});
|
|
34
|
+
const arbitraryBoolLiteral = fc.record({
|
|
35
|
+
type: fc.constant('BoolLiteral'),
|
|
36
|
+
value: fc.boolean(),
|
|
37
|
+
});
|
|
38
|
+
const arbitraryNullLiteral = fc.constant({
|
|
39
|
+
type: 'NullLiteral',
|
|
40
|
+
});
|
|
41
|
+
const arbitraryUndefinedLiteral = fc.constant({
|
|
42
|
+
type: 'UndefinedLiteral',
|
|
43
|
+
});
|
|
44
|
+
const arbitraryLeafExpression = fc.oneof({ weight: 3, arbitrary: arbitraryIdentifier }, { weight: 2, arbitrary: arbitraryIntegerLiteral }, { weight: 1, arbitrary: arbitraryStringLiteral }, { weight: 1, arbitrary: arbitraryCharLiteral }, { weight: 1, arbitrary: arbitraryEnumLiteral }, { weight: 1, arbitrary: arbitraryBoolLiteral }, { weight: 1, arbitrary: arbitraryNullLiteral }, { weight: 1, arbitrary: arbitraryUndefinedLiteral });
|
|
45
|
+
// Type expressions (simple ones for use in declarations)
|
|
46
|
+
const arbitrarySimpleTypeExpression = arbitraryIdentifier;
|
|
47
|
+
const arbitraryOptionalType = fc.record({
|
|
48
|
+
type: fc.constant('OptionalType'),
|
|
49
|
+
child: arbitrarySimpleTypeExpression,
|
|
50
|
+
});
|
|
51
|
+
const arbitraryPointerType = fc.record({
|
|
52
|
+
type: fc.constant('PointerType'),
|
|
53
|
+
size: fc.oneof(fc.constant('one'), fc.constant('many'), fc.constant('slice')),
|
|
54
|
+
isConst: fc.boolean(),
|
|
55
|
+
child: arbitrarySimpleTypeExpression,
|
|
56
|
+
});
|
|
57
|
+
const arbitraryErrorUnionType = fc.record({
|
|
58
|
+
type: fc.constant('ErrorUnionType'),
|
|
59
|
+
error: arbitrarySimpleTypeExpression,
|
|
60
|
+
payload: arbitrarySimpleTypeExpression,
|
|
61
|
+
});
|
|
62
|
+
const arbitraryTypeExpression = fc.oneof({ weight: 4, arbitrary: arbitrarySimpleTypeExpression }, { weight: 1, arbitrary: arbitraryOptionalType }, { weight: 1, arbitrary: arbitraryPointerType }, { weight: 1, arbitrary: arbitraryErrorUnionType });
|
|
63
|
+
// Compound expressions (use leaf operands to avoid precedence issues)
|
|
64
|
+
const arbitraryBuiltinCallExpr = fc.record({
|
|
65
|
+
type: fc.constant('BuiltinCallExpr'),
|
|
66
|
+
name: arbitraryZigIdentifier,
|
|
67
|
+
args: fc.array(arbitraryLeafExpression, { maxLength: 2 }),
|
|
68
|
+
});
|
|
69
|
+
const arbitraryFieldAccessExpr = fc.record({
|
|
70
|
+
type: fc.constant('FieldAccessExpr'),
|
|
71
|
+
operand: arbitraryIdentifier,
|
|
72
|
+
member: arbitraryZigIdentifier,
|
|
73
|
+
});
|
|
74
|
+
const arbitraryCallExpr = fc.record({
|
|
75
|
+
type: fc.constant('CallExpr'),
|
|
76
|
+
callee: arbitraryIdentifier,
|
|
77
|
+
args: fc.array(arbitraryLeafExpression, { maxLength: 2 }),
|
|
78
|
+
});
|
|
79
|
+
const arbitraryIndexExpr = fc.record({
|
|
80
|
+
type: fc.constant('IndexExpr'),
|
|
81
|
+
operand: arbitraryIdentifier,
|
|
82
|
+
index: arbitraryLeafExpression,
|
|
83
|
+
});
|
|
84
|
+
const arbitraryGroupedExpr = fc.record({
|
|
85
|
+
type: fc.constant('GroupedExpr'),
|
|
86
|
+
inner: arbitraryLeafExpression,
|
|
87
|
+
});
|
|
88
|
+
const arbitraryErrorSetExpr = fc.record({
|
|
89
|
+
type: fc.constant('ErrorSetExpr'),
|
|
90
|
+
names: fc.array(arbitraryZigIdentifier, { minLength: 1, maxLength: 3 }),
|
|
91
|
+
});
|
|
92
|
+
const arbitraryStructInitExpr = fc.record({
|
|
93
|
+
type: fc.constant('StructInitExpr'),
|
|
94
|
+
fields: fc.array(fc.record({
|
|
95
|
+
type: fc.constant('StructInitField'),
|
|
96
|
+
name: arbitraryZigIdentifier,
|
|
97
|
+
value: arbitraryLeafExpression,
|
|
98
|
+
}), { maxLength: 3 }),
|
|
99
|
+
});
|
|
100
|
+
const arbitraryArrayInitExpr = fc.record({
|
|
101
|
+
type: fc.constant('ArrayInitExpr'),
|
|
102
|
+
elements: fc.array(arbitraryLeafExpression, { maxLength: 3 }),
|
|
103
|
+
});
|
|
104
|
+
const arbitraryExpression = fc.oneof({ weight: 5, arbitrary: arbitraryLeafExpression }, { weight: 1, arbitrary: arbitraryBuiltinCallExpr }, { weight: 1, arbitrary: arbitraryFieldAccessExpr }, { weight: 1, arbitrary: arbitraryCallExpr }, { weight: 1, arbitrary: arbitraryIndexExpr }, { weight: 1, arbitrary: arbitraryGroupedExpr }, { weight: 1, arbitrary: arbitraryErrorSetExpr }, { weight: 1, arbitrary: arbitraryStructInitExpr }, { weight: 1, arbitrary: arbitraryArrayInitExpr });
|
|
105
|
+
// Expressions safe to use in statement positions (don't start with keywords,
|
|
106
|
+
// which would cause the parser's while/for/block label detector to throw
|
|
107
|
+
// a non-recoverable error from zigIdentifierParser).
|
|
108
|
+
const arbitraryNonKeywordLeafExpression = fc.oneof({ weight: 3, arbitrary: arbitraryIdentifier }, { weight: 2, arbitrary: arbitraryIntegerLiteral }, { weight: 1, arbitrary: arbitraryStringLiteral }, { weight: 1, arbitrary: arbitraryCharLiteral }, { weight: 1, arbitrary: arbitraryEnumLiteral });
|
|
109
|
+
const arbitraryStatementSafeExpression = fc.oneof({ weight: 5, arbitrary: arbitraryNonKeywordLeafExpression }, { weight: 1, arbitrary: arbitraryBuiltinCallExpr }, { weight: 1, arbitrary: arbitraryFieldAccessExpr }, { weight: 1, arbitrary: arbitraryCallExpr }, { weight: 1, arbitrary: arbitraryIndexExpr }, { weight: 1, arbitrary: arbitraryGroupedExpr });
|
|
110
|
+
// Statements
|
|
111
|
+
// Expression statements are bare expressions (no wrapper)
|
|
112
|
+
const arbitraryExprStmt = arbitraryStatementSafeExpression;
|
|
113
|
+
const arbitraryReturnStmt = fc.oneof(fc.constant({ type: 'ReturnStmt' }), fc.record({
|
|
114
|
+
type: fc.constant('ReturnStmt'),
|
|
115
|
+
value: arbitraryLeafExpression,
|
|
116
|
+
}));
|
|
117
|
+
const arbitraryBreakStmt = fc.constant({
|
|
118
|
+
type: 'BreakStmt',
|
|
119
|
+
});
|
|
120
|
+
const arbitraryContinueStmt = fc.constant({
|
|
121
|
+
type: 'ContinueStmt',
|
|
122
|
+
});
|
|
123
|
+
const arbitraryVarDeclStmt = fc.record({
|
|
124
|
+
type: fc.constant('VarDecl'),
|
|
125
|
+
isConst: fc.boolean(),
|
|
126
|
+
isPub: fc.constant(false),
|
|
127
|
+
isExtern: fc.constant(false),
|
|
128
|
+
isComptime: fc.constant(false),
|
|
129
|
+
isThreadlocal: fc.constant(false),
|
|
130
|
+
name: arbitraryZigIdentifier,
|
|
131
|
+
}).chain(base => fc.oneof(
|
|
132
|
+
// With type and init
|
|
133
|
+
fc.record({
|
|
134
|
+
typeExpr: arbitraryTypeExpression,
|
|
135
|
+
initExpr: arbitraryLeafExpression,
|
|
136
|
+
}).map(extra => ({ ...base, ...extra })),
|
|
137
|
+
// With init only
|
|
138
|
+
fc.record({
|
|
139
|
+
initExpr: arbitraryLeafExpression,
|
|
140
|
+
}).map(extra => ({ ...base, ...extra })),
|
|
141
|
+
// With type only (extern style)
|
|
142
|
+
fc.record({
|
|
143
|
+
typeExpr: arbitraryTypeExpression,
|
|
144
|
+
}).map(extra => ({ ...base, isExtern: true, ...extra }))));
|
|
145
|
+
const arbitraryAssignStmt = fc.record({
|
|
146
|
+
type: fc.constant('AssignStmt'),
|
|
147
|
+
target: arbitraryIdentifier,
|
|
148
|
+
operator: fc.oneof(fc.constant('='), fc.constant('+='), fc.constant('-='), fc.constant('*=')),
|
|
149
|
+
value: arbitraryLeafExpression,
|
|
150
|
+
});
|
|
151
|
+
const arbitraryBlockStmt = fc.record({
|
|
152
|
+
type: fc.constant('BlockExpr'),
|
|
153
|
+
statements: fc.constant([]),
|
|
154
|
+
});
|
|
155
|
+
const arbitraryDeferStmt = fc.record({
|
|
156
|
+
type: fc.constant('DeferStmt'),
|
|
157
|
+
isErrdefer: fc.boolean(),
|
|
158
|
+
body: arbitraryStatementSafeExpression,
|
|
159
|
+
});
|
|
160
|
+
const arbitraryStatement = fc.oneof({ weight: 2, arbitrary: arbitraryExprStmt }, { weight: 2, arbitrary: arbitraryVarDeclStmt }, { weight: 2, arbitrary: arbitraryReturnStmt }, { weight: 1, arbitrary: arbitraryAssignStmt }, { weight: 1, arbitrary: arbitraryBreakStmt }, { weight: 1, arbitrary: arbitraryContinueStmt }, { weight: 1, arbitrary: arbitraryBlockStmt }, { weight: 1, arbitrary: arbitraryDeferStmt });
|
|
161
|
+
// Function parameters
|
|
162
|
+
const arbitraryFnParam = fc.oneof(
|
|
163
|
+
// Named parameter
|
|
164
|
+
fc.record({
|
|
165
|
+
type: fc.constant('FnParam'),
|
|
166
|
+
name: arbitraryZigIdentifier,
|
|
167
|
+
isComptime: fc.constant(false),
|
|
168
|
+
isNoalias: fc.constant(false),
|
|
169
|
+
typeExpr: arbitraryTypeExpression,
|
|
170
|
+
}),
|
|
171
|
+
// Unnamed parameter
|
|
172
|
+
fc.record({
|
|
173
|
+
type: fc.constant('FnParam'),
|
|
174
|
+
isComptime: fc.constant(false),
|
|
175
|
+
isNoalias: fc.constant(false),
|
|
176
|
+
typeExpr: arbitraryTypeExpression,
|
|
177
|
+
}));
|
|
178
|
+
// Block expression
|
|
179
|
+
const arbitraryBlockExpr = fc.record({
|
|
180
|
+
type: fc.constant('BlockExpr'),
|
|
181
|
+
statements: fc.array(arbitraryStatement, { maxLength: 3 }),
|
|
182
|
+
});
|
|
183
|
+
// Top-level declarations
|
|
184
|
+
const arbitraryFnDecl = fc.oneof(
|
|
185
|
+
// Function with body
|
|
186
|
+
fc.record({
|
|
187
|
+
type: fc.constant('FnDecl'),
|
|
188
|
+
isPub: fc.boolean(),
|
|
189
|
+
isExtern: fc.constant(false),
|
|
190
|
+
isExport: fc.constant(false),
|
|
191
|
+
isInline: fc.constant(false),
|
|
192
|
+
isComptime: fc.constant(false),
|
|
193
|
+
name: arbitraryZigIdentifier,
|
|
194
|
+
params: fc.array(arbitraryFnParam, { maxLength: 2 }),
|
|
195
|
+
returnType: arbitraryTypeExpression,
|
|
196
|
+
body: arbitraryBlockExpr,
|
|
197
|
+
}),
|
|
198
|
+
// Extern function (no body)
|
|
199
|
+
fc.record({
|
|
200
|
+
type: fc.constant('FnDecl'),
|
|
201
|
+
isPub: fc.boolean(),
|
|
202
|
+
isExtern: fc.constant(true),
|
|
203
|
+
isExport: fc.constant(false),
|
|
204
|
+
isInline: fc.constant(false),
|
|
205
|
+
isComptime: fc.constant(false),
|
|
206
|
+
name: arbitraryZigIdentifier,
|
|
207
|
+
params: fc.array(arbitraryFnParam, { maxLength: 2 }),
|
|
208
|
+
returnType: arbitraryTypeExpression,
|
|
209
|
+
}));
|
|
210
|
+
const arbitraryVarDecl = fc.record({
|
|
211
|
+
type: fc.constant('VarDecl'),
|
|
212
|
+
isConst: fc.boolean(),
|
|
213
|
+
isPub: fc.boolean(),
|
|
214
|
+
isExtern: fc.constant(false),
|
|
215
|
+
isComptime: fc.constant(false),
|
|
216
|
+
isThreadlocal: fc.constant(false),
|
|
217
|
+
name: arbitraryZigIdentifier,
|
|
218
|
+
}).chain(base => fc.oneof(
|
|
219
|
+
// With type and init
|
|
220
|
+
fc.record({
|
|
221
|
+
typeExpr: arbitraryTypeExpression,
|
|
222
|
+
initExpr: arbitraryLeafExpression,
|
|
223
|
+
}).map(extra => ({ ...base, ...extra })),
|
|
224
|
+
// With init only
|
|
225
|
+
fc.record({
|
|
226
|
+
initExpr: arbitraryLeafExpression,
|
|
227
|
+
}).map(extra => ({ ...base, ...extra }))));
|
|
228
|
+
const arbitraryTestDecl = fc.oneof(fc.record({
|
|
229
|
+
type: fc.constant('TestDecl'),
|
|
230
|
+
name: fc.stringMatching(/^[a-zA-Z0-9 ]+$/),
|
|
231
|
+
body: arbitraryBlockExpr,
|
|
232
|
+
}), fc.record({
|
|
233
|
+
type: fc.constant('TestDecl'),
|
|
234
|
+
body: arbitraryBlockExpr,
|
|
235
|
+
}));
|
|
236
|
+
const arbitraryContainerMember = fc.oneof({ weight: 3, arbitrary: arbitraryFnDecl }, { weight: 3, arbitrary: arbitraryVarDecl }, { weight: 1, arbitrary: arbitraryTestDecl });
|
|
237
|
+
export const arbitraryZigRoot = fc.record({
|
|
238
|
+
type: fc.constant('Root'),
|
|
239
|
+
members: fc.array(arbitraryContainerMember, { minLength: 1, maxLength: 4 }),
|
|
240
|
+
});
|
|
@@ -2,4 +2,4 @@ import { type ZipEntry } from './zip.js';
|
|
|
2
2
|
export declare const arbitraryZipStream: import("fast-check").Arbitrary<readonly [{
|
|
3
3
|
comment: string;
|
|
4
4
|
entries: ZipEntry[];
|
|
5
|
-
}, ReadableStream<Uint8Array<ArrayBufferLike>>]>;
|
|
5
|
+
}, import("stream/web").ReadableStream<Uint8Array<ArrayBufferLike>>]>;
|
package/build/arrayParser.js
CHANGED
|
@@ -1,27 +1,86 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
1
53
|
import { getParserName, setParserName } from './parser.js';
|
|
2
54
|
import { isParserParsingFailedError } from './parserError.js';
|
|
3
55
|
export const createArrayParser = (elementParser) => {
|
|
4
56
|
const arrayParser = async (parserContext) => {
|
|
5
57
|
const elements = [];
|
|
6
58
|
while (true) {
|
|
7
|
-
const
|
|
8
|
-
const initialPosition = elementParserContext.position;
|
|
59
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
9
60
|
try {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
61
|
+
const elementParserContext = __addDisposableResource(env_1, parserContext.lookahead(), false);
|
|
62
|
+
const initialPosition = elementParserContext.position;
|
|
63
|
+
try {
|
|
64
|
+
const element = await elementParser(elementParserContext);
|
|
65
|
+
if (elementParserContext.position === initialPosition) {
|
|
66
|
+
return elements;
|
|
67
|
+
}
|
|
68
|
+
elements.push(element);
|
|
69
|
+
elementParserContext.unlookahead();
|
|
13
70
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return elements;
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (isParserParsingFailedError(error)) {
|
|
73
|
+
return elements;
|
|
74
|
+
}
|
|
75
|
+
throw error;
|
|
20
76
|
}
|
|
21
|
-
|
|
77
|
+
}
|
|
78
|
+
catch (e_1) {
|
|
79
|
+
env_1.error = e_1;
|
|
80
|
+
env_1.hasError = true;
|
|
22
81
|
}
|
|
23
82
|
finally {
|
|
24
|
-
|
|
83
|
+
__disposeResources(env_1);
|
|
25
84
|
}
|
|
26
85
|
}
|
|
27
86
|
};
|
package/build/backsmali.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
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
|
|
1
|
+
export declare function baksmaliClass(dexStream: Uint8Array | AsyncIterable<Uint8Array>, smaliFilePath: string, dexEntry?: string): Promise<string>;
|
|
2
|
+
export declare function backsmaliSmaliIsolateClass(dexStream: Uint8Array | AsyncIterable<Uint8Array>, smaliFilePath: string, dexEntry?: string): Promise<Uint8Array>;
|
|
3
|
+
export declare function baksmaliListClasses(dexStream: Uint8Array | AsyncIterable<Uint8Array>, dexEntry?: string): Promise<string[]>;
|
|
4
|
+
export declare function baksmaliListDexFiles(apkStream: Uint8Array | AsyncIterable<Uint8Array>): Promise<string[]>;
|
package/build/backsmali.js
CHANGED
|
@@ -3,17 +3,18 @@ import path from 'node:path';
|
|
|
3
3
|
import { execa } from 'execa';
|
|
4
4
|
import { temporaryDirectory, temporaryFile } from 'tempy';
|
|
5
5
|
import { smaliClass } from './smali.js';
|
|
6
|
-
export async function baksmaliClass(dexStream, smaliFilePath) {
|
|
6
|
+
export async function baksmaliClass(dexStream, smaliFilePath, dexEntry) {
|
|
7
7
|
const inputFilePath = temporaryFile();
|
|
8
8
|
const outputDirectoryPath = temporaryDirectory();
|
|
9
9
|
await fs.writeFile(inputFilePath, dexStream);
|
|
10
|
+
const inputPath = dexEntry ? `${inputFilePath}/${dexEntry}` : inputFilePath;
|
|
10
11
|
await execa('baksmali', [
|
|
11
12
|
'disassemble',
|
|
12
13
|
'--classes',
|
|
13
14
|
'L' + smaliFilePath + ';',
|
|
14
15
|
'--output',
|
|
15
16
|
outputDirectoryPath,
|
|
16
|
-
|
|
17
|
+
inputPath,
|
|
17
18
|
]);
|
|
18
19
|
await fs.unlink(inputFilePath);
|
|
19
20
|
const smaliFilePath_ = path.join(outputDirectoryPath, smaliFilePath + '.smali');
|
|
@@ -23,17 +24,18 @@ export async function baksmaliClass(dexStream, smaliFilePath) {
|
|
|
23
24
|
});
|
|
24
25
|
return smali;
|
|
25
26
|
}
|
|
26
|
-
export async function backsmaliSmaliIsolateClass(dexStream, smaliFilePath) {
|
|
27
|
-
const smali = await baksmaliClass(dexStream, smaliFilePath);
|
|
27
|
+
export async function backsmaliSmaliIsolateClass(dexStream, smaliFilePath, dexEntry) {
|
|
28
|
+
const smali = await baksmaliClass(dexStream, smaliFilePath, dexEntry);
|
|
28
29
|
return smaliClass(smali);
|
|
29
30
|
}
|
|
30
|
-
export async function baksmaliListClasses(dexStream) {
|
|
31
|
+
export async function baksmaliListClasses(dexStream, dexEntry) {
|
|
31
32
|
const inputFilePath = temporaryFile();
|
|
32
33
|
await fs.writeFile(inputFilePath, dexStream);
|
|
34
|
+
const inputPath = dexEntry ? `${inputFilePath}/${dexEntry}` : inputFilePath;
|
|
33
35
|
const result = await execa('baksmali', [
|
|
34
36
|
'list',
|
|
35
37
|
'classes',
|
|
36
|
-
|
|
38
|
+
inputPath,
|
|
37
39
|
]);
|
|
38
40
|
await fs.unlink(inputFilePath);
|
|
39
41
|
if (result.stderr) {
|
|
@@ -48,3 +50,21 @@ export async function baksmaliListClasses(dexStream) {
|
|
|
48
50
|
.replace(/;$/, '')));
|
|
49
51
|
return classes;
|
|
50
52
|
}
|
|
53
|
+
export async function baksmaliListDexFiles(apkStream) {
|
|
54
|
+
const inputFilePath = temporaryFile();
|
|
55
|
+
await fs.writeFile(inputFilePath, apkStream);
|
|
56
|
+
const result = await execa('baksmali', [
|
|
57
|
+
'list',
|
|
58
|
+
'dex',
|
|
59
|
+
inputFilePath,
|
|
60
|
+
]);
|
|
61
|
+
await fs.unlink(inputFilePath);
|
|
62
|
+
if (result.stderr) {
|
|
63
|
+
throw new Error(`baksmali error: ${result.stderr}`);
|
|
64
|
+
}
|
|
65
|
+
const dexFiles = result.stdout
|
|
66
|
+
.split('\n')
|
|
67
|
+
.filter(line => line.trim())
|
|
68
|
+
.map(line => line.trim());
|
|
69
|
+
return dexFiles;
|
|
70
|
+
}
|
package/build/bash.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type BashWord = {
|
|
2
2
|
parts: BashWordPart[];
|
|
3
3
|
};
|
|
4
|
-
export type BashWordPart = BashWordPartLiteral | BashWordPartSingleQuoted | BashWordPartDoubleQuoted | BashWordPartVariable | BashWordPartVariableBraced | BashWordPartCommandSubstitution | BashWordPartBacktickSubstitution | BashWordPartArithmeticExpansion;
|
|
4
|
+
export type BashWordPart = BashWordPartLiteral | BashWordPartSingleQuoted | BashWordPartDoubleQuoted | BashWordPartVariable | BashWordPartVariableBraced | BashWordPartCommandSubstitution | BashWordPartBacktickSubstitution | BashWordPartArithmeticExpansion | BashWordPartProcessSubstitution;
|
|
5
5
|
export type BashWordPartLiteral = {
|
|
6
6
|
type: 'literal';
|
|
7
7
|
value: string;
|
|
@@ -36,6 +36,11 @@ export type BashWordPartArithmeticExpansion = {
|
|
|
36
36
|
type: 'arithmeticExpansion';
|
|
37
37
|
expression: string;
|
|
38
38
|
};
|
|
39
|
+
export type BashWordPartProcessSubstitution = {
|
|
40
|
+
type: 'processSubstitution';
|
|
41
|
+
direction: '<' | '>';
|
|
42
|
+
command: BashCommand;
|
|
43
|
+
};
|
|
39
44
|
export type BashRedirect = {
|
|
40
45
|
fd?: number;
|
|
41
46
|
operator: '>' | '>>' | '<' | '<<' | '<<<' | '>&' | '<&' | '>|';
|