Col-E / Recaf

The modern Java bytecode editor
https://recaf.coley.software
MIT License
6.02k stars 465 forks source link

Escaping characters are double-escaped after editing in the assembly pane #723

Closed lanvent closed 1 week ago

lanvent commented 1 year ago

Hi, I have been using your tool for manipulating Java bytecode and it has been extremely useful. However, I recently stumbled upon a bug in version 3.x that has been quite troubling.

When editing Java bytecode in the assembly pane (not the decompile pane), the escape characters get double-escaped after making a change to the code. This issue is specific to version 3.x, as the same changes do not result in this problem in version 2.21.

Steps to Reproduce:

  1. Given the source code:
package org.test;

public class recaf {
    public recaf() {
    }

    public static void main(String[] args) {
        String str = "\"test\"";
        System.out.println(str);
        System.out.println(str);
    }
}
  1. Generate the class file for the above code. Open the class file in the assembly pane.
  2. Delete one of the System.out.println(str); related lines.
  3. After the deletion, the source code appears as:
package org.test;

public class recaf {
    public static void main(String[] args) {
        String str = "\\\"test\\\"";
        System.out.println(str);
    }
}

As you can see, the String str = "\"test\""; has been transformed into String str = "\\\"test\\\"";, which should not happen.

In version 2.21, this issue does not occur, and the string remains as String str = "\"test\"";.

Thank you for your time and efforts on this great tool.

Col-E commented 1 year ago

We were handling escaping in a number of different places and it led to a bit of a mess of "who's doing what where?"

The parser back-end JASM has been rewritten and is being re-incorporated here: https://github.com/Col-E/Recaf/pull/722

It handles all of the escaping locally so its no longer as messy as it was before, and we've confirmed the issue is solved in the rewrite.

lanvent commented 1 year ago

Thank you for your quick response to the issue. It's great to hear that the problem has been identified and is already being addressed. Looking forward to either seeing this fix incorporated into an upcoming 3.x version or experiencing the enhanced assembly functionalities in the forthcoming 4.x. The assembly functionality is crucial for many users like myself, and it's exciting to see it getting the attention it deserves for further refinement.

Col-E commented 1 week ago

JASM's escape handling has now been in 4.X for a while, closing