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

The following examples show how to use ghidra.app.util.bin.format.FactoryBundledWithBinaryReader#readAsciiString() . 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: BoundImportDescriptor.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void initBoundImportDescriptor(FactoryBundledWithBinaryReader reader, int readerIndex, int biddIndex) throws IOException {
    timeDateStamp               = reader.readInt  (readerIndex); readerIndex += BinaryReader.SIZEOF_INT;
    offsetModuleName            = reader.readShort(readerIndex); readerIndex += BinaryReader.SIZEOF_SHORT;
    numberOfModuleForwarderRefs = reader.readShort(readerIndex); readerIndex += BinaryReader.SIZEOF_SHORT;
    if (offsetModuleName < 0) {
    	Msg.error(this, "Invalid offsetModuleName "+offsetModuleName);
    	return;
    }

    moduleName = reader.readAsciiString(biddIndex + offsetModuleName);

    for (int i = 0 ; i < numberOfModuleForwarderRefs ; ++i) {
        forwarders.add(BoundImportForwarderRef.createBoundImportForwarderRef(reader, readerIndex, biddIndex));
        readerIndex += BoundImportForwarderRef.IMAGE_SIZEOF_BOUND_IMPORT_FORWARDER_REF;
    }
}
 
Example 2
Source File: BoundImportForwarderRef.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void initBoundImportForwarderRef(FactoryBundledWithBinaryReader reader, int readerIndex, int biddIndex) throws IOException {
    timeDateStamp    = reader.readInt  (readerIndex); readerIndex += BinaryReader.SIZEOF_INT;
    offsetModuleName = reader.readShort(readerIndex); readerIndex += BinaryReader.SIZEOF_SHORT;
    reserved         = reader.readShort(readerIndex); readerIndex += BinaryReader.SIZEOF_SHORT;
    if (offsetModuleName < 0) {
    	Msg.error(this, "Invalid offsetModuleName "+Integer.toHexString(offsetModuleName));
    	return;
    }

    moduleName = reader.readAsciiString(biddIndex + offsetModuleName);
}
 
Example 3
Source File: DelayImportDescriptor.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void readName(NTHeader ntHeader, FactoryBundledWithBinaryReader reader)
		throws IOException {
	if (szName == 0) {
		return;
	}
	long namePtr =
		(isUsingRVA() ? ntHeader.rvaToPointer(szName) : ntHeader.vaToPointer(szName));
	if (!ntHeader.checkPointer(namePtr)) {
		Msg.warn(this, "Invalid namePtr for "+Long.toHexString(szName));
		return;
	}
	dllName = reader.readAsciiString((int) namePtr);
}
 
Example 4
Source File: LoadCommandString.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void initLoadCommandString(FactoryBundledWithBinaryReader reader, LoadCommand command)
		throws IOException {
	offset = reader.readNextInt();
	string = reader.readAsciiString(command.getStartIndex() + offset);
}
 
Example 5
Source File: ElfString.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void initElfString(FactoryBundledWithBinaryReader reader, int stringOffset,
		ElfHeader header) throws IOException {
	this.header = header;
	this.stringOffset = stringOffset;
	this.string = reader.readAsciiString(0);
}
 
Example 6
Source File: DebugCOFFSymbolAux.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void initAuxFile(FactoryBundledWithBinaryReader reader, int index) throws IOException {
    name = reader.readAsciiString(index, DebugCOFFSymbol.IMAGE_SIZEOF_SYMBOL);
}
 
Example 7
Source File: SeparateDebugHeader.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * 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 8
Source File: NList.java    From ghidra with Apache License 2.0 3 votes vote down vote up
/**
 * Initialize the string from the string table.
 * <p>
 * You MUST call this method after the NLIST element is created!
 * <p>
 * Reading a large NList table can cause a large performance issue if the strings
 * are initialized as the NList entry is created.  The string table indexes are
 * scattered.  Initializing the strings linearly from the string table is much
 * faster.
 * 
 * @param reader 
 * @param stringTableOffset offset of the string table
 */
public void initString(FactoryBundledWithBinaryReader reader, long stringTableOffset) {
	try {
		string = reader.readAsciiString(stringTableOffset + n_strx);
	}
	catch (Exception e) {
		string = "";
	}
}