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

The following examples show how to use ghidra.app.util.bin.format.FactoryBundledWithBinaryReader#readNextLong() . 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: RoutinesCommand.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void initRoutinesCommand(FactoryBundledWithBinaryReader reader, boolean is32bit)
		throws IOException {
	initLoadCommand(reader);
	this.is32bit = is32bit;
	if (is32bit) {
		init_address = reader.readNextInt() & 0xffffffffL;
		init_module  = reader.readNextInt() & 0xffffffffL;
		reserved1    = reader.readNextInt() & 0xffffffffL;
		reserved2    = reader.readNextInt() & 0xffffffffL;
		reserved3    = reader.readNextInt() & 0xffffffffL;
		reserved4    = reader.readNextInt() & 0xffffffffL;
		reserved5    = reader.readNextInt() & 0xffffffffL;
		reserved6    = reader.readNextInt() & 0xffffffffL;
	}
	else {
		init_address = reader.readNextLong();
		init_module  = reader.readNextLong();
		reserved1    = reader.readNextLong();
		reserved2    = reader.readNextLong();
		reserved3    = reader.readNextLong();
		reserved4    = reader.readNextLong();
		reserved5    = reader.readNextLong();
		reserved6    = reader.readNextLong();			
	}
}
 
Example 2
Source File: ThreadStateX86_64.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void initThreadStateX86_64(FactoryBundledWithBinaryReader reader) throws IOException {
	rax = reader.readNextLong();
	rbx = reader.readNextLong();
	rcx = reader.readNextLong();
	rdx = reader.readNextLong();
	rdi = reader.readNextLong();
	rsi = reader.readNextLong();
	rbp = reader.readNextLong();
	rsp = reader.readNextLong();
	r8 = reader.readNextLong();
	r9 = reader.readNextLong();
	r10 = reader.readNextLong();
	r11 = reader.readNextLong();
	r12 = reader.readNextLong();
	r13 = reader.readNextLong();
	r14 = reader.readNextLong();
	r15 = reader.readNextLong();
	rip = reader.readNextLong();
	rflags = reader.readNextLong();
	cs = reader.readNextLong();
	fs = reader.readNextLong();
	gs = reader.readNextLong();
}
 
Example 3
Source File: ElfRelocation.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void readEntryData(FactoryBundledWithBinaryReader reader) throws IOException {
	if (is32bit) {
		this.r_offset = reader.readNextInt() & Conv.INT_MASK;
		this.r_info = reader.readNextInt() & Conv.INT_MASK;
		if (hasAddend) {
			r_addend = reader.readNextInt() & Conv.INT_MASK;
		}
	}
	else {
		this.r_offset = reader.readNextLong();
		this.r_info = reader.readNextLong();
		if (hasAddend) {
			r_addend = reader.readNextLong();
		}
	}
}
 
Example 4
Source File: Section.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void initSection(FactoryBundledWithBinaryReader reader, boolean is32bit)
		throws IOException {
	this.reader = reader;
	this.is32bit = is32bit;

	sectname = reader.readNextAsciiString(MachConstants.NAME_LENGTH);
	segname = reader.readNextAsciiString(MachConstants.NAME_LENGTH);
	if (is32bit) {
		addr = reader.readNextInt() & 0xffffffffL;
		size = reader.readNextInt() & 0xffffffffL;
	}
	else {
		addr = reader.readNextLong();
		size = reader.readNextLong();
	}
	offset = reader.readNextInt();
	align = reader.readNextInt();
	reloff = reader.readNextInt();
	nrelocs = reader.readNextInt();
	flags = reader.readNextInt();
	reserved1 = reader.readNextInt();
	reserved2 = reader.readNextInt();

	if (!is32bit) {
		reserved3 = reader.readNextInt();
	}

	long index = reader.getPointerIndex();
	reader.setPointerIndex(reloff);
	for (int i = 0; i < nrelocs; ++i) {
		relocations.add(RelocationFactory.readRelocation(reader, is32bit));
	}
	reader.setPointerIndex(index);
}
 
Example 5
Source File: NList.java    From ghidra with Apache License 2.0 5 votes vote down vote up
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 6
Source File: SegmentCommand.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void initSegmentCommand(FactoryBundledWithBinaryReader reader, boolean is32bit)
		throws IOException {
	initLoadCommand(reader);
	this.is32bit = is32bit;

	segname = reader.readNextAsciiString(MachConstants.NAME_LENGTH);
	if (is32bit) {
		vmaddr = reader.readNextInt() & 0xffffffffL;
		vmsize = reader.readNextInt() & 0xffffffffL;
		fileoff = reader.readNextInt() & 0xffffffffL;
		filesize = reader.readNextInt() & 0xffffffffL;
	}
	else {
		vmaddr = reader.readNextLong();
		vmsize = reader.readNextLong();
		fileoff = reader.readNextLong();
		filesize = reader.readNextLong();
	}
	maxprot = reader.readNextInt();
	initprot = reader.readNextInt();
	nsects = reader.readNextInt();
	flags = reader.readNextInt();

	for (int i = 0; i < nsects; ++i) {
		sections.add(Section.createSection(reader, is32bit));
	}
}
 
Example 7
Source File: ThreadStateARM_64.java    From ghidra with Apache License 2.0 5 votes vote down vote up
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: ElfDynamic.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void initElfDynamic(FactoryBundledWithBinaryReader reader, ElfHeader elf)
	throws IOException {
this.elf = elf;
if (elf.is32Bit()) {
	d_tag = reader.readNextInt();
          d_val = reader.readNextInt() & Conv.INT_MASK;
      }
      else {
	d_tag = (int) reader.readNextLong();
          d_val = reader.readNextLong();
      }
  }
 
Example 9
Source File: SourceVersionCommand.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void initEntryPointCommand(FactoryBundledWithBinaryReader reader) throws IOException {
	initLoadCommand(reader);
	version = reader.readNextLong();
}
 
Example 10
Source File: EntryPointCommand.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void initEntryPointCommand(FactoryBundledWithBinaryReader reader) throws IOException {
	initLoadCommand(reader);
	entryOffset = reader.readNextLong();
	stackSize = reader.readNextLong();
}
 
Example 11
Source File: ThreadStatePPC.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private long read(FactoryBundledWithBinaryReader reader, boolean is32bit) throws IOException {
	if (is32bit) {
		return reader.readNextInt() & 0xffffffffL;
	}
	return reader.readNextLong();
}
 
Example 12
Source File: ElfSymbol.java    From ghidra with Apache License 2.0 4 votes vote down vote up
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 13
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);
	}
}