You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
results in the token positions 81, 125, 176, 228 (expand to see highlights generated by Enigma).
Then I used this code to add comments to classes/fields/methods:
token positions correctly offset by 25 (char count of // + comment + LF): 106, 150, 201, 253
The janky approach above was necessary because JADX 1.4 didn't offer better APIs. After having upgraded to the latest master build, I wanted to make this cleaner, so I switched to using a plugin instead (more or less a 1:1 copy of the rename-mappings plugin, reduced to just the code-comment providing code). Surprisingly however, this results in JADX reporting misplaced token positions, they don't seem to take into account the additional offset caused by the comments:
token positions unchanged at 81, 125, 176, 228
The text was updated successfully, but these errors were encountered:
NebelNidas
changed the title
ICodeAnnotation positions in CodeInfo sometimes don't adjust to code commentsICodeAnnotation positions sometimes don't take code comments into account
Apr 7, 2024
@NebelNidas looks like something not updated or cached.
Can you point me to a branch with last approach, so I can debug this issue and maybe provide fixes?
I use AtomicReference to save variable inside lambda, you can use any other method if you want to.
Long version:
Because caching is disabled, decompilation executed with every cls.getCodeInfo() call.
But after decompilation, all data in ClassNode is unloaded (resetted), so next decompilation did not contain added comment, and this lead to new (and wrong) positions.
If you want to add comment for every decompilation it is possible to make a decompile pass instead prepare and add comment in class node visit method.
Running
javaClass.getCodeInfo().getCodeMetadata().searchDown
for the following decompilation result:results in the token positions 81, 125, 176, 228 (expand to see highlights generated by Enigma).
Then I used this code to add comments to classes/fields/methods:
token positions correctly offset by 25 (char count of
//
+ comment + LF): 106, 150, 201, 253The janky approach above was necessary because JADX 1.4 didn't offer better APIs. After having upgraded to the latest master build, I wanted to make this cleaner, so I switched to using a plugin instead (more or less a 1:1 copy of the
rename-mappings
plugin, reduced to just the code-comment providing code). Surprisingly however, this results in JADX reporting misplaced token positions, they don't seem to take into account the additional offset caused by the comments:token positions unchanged at 81, 125, 176, 228
The text was updated successfully, but these errors were encountered: