[diffoscope] Procyon decompiler outputs with ANSI color codes so --text-color has no effect on it

Aman Sharma amansha at kth.se
Thu Aug 15 19:43:09 UTC 2024


Hi,


I have to report a bug and its plausible solution. I read the contributing guidelines and tried signing up on salsa.debian.org, however the OAuth with GitLab was failing and form registration requires approval so I will wait for that. Once I am in, I will also post it there if asked for 😊


Bug


The Procyon decompiler which is used as a comparator for diff-ing Java bytecode outputs the decompiled version with ANSI color code by default. I assume this output is taken as input by diffoscope to produce the diff. Hence, the final diff also has decompiled Java code with syntax highlighting in the terminal.


I wanted this diff in a plain text file without ANSI colour codes so I tried using option `--text-color never`. This removed the colours from '+' and '-' which are green and red respectively. However, the synatx highlighting was still there. This happens because `ProcyonDecompiler` comparator by default outputs the decompiled Java code with syntax highlighting.


Reproduce


diffoscope A.class B.class

> files are attached


[cid:cc73313f-ea27-48dc-a4d7-e4ef98f91ad7]

As you can see the output is syntax highlighted which is expected in this case.

diffoscope --text-color never A.class B.class

[cid:60f431d6-3324-4496-ac85-7adc1430de54]

I would expect that syntax highlighting is also not present here. It only removes ANSI code for `+` and `-`.

Solution


  1.  Procyon provides flag ` --output-directory` which outputs the decompiled source into a file without any syntax highlighting. We could use this option for the decompiler if `--text-color` is set to never or `--text` has a file path.
  2.  We ask procyon to have an option which outputs without syntax highlighting on terminal.
  3.  We use regex to remove all ANSI codes while processing the diff in diffoscope.


Regards,
Aman Sharma

PhD Student
KTH Royal Institute of Technology
School of Electrical Engineering and Computer Science (EECS)
Department of Theoretical Computer Science (TCS)
<http://www.kth.se><https://www.kth.se/profile/amansha><https://www.kth.se/profile/amansha>
<https://www.kth.se/profile/amansha>https://algomaster99.github.io/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/diffoscope/attachments/20240815/03321f41/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedImage.png
Type: image/png
Size: 150287 bytes
Desc: pastedImage.png
URL: <http://lists.reproducible-builds.org/pipermail/diffoscope/attachments/20240815/03321f41/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedImage.png
Type: image/png
Size: 148158 bytes
Desc: pastedImage.png
URL: <http://lists.reproducible-builds.org/pipermail/diffoscope/attachments/20240815/03321f41/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: A.class
Type: application/java-vm
Size: 7254 bytes
Desc: A.class
URL: <http://lists.reproducible-builds.org/pipermail/diffoscope/attachments/20240815/03321f41/attachment.class>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: B.class
Type: application/java-vm
Size: 6986 bytes
Desc: B.class
URL: <http://lists.reproducible-builds.org/pipermail/diffoscope/attachments/20240815/03321f41/attachment-0001.class>


More information about the diffoscope mailing list