简体   繁体   English

是否可以从 dex 文件中获取特定行的 java 代码?

[英]Is it possible to get the java code for a specific line from the dex file?

I am trying to analyse dex files, and I want to know if I can get the java code or what a specific bytes from the dex file mean.我正在尝试分析 dex 文件,我想知道是否可以获得 java 代码或 dex 文件中的特定字节的含义。

Any help will be appreciated!任何帮助将不胜感激!

Getting java code from bytecode is called decompilation, and you will need to use a decompiler.从字节码中获取 java 代码称为反编译,您需要使用反编译器。 Although I'm not aware of any decompiler that will do partial decompilation of just a snippet of bytecode.尽管我不知道有任何反编译器会仅对一小段字节码进行部分反编译。 There may not even be enough info in that snippet to perform a proper decompilation.该片段中甚至可能没有足够的信息来执行正确的反编译。

"Or what specific bytes from the dex file mean" - you could try using baksmali's annotated dump functionality. “或者 dex 文件中的特定字节是什么意思” - 您可以尝试使用 baksmali 的带注释转储功能。 It writes out a format that has the binary bytes on the left side, and a structured text view on the right side corresponding to the bytes on the left side.它写出一种格式,左侧是二进制字节,右侧是结构化文本视图,对应于左侧的字节。

eg baksmali dump HelloWorld.dex例如baksmali dump HelloWorld.dex

...
                           |-----------------------------
                           |code_item section
                           |-----------------------------
                           |
                           |[0] code_item: LHelloWorld;->main([Ljava/lang/String
                           |;)V
0001c4: 0200               |  registers_size = 2
0001c6: 0100               |  ins_size = 1
0001c8: 0200               |  outs_size = 2
0001ca: 0000               |  tries_size = 0
0001cc: 0000 0000          |  debug_info_off = 0x0
0001d0: 0800 0000          |  insns_size = 0x8
                           |  instructions:
0001d4: 6200 0000          |    sget-object v0, Ljava/lang/System;->out:Ljava/io
                           |/PrintStream;
0001d8: 1a01 0000          |    const-string v1, "Hello World!"
0001dc: 6e20 0100 1000     |    invoke-virtual {v0, v1}, Ljava/io/PrintStream;->
                           |println(Ljava/lang/String;)V
0001e2: 0e00               |    return-void
...

On the left side we have [offset]: [binary data] and then the right side has the interpreted view.在左侧我们有[offset]: [binary data]然后右侧有解释视图。 eg field name and value, or disassembled instruction, etc.例如字段名称和值,或反汇编指令等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM