ghidra.program.model.address.AddressSpace Java Examples

The following examples show how to use ghidra.program.model.address.AddressSpace. 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: OverlaySpaceAdapterDB.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Adds existing overlay spaces to the factory.
 * @param factory the factory to add overlay spaces to
 * @throws IOException
 */
void initializeOverlaySpaces(ProgramAddressFactory factory) throws IOException {
	Table table = db.getTable(TABLE_NAME);
	if (table != null) {
		RecordIterator it = table.iterator();
		while (it.hasNext()) {
			Record rec = it.next();
			String spaceName = rec.getString(OV_SPACE_NAME_COL);
			String templateSpaceName = rec.getString(OV_SPACE_BASE_COL);
			long minOffset = rec.getLongValue(OV_MIN_OFFSET_COL);
			long maxOffset = rec.getLongValue(OV_MAX_OFFSET_COL);
			AddressSpace space = factory.getAddressSpace(templateSpaceName);
			try {
				OverlayAddressSpace sp =
					factory.addOverlayAddressSpace(spaceName, space, minOffset, maxOffset);
				sp.setDatabaseKey(rec.getKey());
			}
			catch (DuplicateNameException e) {
				throw new AssertException(
					"Should not have duplicateNameException when recreating factory");
			}
		}
	}
}
 
Example #2
Source File: EditExternalLocationPanel.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private boolean validLocationAddress() {

		AddressSpace locationAddressSpace = extAddressInputWidget.getAddressSpace();
		if (locationAddressSpace != null) {
			if (extAddressInputWidget.hasInput()) {
				Address locationAddress = extAddressInputWidget.getAddress();
				if (locationAddress == null) {
					showInputErr("Invalid address specified, " + locationAddressSpace.getName() +
						" offset must be in range: " +
						locationAddressSpace.getMinAddress().toString(false) + " to " +
						locationAddressSpace.getMaxAddress().toString(false));
					return false;
				}
			}
		}
		return true;
	}
 
Example #3
Source File: SymbolDatabaseAdapterV2.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * @see ghidra.program.database.symbol.SymbolDatabaseAdapter#getMaxSymbolAddress(ghidra.program.model.address.AddressSpace)
 */
@Override
Address getMaxSymbolAddress(AddressSpace space) throws IOException {
	if (space.isMemorySpace()) {
		AddressIndexKeyIterator addressKeyIterator =
			new AddressIndexKeyIterator(symbolTable, SYMBOL_ADDR_COL, addrMap,
				space.getMinAddress(), space.getMaxAddress(), false);
		if (addressKeyIterator.hasNext()) {
			return addrMap.decodeAddress(addressKeyIterator.next());
		}
	}
	else {
		LongField max = new LongField(addrMap.getKey(space.getMaxAddress(), false));
		DBFieldIterator iterator =
			symbolTable.indexFieldIterator(null, max, false, SYMBOL_ADDR_COL);
		if (iterator.hasPrevious()) {
			LongField val = (LongField) iterator.previous();
			Address addr = addrMap.decodeAddress(val.getLongValue());
			if (space.equals(addr.getAddressSpace())) {
				return addr;
			}
		}
	}
	return null;
}
 
Example #4
Source File: SecurityDataDirectory.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void markup(Program program, boolean isBinary, TaskMonitor monitor, MessageLog log,
		NTHeader ntHeader) throws DuplicateNameException, CodeUnitInsertionException,
		DataTypeConflictException, IOException {

	if (!isBinary) {//certificates are never mapped into running program...
		return;
	}

	monitor.setMessage(program.getName()+": security data...");

	AddressSpace space = program.getAddressFactory().getDefaultAddressSpace();
	Address addr = space.getAddress(virtualAddress);//NOTE: virtualAddress is only a binary offset inside file!!!

	createDirectoryBookmark(program, addr);

	program.getListing().clearCodeUnits(addr, addr, false);

	for (SecurityCertificate cert : certificates) {
		DataType dt = cert.toDataType();
		program.getListing().createData(addr, dt);
		addr = addr.add(dt.getLength());
	}
}
 
