Skip to content

Latest commit

 

History

History
50 lines (37 loc) · 1.88 KB

README.md

File metadata and controls

50 lines (37 loc) · 1.88 KB

Rust Dalvik VM

Introduction

This is a project I'm writing purely for educational purposes.

Plan

  • Parse DEX file (I'm aware of dexparser and dex crates, but I want to do it myself to better understand DEX file structure)
  • Be able to interpret simple DEX file (hello.dex in tests/vm/hello.dex, compiled from tests/interpreter/hello.smali)
  • Add more tests for DEX file parser.
  • Fix endianness support in DEX file parser. (currently it's only partial).
  • Memory allocations?
  • Garbage collection?
  • JIT?
  • AOT?
  • JNI?
  • Debugging?
  • Something else I'm currently not aware of 😀

Prerequisites

  • MacOS / Linux
  • Proguard (brew install proguard on MacOS)
  • Android SDK (required for d8)
  • ANDROID_HOME or ANDROID_SDK_ROOT environment variable pointing to Android SDK directory

Project structure

DEX file parser

  • src/dex/raw_dex_file.rs - raw DEX file parser. It parses DEX file to a struct which is almost a 1:1 representation of DEX file structure.
  • src/dex/dex_file.rs - DEX file parser. It uses raw dex file parser result to construct full in-memory representation of all parts of DEX file.

Smali interpreter

As a first step I wanted to write a smali interpreter before writing an actual DEX interpreter. However, my current Rust skills are not enough to make it work (lifetimes are evil 😰), so now this pars of VM is abandoned. Maybe in the future I will add support for direct smali interpretation. It should not be that hard, I will just need to parse Smali code to some intermediate representation shared with DEX file parser and then interpret it.

  • src/gen/smali - smali parser generated by antlr4rust official Smali grammar. I'm not going to use it for now.
  • src/smali/ast - smali AST parser which I wanted to use for better Smali code representation (antlr4rust one is quite inconvenient).