Skip to content

Commit

Permalink
docs: add example
Browse files Browse the repository at this point in the history
  • Loading branch information
algomaster99 committed Aug 5, 2024
1 parent 4b0bf4e commit 6ad15f2
Showing 1 changed file with 122 additions and 1 deletion.
123 changes: 122 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1197,4 +1197,125 @@ lot of noise, see example 2.
java.lang.classfile.CodeModel: CodeModel [334,343]
at 5]
```
The diff shows three instructions are added in the new bytecode - `GETSTATIC`, `LDC`, and `INVOKEVIRTUAL`.
The diff shows three instructions are added in the new bytecode - `GETSTATIC`, `LDC`, and `INVOKEVIRTUAL`.

4. Diff between bytecode and decompiled-compiled-bytecode

<details>
<summary>
<h4>With diffoscope 272</h4>
<blockquote>Java 22</blockquote>
</summary>
<pre>
--- /home/aman/Desktop/personal/bytecode-diff/src/test/resources/infiniteRecursion/decompiled/A.class
+++ /home/aman/Desktop/personal/bytecode-diff/src/test/resources/infiniteRecursion/original/A.class
├── javap -verbose -constants -s -l -private {}
│ @@ -1,8 +1,8 @@
│ - SHA-256 checksum 039eb028d004305c9ee56b5429d116f773b75265617153c072ac6eb1d34d83b4
│ + SHA-256 checksum 44a81df8eb39d7819ae5e8f07f5eb483f7a8fd363776f0307ec0ebfb3057ce6c
│ Compiled from "A.java"
│ public class A
│ minor version: 0
│ major version: 65
│ flags: (0x0021) ACC_PUBLIC, ACC_SUPER
│ this_class: #13 // A
│ super_class: #2 // java/lang/Object
│ @@ -21,34 +21,36 @@
│ #11 = Methodref #9.#3 // java/lang/StringBuffer."<init>":()V
│ #12 = Methodref #13.#14 // A.applyRules:(Ljava/lang/String;Ljava/lang/StringBuffer;)Ljava/lang/StringBuffer;
│ #13 = Class #15 // A
│ #14 = NameAndType #16:#17 // applyRules:(Ljava/lang/String;Ljava/lang/StringBuffer;)Ljava/lang/StringBuffer;
│ #15 = Utf8 A
│ #16 = Utf8 applyRules
│ #17 = Utf8 (Ljava/lang/String;Ljava/lang/StringBuffer;)Ljava/lang/StringBuffer;
│ - #18 = Utf8 Code
│ - #19 = Utf8 LineNumberTable
│ - #20 = Utf8 main
│ - #21 = Utf8 ([Ljava/lang/String;)V
│ - #22 = Utf8 (Ljava/lang/String;Ljava/lang/Appendable;)Ljava/lang/Appendable;
│ - #23 = Utf8 Signature
│ - #24 = Utf8 <B::Ljava/lang/Appendable;>(Ljava/lang/String;TB;)TB;
│ - #25 = Utf8 SourceFile
│ - #26 = Utf8 A.java
│ + #18 = Methodref #13.#19 // A.applyRules:(Ljava/lang/String;Ljava/lang/Appendable;)Ljava/lang/Appendable;
│ + #19 = NameAndType #16:#20 // applyRules:(Ljava/lang/String;Ljava/lang/Appendable;)Ljava/lang/Appendable;
│ + #20 = Utf8 (Ljava/lang/String;Ljava/lang/Appendable;)Ljava/lang/Appendable;
│ + #21 = Utf8 Code
│ + #22 = Utf8 LineNumberTable
│ + #23 = Utf8 main
│ + #24 = Utf8 ([Ljava/lang/String;)V
│ + #25 = Utf8 Signature
│ + #26 = Utf8 <B::Ljava/lang/Appendable;>(Ljava/lang/String;TB;)TB;
│ + #27 = Utf8 SourceFile
│ + #28 = Utf8 A.java
│ {
│ public A();
│ descriptor: ()V
│ flags: (0x0001) ACC_PUBLIC
│ Code:
│ stack=1, locals=1, args_size=1
│ 0: aload_0
│ 1: invokespecial #1 // Method java/lang/Object."<init>":()V
│ 4: return
│ LineNumberTable:
│ - line 3: 0
│ + line 4: 0
│ public static void main(java.lang.String[]);
│ descriptor: ([Ljava/lang/String;)V
│ flags: (0x0009) ACC_PUBLIC, ACC_STATIC
│ Code:
│ stack=3, locals=1, args_size=1
│ 0: ldc #7 // String Hello, World!
│ @@ -67,22 +69,23 @@
│ flags: (0x000a) ACC_PRIVATE, ACC_STATIC
│ Code:
│ stack=1, locals=2, args_size=2
│ 0: aload_1
│ 1: areturn
│ LineNumberTable:
│ line 10: 0
│ - Signature: #24 // <B::Ljava/lang/Appendable;>(Ljava/lang/String;TB;)TB;
│ + Signature: #26 // <B::Ljava/lang/Appendable;>(Ljava/lang/String;TB;)TB;
│ protected static java.lang.StringBuffer applyRules(java.lang.String, java.lang.StringBuffer);
│ descriptor: (Ljava/lang/String;Ljava/lang/StringBuffer;)Ljava/lang/StringBuffer;
│ flags: (0x000c) ACC_PROTECTED, ACC_STATIC
│ Code:
│ stack=2, locals=2, args_size=2
│ 0: aload_0
│ 1: aload_1
│ - 2: invokestatic #12 // Method applyRules:(Ljava/lang/String;Ljava/lang/StringBuffer;)Ljava/lang/StringBuffer;
│ - 5: areturn
│ + 2: invokestatic #18 // Method applyRules:(Ljava/lang/String;Ljava/lang/Appendable;)Ljava/lang/Appendable;
│ + 5: checkcast #9 // class java/lang/StringBuffer
│ + 8: areturn
│ LineNumberTable:
│ line 14: 0
│ }
│ SourceFile: "A.java"
</pre>
</details>

#### With our tool

```text
[===
update-node
---
METHOD_INVOKED_RETURN_TYPE: (Ljava/lang/String;Ljava/lang/Appendable;)Ljava/lang/Appendable; [0,0]
replace (Ljava/lang/String;Ljava/lang/Appendable;)Ljava/lang/Appendable; by (Ljava/lang/String;Ljava/lang StringBuffer;)Ljava/lang/StringBuffer;,
===
delete-node
---
CHECKCAST [0,0]
===]
```

Our tool precisely detects there has been change in two OPCODEs.
Also, `diffiscope` fallbacks to `javap` as they don't detect a change in sources.
This bug has been discovered by paper
[Java Decompiler Diversity and its Application to Meta-decompilation](https://arxiv.org/abs/2005.11315).
Its case study 4.3.2 outlines this case.
This bug makes diffoscope diff noisy.

0 comments on commit 6ad15f2

Please sign in to comment.