Java Code Examples for ghidra.app.util.bin.format.FactoryBundledWithBinaryReader#readNextByteArray()

The following examples show how to use ghidra.app.util.bin.format.FactoryBundledWithBinaryReader#readNextByteArray() . 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: DebugMisc.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void initDebugMisc(FactoryBundledWithBinaryReader reader, DebugDirectory debugDir,
		OffsetValidator validator) throws IOException {
	this.debugDir = debugDir;

	long oldIndex = reader.getPointerIndex();

	long index = debugDir.getPointerToRawData() & Conv.INT_MASK;
	if (!validator.checkPointer(index)) {
		Msg.error(this, "Invalid file index " + Long.toHexString(index));
		return;
	}
	reader.setPointerIndex(index);

	dataType = reader.readNextInt();
	length = reader.readNextInt();
	unicode = reader.readNextByte() == 1;
	reserved = reader.readNextByteArray(3);
	if (length > 0) {
		actualData =
			(unicode ? reader.readNextUnicodeString(length) : reader.readNextAsciiString());
	}
	else {
		Msg.error(this, "Bad string length " + Integer.toHexString(length));
	}

	reader.setPointerIndex(oldIndex);
}
 
Example 2
Source File: UuidCommand.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void initUuidCommand(FactoryBundledWithBinaryReader reader) throws IOException {
	initLoadCommand(reader);
	uuid = reader.readNextByteArray(16);
}
 
Example 3
Source File: ElfHeader.java    From ghidra with Apache License 2.0 4 votes vote down vote up
protected void initElfHeader(GenericFactory factory, ByteProvider provider)
		throws ElfException {
	try {

		determineHeaderEndianess(provider);

		reader = new FactoryBundledWithBinaryReader(factory, provider, hasLittleEndianHeaders);

		e_ident_magic_num = reader.readNextByte();
		e_ident_magic_str = reader.readNextAsciiString(ElfConstants.MAGIC_STR_LEN);

		boolean magicMatch = ElfConstants.MAGIC_NUM == e_ident_magic_num &&
			ElfConstants.MAGIC_STR.equalsIgnoreCase(e_ident_magic_str);

		if (!magicMatch) {
			throw new ElfException("Not a valid ELF executable.");
		}

		e_ident_class = reader.readNextByte();
		e_ident_data = reader.readNextByte();
		e_ident_version = reader.readNextByte();
		e_ident_osabi = reader.readNextByte();
		e_ident_abiversion = reader.readNextByte();
		e_ident_pad = reader.readNextByteArray(PAD_LENGTH);
		e_type = reader.readNextShort();
		e_machine = reader.readNextShort();
		e_version = reader.readNextInt();

		if (is32Bit()) {
			e_entry = reader.readNextInt() & 0xffffffffL;
			e_phoff = reader.readNextInt() & 0xffffffffL;
			e_shoff = reader.readNextInt() & 0xffffffffL;
		}
		else if (is64Bit()) {
			e_entry = reader.readNextLong();
			e_phoff = reader.readNextLong();
			e_shoff = reader.readNextLong();
		}
		else {
			throw new ElfException("Only 32-bit and 64-bit ELF headers are supported.");
		}

		e_flags = reader.readNextInt();
		e_ehsize = reader.readNextShort();
		e_phentsize = reader.readNextShort();
		e_phnum = reader.readNextShort();
		if (e_phnum < 0) {
			e_phnum = 0; // protect against stripped program headers
		}
		e_shentsize = reader.readNextShort();
		e_shnum = reader.readNextShort();
		if (e_shnum < 0) {
			e_shnum = 0; // protect against stripped section headers (have seen -1)
		}
		e_shstrndx = reader.readNextShort();
	}
	catch (IOException e) {
		throw new ElfException(e);
	}
}