Java Code Examples for ghidra.app.util.bin.BinaryReader#readNextShort()

The following examples show how to use ghidra.app.util.bin.BinaryReader#readNextShort() . 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: CodeAttribute.java    From ghidra with Apache License 2.0 6 votes vote down vote up
public CodeAttribute(BinaryReader reader, AbstractConstantPoolInfoJava[] constantPool)
		throws IOException {
	super(reader);

	maxStack = reader.readNextShort();
	maxLocals = reader.readNextShort();
	codeLength = reader.readNextInt();
	_codeOffset = reader.getPointerIndex();
	code = reader.readNextByteArray(codeLength);
	exceptionTableLength = reader.readNextShort();
	exceptionTable = new ExceptionHandlerJava[getExceptionTableLength()];
	for (int i = 0; i < getExceptionTableLength(); i++) {
		exceptionTable[i] = new ExceptionHandlerJava(reader);
	}
	attributesCount = reader.readNextShort();
	attributes = new AbstractAttributeInfo[getAttributesCount()];
	for (int i = 0; i < getAttributesCount(); i++) {
		attributes[i] = AttributeFactory.get(reader, constantPool);
	}
}
 
Example 2
Source File: CliTableMethodDef.java    From ghidra with Apache License 2.0 6 votes vote down vote up
public CliTableMethodDef(BinaryReader reader, CliStreamMetadata stream, CliTypeTable tableId)
		throws IOException {
	super(reader, stream, tableId);
	CliMethodDefRow lastRow = null;
	for (int i = 0; i < this.numRows; i++) {
		CliMethodDefRow row =
			new CliMethodDefRow(reader.readNextInt(), reader.readNextShort(),
				reader.readNextShort(), readStringIndex(reader), readBlobIndex(reader),
				readTableIndex(reader, CliTypeTable.Param));
		rows.add(row);
		strings.add(row.nameIndex);

		if (lastRow != null) {
			lastRow.nextRowParamIndex = row.paramIndex;
		}
		lastRow = row;
	}
	reader.setPointerIndex(this.readerOffset); // TODO: why do this, also elsewhere
}
 
Example 3
Source File: OmfLibraryRecord.java    From ghidra with Apache License 2.0 6 votes vote down vote up
public static boolean checkMagicNumer(BinaryReader reader) throws IOException {
	byte type = reader.readNextByte();
	if (type != (byte)0xF0)
		return false;

	int pageSize = (reader.readNextShort() & 0xffff) + 3;
	// Make sure page size is a power of 2,   2^4 - 2^15
	int count = 0;
	int mask = pageSize;
	while((mask & 1)==0) {
		count += 1;
		mask >>>= 1;
	}
	if (mask != 1) return false;		// Test if this is a power of 2
	if (count < 4) return false;
	if (count > 15) return false;
	reader.align(pageSize);
	type = reader.readNextByte();
	if ((type & 0xfc) != 0x80) return false;
	return true;
}
 
Example 4
Source File: OmfSegmentHeader.java    From ghidra with Apache License 2.0 6 votes vote down vote up
public OmfSegmentHeader(BinaryReader reader) throws IOException {
	readRecordHeader(reader);
	boolean hasBigFields = hasBigFields();
	segAttr = reader.readNextByte();
	int A = (segAttr >> 5) & 7;
	if (A == 0) {
		frameNumber = reader.readNextShort() & 0xffff;
		offset = reader.readNextByte() & 0xff;
		vma = (long)frameNumber + offset;
	}
	segmentLength = OmfRecord.readInt2Or4(reader, hasBigFields) & 0xffffffffL;
	segmentNameIndex = OmfRecord.readIndex(reader);
	classNameIndex = OmfRecord.readIndex(reader);
	overlayNameIndex = OmfRecord.readIndex(reader);
	readCheckSumByte(reader);
	int B = (segAttr>>1) & 1;
	if (B==1) {		// Ignore the segmentLength field
		if (getRecordType() == OmfRecord.SEGDEF) {
			segmentLength = 0x10000L;		// Exactly 64K segment
		}
		else {
			segmentLength = 0x100000000L;	// Exactly 4G segment
		}
	}
}
 
