From f82699bedeff6259338eb04745d711ecaa306aef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 9 Nov 2025 18:56:46 +0000 Subject: [PATCH 1/3] Initial plan From 9db409be803254842c69da9dca34d6fc775e627e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 9 Nov 2025 19:06:27 +0000 Subject: [PATCH 2/3] Implement Format 31c (const-string/jumbo) parser for Dalvik bytecode Co-authored-by: futpib <4330357+futpib@users.noreply.github.com> --- DALVIK_MISSING_PARSERS.md | 16 ++++++++------ src/dalvikBytecodeParser.ts | 24 ++++++++++++++++++++ src/dalvikBytecodeParser/formatParsers.ts | 27 ++++++++++++++++++++++- 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/DALVIK_MISSING_PARSERS.md b/DALVIK_MISSING_PARSERS.md index 83a16fa..5d2c768 100644 --- a/DALVIK_MISSING_PARSERS.md +++ b/DALVIK_MISSING_PARSERS.md @@ -7,8 +7,8 @@ Reference: [Android Dalvik Bytecode Specification](https://source.android.com/do ## Implementation Status **Total formats:** 32 -**Implemented:** 23 -**Missing:** 9 +**Implemented:** 24 +**Missing:** 8 ## Missing Format Parsers Checklist @@ -26,11 +26,13 @@ Reference: [Android Dalvik Bytecode Specification](https://source.android.com/do - **Syntax:** `AA|op BBBBlo BBBBhi` - **Use case:** Wide (64-bit) constant values -- [ ] **Format 31c** (const-string/jumbo) - - **Description:** vAA, thing@BBBBBBBB - Constant pool index with 8-bit register +- [x] **Format 31c** (const-string/jumbo) - ✅ IMPLEMENTED + - **Description:** vAA, thing@BBBBBBBB - Constant pool index with 8-bit register and 32-bit index - **Size:** 6 bytes (3 units) - **Syntax:** `AA|op BBBBlo BBBBhi` - **Use case:** Large constant pool references (> 65535 items) + - **Opcode:** 0x1b + - **Implementation:** `createDalvikBytecodeFormat31cParser` in `src/dalvikBytecodeParser/formatParsers.ts` ### Method Invocation Formats (Deprecated/Optimized) @@ -138,7 +140,7 @@ export const dalvikBytecodeFormat11nParser: Parser = promiseCompose( + createTupleParser([ + createExactElementParser(0x1b), + createDalvikBytecodeFormat31cParser({ + isoIndex: isoIndexIntoStringIds, + }), + ]), + ([ _opcode, { index, registers } ]) => ({ + operation: 'const-string/jumbo', + stringIndex: index, + registers, + }), +); + +setParserName(dalvikBytecodeOperationConstStringJumboParser, 'dalvikBytecodeOperationConstStringJumboParser'); + type DalvikBytecodeOperationConstMethodHandle = { operation: 'const-method-handle'; methodIndex: IndexIntoMethodIds; @@ -2195,6 +2218,7 @@ const dalvikBytecodeOperationParser: Parser = { + index: Index; + registers: number[]; +}; + +export const createDalvikBytecodeFormat31cParser = ({ + isoIndex, +}: { + isoIndex: Iso; +}): Parser, Uint8Array> => promiseCompose( + createTupleParser([ + ubyteParser, + uintParser, + ]), + ([ + register0, + index, + ]) => ({ + index: isoIndex.wrap(index), + registers: [ + register0, + ], + }), +); + type DalvikBytecodeFormat31t = { branchOffset: number; registers: number[]; From 7f00487a0a2a317ab31de36c01458f9a35862a5f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 9 Nov 2025 19:15:48 +0000 Subject: [PATCH 3/3] Remove implemented formats from DALVIK_MISSING_PARSERS.md, keep only missing ones Co-authored-by: futpib <4330357+futpib@users.noreply.github.com> --- DALVIK_MISSING_PARSERS.md | 91 +++------------------------------------ 1 file changed, 6 insertions(+), 85 deletions(-) diff --git a/DALVIK_MISSING_PARSERS.md b/DALVIK_MISSING_PARSERS.md index 5d2c768..c973432 100644 --- a/DALVIK_MISSING_PARSERS.md +++ b/DALVIK_MISSING_PARSERS.md @@ -10,29 +10,7 @@ Reference: [Android Dalvik Bytecode Specification](https://source.android.com/do **Implemented:** 24 **Missing:** 8 -## Missing Format Parsers Checklist - -### High Priority Formats - -- [x] **Format 11n** (const/4) - ✅ IMPLEMENTED - - **Description:** vA, #+B - Immediate constant with 4-bit register and 4-bit signed immediate value - - **Size:** 2 bytes (1 unit) - - **Syntax:** `AA|op BBBB` - - **Use case:** Small constant values (e.g., `const/4`) - -- [x] **Format 51l** (const-wide) - ✅ IMPLEMENTED - - **Description:** vAA, #+BBBBBBBBBBBBBBBB - 64-bit immediate constant - - **Size:** 10 bytes (5 units) - - **Syntax:** `AA|op BBBBlo BBBBhi` - - **Use case:** Wide (64-bit) constant values - -- [x] **Format 31c** (const-string/jumbo) - ✅ IMPLEMENTED - - **Description:** vAA, thing@BBBBBBBB - Constant pool index with 8-bit register and 32-bit index - - **Size:** 6 bytes (3 units) - - **Syntax:** `AA|op BBBBlo BBBBhi` - - **Use case:** Large constant pool references (> 65535 items) - - **Opcode:** 0x1b - - **Implementation:** `createDalvikBytecodeFormat31cParser` in `src/dalvikBytecodeParser/formatParsers.ts` +## Missing Format Parsers ### Method Invocation Formats (Deprecated/Optimized) @@ -90,22 +68,17 @@ Reference: [Android Dalvik Bytecode Specification](https://source.android.com/do - **Syntax:** `AA|op BBBB CCCC HHHH` - **Use case:** Range version of polymorphic invocation -## Implementation Notes - -### Priority Recommendations +## Priority Recommendations -1. **Immediate Priority:** - - Format 31c - Needed for large DEX files with many string/type references - -2. **Medium Priority:** +1. **Medium Priority:** - Format 45cc and 4rcc - Required for Android 8.0+ features (method handles) - Format 20bc - Needed for complete verification error handling -3. **Low Priority (Deprecated):** +2. **Low Priority (Deprecated):** - Formats 35mi, 35ms, 3rmi, 3rms, 22cs - These are deprecated optimization formats - Only implement if parsing legacy/optimized DEX files is required -### Implementation Guidelines +## Implementation Guidelines For each format parser, the following should be implemented: @@ -117,20 +90,7 @@ For each format parser, the following should be implemented: ### Example Implementation Pattern -```typescript -type DalvikBytecodeFormat11n = { - value: number; - registers: number[]; -}; - -export const dalvikBytecodeFormat11nParser: Parser = promiseCompose( - nibblesParser, - ([value, register0]) => ({ - value: value << 28 >> 28, // Sign extend 4-bit value - registers: [register0], - }), -); -``` +See existing parsers in `src/dalvikBytecodeParser/formatParsers.ts` for reference. ## References @@ -138,45 +98,6 @@ export const dalvikBytecodeFormat11nParser: Parser