Recaf icon indicating copy to clipboard operation
Recaf copied to clipboard

Create bookmarks/comments API

Open Col-E opened this issue 2 years ago • 0 comments

Purpose

Allow assigning comments to different classes/fields/methods. When decompiling, comments are "injected" at the relevant locations.

This can also double as a bookmarking system, where you write a comment at a location you want to jump back to later.

Outline

interface CommentsApi {
    void setComment(ClassPathNode path, String comment) { ... }
    void setComment(ClassMemberPathNode path, String comment) { ... }
    void removeComment(ClassPathNode path) { ... }
    void removeComment(ClassMemberPathNode path) { ... }
}

Implementation

Prior versions of Recaf did support serialized comments in the class via annotations, with the comment being stored inline. This worked, but was subject to abuse since the annotation names were consistent. We can adapt this approach to be more resilient.

  1. Associate comments with a UUID key
  2. Use annotations with the key embedded in the name, such as COMMENT-0000-000-000-0000
  3. Store the actual comment info in Recaf's data directory
  4. Substitute the annotation for a comment at decompile/disassemble time

The last step can be done with basic text matching in decompiled output, so it is agnostic to the decompiler used. As for the assembler, we can do something similar there (which we did in the old Recaf assembler)

Col-E avatar Sep 08 '23 02:09 Col-E