Wrap and improve the logging. It's the messages will be logged to System.out and the given TaskMonitor

This commit is contained in:
Maschell 2019-03-10 17:31:05 +01:00
parent eba14fb8f5
commit 194e36f4c2
2 changed files with 16 additions and 5 deletions

View File

@ -2,6 +2,8 @@ package de.mas.ghidra.utils;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import ghidra.util.task.TaskMonitor;
public class Utils { public class Utils {
private Utils() { private Utils() {
} }
@ -38,4 +40,12 @@ public class Utils {
return result.toString(); return result.toString();
} }
public static void logWrapper(String msg, TaskMonitor monitor) {
if (monitor != null) {
monitor.setMessage(msg);
}
System.out.println(msg);
}
} }

View File

@ -78,7 +78,9 @@ public class RPXUtils {
curSize = 0; curSize = 0;
} else { } else {
if ((flags & SHF_RPL_ZLIB) == SHF_RPL_ZLIB) { if ((flags & SHF_RPL_ZLIB) == SHF_RPL_ZLIB) {
monitor.setMessage("Decompressing section " + h.getTypeAsString()); Utils.logWrapper(
"Decompressing section " + Utils.stringFromStringTable(sh_str_sh_data, h.getName()),
monitor);
long section_size_inflated = ByteBuffer.wrap(Arrays.copyOf(data, 4)).getInt() & 0xFFFFFFFF; long section_size_inflated = ByteBuffer.wrap(Arrays.copyOf(data, 4)).getInt() & 0xFFFFFFFF;
Inflater inflater = new Inflater(); Inflater inflater = new Inflater();
inflater.setInput(data, 4, (int) h.getSize() - 4); // the first byte is the size inflater.setInput(data, 4, (int) h.getSize() - 4); // the first byte is the size
@ -108,7 +110,7 @@ public class RPXUtils {
if (h.getType() == ElfSectionHeaderConstants.SHT_SYMTAB if (h.getType() == ElfSectionHeaderConstants.SHT_SYMTAB
|| h.getType() == ElfSectionHeaderConstants.SHT_DYNSYM) { || h.getType() == ElfSectionHeaderConstants.SHT_DYNSYM) {
monitor.setMessage("Fix import/exports" + h.getTypeAsString()); Utils.logWrapper("Fix imports for section " + sectionName + " (" + h.getTypeAsString() + ")", monitor);
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++) {
@ -134,10 +136,9 @@ public class RPXUtils {
buffer = Utils.checkAndGrowByteBuffer(buffer, shdr_elf_offset + 0x28); buffer = Utils.checkAndGrowByteBuffer(buffer, shdr_elf_offset + 0x28);
monitor.setMessage("Converting section " + h.getTypeAsString()); Utils.logWrapper("Converting section " + sectionName + " (" + h.getTypeAsString() + ")", monitor);
buffer.position((int) shdr_elf_offset); buffer.position((int) shdr_elf_offset);
System.out.println("Write header " + String.format("%08X", shdr_elf_offset));
buffer.putInt(h.getName()); buffer.putInt(h.getName());
if (h.getType() == SHT_RPL_CRCS || h.getType() == SHT_RPL_FILEINFO) { if (h.getType() == SHT_RPL_CRCS || h.getType() == SHT_RPL_FILEINFO) {
buffer.putInt(ElfSectionHeaderConstants.SHT_NULL); buffer.putInt(ElfSectionHeaderConstants.SHT_NULL);
@ -165,7 +166,7 @@ public class RPXUtils {
shdr_elf_offset += 0x28; shdr_elf_offset += 0x28;
} }
monitor.setMessage("Create new ELF header"); Utils.logWrapper("Create new ELF header", monitor);
buffer = Utils.checkAndGrowByteBuffer(buffer, 36); buffer = Utils.checkAndGrowByteBuffer(buffer, 36);