Recaf icon indicating copy to clipboard operation
Recaf copied to clipboard

Order in mapping files

Open BaalNetbek opened this issue 1 year ago • 3 comments

Bring order to exported mapping files

The feature I would like to see is the order of names in exported mapping to be the same as they are declared in a class.

As I was deobfuscating a .jar and commiting updates to the mapping file...

my routine is:

  1. load original .jar
  2. load last mapping
  3. change names
  4. export mapping

...I noticed that order of fileds in exported mapping files changes everytime (I think only in in scope of Classes that just had any fields or methods mapping edited). They shuffle in unknown to me pattern.

PS. Type of mapping (proguard, simlple etc.) doesn't matter they all shuffle.

BaalNetbek avatar Nov 21 '24 19:11 BaalNetbek

Ofcourse I'm using latest Recaf 4

BaalNetbek avatar Nov 21 '24 19:11 BaalNetbek

The mapping system is designed to be independent of others, so it is not currently aware of the structures of classes mappings are registered for. Currently, it will export classes in natural sorted order by name, and the fields/methods of each class will be written in the order they were added to the mapping. So if you rename fields or methods in a single class such as a -> x, b -> y, and c -> z, you should see those in that exact order.

I looked at your sample and mappings and ran some tests. Reading in a mapping file and writing it back (from an API standpoint using our SimpleMappings class) yields the exact same contents as the input. My best guess at the moment is that the multi-threading in MappingApplier and updates tracked in AggregateMappings are leading to the changes you're seeing.

Col-E avatar Nov 24 '24 08:11 Col-E

When writing mappings via Mapping-IO, you can use the VisitOrder class to declare a stable output order.

NebelNidas avatar Jan 18 '25 14:01 NebelNidas