I'm implementing Amiga Executable Hunks loader, and this binary format has relocation tables, like in PE/NE files. There is getRelocationTable() method in Program object, which returns RelocationTable object. This table has public Relocation add(Address addr, int type, long[] values, byte[] bytes, String symbolName); method, but I don't understand what I must pass as type, values, and 'bytes' values.
Type is int, and values, that are used in other loaders, are for PE and ELF formats only.
Typically the _type_ is the relocation type as defined in a header file, the _values_ are the new bytes after you fixed up the relocation, and the _bytes_ are the original bytes as they were before the relocation. You have some freedom the make these what you want though...this table is more of a way for you describe what relocations you performed in your loader.
Values are longs, not bytes.
And which header file do you mean?
I thought that Ghidra uses that table during xrefs calculation. But now it seems that this table must be used by you to patch memory with correct offsets, right?
All 3 fields are arbitrary. If you don't have a header file that defines different relocation types, you can just use 0 for the type. The values are longs so you have the freedom to describe the relocation in different ways.
I thought that Ghidra uses that table during xrefs calculation. But now it seems that this table must be used by you to patch memory with correct offsets, right?
No, you must manually perform the relocation by modifying the bytes directly. The relocation table is simply a way for you to display back to the user what relocations were performed.
Thank you:)
And what should I hook to apply new offsets when Ghidra changes ImageBase?
You have to create a class that extends RelocationFixupHandler.
And make sure your subclass name ends with "RelocationFixupHandler". That's how our extension point mechanism finds it at runtime.
It doesn't work for me.
RelocationTable in load() method during binary parsing.program.setImageBase(0x123456).

What if you change the image base address through the GUI? (it's a button in the memory map) Is your handlesProgram() method never being called?
Yes, it calls my relocator only when changing image base using GUI.
program.setImageImage() doesn't call it.
Ok, would you mind submitting that as a separate bug issue?