• No results found

Disassembling Android applications

N/A
N/A
Protected

Academic year: 2021

Share "Disassembling Android applications"

Copied!
15
0
0

Loading.... (view fulltext now)

Full text

(1)

Disassembling Android applications

Workshop

Passage en Seine III June 17 th 2011

Pierre Pronchery <khorben@defora.org>

(2)

Android: about

Seen on http://www.dalvikvm.com/

« Android programs are compiled into .dex (Dalvik Executable) files, which are in turn zipped into a

single .apk (Android Package) file on the device. .dex files can be created by automatically translating

compiled applications written in the Java programming language »

Let's see for ourselves...

(3)

Android: just a ZIP archive #1

$ file app.apk

app.apk: Zip archive data, at least v2.0 to extract

$ unzip app.apk [...]

$ ls

AndroidManifest.xml META-INF/

assets/

classes.dex res/

resources.arsc

(4)

Android: just a ZIP archive #2

$ file *

AndroidManifest.xml: DBase 3 data file META-INF: directory

assets: directory

classes.dex: Dalvik dex file version 035 res: directory

resources.arsc: data

$ wtf dex

wtf: I don't know what dex means!

(5)

Android: DEX executables

http://www.netmite.com/android/mydroid/dalvik/docs/

DEX file layout:

Inspired from the DWARF file format

Header, identifiers, types, encodings, maps, items...

Dalvik bytecode instruction list

Java bytecode instruction list (for comparison)

(6)

Android: to be or not to be Java #1

On http://en.wikipedia.org/wiki/Dalvik_virtual_machine :

« Dalvik [is] a clean-room implementation rather than a development on top of a standard Java runtime, [and]

does not inherit copyright-based license restrictions

from either the standard-edition or open-source-edition Java runtimes. »

« Dalvik does not align to Java SE nor Java ME class library profiles (e.g., Java ME classes, AWT or Swing are not supported). Instead it uses its own library built on a subset of the Apache Harmony Java

implementation. »

(7)

Android: to be or not to be Java #2

On http://en.wikipedia.org/wiki/Dalvik_virtual_machine :

« Unlike Java VMs, which are stack machines, the Dalvik VM is a register-based architecture:

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to simplify the interpreter

Standard Java bytecode executes 8-bit stack instructions.

Local variables must be copied [...] by separate instructions.

Dalvik [uses a] 16-bit instruction set that works directly on

local variables. The local variable is commonly picked by a 4-

bit 'virtual register' field. »

(8)

Android: Dalvik bytecode

$ cat src/arch/dalvik.ins [...]

{ "add-double", 0xab, OP1F, OP_REG8, OP_REG8, OP_REG8 },

{ "add-double/2addr", 0xcb, OP1F, OP_REG4, OP_REG4, AOT_NONE },

{ "add-float", 0xa6, OP1F, OP_REG8, OP_REG8, OP_REG8 },

{ "add-float/2addr", 0xc6, OP1F, OP_REG4, OP_REG4, AOT_NONE },

{ "add-int", 0x90, OP1F, OP_REG8, OP_REG8, OP_REG8 },

{ "add-int/2addr", 0xb0, OP1F, OP_REG4, OP_REG4, AOT_NONE },

{ "add-int/lit8", 0xd8, OP1F, OP_REG8, OP_REG8, OP_U8 },

{ "add-int/lit16", 0xd0, OP1F, OP_REG4, OP_REG4, OP_U16 },

{ "add-long", 0x9b, OP1F, OP_REG8, OP_REG8, OP_REG8 },

{ "add-long/2addr", 0xbb, OP1F, OP_REG4, OP_REG4, AOT_NONE },

{ "aget", 0x44, OP1F, OP_REG8, OP_REG8, OP_REG8 },

{ "aget-boolean", 0x47, OP1F, OP_REG8, OP_REG8, OP_REG8 },

{ "aget-byte", 0x48, OP1F, OP_REG8, OP_REG8, OP_REG8 },

{ "aget-char", 0x49, OP1F, OP_REG8, OP_REG8, OP_REG8 },

{ "aget-object", 0x46, OP1F, OP_REG8, OP_REG8, OP_REG8 },

{ "aget-short", 0x4a, OP1F, OP_REG8, OP_REG8, OP_REG8 },

