Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 8 additions & 85 deletions DALVIK_MISSING_PARSERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,10 @@ 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

### 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

- [ ] **Format 31c** (const-string/jumbo)
- **Description:** vAA, thing@BBBBBBBB - Constant pool index with 8-bit register
- **Size:** 6 bytes (3 units)
- **Syntax:** `AA|op BBBBlo BBBBhi`
- **Use case:** Large constant pool references (> 65535 items)
## Missing Format Parsers

### Method Invocation Formats (Deprecated/Optimized)

Expand Down Expand Up @@ -88,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:

Expand All @@ -115,66 +90,14 @@ For each format parser, the following should be implemented:

### Example Implementation Pattern

```typescript
type DalvikBytecodeFormat11n = {
value: number;
registers: number[];
};

export const dalvikBytecodeFormat11nParser: Parser<DalvikBytecodeFormat11n, Uint8Array> = 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

- [Android Dalvik Bytecode Format](https://source.android.com/docs/core/runtime/dalvik-bytecode)
- [Dalvik Instruction Formats](https://source.android.com/docs/core/runtime/instruction-formats)
- [DEX File Format Specification](https://source.android.com/docs/core/runtime/dex-format)

## Current Implementation Status

### Implemented Formats (23/32)

- ✓ Format 10t
- ✓ Format 10x
- ✓ Format 11n
- ✓ Format 11x
- ✓ Format 12x
- ✓ Format 20t
- ✓ Format 21c
- ✓ Format 21h
- ✓ Format 21s
- ✓ Format 21t
- ✓ Format 22b
- ✓ Format 22c
- ✓ Format 22s
- ✓ Format 22t
- ✓ Format 22x
- ✓ Format 23x
- ✓ Format 30t
- ✓ Format 31i
- ✓ Format 31t
- ✓ Format 32x
- ✓ Format 35c
- ✓ Format 3rc
- ✓ Format 51l

### Not Implemented Formats (9/32)
- ✗ Format 20bc
- ✗ Format 22cs
- ✗ Format 31c
- ✗ Format 35mi
- ✗ Format 35ms
- ✗ Format 3rmi
- ✗ Format 3rms
- ✗ Format 45cc
- ✗ Format 4rcc

---

*Last updated: 2025-11-09*
24 changes: 24 additions & 0 deletions src/dalvikBytecodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
createDalvikBytecodeFormat22sParser,
createDalvikBytecodeFormat22tParser,
dalvikBytecodeFormat23xParser,
createDalvikBytecodeFormat31cParser,
dalvikBytecodeFormat31iParser,
dalvikBytecodeFormat31tParser,
createDalvikBytecodeFormat35cParser,
Expand Down Expand Up @@ -1605,6 +1606,28 @@ const dalvikBytecodeOperationConstStringParser: Parser<DalvikBytecodeOperationCo

setParserName(dalvikBytecodeOperationConstStringParser, 'dalvikBytecodeOperationConstStringParser');

type DalvikBytecodeOperationConstStringJumbo = {
operation: 'const-string/jumbo';
stringIndex: IndexIntoStringIds;
registers: number[];
};

const dalvikBytecodeOperationConstStringJumboParser: Parser<DalvikBytecodeOperationConstStringJumbo, Uint8Array> = 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;
Expand Down Expand Up @@ -2195,6 +2218,7 @@ const dalvikBytecodeOperationParser: Parser<DalvikBytecodeOperation | undefined,
dalvikBytecodeOperationStaticFieldParser,

dalvikBytecodeOperationConstStringParser,
dalvikBytecodeOperationConstStringJumboParser,
dalvikBytecodeOperationConstMethodHandleParser,
dalvikBytecodeOperationConstClassParser,

Expand Down
27 changes: 26 additions & 1 deletion src/dalvikBytecodeParser/formatParsers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Iso } from "monocle-ts";
import { byteParser, intParser, longParser, shortParser, ubyteParser, ushortParser } from "../dalvikExecutableParser/typeParsers.js";
import { byteParser, intParser, longParser, shortParser, ubyteParser, uintParser, ushortParser } from "../dalvikExecutableParser/typeParsers.js";
import { createElementParser } from "../elementParser.js";
import { Parser, setParserName } from "../parser.js";
import { promiseCompose } from "../promiseCompose.js";
Expand Down Expand Up @@ -366,6 +366,31 @@ export const dalvikBytecodeFormat31iParser: Parser<DalvikBytecodeFormat31i, Uint
}),
);

type DalvikBytecodeFormat31c<Index> = {
index: Index;
registers: number[];
};

export const createDalvikBytecodeFormat31cParser = <Index>({
isoIndex,
}: {
isoIndex: Iso<Index, number>;
}): Parser<DalvikBytecodeFormat31c<Index>, Uint8Array> => promiseCompose(
createTupleParser([
ubyteParser,
uintParser,
]),
([
register0,
index,
]) => ({
index: isoIndex.wrap(index),
registers: [
register0,
],
}),
);

type DalvikBytecodeFormat31t = {
branchOffset: number;
registers: number[];
Expand Down