Example #5
Source File: AddBlockModelTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateOverlayBlock2() throws Exception {

	model.setBlockName(".test");
	model.setStartAddress(getAddr(0x01001000));
	model.setLength(100);
	model.setBlockType(MemoryBlockType.DEFAULT);
	model.setOverlay(true);
	model.setInitializedType(InitializedType.INITIALIZED_FROM_VALUE);
	model.setInitialValue(0xa);
	assertTrue(model.execute());
	MemoryBlock block = null;
	AddressSpace[] spaces = program.getAddressFactory().getAddressSpaces();
	AddressSpace ovSpace = null;
	for (AddressSpace space : spaces) {
		if (space.isOverlaySpace()) {
			ovSpace = space;
			Address blockAddr = space.getAddress(0x1001000);
			block = program.getMemory().getBlock(blockAddr);
			break;
		}
	}
	assertNotNull(block);
	assertEquals((byte) 0xa, block.getByte(ovSpace.getAddress(0x1001000)));
}
 
Example #6
Source File: MapLoader.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options, Program prog,
		TaskMonitor monitor, MessageLog log) throws IOException {

	if (!prog.getExecutableFormat().equals(PeLoader.PE_NAME)) {
		throw new IOException("Program must be a " + PeLoader.PE_NAME);
	}

	SymbolTable symtab = prog.getSymbolTable();
	AddressSpace space = prog.getAddressFactory().getDefaultAddressSpace();
	List<MapExport> exports = parseExports(provider, log);
	int successCount = 0;
	for (MapExport exp : exports) {
		try {
			symtab.createLabel(space.getAddress(exp.addr), exp.name,
				SourceType.IMPORTED).setPrimary();
			successCount++;
		}
		catch (InvalidInputException e) {
			log.appendMsg(e.getMessage());
		}
	}
	log.appendMsg("Added " + successCount + " symbols.");
}
 
Example #7
Source File: SymbolEntry.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected void buildRangelistXML(StringBuilder res) {
	if (pcaddr == null || pcaddr.isExternalAddress()) {
		res.append("<rangelist/>");
		return;
	}
	res.append("<rangelist>");
	AddressSpace space = pcaddr.getAddressSpace();
	long off;
	if (space.isOverlaySpace()) {
		space = space.getPhysicalSpace();
		off = space.getAddress(pcaddr.getOffset()).getUnsignedOffset();
	}
	else {
		off = pcaddr.getUnsignedOffset();
	}
	res.append("<range");
	SpecXmlUtils.encodeStringAttribute(res, "space", space.getName());
	SpecXmlUtils.encodeUnsignedIntegerAttribute(res, "first", off);
	SpecXmlUtils.encodeUnsignedIntegerAttribute(res, "last", off);
	res.append("/>");
	res.append("</rangelist>\n");
}
 
Example #8
Source File: ListingDisplaySearchAddressIterator.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void updateLastAddress(Address startAddress) {
	if (startAddress == null) {
		return;
	}

	if (forward) {
		if (startAddress.getOffset() > 0) {
			lastAddress = startAddress.subtract(1);
		}
	}
	else {
		// don't add past the address range
		AddressSpace addressSpace = startAddress.getAddressSpace();
		Address maxAddress = addressSpace.getMaxAddress();
		long maxOffset = maxAddress.getOffset();
		long startOffset = startAddress.getOffset();
		long result = startOffset + 1;
		if (result > startOffset && result < maxOffset) {
			lastAddress = startAddress.add(1);
		}
	}
}
 
Example #9
Source File: PcodeFormatter.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void formatMemoryInput(Program program, VarnodeTpl input0, VarnodeTpl input1,
		List<AttributedString> lineList) {
	if (!input0.getSpace().isConstSpace() || input0.getOffset().getType() != ConstTpl.REAL) {
		throw new RuntimeException("Expected constant input[0] for LOAD/STORE pcode op");
	}
	int id = (int) input0.getOffset().getReal();
	AddressSpace space = program.getAddressFactory().getAddressSpace(id);
	String spaceName;
	if (space == null) {
		Msg.error(PcodeFormatter.class, "Address space id not found: " + id);
		spaceName = "unknown";
	}
	else {
		spaceName = space.getName();
	}
	lineList.add(new AttributedString(spaceName, Color.BLUE, metrics));
	lineList.add(LEFT_PAREN);
	formatVarnodeTpl(program, -1, 1, input1, lineList);
	lineList.add(RIGHT_PAREN);
}
 
