Java Code Examples for ghidra.app.util.bin.format.FactoryBundledWithBinaryReader#readNextInt()
The following examples show how to use
ghidra.app.util.bin.format.FactoryBundledWithBinaryReader#readNextInt() .
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: ThreadStateX86_32.java From ghidra with Apache License 2.0 | 6 votes |
private void initThreadStateX86_32(FactoryBundledWithBinaryReader reader) throws IOException { eax = reader.readNextInt(); ebx = reader.readNextInt(); ecx = reader.readNextInt(); edx = reader.readNextInt(); edi = reader.readNextInt(); esi = reader.readNextInt(); ebp = reader.readNextInt(); esp = reader.readNextInt(); ss = reader.readNextInt(); eflags = reader.readNextInt(); eip = reader.readNextInt(); cs = reader.readNextInt(); ds = reader.readNextInt(); es = reader.readNextInt(); fs = reader.readNextInt(); gs = reader.readNextInt(); }
Example 2
Source File: RelocationInfo.java From ghidra with Apache License 2.0 | 6 votes |
private void initRelocationInfo(FactoryBundledWithBinaryReader reader) throws IOException { r_address = reader.readNextInt(); int value = reader.readNextInt(); if (reader.isLittleEndian()) { r_symbolnum = (value & 0x00ffffff); r_pcrel = (value & 0x01000000) >> 24; r_length = (value & 0x06000000) >> 25; r_extern = (value & 0x08000000) >> 27; r_type = (value & 0xf0000000) >> 28; } else { r_symbolnum = (value & 0xffffff00) >> 8; r_pcrel = (value & 0x00000080) >> 7; r_length = (value & 0x00000060) >> 5; r_extern = (value & 0x00000010) >> 4; r_type = (value & 0x0000000f); } }
Example 3
Source File: ThreadStateARM.java From ghidra with Apache License 2.0 | 6 votes |
private void initThreadStateARM(FactoryBundledWithBinaryReader reader) throws IOException { r0 = reader.readNextInt(); r1 = reader.readNextInt(); r2 = reader.readNextInt(); r3 = reader.readNextInt(); r4 = reader.readNextInt(); r5 = reader.readNextInt(); r6 = reader.readNextInt(); r7 = reader.readNextInt(); r8 = reader.readNextInt(); r9 = reader.readNextInt(); r10 = reader.readNextInt(); r11 = reader.readNextInt(); r12 = reader.readNextInt(); sp = reader.readNextInt(); lr = reader.readNextInt(); pc = reader.readNextInt(); cpsr = reader.readNextInt(); }
Example 4
Source File: VS_VERSION_INFO.java From ghidra with Apache License 2.0 | 5 votes |
/** * Constructs a new VS_VERSION_INFO object. * @param reader the binary reader * @param index the index where the VS_VERSION_INFO begins * @throws IOException if an I/O error occurs */ public VS_VERSION_INFO(FactoryBundledWithBinaryReader reader, int index) throws IOException { long oldIndex = reader.getPointerIndex(); reader.setPointerIndex(index); structLength = reader.readNextShort(); valueLength = reader.readNextShort(); structType = reader.readNextShort(); info = reader.readNextUnicodeString(); alignment = reader.align(4); // start of VS_FIXEDFILEINFO signature = reader.readNextInt(); structVersion = shortArrayToString(reader, 2); fileVersion = shortArrayToString(reader, 4); productVersion = shortArrayToString(reader, 4); fileFlagsMask = intArrayToString(reader, 2); fileFlags = reader.readNextInt(); fileOS = reader.readNextInt(); fileType = reader.readNextInt(); fileSubtype = reader.readNextInt(); fileTimestamp = reader.readNextInt(); while (reader.getPointerIndex() < index + structLength) { // TODO: is alignment needed? children.add(new VS_VERSION_CHILD(reader, reader.getPointerIndex() - index, null, valueMap)); } reader.setPointerIndex(oldIndex); }
Example 5
Source File: FatArch.java From ghidra with Apache License 2.0 | 5 votes |
private void initFatArch(FactoryBundledWithBinaryReader reader) throws IOException { cputype = reader.readNextInt(); cpusubtype = reader.readNextInt(); offset = reader.readNextInt(); size = reader.readNextInt(); align = reader.readNextInt(); }
Example 6
Source File: EncryptedInformationCommand.java From ghidra with Apache License 2.0 | 5 votes |
private void initEncryptedInformationCommand(FactoryBundledWithBinaryReader reader) throws IOException { initLoadCommand(reader); cryptoff = reader.readNextInt(); cryptsize = reader.readNextInt(); cryptid = reader.readNextInt(); }
Example 7
Source File: ThreadStateARM_64.java From ghidra with Apache License 2.0 | 5 votes |
private void initThreadStateARM_64(FactoryBundledWithBinaryReader reader) throws IOException { x0 = reader.readNextLong(); x1 = reader.readNextLong(); x2 = reader.readNextLong(); x3 = reader.readNextLong(); x4 = reader.readNextLong(); x5 = reader.readNextLong(); x6 = reader.readNextLong(); x7 = reader.readNextLong(); x8 = reader.readNextLong(); x9 = reader.readNextLong(); x10 = reader.readNextLong(); x11 = reader.readNextLong(); x12 = reader.readNextLong(); x13 = reader.readNextLong(); x14 = reader.readNextLong(); x15 = reader.readNextLong(); x16 = reader.readNextLong(); x17 = reader.readNextLong(); x18 = reader.readNextLong(); x19 = reader.readNextLong(); x20 = reader.readNextLong(); x21 = reader.readNextLong(); x22 = reader.readNextLong(); x23 = reader.readNextLong(); x24 = reader.readNextLong(); x25 = reader.readNextLong(); x26 = reader.readNextLong(); x27 = reader.readNextLong(); x28 = reader.readNextLong(); fp = reader.readNextLong(); lr = reader.readNextLong(); sp = reader.readNextLong(); pc = reader.readNextLong(); cpsr = reader.readNextInt(); pad = reader.readNextInt(); }
Example 8
Source File: NList.java From ghidra with Apache License 2.0 | 5 votes |
private void initNList(FactoryBundledWithBinaryReader reader, boolean is32bit) throws IOException { this.is32bit = is32bit; n_strx = reader.readNextInt(); n_type = reader.readNextByte(); n_sect = reader.readNextByte(); n_desc = reader.readNextShort(); if (is32bit) { n_value = reader.readNextInt() & 0xffffffffL; } else { n_value = reader.readNextLong(); } }
Example 9
Source File: BuildVersionCommand.java From ghidra with Apache License 2.0 | 5 votes |
private void initEntryPointCommand(FactoryBundledWithBinaryReader reader) throws IOException { initLoadCommand(reader); platform = reader.readNextInt(); minos = reader.readNextInt(); sdk = reader.readNextInt(); ntools = reader.readNextInt(); buildToolVersions = new BuildToolVersion[ntools]; for (int i = 0; i < ntools; i++) { buildToolVersions[i] = new BuildToolVersion(reader.readNextInt(), reader.readNextInt()); } }
Example 10
Source File: MachHeader.java From ghidra with Apache License 2.0 | 5 votes |
private void initMachHeader(GenericFactory factory, ByteProvider provider, long machHeaderStartIndexInProvider, boolean isRemainingMachoRelativeToStartIndex) throws IOException, MachException { magic = readMagic(provider, machHeaderStartIndexInProvider); if (!MachConstants.isMagic(magic)) { throw new MachException("Invalid Mach-O binary."); } if (isRemainingMachoRelativeToStartIndex) { _machHeaderStartIndexInProvider = machHeaderStartIndexInProvider; } _reader = new FactoryBundledWithBinaryReader(factory, provider, isLittleEndian()); _reader.setPointerIndex(machHeaderStartIndexInProvider + 4);//skip magic number... cpuType = _reader.readNextInt(); cpuSubType = _reader.readNextInt(); fileType = _reader.readNextInt(); nCmds = _reader.readNextInt(); sizeOfCmds = _reader.readNextInt(); flags = _reader.readNextInt(); _is32bit = (cpuType & CpuTypes.CPU_ARCH_ABI64) == 0; if (!_is32bit) { reserved = _reader.readNextInt(); } _commandIndex = _reader.getPointerIndex(); }
Example 11
Source File: DyldInfoCommand.java From ghidra with Apache License 2.0 | 5 votes |
private void initDyldInfoCommand(FactoryBundledWithBinaryReader reader) throws IOException { initLoadCommand(reader); rebase_off = reader.readNextInt(); rebase_size = reader.readNextInt(); bind_off = reader.readNextInt(); bind_size = reader.readNextInt(); weak_bind_off = reader.readNextInt(); weak_bind_size = reader.readNextInt(); lazy_bind_off = reader.readNextInt(); lazy_bind_size = reader.readNextInt(); export_off = reader.readNextInt(); export_size = reader.readNextInt(); }
Example 12
Source File: ScatteredRelocationInfo.java From ghidra with Apache License 2.0 | 5 votes |
private void initScatteredRelocationInfo(FactoryBundledWithBinaryReader reader) throws IOException { int mask = reader.readNextInt(); r_scattered = ((mask & 0x80000000) >> 31) & 0x1; r_pcrel = ((mask & 0x40000000) >> 30); r_length = ((mask & 0x30000000) >> 28); r_type = ((mask & 0x0f000000) >> 24); r_address = ((mask & 0x00ffffff)); r_value = reader.readNextInt(); }
Example 13
Source File: DebugDirectory.java From ghidra with Apache License 2.0 | 5 votes |
private void initDebugDirectory(FactoryBundledWithBinaryReader reader, long index, OffsetValidator validator) throws IOException { long oldIndex = reader.getPointerIndex(); reader.setPointerIndex(index); characteristics = reader.readNextInt(); timeDateStamp = reader.readNextInt(); majorVersion = reader.readNextShort(); minorVersion = reader.readNextShort(); type = reader.readNextInt(); sizeOfData = reader.readNextInt(); addressOfRawData = reader.readNextInt(); pointerToRawData = reader.readNextInt(); if (type < 0 || type > 16 || sizeOfData < 0) { Msg.error(this, "Invalid DebugDirectory"); sizeOfData = 0; reader.setPointerIndex(oldIndex); return; } if (sizeOfData > 0) { if (!validator.checkPointer(pointerToRawData)) { Msg.error(this, "Invalid pointerToRawData " + pointerToRawData); sizeOfData = 0; reader.setPointerIndex(oldIndex); return; } blobBytes = reader.readByteArray(pointerToRawData, sizeOfData); } this.index = index; reader.setPointerIndex(oldIndex); }
Example 14
Source File: LinkEditDataCommand.java From ghidra with Apache License 2.0 | 4 votes |
private void initLinkEditDataCommand(FactoryBundledWithBinaryReader reader) throws IOException { initLoadCommand(reader); dataoff = reader.readNextInt(); datasize = reader.readNextInt(); }
Example 15
Source File: LoadCommandString.java From ghidra with Apache License 2.0 | 4 votes |
private void initLoadCommandString(FactoryBundledWithBinaryReader reader, LoadCommand command) throws IOException { offset = reader.readNextInt(); string = reader.readAsciiString(command.getStartIndex() + offset); }
Example 16
Source File: ElfSymbol.java From ghidra with Apache License 2.0 | 4 votes |
private void initElfSymbol(FactoryBundledWithBinaryReader reader, int symbolIndex, ElfSymbolTable symbolTable, ElfStringTable stringTable, ElfHeader header) throws IOException { this.header = header; this.symbolTable = symbolTable; this.symbolTableIndex = symbolIndex; if (header.is32Bit()) { st_name = reader.readNextInt(); st_value = reader.readNextInt() & Conv.INT_MASK; st_size = reader.readNextInt() & Conv.INT_MASK; st_info = reader.readNextByte(); st_other = reader.readNextByte(); st_shndx = reader.readNextShort(); } else { st_name = reader.readNextInt(); st_info = reader.readNextByte(); st_other = reader.readNextByte(); st_shndx = reader.readNextShort(); st_value = reader.readNextLong(); st_size = reader.readNextLong(); } if (st_name == 0) { if (getType() == STT_SECTION) { ElfSectionHeader[] sections = header.getSections(); if (st_shndx < 0 || st_shndx >= sections.length) { //invalid section reference... //this is a bug in objcopy, whereby sections are removed //but the corresponding section symbols are left behind. } else { ElfSectionHeader section = sections[st_shndx]; nameAsString = section.getNameAsString(); } } } else { nameAsString = stringTable.readString(reader, st_name); } }
Example 17
Source File: DynamicSymbolTableCommand.java From ghidra with Apache License 2.0 | 4 votes |
private void initDynamicSymbolTableCommand(FactoryBundledWithBinaryReader reader, MachHeader header) throws IOException { initLoadCommand(reader); ilocalsym = reader.readNextInt(); nlocalsym = reader.readNextInt(); iextdefsym = reader.readNextInt(); nextdefsym = reader.readNextInt(); iundefsym = reader.readNextInt(); nundefsym = reader.readNextInt(); tocoff = reader.readNextInt(); ntoc = reader.readNextInt(); modtaboff = reader.readNextInt(); nmodtab = reader.readNextInt(); extrefsymoff = reader.readNextInt(); nextrefsyms = reader.readNextInt(); indirectsymoff = reader.readNextInt(); nindirectsyms = reader.readNextInt(); extreloff = reader.readNextInt(); nextrel = reader.readNextInt(); locreloff = reader.readNextInt(); nlocrel = reader.readNextInt(); long index = reader.getPointerIndex(); if (tocoff > 0) { reader.setPointerIndex(header.getStartIndexInProvider() + tocoff); for (int i = 0; i < ntoc; ++i) { tocList.add(TableOfContents.createTableOfContents(reader)); } } if (modtaboff > 0) { reader.setPointerIndex(header.getStartIndexInProvider() + modtaboff); for (int i = 0; i < nmodtab; ++i) { moduleList.add(DynamicLibraryModule.createDynamicLibraryModule(reader, header)); } } if (extrefsymoff > 0) { reader.setPointerIndex(header.getStartIndexInProvider() + extrefsymoff); for (int i = 0; i < nextrefsyms; ++i) { referencedList.add(DynamicLibraryReference.createDynamicLibraryReference(reader)); } } if (indirectsymoff > 0) { reader.setPointerIndex(header.getStartIndexInProvider() + indirectsymoff); indirectSymbols = new int[nindirectsyms]; for (int i = 0; i < nindirectsyms; ++i) { indirectSymbols[i] = reader.readNextInt(); } } if (extreloff > 0) { reader.setPointerIndex(header.getStartIndexInProvider() + extreloff); for (int i = 0; i < nextrel; ++i) { externalRelocations.add(RelocationFactory.readRelocation(reader, header.is32bit())); } } if (locreloff > 0) { reader.setPointerIndex(header.getStartIndexInProvider() + locreloff); for (int i = 0; i < nlocrel; ++i) { localRelocations.add(RelocationFactory.readRelocation(reader, header.is32bit())); } } reader.setPointerIndex(index); }
Example 18
Source File: ThreadStatePPC.java From ghidra with Apache License 2.0 | 4 votes |
private long read(FactoryBundledWithBinaryReader reader, boolean is32bit) throws IOException { if (is32bit) { return reader.readNextInt() & 0xffffffffL; } return reader.readNextLong(); }
Example 19
Source File: SeparateDebugHeader.java From ghidra with Apache License 2.0 | 4 votes |
/** * Constructs a new separate debug header using the specified byte provider. * @param bp the byte provider * @throws IOException if an I/O error occurs. */ public SeparateDebugHeader(GenericFactory factory, ByteProvider bp) throws IOException { FactoryBundledWithBinaryReader reader = new FactoryBundledWithBinaryReader(factory, bp, true); reader.setPointerIndex(0); signature = reader.readNextShort(); if (signature != IMAGE_SEPARATE_DEBUG_SIGNATURE) { return; } flags = reader.readNextShort(); machine = reader.readNextShort(); characteristics = reader.readNextShort(); timeDateStamp = reader.readNextInt(); checkSum = reader.readNextInt(); imageBase = reader.readNextInt(); sizeOfImage = reader.readNextInt(); numberOfSections = reader.readNextInt(); exportedNamesSize = reader.readNextInt(); debugDirectorySize = reader.readNextInt(); sectionAlignment = reader.readNextInt(); reserved = reader.readNextIntArray(2); if (numberOfSections > NTHeader.MAX_SANE_COUNT) { Msg.error(this, "Number of sections " + numberOfSections); return; } long ptr = reader.getPointerIndex(); sections = new SectionHeader[numberOfSections]; for (int i = 0; i < numberOfSections; ++i) { sections[i] = SectionHeader.createSectionHeader(reader, ptr); ptr += SectionHeader.IMAGE_SIZEOF_SECTION_HEADER; } long tmp = ptr; List<String> exportedNameslist = new ArrayList<String>(); while (true) { String str = reader.readAsciiString(tmp); if (str == null || str.length() == 0) { break; } tmp += str.length() + 1; exportedNameslist.add(str); } exportedNames = new String[exportedNameslist.size()]; exportedNameslist.toArray(exportedNames); ptr += exportedNamesSize; parser = DebugDirectoryParser.createDebugDirectoryParser(reader, ptr, debugDirectorySize, this); }
Example 20
Source File: LoadConfigDirectory.java From ghidra with Apache License 2.0 | 4 votes |
private void initLoadConfigDirectory(FactoryBundledWithBinaryReader reader, int index, OptionalHeader oh) throws IOException { is64bit = oh.is64bit(); long oldIndex = reader.getPointerIndex(); reader.setPointerIndex(index); // Read original fields size = reader.readNextInt(); timeDateStamp = reader.readNextInt(); majorVersion = reader.readNextShort(); minorVersion = reader.readNextShort(); globalFlagsClear = reader.readNextInt(); globalFlagsSet = reader.readNextInt(); criticalSectionDefaultTimeout = reader.readNextInt(); deCommitFreeBlockThreshold = readPointer(reader); deCommitTotalFreeThreshold = readPointer(reader); lockPrefixTable = readPointer(reader); maximumAllocationSize = readPointer(reader); virtualMemoryThreshold = readPointer(reader); if (is64bit) { processAffinityMask = readPointer(reader); processHeapFlags = reader.readNextInt(); } else { processHeapFlags = reader.readNextInt(); processAffinityMask = readPointer(reader); } csdVersion = reader.readNextShort(); dependentLoadFlags = reader.readNextShort(); editList = readPointer(reader); // If the structure size indicates there are more fields, we are dealing with // a newer version of the structure. Each size check represents a new version // of the structure. if (reader.getPointerIndex() - index < size) { securityCookie = readPointer(reader); seHandlerTable = readPointer(reader); seHandlerCount = readPointer(reader); } if (reader.getPointerIndex() - index < size) { guardCfcCheckFunctionPointer = readPointer(reader); guardCfDispatchFunctionPointer = readPointer(reader); guardCfFunctionTable = readPointer(reader); guardCfFunctionCount = readPointer(reader); guardFlags = new GuardFlags(reader.readNextInt()); } if (reader.getPointerIndex() - index < size) { codeIntegrity = new CodeIntegrity(reader); } if (reader.getPointerIndex() - index < size) { guardAddressTakenIatEntryTable = readPointer(reader); guardAddressTakenIatEntryCount = readPointer(reader); guardLongJumpTargetTable = readPointer(reader); guardLongJumpTargetCount = readPointer(reader); } if (reader.getPointerIndex() - index < size) { dynamicValueRelocTable = readPointer(reader); chpeMetadataPointer = readPointer(reader); } if (reader.getPointerIndex() - index < size) { guardRfFailureRoutine = readPointer(reader); guardRfFailureRoutineFunctionPointer = readPointer(reader); dynamicValueRelocTableOffset = reader.readNextInt(); dynamicValueRelocTableSection = reader.readNextShort(); reserved1 = reader.readNextShort(); } if (reader.getPointerIndex() - index < size) { guardRfVerifyStackPointerFunctionPointer = readPointer(reader); hotPatchTableOffset = reader.readNextInt(); } if (reader.getPointerIndex() - index < size) { reserved2 = reader.readNextInt(); reserved3 = readPointer(reader); } reader.setPointerIndex(oldIndex); }