Example 5
Source File: CliTableProperty.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public CliTableProperty(BinaryReader reader, CliStreamMetadata stream, CliTypeTable tableId) throws IOException {
	super(reader, stream, tableId);
	for (int i = 0; i < this.numRows; i++) {
		CliPropertyRow row = new CliPropertyRow(reader.readNextShort(), readStringIndex(reader), readBlobIndex(reader));
		rows.add(row);
		strings.add(row.nameIndex);
	}
	reader.setPointerIndex(this.readerOffset);
}
 
Example 6
Source File: AnnotationJava.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public AnnotationJava(BinaryReader reader) throws IOException {
	typeIndex = reader.readNextShort();
	numberOfElementValuePairs = reader.readNextShort();
	elementValuePairs = new AnnotationElementValuePair[getNumberOfElementValuePairs()];
	for (int i = 0; i < getNumberOfElementValuePairs(); ++i) {
		elementValuePairs[i] = new AnnotationElementValuePair(reader);
	}
}
 
Example 7
Source File: XCoffSymbol.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public XCoffSymbol(BinaryReader reader, XCoffOptionalHeader optionalHeader) throws IOException {
	_optionalHeader = optionalHeader;

	n_name  = reader.readNextByteArray(SYMNMLEN);
	n_value  = reader.readNextInt();
	n_scnum  = reader.readNextShort();
	n_type   = reader.readNextShort();
	n_sclass = reader.readNextByte();
	n_numaux = reader.readNextByte();

	aux = new byte[n_numaux * SYMSZ];

	// 11th byte in the last auxiliary entry (csect)
	x_smclas = (n_numaux > 0) ? aux[aux.length - 7] : 0;	
}
 
Example 8
Source File: Ext4GroupDescriptor.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public Ext4GroupDescriptor( BinaryReader reader, boolean is64Bit ) throws IOException {
	this.is64Bit = is64Bit;
	
	bg_block_bitmap_lo = reader.readNextInt();
	bg_inode_bitmap_lo = reader.readNextInt();
	bg_inode_table_lo = reader.readNextInt();
	bg_free_blocks_count_lo = reader.readNextShort();
	bg_free_inodes_count_lo = reader.readNextShort();
	bg_used_dirs_count_lo = reader.readNextShort();
	bg_flags = reader.readNextShort();
	bg_exclude_bitmap_lo = reader.readNextInt();
	bg_block_bitmap_csum_lo = reader.readNextShort();
	bg_inode_bitmap_csum_lo = reader.readNextShort();
	bg_itable_unused_lo = reader.readNextShort();
	bg_checksum = reader.readNextShort();
	if( !this.is64Bit ) {
		return;
	}
	bg_block_bitmap_hi = reader.readNextInt();
	bg_inode_bitmap_hi = reader.readNextInt();
	bg_inode_table_hi = reader.readNextInt();
	bg_free_blocks_count_hi = reader.readNextShort();
	bg_free_inodes_count_hi = reader.readNextShort();
	bg_used_dirs_count_hi = reader.readNextShort();
	bg_itable_unused_hi = reader.readNextShort();
	bg_exclude_bitmap_hi = reader.readNextInt();
	bg_block_bitmap_csum_hi = reader.readNextShort();
	bg_inode_bitmap_csum_hi = reader.readNextShort();
	bg_reserved = reader.readNextInt();
}
 
Example 9
Source File: CliBlob.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private static int decodeCompressedInt(BinaryReader reader, boolean signed) throws IOException {
	byte firstByte = reader.peekNextByte();
	boolean isLittleEndian = reader.isLittleEndian();
	reader.setLittleEndian(false);
	int numBytes = getNumberBytesInCodedInt(firstByte);
	int decodedSize = 0;
	switch (numBytes) {
		case 1:
			byte codedByte = reader.readNextByte();
			if (signed)
				decodedSize = decodeCompressedSigned(codedByte);
			else
				decodedSize = decodeCompressedUnsigned(codedByte);
			break;
			
		case 2:
			short codedShort = reader.readNextShort();
			if (signed)
				decodedSize = decodeCompressedSigned(codedShort);
			else
				decodedSize = decodeCompressedUnsigned(codedShort);
			break;
			
		case 4:
			int codedInt = reader.readNextInt();
			if (signed)
				decodedSize = decodeCompressedSigned(codedInt);
			else
				decodedSize = decodeCompressedUnsigned(codedInt);
			break;
			
		default:
			break;
	}
	reader.setLittleEndian(isLittleEndian);
	return decodedSize;
}
 
