First, introduce a few commands:
Compiling the Hello.java file into a hello.class file
F:\adt-bundle-windows-x86_64\sdk\build-tools\android-4.4.2>javac-source 1.6-target 1.6 Hello.java
Decompile the Java assembly code for the Hello.class file
F:\adt-bundle-windows-x86_64\sdk\build-tools\android-4.4.2>javap-c-classpath. Hello
Compiling the Hello.class file into a hello.dex file
F:\ADT-BUNDLE-WINDOWS-X86_64\SDK\BUILD-TOOLS\ANDROID-4.4.2>DX--dex--output Hello.dex Hello.class
Decompile the. dex file into Dalvik assembly code
F:\adt-bundle-windows-x86_64\sdk\build-tools\android-4.4.2>dexdump.exe-d Hello.dex
Second, such as the following Java code, I want to see the anti-compiled Android assembly code, should be as follows:
Public class Hello { publicint foo (intint b) { return ( A+B) * (A-b) ; } Public Static void Main (string[] argc) { new Hello (); System.out.println (H.foo (5, 3));} }
1. Put the DX path into the environment variable path, for example my path is F:\adt-bundle-windows-x86_64\sdk\build-tools\android-4.4.2
2. Compiling Java code into a Java bytecode file (class file)
Because the JDK version is too high, use the following command:
F:\adt-bundle-windows-x86_64\sdk\build-tools\android-4.4.2>javac-source 1.6-target 1.6 Hello.java
2. Place the Hello.class file under the DX path
3. Convert the Hello.class file (Java bytecode) to an Android Hello.dex file (Dalvik bytecode) via the DX tool
F:\ADT-BUNDLE-WINDOWS-X86_64\SDK\BUILD-TOOLS\ANDROID-4.4.2>DX--dex--output Hello.dex Hello.class
4. decompile the Hello.dex file into Dalvik assembly code via Dexdump.exe
F:\adt-bundle-windows-x86_64\sdk\build-tools\android-4.4.2>dexdump.exe-d Hello.dex
The final generated Dalvik assembly code is as follows:
Processing ' Hello.dex '... Opened' Hello.dex ', Dex version ' 035 'Class #0-Class Descriptor:' Lhello; 'Access Flags:0x0001(public) Superclass:' Ljava/lang/object; 'Interfaces-Static Fields-Instance Fields-Direct Methods- #0: (in Lhello;) Name:' <init> 'Type:' () V 'Access:0x10001(public CONSTRUCTOR) code-Registers:1Ins:1Outs:1Insns Size:4 16-bit code units00014c:| [00014c] Hello.<init>:() V00015C:7010 0400 0000 |0000:invoke-direct {V0}, ljava/Lang/object;. <init>:() V//[email protected]000162:0e00 |0003:return-voidcatches: (none) positions:0x0000 line=1Locals:0x0000-0x0004 reg=0 ThisLhello; #1: (in Lhello;) Name:' Main 'Type:' ([ljava/lang/string;) V 'Access:0x0009(public STATIC) code-Registers:5Ins:1Outs:3Insns Size:17 16-bit code units000164: | [000164] Hello.main: ([ljava/Lang/String;) V000174:2,200 0100 |0000:New-instance V0, Lhello; [email protected]000178:7010 0000 0000 |0002:invoke-Direct {v0}, Lhello;.<init>:() V//[email protected]00017e:6201 0000 |0005:sget-object v1, ljava/Lang/system;. Out:ljava/io/printstream;//[email protected]000182:1252 |0007:Const/4 v2, #int5//#5000184:1233 |0008:Const/4 v3, #int3//#3000186:6e30 0100 2003 |0009:invoke-Virtual {v0, V2, v3}, Lhello;. Foo: (II) I//[email protected]00018c:0a00 |000c:move-result V000018e:6e200300 0100 |000d:invoke-Virtual {v1, v0}, Ljava/io/printstream;. println: (I) V//[email protected]000194:0e00 |0010:return-voidcatches: (none) positions:0x0000 line=6 0x0005 line=7 0x0010 line=8locals:virtual Methods- #0: (in Lhello;) Name:' Foo 'Type:' (II) I 'Access:0x0001(public) Code-Registers:5Ins:3Outs:0Insns Size:6 16-bit code units000198: | [000198] Hello.foo: (II) I0001a8:9000 0304 |0000:add-intV0, v3, V40001ac:9101 0304 |0002:sub-intv1, v3, v40001b0:b210|0004:mul-int/2addr V0, v10001b2:0f00|0005:returnV0 catches: (none) positions:0x0000 line=3Locals:0x0000-0x0006 reg=2 ThisLhello; SOURCE_FILE_IDX:1 (Hello.java)