mirror of
https://github.com/cemu-project/GhidraRPXLoader.git
synced 2024-11-22 09:19:17 +01:00
Set a custom address for import symbols.
This commit is contained in:
parent
3085d0b374
commit
30dd840300
@ -37,6 +37,8 @@ public class RPXUtils {
|
|||||||
long shdr_elf_offset = elfFile.e_ehsize() & 0xFFFFFFFF;
|
long shdr_elf_offset = elfFile.e_ehsize() & 0xFFFFFFFF;
|
||||||
long shdr_data_elf_offset = shdr_elf_offset + elfFile.e_shnum() * elfFile.e_shentsize();
|
long shdr_data_elf_offset = shdr_elf_offset + elfFile.e_shnum() * elfFile.e_shentsize();
|
||||||
|
|
||||||
|
long curSymbolAddress = 0x01000000;
|
||||||
|
|
||||||
for (ElfSectionHeader h : elfFile.getSections()) {
|
for (ElfSectionHeader h : elfFile.getSections()) {
|
||||||
monitor.checkCanceled();
|
monitor.checkCanceled();
|
||||||
long curSize = h.getSize();
|
long curSize = h.getSize();
|
||||||
@ -82,21 +84,23 @@ public class RPXUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hacky way to fix import relocations
|
if (h.getType() == ElfSectionHeaderConstants.SHT_SYMTAB
|
||||||
if (h.getType() == ElfSectionHeaderConstants.SHT_SYMTAB) {
|
|| h.getType() == ElfSectionHeaderConstants.SHT_DYNSYM) {
|
||||||
monitor.setMessage("Fix import relocations " + h.getTypeAsString());
|
monitor.setMessage("Fix import/exports" + h.getTypeAsString());
|
||||||
int symbolCount = (int) ((int) (curSize) / h.getEntrySize());
|
int symbolCount = (int) ((int) (curSize) / h.getEntrySize());
|
||||||
long entryPos = 0;
|
long entryPos = 0;
|
||||||
for (int i = 0; i < symbolCount; i++) {
|
for (int i = 0; i < symbolCount; i++) {
|
||||||
monitor.checkCanceled();
|
monitor.checkCanceled();
|
||||||
long test_offset = (int) (offset + entryPos + 4);
|
long entry_offset = (int) (offset + entryPos);
|
||||||
buffer.position((int) test_offset);
|
|
||||||
int val = buffer.getInt();
|
|
||||||
|
|
||||||
if ((val & 0xF0000000L) == 0xC0000000L) {
|
int sectionIndex = buffer.getShort((int) entry_offset + 14) & 0xFFFF;
|
||||||
long fixedAddress = val - 0xC0000000L + 0x01000000L;
|
int type = elfFile.getSections()[sectionIndex].getType();
|
||||||
buffer.position((int) test_offset);
|
|
||||||
buffer.putInt((int) fixedAddress);
|
if (type == SHT_RPL_IMPORTS) {
|
||||||
|
// Set Value to 0
|
||||||
|
buffer.position((int) (entry_offset + 4));
|
||||||
|
curSymbolAddress += 4;
|
||||||
|
buffer.putInt((int) curSymbolAddress);
|
||||||
}
|
}
|
||||||
entryPos += h.getEntrySize();
|
entryPos += h.getEntrySize();
|
||||||
}
|
}
|
||||||
@ -118,8 +122,8 @@ public class RPXUtils {
|
|||||||
buffer.putInt((int) flags);
|
buffer.putInt((int) flags);
|
||||||
|
|
||||||
// Hacky way to fix import relocations
|
// Hacky way to fix import relocations
|
||||||
if ((h.getAddress() & 0xF0000000L) == 0xC0000000L) {
|
if (h.getType() == SHT_RPL_IMPORTS) {
|
||||||
long fixedAddress = h.getAddress() - 0xC0000000L + 0x01000000L;
|
long fixedAddress = 0;
|
||||||
buffer.putInt((int) fixedAddress);
|
buffer.putInt((int) fixedAddress);
|
||||||
} else {
|
} else {
|
||||||
buffer.putInt((int) h.getAddress());
|
buffer.putInt((int) h.getAddress());
|
||||||
|
Loading…
Reference in New Issue
Block a user