{ "aget-wide", 0x45, OP1F, OP_REG8, OP_REG8, OP_REG8 },

{ "and-int", 0x95, OP1F, OP_REG8, OP_REG8, OP_REG8 },

{ "and-int/2addr", 0xb5, OP1F, OP_REG4, OP_REG4, AOT_NONE },

{ "and-int/lit8", 0xdd, OP1F, OP_REG8, OP_REG8, OP_U8 },

{ "and-int/lit16", 0xd5, OP1F, OP_REG4, OP_REG4, OP_U16 },

{ "and-so/muchmore", 0xc0, OP1F, OP_REG4, OP_REG4, AOT_NONE },

(9)

June 17th 2011 PSES III - 2011 9

Get the code: what and where

Disassembler found in the DeforaOS asm project

Hosted by and part of DeforaOS

Development happens in a CVS tree:

$ cvs

-d:pserver:anonymous@anoncvs.defora.org:/Data/C VS co DeforaOS

Formal releases available

Web interface and daily archives available

asm depends on libSystem and libcpp

(10)

June 17th 2011 PSES III - 2011 10

Get the code: formal releases

Fresh from yesterday:

http://www.defora.org/os/download/download/3527/libSystem-0.1.6.tar.gz

http://www.defora.org/os/download/download/3542/cpp-0.0.1.tar.gz

http://www.defora.org/os/download/download/3545/asm-0.2.0.tar.gz Simple as pie hopefully:

$ make PREFIX=”/usr/local” install [...]

(may install a conflicting cpp binary; just remove it)

(11)

June 17th 2011 PSES III - 2011 11

Get the code: compilation

$ make bootstrap [...]

The source tree is now configured for your

environment. Essential libraries and tools will now be installed in this folder: "/usr/local"

You can still exit this script with the CTRL+C key combination.

Otherwise, press ENTER to proceed.

CTRL+C

$ (cd System/src/libSystem && make install)

$ (cd Apps/Devel/src/cpp && make install && rm -f /usr/local/cpp)

$ (cd Apps/Devel/src/asm && make install)

(12)

June 17th 2011 PSES III - 2011 12

Use the code: disassemble

$ deasm

Usage: deasm [-a arch][-f format] filename deasm [-a arch][-f format] -s string deasm -l

$ deasm classes.dex

classes.dex: dex-dalvik

Disassembly of section .text:

[...]

(13)

June 17th 2011 PSES III - 2011 13

Modify the code: contributing

Through DeforaOS:

Introduce yourself on devel@lists.defora.org

Report bugs or wishes

Send patches

Gain my trust (and an account)

Commit directly :)

(14)

June 17th 2011 PSES III - 2011 14

Android: Google did it

Some links to share:

http://mylifewithandroid.blogspot.com/

http://pallergabor.uw.hu/androidblog/

http://developer.android.com/reference/dalvik/bytecode/Opcodes.html

http://zeaster.blogspot.com/2007/11/how-to-decompile-dex-file-on-android_28.html

http://www.dalvikvm.com/

(15)

June 17th 2011 PSES III - 2011 15

Suggestions

Anything I may have missed?

Feedback, <3 and !<3 mail at khorben@defora.org

References

Related documents

There is plenty of future work to be done, ranging from implementing more invariants, constraints, and neighbourhoods to improving the algorithms for incrementally maintaining

This study examines American and British middle class expats’ educational strategies in Berlin, Germany, from a Bourdieusian perspective. I argue that globalization and an

You suspect that the icosaeder is not fair - not uniform probability for the different outcomes in a roll - and therefore want to investigate the probability p of having 9 come up in

File (#N7:1) The location of the sequencer file Mask (0F0F) The fixed hexadecimal value of the mask Destination (O:014) The output image address to be changed Control (R6:20)

Relying on stakeholder theory, stakeholder salience and social movement frameworks, the research has shown that Food Hubs consider their internal and customer stakeholders as

This is when a client sends a request to the tracking server for information about the statistics of the torrent, such as with whom to share the file and how well those other

kulturella och inte farmakologiska faktorer (Schlosser 2003: 17). För att utveckla Schlossers förklaring är det möjligt att då cannabis är kriminaliserat sätts cannabisanvändaren

I started off with an idea that instead of cnc-mill plywood and get a contoured model I wanted to com- pose the stock myself.. Idid some quick Rhino tests and I liked patterns