Example #10
Source File: DebugDataDirectory.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void markupDebugCodeView(Program program, boolean isBinary,
		MessageLog log, AddressSpace space) throws DuplicateNameException, IOException {
	DebugCodeView dcv = parser.getDebugCodeView();
	if (dcv != null) {
		Address dataAddr = getDataAddress(dcv.getDebugDirectory(), isBinary, space, ntHeader);
		if (dataAddr != null) {
			PdbInfoIface pdbInfo = dcv.getPdbInfo();
			if (pdbInfo != null) {
				setPlateComment(program, dataAddr, "CodeView PDB Info");
				PeUtils.createData(program, dataAddr, pdbInfo.toDataType(), log);
			}
			PdbInfoDotNetIface dotNetPdbInfo = dcv.getDotNetPdbInfo();
			if (dotNetPdbInfo != null) {
				setPlateComment(program, dataAddr, ".NET PDB Info");
				PeUtils.createData(program, dataAddr, dotNetPdbInfo.toDataType(), log);
			}
		}
	}
}
 
Example #11
Source File: InjectPayloadDexRange.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public PcodeOp[] getPcode(Program program, InjectContext con) {
	if (con.inputlist.size() != 2) {
		return null;			// Error
	}
	// The first Varnode must be a constant specifying the number of parameters
	int numParams = (int) con.inputlist.get(0).getOffset();
	// The second Varnode must be the first register to be moved
	long fromOffset = con.inputlist.get(1).getOffset();
	// Base of designated input registers
	long toOffset = InjectPayloadDexParameters.INPUT_REGISTER_START;
	AddressSpace registerSpace = program.getAddressFactory().getAddressSpace("register");
	PcodeOp[] resOps = new PcodeOp[numParams];
	for (int i = 0; i < numParams; ++i) {
		Address fromAddr = registerSpace.getAddress(fromOffset);
		Address toAddr = registerSpace.getAddress(toOffset);
		fromOffset += 4;
		toOffset += 4;
		PcodeOp op = new PcodeOp(con.baseAddr, i, PcodeOp.COPY);
		op.setInput(new Varnode(fromAddr, 4), 0);
		op.setOutput(new Varnode(toAddr, 4));
		resOps[i] = op;
	}
	return resOps;
}
 
Example #12
Source File: VariableLocation.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void restoreState(Program p, SaveState obj) {
	super.restoreState(p, obj);
	isParameter = obj.getBoolean("_IS_PARAMETER", false);
	ordinalOrfirstUseOffset = obj.getInt("_ORDINAL_FIRST_USE_OFFSET", 0);
	variableAddress = Address.NO_ADDRESS; // corresponds to return parameter
	if (obj.hasValue("_VARIABLE_OFFSET")) {
		long offset = obj.getLong("_VARIABLE_OFFSET", -1L);
		if (offset != -1) {
			variableAddress = AddressSpace.VARIABLE_SPACE.getAddress(offset);
		}
	}
}
 
Example #13
Source File: BoundImportDataDirectory.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void markup(Program program, boolean isBinary, TaskMonitor monitor, MessageLog log,
		NTHeader ntHeader) throws DuplicateNameException, CodeUnitInsertionException {

   	monitor.setMessage(program.getName()+": bound import(s)...");
	Address addr = PeUtils.getMarkupAddress(program, isBinary, ntHeader, virtualAddress);
	if (!program.getMemory().contains(addr)) {
		return;
	}
	createDirectoryBookmark(program, addr);

	AddressSpace space = program.getAddressFactory().getDefaultAddressSpace();

	for (BoundImportDescriptor descriptor : descriptors) {
           if (monitor.isCancelled()) {
               return;
           }
           DataType dt = descriptor.toDataType();
		PeUtils.createData(program, addr, dt, log);
           addr = addr.add(dt.getLength());

           long namePtr = descriptor.getOffsetModuleName()+virtualAddress;
           Address nameAddr = space.getAddress(va(namePtr, isBinary));
           createTerminatedString(program, nameAddr, false, log);
       }

	BoundImportDescriptor terminator = new BoundImportDescriptor();
	PeUtils.createData(program, addr, terminator.toDataType(), log);
   }
 
Example #14
Source File: CoffSectionHeader.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private static int getOffsetUnitSize(Language language, CoffSectionHeader section) {
	// Assumes all offset utilize a consistent unit size based upon the code space.
	// Keep notes here when this offset characterization is violated and a new one established.
	//   TMS320C55x appears to use byte offsets (unit sizes: code=1 data=2)
	AddressSpace codeSpace = language.getDefaultSpace(); // presumed code space
	if (section == null || !section.isExplicitlyByteAligned()) {
		return codeSpace.getAddressableUnitSize();
	}
	return 1;
}
 
