ghidra.program.model.data.DataTypeConflictException Java Examples
The following examples show how to use
ghidra.program.model.data.DataTypeConflictException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IPCAnalyzer.java From Ghidra-Switch-Loader with ISC License | 7 votes |
protected int createPointer(Program program, Address address) { Data d = program.getListing().getDataAt(address); if (d == null) { try { d = program.getListing().createData(address, PointerDataType.dataType, 8); } catch (CodeUnitInsertionException | DataTypeConflictException e) { Msg.error(this, String.format("Failed to create pointer at 0x%X", address.getOffset()), e); } } return d.getLength(); }
Example #2
Source File: NXProgramBuilder.java From Ghidra-Switch-Loader with ISC License | 6 votes |
protected void setupStringTable() throws AddressOverflowException, CodeUnitInsertionException, DataTypeConflictException { NXOAdapter adapter = this.nxo.getAdapter(); ElfStringTable stringTable = adapter.getStringTable(this.program); if (stringTable == null) return; long stringTableAddrOffset = stringTable.getAddressOffset(); Address address = this.aSpace.getAddress(stringTableAddrOffset); Address end = address.addNoWrap(stringTable.getLength() - 1); while (address.compareTo(end) < 0) { int length = this.createString(address); address = address.addNoWrap(length); } }
Example #3
Source File: LoadConfigDataDirectory.java From ghidra with Apache License 2.0 | 6 votes |
@Override public void markup(Program program, boolean isBinary, TaskMonitor monitor, MessageLog log, NTHeader ntHeader) throws DuplicateNameException, CodeUnitInsertionException, DataTypeConflictException, IOException { monitor.setMessage(program.getName()+": load config directory..."); Address addr = PeUtils.getMarkupAddress(program, isBinary, ntHeader, virtualAddress); if (!program.getMemory().contains(addr)) { return; } createDirectoryBookmark(program, addr); PeUtils.createData(program, addr, lcd.toDataType(), log); markupSeHandler(program, isBinary, monitor, log, ntHeader); ControlFlowGuard.markup(lcd, program, log, ntHeader); }
Example #4
Source File: NXProgramBuilder.java From Ghidra-Switch-Loader with ISC License | 5 votes |
protected int createString(Address address) throws CodeUnitInsertionException, DataTypeConflictException { Data d = this.program.getListing().getDataAt(address); if (d == null || !TerminatedStringDataType.dataType.isEquivalent(d.getDataType())) { d = this.program.getListing().createData(address, TerminatedStringDataType.dataType, -1); } return d.getLength(); }
Example #5
Source File: NXProgramBuilder.java From Ghidra-Switch-Loader with ISC License | 5 votes |
protected int createPointer(Address address) throws CodeUnitInsertionException, DataTypeConflictException { NXOAdapter adapter = this.nxo.getAdapter(); Data d = this.program.getListing().getDataAt(address); if (d == null || !PointerDataType.dataType.isEquivalent(d.getDataType())) { d = this.program.getListing().createData(address, PointerDataType.dataType, adapter.getOffsetSize()); } return d.getLength(); }
Example #6
Source File: NXProgramBuilder.java From Ghidra-Switch-Loader with ISC License | 4 votes |
public void load(TaskMonitor monitor) { NXOAdapter adapter = this.nxo.getAdapter(); ByteProvider memoryProvider = adapter.getMemoryProvider(); this.aSpace = program.getAddressFactory().getDefaultAddressSpace(); try { this.memBlockHelper = new MemoryBlockHelper(monitor, this.program, memoryProvider); NXOSection text = adapter.getSection(NXOSectionType.TEXT); NXOSection rodata = adapter.getSection(NXOSectionType.RODATA); NXOSection data = adapter.getSection(NXOSectionType.DATA); if (adapter.getDynamicSize() == 0) { // We can't create .dynamic, so work with what we've got. return; } this.memBlockHelper.addSection(".dynamic", adapter.getDynamicOffset(), adapter.getDynamicOffset(), adapter.getDynamicSize(), true, true, false); // Create dynamic sections this.tryCreateDynBlock(".dynstr", ElfDynamicType.DT_STRTAB, ElfDynamicType.DT_STRSZ); this.tryCreateDynBlock(".init_array", ElfDynamicType.DT_INIT_ARRAY, ElfDynamicType.DT_INIT_ARRAYSZ); this.tryCreateDynBlock(".fini_array", ElfDynamicType.DT_FINI_ARRAY, ElfDynamicType.DT_FINI_ARRAYSZ); this.tryCreateDynBlock(".rela.dyn", ElfDynamicType.DT_RELA, ElfDynamicType.DT_RELASZ); this.tryCreateDynBlock(".rel.dyn", ElfDynamicType.DT_REL, ElfDynamicType.DT_RELSZ); if (adapter.isAarch32()) { this.tryCreateDynBlock(".rel.plt", ElfDynamicType.DT_JMPREL, ElfDynamicType.DT_PLTRELSZ); } else { this.tryCreateDynBlock(".rela.plt", ElfDynamicType.DT_JMPREL, ElfDynamicType.DT_PLTRELSZ); } this.tryCreateDynBlockWithRange(".hash", ElfDynamicType.DT_HASH, ElfDynamicType.DT_GNU_HASH); this.tryCreateDynBlockWithRange(".gnu.hash", ElfDynamicType.DT_GNU_HASH, ElfDynamicType.DT_SYMTAB); if (adapter.getSymbolTable(this.program) != null) { Msg.info(this, String.format("String table offset %X, base addr %X", adapter.getSymbolTable(this.program).getFileOffset(), this.nxo.getBaseAddress())); this.memBlockHelper.addSection(".dynsym", adapter.getSymbolTable(this.program).getFileOffset() - this.nxo.getBaseAddress(), adapter.getSymbolTable(this.program).getFileOffset() - this.nxo.getBaseAddress(), adapter.getSymbolTable(this.program).getLength(), true, false, false); } this.setupRelocations(); this.createGlobalOffsetTable(); this.memBlockHelper.addFillerSection(".text", text.getOffset(), text.getSize(), true, false, true); this.memBlockHelper.addFillerSection(".rodata", rodata.getOffset(), rodata.getSize(), true, false, false); this.memBlockHelper.addFillerSection(".data", data.getOffset(), data.getSize(), true, true, false); this.setupStringTable(); this.setupSymbolTable(); // Create BSS. This needs to be done before the EXTERNAL block is created in setupImports Address bssStartAddr = aSpace.getAddress(this.nxo.getBaseAddress() + adapter.getBssOffset()); Msg.info(this, String.format("Created bss from 0x%X to 0x%X", bssStartAddr.getOffset(), bssStartAddr.getOffset() + adapter.getBssSize())); MemoryBlockUtils.createUninitializedBlock(this.program, false, ".bss", bssStartAddr, adapter.getBssSize(), "", null, true, true, false, new MessageLog()); this.setupImports(monitor); this.performRelocations(); // Set all data in the GOT to the pointer data type // NOTE: Currently the got range may be null in e.g. old libnx nros // We may want to manually figure this out ourselves in future. if (adapter.getGotSize() > 0) { for (Address addr = this.aSpace.getAddress(adapter.getGotOffset()); addr.compareTo(this.aSpace.getAddress(adapter.getGotOffset() + adapter.getGotSize())) < 0; addr = addr.add(adapter.getOffsetSize())) { this.createPointer(addr); } } } catch (IOException | NotFoundException | AddressOverflowException | AddressOutOfBoundsException | CodeUnitInsertionException | DataTypeConflictException | MemoryAccessException | InvalidInputException e) { e.printStackTrace(); } // Ensure memory blocks are ordered from first to last. // Normally they are ordered by the order they are added. UIUtil.sortProgramTree(this.program); }
Example #7
Source File: NXProgramBuilder.java From Ghidra-Switch-Loader with ISC License | 4 votes |
protected void setupRelocations() throws AddressOverflowException, AddressOutOfBoundsException, IOException, NotFoundException, CodeUnitInsertionException, DataTypeConflictException { NXOAdapter adapter = this.nxo.getAdapter(); ByteProvider memoryProvider = adapter.getMemoryProvider(); BinaryReader memoryReader = adapter.getMemoryReader(); ImmutableList<NXRelocation> pltRelocs = adapter.getPltRelocations(this.program); if (pltRelocs.isEmpty()) { Msg.info(this, "No plt relocations found."); return; } long pltGotStart = pltRelocs.get(0).offset; long pltGotEnd = pltRelocs.get(pltRelocs.size() - 1).offset + adapter.getOffsetSize(); if (adapter.getDynamicTable(this.program).containsDynamicValue(ElfDynamicType.DT_PLTGOT)) { long pltGotOff = adapter.getDynamicTable(this.program).getDynamicValue(ElfDynamicType.DT_PLTGOT); this.memBlockHelper.addSection(".got.plt", pltGotOff, pltGotOff, pltGotEnd - pltGotOff, true, false, false); } // Only add .plt on aarch64 if (adapter.isAarch32()) { return; } int last = 12; while (true) { int pos = -1; for (int i = last; i < adapter.getSection(NXOSectionType.TEXT).getSize(); i++) { if (memoryReader.readInt(i) == 0xD61F0220) { pos = i; break; } } if (pos == -1) break; last = pos + 1; if ((pos % 4) != 0) continue; int off = pos - 12; long a = Integer.toUnsignedLong(memoryReader.readInt(off)); long b = Integer.toUnsignedLong(memoryReader.readInt(off + 4)); long c = Integer.toUnsignedLong(memoryReader.readInt(off + 8)); long d = Integer.toUnsignedLong(memoryReader.readInt(off + 12)); if (d == 0xD61F0220L && (a & 0x9f00001fL) == 0x90000010L && (b & 0xffe003ffL) == 0xf9400211L) { long base = off & ~0xFFFL; long immhi = (a >> 5) & 0x7ffffL; long immlo = (a >> 29) & 3; long paddr = base + ((immlo << 12) | (immhi << 14)); long poff = ((b >> 10) & 0xfffL) << 3; long target = paddr + poff; if (pltGotStart <= target && target < pltGotEnd) this.pltEntries.add(new PltEntry(off, target)); } } long pltStart = this.pltEntries.get(0).off; long pltEnd = this.pltEntries.get(this.pltEntries.size() - 1).off + 0x10; this.memBlockHelper.addSection(".plt", pltStart, pltStart, pltEnd - pltStart, true, false, false); }