Example 10
Source File: ModuleAttribute.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public ModuleAttributeExports(BinaryReader reader) throws IOException {
	exports_index = reader.readNextShort();
	exports_flags = reader.readNextShort();
	exports_to_count = reader.readNextShort();
	exports_to_index = new short[getExportsToCount()];
	for (int i = 0; i < getExportsToCount(); i++) {
		exports_to_index[i] = reader.readNextShort();
	}
}
 
Example 11
Source File: ConstantValueAttribute.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public ConstantValueAttribute(BinaryReader reader) throws IOException {
	super(reader);
	constantValueIndex = reader.readNextShort();
}
 
Example 12
Source File: ConstantPoolDynamicInfo.java    From ghidra with Apache License 2.0 4 votes vote down vote up
protected ConstantPoolDynamicInfo(BinaryReader reader) throws IOException {
	super(reader);
	bootstrap_method_attr_index = reader.readNextShort();
	name_and_type_index = reader.readNextShort();
}
 
Example 13
Source File: ModuleMainClassAttribute.java    From ghidra with Apache License 2.0 4 votes vote down vote up
protected ModuleMainClassAttribute(BinaryReader reader) throws IOException {
	super(reader);
	main_class_index = reader.readNextShort();
}
 
Example 14
Source File: CliCodedIndexUtils.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public static int readCodedIndex(BinaryReader reader, CliStreamMetadata stream, int bitsUsed, CliTypeTable tables[]) throws IOException {
	if (toDataType(stream, bitsUsed, tables).getLength() == WordDataType.dataType.getLength()) {
		return reader.readNextShort();
	}
	return reader.readNextInt();
}
 
Example 15
Source File: NestHostAttribute.java    From ghidra with Apache License 2.0 4 votes vote down vote up
protected NestHostAttribute(BinaryReader reader) throws IOException {
	super(reader);
	host_class_index = reader.readNextShort();
}
 
Example 16
Source File: ConstantPoolMethodHandleInfo.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public ConstantPoolMethodHandleInfo(BinaryReader reader) throws IOException {
	super(reader);
	referenceKind = reader.readNextByte();
	referenceIndex = reader.readNextShort();
}
 
Example 17
Source File: ConstantPoolClassInfo.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public ConstantPoolClassInfo(BinaryReader reader) throws IOException {
	super(reader);

	nameIndex = reader.readNextShort();
}
 
Example 18
Source File: AnnotationElementValuePair.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public AnnotationElementValuePair(BinaryReader reader) throws IOException {
	elementNameIndex = reader.readNextShort();
	value = new AnnotationElementValue(reader);
}
 
Example 19
Source File: CoffSymbolAuxEndOfStruct.java    From ghidra with Apache License 2.0 4 votes vote down vote up
CoffSymbolAuxEndOfStruct(BinaryReader reader) throws IOException {
	tagIndex = reader.readNextInt();
	unused1  = reader.readNextByteArray(2);
	size     = reader.readNextShort();
	unused2  = reader.readNextByteArray(10);
}
 
Example 20
Source File: CliAbstractTable.java    From ghidra with Apache License 2.0 2 votes vote down vote up
/**
 * Reads the GUID index that the reader is positioned at.
 * 
 * @param reader A reader that is positioned at the GUID index to read.
 * @return The GUID index that the reader is positioned at.
 * @throws IOException if there is a problem reading the GUID index.
 */
protected int readGuidIndex(BinaryReader reader) throws IOException {
	return metadataStream.getGuidIndexDataType() == DWordDataType.dataType
			? reader.readNextInt()
			: reader.readNextShort() & 0xffff;
}