Java Code Examples for ghidra.app.util.bin.BinaryReader#readInt()
The following examples show how to use
ghidra.app.util.bin.BinaryReader#readInt() .
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: UniversalBinaryFileSystem.java From ghidra with Apache License 2.0 | 5 votes |
@Override public boolean isValid(TaskMonitor monitor) throws IOException { boolean isLittleEndian = false;// always big endian BinaryReader reader = new BinaryReader(provider, isLittleEndian); int magic = reader.readInt(0); int nArch = reader.readInt(4); if (magic == FatHeader.FAT_MAGIC || magic == FatHeader.FAT_CIGAM) { return nArch < 0x20; } return false; }
Example 2
Source File: BinaryPropertyListTrailer.java From ghidra with Apache License 2.0 | 5 votes |
public BinaryPropertyListTrailer( BinaryReader reader ) throws IOException { trailerIndex = reader.length( ) - BinaryPropertyListConstants.TRAILER_SIZE; offsetSize = reader.readByte( trailerIndex + 6 ) & 0xff; objectRefSize = reader.readByte( trailerIndex + 7 ) & 0xff; objectCount = reader.readInt( trailerIndex + 12 ) & 0xffffffff; topObject = reader.readInt( trailerIndex + 20 ) & 0xffffffff; offsetTableOffset = reader.readInt( trailerIndex + 28 ) & 0xffffffff; // if ( offsetSize != 4 ) { // throw new IOException( "Unsupported binary PLIST offset size: " + // offsetSize ); // } offsetTable = new int [ objectCount ]; for ( int i = 0 ; i < objectCount ; ++i ) { if ( offsetSize == 4 ) { offsetTable[ i ] = reader.readInt( offsetTableOffset + i * offsetSize ); } else if ( offsetSize == 2 ) { offsetTable[ i ] = reader.readShort( offsetTableOffset + i * offsetSize ) & 0xffff; } else if ( offsetSize == 1 ) { offsetTable[ i ] = reader.readByte( offsetTableOffset + i * offsetSize ) & 0xff; } else { throw new RuntimeException( "Invalid offset size in binary PList" ); } } }
Example 3
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); }
Example 4
Source File: RichTable.java From ghidra with Apache License 2.0 | 4 votes |
private static int readInt(BinaryReader reader, long offset) throws IOException { return reader.readInt(offset) & 0xFFFFFFFF; }