Storyyeller / Krakatau

Java decompiler, assembler, and disassembler
GNU General Public License v3.0
1.97k stars 220 forks source link

Add option to disassembly and reassembly, only 1 method from class fie #136

Closed userDevop123 closed 6 years ago

userDevop123 commented 6 years ago

I want to edit only 1 method from class file, but I dont want that it affect on another methode at all (even unseen changed like number of lable and number of const)

So i offer add option to disassembly and reassembly, only 1 method from class fie

Storyyeller commented 6 years ago

Krakatau already preserves everything. If you want to keep the exact layout of the constant pool, just pass the -roundtrip option to the disassembler. Anything you don't touch will stay the exact same.

userDevop123 commented 6 years ago

@Storyyeller when disassemble class (even with roundtrip ), then add

ldc "Hello World" to 1 of function, and then reassemble , I see change not only on this function because Krakatautakes takes the string "Hello World" and push it to const area(if I remember well) so that makes change on rest of functions

Janmm14 commented 6 years ago

its required to push it to the constant pool

userDevop123 commented 6 years ago

@Janmm14 I don't get you, can you explain ,more? I know that ldc "Hello World" save the "Hello World" on const pool , but when I add it that changed the ordering of the rest of const pool , and becausae of that the rest of fcuntions that point to const pool changed

Storyyeller commented 6 years ago

If you disassemble in roundtrip mode, it will preserve all existing constant pool entries, which means that any constant pool entries you add should be put after them in the constant pool. Is that not what you see happening?

userDevop123 commented 6 years ago

@Storyyeller I will try it again But I want to understand. If I disassemble class file (without roundtrip ) to j file and than reassemble it to class file ,is there a chance that non important thing (like ordering of const pool ) will be diffrent? But if I disassemble class file (with roundtrip ) to j file and than reassemble to class file nothing but the changes I made should not change?

If yes that stange ,becuase the re-order of const pool happend on reassemble , and the roundtrip is flag for disassemble ? how does the reassemble operation know that when I disassemble the class file I put roundtrip??

thank you

Storyyeller commented 6 years ago

That is correct.

The assembler doesn't care where the .j file came from. It could have come from the disassembler or you could have written it yourself. The -roundtrip option tells the disassembler to emit information in the .j file which will cause the assembler to output the original classfile.

userDevop123 commented 6 years ago

@Storyyeller so when I put -roundtrip , on the .j file I can see some flag or string that the reassemble serach it and know to save all the details from j file? what is that flag/string? I search and couldn't find that on j file.

by the way when I disassemble and than reassemble , someone else can know that this file reassemble ? there are somewhere information(apart from modify time) that this file reassemble ?

thank you all!

Storyyeller commented 6 years ago

If you disassemble and reassemble in roundtrip mode without modifications, the resulting classfile will be bit for bit identical to the original, so there is no way to tell. In regular mode, they might theoretically be able to guess from the way the constant pool is rearranged, but there would be no hard evidence.

As for the differences in the .j file, there is no magic string or anything. The assembly format is the same either way, roundtrip mode just causes the disassembler to output extra information. The primary difference is that in roundtrip mode, all constant pool references are raw. Apart from that, it also preserves the representation of non standard NaN values and preserves the ordering of the StackMapTable and BootstrapMethods attributes.

Why don't you try looking at the .j files and playing around with them yourself? I think that would help you understand better than just talking to me.