Example #15
Source File: TRICOREEmulateInstructionStateModifier.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void evaluate(Emulate emu, Varnode outputVarnode, Varnode[] inputs) {
	int numArgs = inputs.length - 1;
	if (numArgs != 3) throw new LowlevelError(this.getClass().getName() + ": requires 3 inputs (FCX, LCX, PCXI), got " + numArgs);

	MemoryState memoryState = emu.getMemoryState();

	// compute new EA
	BigInteger FCXvalue = memoryState.getBigInteger(FCX);
	BigInteger PCXIvalue = memoryState.getBigInteger(PCXI);
	
	// read the value at FCX, if get nothing, then assume just increment the FCX to get to new node.
	
	// EA = {FCX.FCXS, 6'b0, FCX.FCXO, 6'b0};
	long ea = PCXIvalue.longValue();
	ea = ((ea & 0xffff0000) << 12) | ((ea & 0xffff) << 6);
	
	Address EA_addr = emu.getExecuteAddress().getNewAddress(ea);
	AddressSpace addressSpace = emu.getExecuteAddress().getAddressSpace();
	
	// read the bytes
	byte[] inBytes = new byte[4*16];
	memoryState.getChunk(inBytes, addressSpace, EA_addr.getOffset(), 4*16, true);
	//	{PCXI, PSW, A[10], A[11], D[8], D[9], D[10], D[11], A[12], A[13], A[14], A[15], D[12], D[13], D[14], D[15] = M(EA,16 * word)};
	int index = 0;
	index += copyArrayToRegister(PCXI, PCXI.getBitLength()/8, memoryState, inBytes, index);
	index += copyArrayToRegister(PSW, PSW.getBitLength()/8, memoryState, inBytes, index);
	index += copyArrayToRegister(a10, 2 * a10.getBitLength()/8, memoryState, inBytes, index);
	index += copyArrayToRegister(d8, 4 * d8.getBitLength()/8, memoryState, inBytes, index);
	index += copyArrayToRegister(a12, 4 * a12.getBitLength()/8, memoryState, inBytes, index);
	index += copyArrayToRegister(d12, 4 * d12.getBitLength()/8, memoryState, inBytes, index);	
		
	// M(EA, word) = FCX;
	memoryState.setValue(EA_addr.getAddressSpace(), EA_addr.getOffset(), 4, FCXvalue);

	// FCX[19:0] = new_FCX[19:0];
	FCXvalue = FCXvalue.andNot(BigInteger.valueOf(0x000fffff)).or(PCXIvalue.and(BigInteger.valueOf(0x000fffff)));
	memoryState.setValue(FCX, FCXvalue);
}
 
Example #16
Source File: AddressFieldFactory.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private String getAddressString(CodeUnit cu) {
	Address addr = cu.getMinAddress();
	AddressSpace space = addr.getAddressSpace();
	if (displayBlockName) {
		String text = addr.toString(false, padZeros ? 16 : minHexDigits);
		MemoryBlock block = cu.getProgram().getMemory().getBlock(addr);
		if (block != null) {
			return block.getName() + ":" + text;
		}
	}
	return addr.toString(space.showSpaceName(), padZeros ? 16 : minHexDigits);
}
 
Example #17
Source File: VarnodeBank.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public Iterator<VarnodeAST> locRange(AddressSpace spaceid) {
	VarnodeAST searchvn1 = new VarnodeAST(spaceid.getAddress(0),0,0);
	searchvn1.setInput(true);
	VarnodeAST searchvn2 = new VarnodeAST(spaceid.getAddress(Long.MAX_VALUE),0,0);
	searchvn2.setInput(true);
	return locTree.subSet(searchvn1,searchvn2).iterator();
}
 
Example #18
Source File: DelayImportDataDirectory.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void markupThunk(Program program, 
					boolean isBinary, 
					AddressSpace space, 
					DelayImportDescriptor descriptor,
					long ptr,
					List<ThunkData> thunks,
					TaskMonitor monitor,
					MessageLog log) {

	DataType dt = ntHeader.getOptionalHeader().is64bit() 
			? (DataType)QWORD 
			: (DataType)DWORD;
	
	long thunkPtr = va(ptr, isBinary);
	if (!descriptor.isUsingRVA()) {
		thunkPtr -= ntHeader.getOptionalHeader().getImageBase();
	}

	for (ThunkData thunk : thunks) {
		if (monitor.isCancelled()) {
			return;
		}
		Address thunkAddress = space.getAddress(thunkPtr);
		PeUtils.createData(program, thunkAddress, dt, log);
		setEolComment(program, thunkAddress, thunk.getStructName());
		thunkPtr += thunk.getStructSize();
	}
}
 
Example #19
Source File: TRICOREEmulateInstructionStateModifier.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private int copyArrayToRegister(Register reg, int len, MemoryState memoryState, byte[] inBytes, int i) {
	byte[] vBytes = new byte[len];
	AddressSpace spc = reg.getAddressSpace();
	System.arraycopy(inBytes, i, vBytes, 0, vBytes.length);
	memoryState.setChunk(vBytes, spc, reg.getOffset(), vBytes.length);
	return len;
}
 
Example #20
Source File: PIC30_ElfExtension.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public AddressSpace getPreferredSegmentAddressSpace(ElfLoadHelper elfLoadHelper,
		ElfProgramHeader elfProgramHeader) {
	Language language = elfLoadHelper.getProgram().getLanguage();
	if (isDataLoad(elfProgramHeader)) {
		return language.getDefaultDataSpace();
	}
	return language.getDefaultSpace();
}
 
Example #21
Source File: DynamicEntry.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public VariableStorage getStorage() {
	Program program = symbol.getProgram();
	try {
		return new VariableStorage(program, AddressSpace.HASH_SPACE.getAddress(getHash()),
			getSize());
	}
	catch (InvalidInputException e) {
		throw new AssertException("Unexpected exception", e);
	}
}
 
Example #22
Source File: TLSDataDirectory.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void markup(Program program, boolean isBinary, TaskMonitor monitor, MessageLog log,
		NTHeader ntHeader) throws DuplicateNameException, CodeUnitInsertionException,
		DataTypeConflictException, IOException {

	monitor.setMessage(program.getName()+": TLS...");
	Address addr = PeUtils.getMarkupAddress(program, isBinary, ntHeader, virtualAddress);
	if (!program.getMemory().contains(addr)) {
		return;
	}
	createDirectoryBookmark(program, addr);
	PeUtils.createData(program, addr, tls.toDataType(), log);

	// Markup TLS callback functions
	if (tls.getAddressOfCallBacks() != 0) {
		AddressSpace space = program.getImageBase().getAddressSpace();
		DataType pointerDataType = PointerDataType.dataType.clone(program.getDataTypeManager());
		try {
			for (int i = 0; i < 20; i++) { // cap # of TLS callbacks as a precaution (1 is the norm)
				Address nextCallbackPtrAddr = space.getAddress(
					tls.getAddressOfCallBacks() + i * pointerDataType.getLength());
				Address nextCallbackAddr = PointerDataType.getAddressValue(
					new DumbMemBufferImpl(program.getMemory(), nextCallbackPtrAddr),
					pointerDataType.getLength(), space);
				if (nextCallbackAddr.getOffset() == 0) {
					break;
				}
				PeUtils.createData(program, nextCallbackPtrAddr, pointerDataType, log);
				program.getSymbolTable().createLabel(nextCallbackAddr, "tls_callback_" + i,
					SourceType.IMPORTED);
				program.getSymbolTable().addExternalEntryPoint(nextCallbackAddr);
			}
		}
		catch (InvalidInputException e) {
			log.appendMsg("TLS", "Failed to markup TLS callback functions: " + e.getMessage());
		}
	}
}
 
Example #23
Source File: FilteredMemoryState.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public int getChunk(byte[] res, AddressSpace spc, long off, int size,
		boolean stopOnUnintialized) {
	int readLen = super.getChunk(res, spc, off, size, stopOnUnintialized);
	if (filterEnabled && filter != null) {
		filterEnabled = false;
		try {
			filter.filterRead(spc, off, readLen, res);
		}
		finally {
			filterEnabled = true;
		}
	}
	return readLen;
}
 
Example #24
Source File: FilteredMemoryState.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void setChunk(byte[] res, AddressSpace spc, long off, int size) {
	super.setChunk(res, spc, off, size);
	if (filterEnabled && filter != null) {
		filterEnabled = false;
		try {
			filter.filterWrite(spc, off, size, res);
		}
		finally {
			filterEnabled = true;
		}
	}
}
 
Example #25
Source File: DebugDataDirectory.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void markupDebigMisc(Program program, boolean isBinary,
		MessageLog log, AddressSpace space) throws DuplicateNameException {
	DebugMisc dm = parser.getDebugMisc();
	if (dm != null) {
		Address dataAddr = getDataAddress(dm.getDebugDirectory(), isBinary, space, ntHeader);
		if (dataAddr != null) {
			setPlateComment(program, dataAddr, "Misc Debug Info");
			PeUtils.createData(program, dataAddr, dm.toDataType(), log);
		}
	}
}
 
Example #26
Source File: DexAnalysisState.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Calculate the Address for every method in the list and add an entry to -methodMap-
 * @param defaultAddressSpace is the AddressSpace all encoded offsets are relative to
 * @param methodList is the list of encoded methods
 */
private void installMethodList(AddressSpace defaultAddressSpace,
		List<EncodedMethod> methodList) {
	for (EncodedMethod encodedMethod : methodList) {
		Address methodAddress = defaultAddressSpace.getAddress(
			DexUtil.METHOD_ADDRESS + encodedMethod.getCodeOffset());
		methodMap.put(methodAddress, encodedMethod);
	}
}
 
Example #27
Source File: StringsAnalyzerTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateStringOverUndefined() throws Exception {

	Program testProgram = buildProgram("stringOverUndefinedTest", false);

	Listing listing = testProgram.getListing();
	AddressSpace space = testProgram.getLanguage().getAddressFactory().getDefaultAddressSpace();
	Address addr = addr(space, 0x11000);

	// Create undefined data type at start and middle of string
	listing.createData(addr, Undefined.getUndefinedDataType(1));
	listing.createData(addr.add(3), Undefined.getUndefinedDataType(1));
	Data data = listing.getDefinedDataAt(addr);
	assertNotNull(data);

	// Run StringAnalyzer
	AutoAnalysisManager manager = AutoAnalysisManager.getAnalysisManager(testProgram);
	StringsAnalyzer analyzer = new StringsAnalyzer();
	analyzer.added(testProgram, null, monitor, manager.getMessageLog());

	// Make sure our string got created, despite the undefined being there
	data = listing.getDefinedDataAt(addr);
	assertNotNull(data);
	String type = data.getDataType().getName().toLowerCase();
	assertTrue("Data at address " + addr + " should be a type of string instead of " + type,
		type.contains("string"));
}
 
Example #28
Source File: MemoryState.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * This is the main interface for reading values from the MemoryState.
 * If there is no registered MemoryBank for the desired address space, or
 * if there is some other error, an exception is thrown.
 * @param spc is the address space being queried
 * @param off is the offset of the value being queried
 * @param size is the number of bytes to query
 * @param signed true if signed value should be returned, false for unsigned value
 * @return the queried unsigned value
 */
public final BigInteger getBigInteger(AddressSpace spc, long off, int size, boolean signed) {
	if (spc.isConstantSpace()) {
		if (!signed && off < 0) {
			return new BigInteger(1, Utils.longToBytes(off, 8, true));
		}
		return BigInteger.valueOf(off);
	}
	byte[] bytes = new byte[size];
	getChunk(bytes, spc, off, size, false);
	return Utils.bytesToBigInteger(bytes, size, language.isBigEndian(), signed);
}
 
Example #29
Source File: MemoryState.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Any MemoryBank that has been registered with this MemoryState can be retrieved via this
 * method if the MemoryBank's associated address space is known.
 * @param spc is the address space of the desired MemoryBank
 * @return the MemoryBank or null if no bank is associated with spc.
 */
public final MemoryBank getMemoryBank(AddressSpace spc) {
	int index = spc.getUnique();
	if (index >= memspace.size())
		return null;
	return memspace.get(index);
}
 
Example #30
Source File: PcodeFormatter.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Format VarnodeTpl in a manner consistent with Varnode.toString().
 * @param space address space
 * @param offset offset of type ConstTpl.REAL
 * @param size size of type ConstTpl.REAL
 * @param lineList
 */
private void formatRaw(AddressSpace space, ConstTpl offset, ConstTpl size,
		List<AttributedString> lineList) {
	// same format as the Varnode.toString
	String str =
		"(" + space.getName() + ", 0x" + Long.toHexString(offset.getReal()) + ", " +
			size.getReal() + ")";
	lineList.add(new AttributedString(str, Color.BLUE, metrics));
}