ghidra.app.util.importer.MessageLog Java Examples

The following examples show how to use ghidra.app.util.importer.MessageLog. 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: XmlLoader.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private boolean doImportWork(final ProgramXmlMgr mgr, final List<Option> options,
		final MessageLog log, Program prog, TaskMonitor monitor,
		final boolean isAddToProgram) throws IOException {
	MessageLog mgrLog = null;
	boolean success = false;
	try {
		XmlProgramOptions xmlOptions = new XmlProgramOptions();
		xmlOptions.setOptions(options);
		xmlOptions.setAddToProgram(isAddToProgram);
		mgrLog = mgr.read(prog, monitor, xmlOptions);
		log.copyFrom(mgrLog);
		success = true;
	}
	catch (Exception e) {
		String message = "(empty)";
		if (mgrLog != null && !"".equals(mgrLog.toString())) {
			message = mgrLog.toString();
		}
		if (log != null && !"".equals(log.toString())) {
			message = log.toString();
		}
		Msg.warn(this, "XML import exception, log: " + message, e);
		throw new IOException(e.getMessage(), e);
	}
	return success;
}
 
Example #2
Source File: PefLoader.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private MemoryBlock makeFakeImportBlock(Program program, List<ImportedSymbol> symbols,
		MessageLog log, TaskMonitor monitor) {
	int size = symbols.size() * 4;
	if (size == 0) {
		return null;
	}
	Address start = getImportSectionAddress(program);
	try {
		return program.getMemory().createInitializedBlock("IMPORTS", start, size, (byte) 0x00,
			monitor, false);
	}
	catch (Exception e) {
		log.appendException(e);
	}
	return null;
}
 
Example #3
Source File: DyldCacheAccelerateInfo.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void parseImageInfoExtra(Program program, Address accelerateInfoAddr, MessageLog log,
		TaskMonitor monitor) throws CancelledException {
	monitor.setMessage("Parsing DYLD image image info extras...");
	monitor.initialize(imageExtrasCount);
	reader.setPointerIndex(imagesExtrasOffset);
	try {
		for (int i = 0; i < imageExtrasCount; ++i) {
			imageInfoExtraList.add(new DyldCacheImageInfoExtra(reader));
			monitor.checkCanceled();
			monitor.incrementProgress(1);
		}
	}
	catch (IOException e) {
		log.appendMsg(DyldCacheAccelerateInfo.class.getSimpleName(),
			"Failed to parse dyld_cache_image_info_extra.");
	}
}
 
Example #4
Source File: AbstractDemanglerAnalyzer.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * This calss's default demangle method.  This may be overridden to change how errors are
 * handled.
 *  
 * @param mangled the mangled string
 * @param options the demangler options
 * @param log the error log
 * @return the demangled object; null if unsuccessful
 */
protected DemangledObject demangle(String mangled, DemanglerOptions options,
		MessageLog log) {

	DemangledObject demangled = null;
	try {
		demangled = doDemangle(mangled, options, log);
	}
	catch (Throwable e) {

		if (e instanceof DemangledException) {
			if (((DemangledException) e).isInvalidMangledName()) {
				//ignore invalid names, consider as not an error
				return null;
			}
		}

		log.appendMsg(getName(),
			"Unable to demangle symbol: " + mangled + ".  Message: " + e.getMessage());
		return null;
	}

	return demangled;
}
 
Example #5
Source File: HCS12ConventionAnalyzer.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public boolean added(Program program, AddressSetView set, TaskMonitor monitor, MessageLog log)
		throws CancelledException {

	// get all functions within the set
	FunctionIterator functions = program.getFunctionManager().getFunctions(set, true);
	for (Function function : functions) {

		// for each function body, search instructions
		AddressSetView body = function.getBody();
		InstructionIterator instructions = program.getListing().getInstructions(body, true);
		for (Instruction instr : instructions) {
			if (instr.getFlowType().isTerminal()) {
				checkReturn(program, instr);
			}
		}
	}
	return true;
}
 
Example #6
Source File: EntryPointCommand.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void markup(MachHeader header, FlatProgramAPI api, Address baseAddress, boolean isBinary,
		ProgramModule parentModule, TaskMonitor monitor, MessageLog log) {

	updateMonitor(monitor);
	try {
		if (isBinary) {
			createFragment(api, baseAddress, parentModule);
			Address address = baseAddress.getNewAddress(getStartIndex());
			api.createData(address, toDataType());
		}
	}
	catch (Exception e) {
		log.appendMsg("Unable to create " + getCommandName());
	}

}
 
Example #7
Source File: DexLoader.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void createMethods( Program program, DexHeader header, ClassDefItem item, List< EncodedMethod > methods, TaskMonitor monitor, MessageLog log ) throws Exception {
	for ( int i = 0 ; i < methods.size( ) ; ++i ) {
		monitor.checkCanceled( );

		EncodedMethod encodedMethod = methods.get( i );

		CodeItem codeItem = encodedMethod.getCodeItem( );

		Address methodIndexAddress = DexUtil.toLookupAddress( program, encodedMethod.getMethodIndex( ) );

		if ( codeItem == null ) {//external method
			//TODO
		}
		else {
			Address methodAddress = toAddr( program, DexUtil.METHOD_ADDRESS + encodedMethod.getCodeOffset( ) );

			byte [] instructionBytes = codeItem.getInstructionBytes( );
			program.getMemory( ).setBytes( methodAddress, instructionBytes );

			program.getMemory( ).setInt( methodIndexAddress, (int) methodAddress.getOffset( ) );
		}
	}
}
 
Example #8
Source File: DyldCacheHeader.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void markupAcceleratorInfo(Program program, AddressSpace space, TaskMonitor monitor,
		MessageLog log) throws CancelledException {
	monitor.setMessage("Marking up DYLD accelerator info...");
	monitor.initialize(1);
	try {
		if (accelerateInfo != null) {
			Address addr = space.getAddress(accelerateInfoAddr);
			DataUtilities.createData(program, addr, accelerateInfo.toDataType(), -1, false,
				DataUtilities.ClearDataMode.CHECK_FOR_SPACE);
			accelerateInfo.markup(program, addr, monitor, log);
		}
		monitor.incrementProgress(1);
	}
	catch (CodeUnitInsertionException | DuplicateNameException | IOException e) {
		log.appendMsg(DyldCacheHeader.class.getSimpleName(),
			"Failed to markup dyld_cache_accelerator_info.");
	}
}
 
Example #9
Source File: DataTypesXmlMgr.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Output data types in XML format for debugging purposes.
 * NOTE: There is no support for reading the XML produced by this
 * method.
 * @param outputFilename name of the output file
 * @throws IOException if there was a problem writing to the file
 */
public static void writeAsXMLForDebug(DataTypeManager dataManager, String outputFilename)
		throws IOException {
	if (!outputFilename.endsWith(".xml")) {
		outputFilename = outputFilename + ".xml";
	}
	File file = new File(outputFilename);

	XmlWriter writer = new XmlWriter(file, "PROGRAM.DTD");

	MessageLog log = new MessageLog();
	DataTypesXmlMgr mgr = new DataTypesXmlMgr(dataManager, log);
	try {
		mgr.write(writer, TaskMonitorAdapter.DUMMY_MONITOR);
	}
	catch (CancelledException e) {
	}

	writer.close();
}
 
Example #10
Source File: PeLoader.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void setProcessorContext(FileHeader fileHeader, Program program, TaskMonitor monitor,
		MessageLog log) {

	try {
		String machineName = fileHeader.getMachineName();
		if ("450".equals(machineName) || "452".equals(machineName)) {
			Register tmodeReg = program.getProgramContext().getRegister("TMode");
			if (tmodeReg == null) {
				return;
			}
			RegisterValue thumbMode = new RegisterValue(tmodeReg, BigInteger.ONE);
			AddressSpace space = program.getAddressFactory().getDefaultAddressSpace();
			program.getProgramContext().setRegisterValue(space.getMinAddress(),
				space.getMaxAddress(), thumbMode);
		}
	}
	catch (ContextChangeException e) {
		throw new AssertException("instructions should not exist");
	}
}
 
Example #11
Source File: BuildVersionCommand.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void markup(MachHeader header, FlatProgramAPI api, Address baseAddress, boolean isBinary,
		ProgramModule parentModule, TaskMonitor monitor, MessageLog log) {

	updateMonitor(monitor);
	try {
		if (isBinary) {
			createFragment(api, baseAddress, parentModule);
			Address address = baseAddress.getNewAddress(getStartIndex());
			api.createData(address, toDataType());
		}
	}
	catch (Exception e) {
		log.appendMsg("Unable to create " + getCommandName());
	}
}
 
Example #12
Source File: RunPathCommand.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void markup(MachHeader header, FlatProgramAPI api, Address baseAddress, boolean isBinary,
		ProgramModule parentModule, TaskMonitor monitor, MessageLog log) {
	updateMonitor(monitor);
	try {
		if (isBinary) {
			createFragment(api, baseAddress, parentModule);
			Address address = baseAddress.getNewAddress(getStartIndex());
			api.createData(address, toDataType());
			int length = getCommandSize() - path.getOffset();
			api.createAsciiString(address.add(path.getOffset()), length);
		}
	}
	catch (Exception e) {
		log.appendMsg("Unable to create " + getCommandName());
	}
}
 
Example #13
Source File: LoadConfigDataDirectory.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void markupSeHandler(Program program, boolean isBinary, TaskMonitor monitor,
		MessageLog log, NTHeader ntHeader) {
	long exceptionCount = lcd.getSeHandlerCount();
	long exceptionTable = lcd.getSeHandlerTable() - ntHeader.getOptionalHeader().getImageBase();
	if (exceptionCount > NTHeader.MAX_SANE_COUNT) {
		// a heuristic but...
		return;
	}

	Address addr = program.getAddressFactory().getDefaultAddressSpace().getAddress(
		va(exceptionTable, isBinary));
	setPlateComment(program, addr,
		"SEHandlerTable (0x" + Long.toHexString(exceptionCount) + " entries)");

	for (int i = 0; i < (int) exceptionCount; ++i) {
		if (monitor.isCancelled()) {
			return;
		}
		DataType dt = ntHeader.getOptionalHeader().is64bit() ? new ImageBaseOffset64DataType() : new ImageBaseOffset32DataType();

		PeUtils.createData(program, addr, dt, log);

		addr = addr.add(dt.getLength());
	}
}
 
Example #14
Source File: MemoryBlockUtilTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testDuplicateExceptionHandling() throws Exception {
	ByteProvider byteProvider = new ByteArrayProvider(new byte[1000]);
	FileBytes fileBytes =
		MemoryBlockUtils.createFileBytes(prog, byteProvider, TaskMonitor.DUMMY);

	MemoryBlockUtils.createInitializedBlock(prog, true, "test", addr(0), fileBytes, 0, 10, "",
		"", true, true, true, new MessageLog());
	MemoryBlockUtils.createInitializedBlock(prog, true, "test", addr(0), fileBytes, 0, 10, "",
		"", true, true, true, new MessageLog());
	MemoryBlockUtils.createInitializedBlock(prog, true, "test", addr(0), fileBytes, 0, 10, "",
		"", true, true, true, new MessageLog());

	MemoryBlock[] blocks = prog.getMemory().getBlocks();
	assertEquals(3, blocks.length);

	assertEquals("test", blocks[0].getName());
	assertEquals("test_1", blocks[1].getName());
	assertEquals("test_2", blocks[2].getName());

}
 
Example #15
Source File: ImportDataDirectory.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void markupINT(int intptr, int iatptr, boolean isBinary, Program program,
		ThunkData thunk, MessageLog log) {

	AddressSpace space = program.getAddressFactory().getDefaultAddressSpace();
	long thunkAddr = va(intptr, isBinary);
	Address thunkAddress = space.getAddress(thunkAddr);
	setEolComment(program, thunkAddress, thunk.getStructName());

	DataType dt = null;
	if (intptr == iatptr && !isBinary) {
		dt = PointerDataType.getPointer(null, program.getMinAddress().getPointerSize());
	}
	else {
		dt = ntHeader.getOptionalHeader().is64bit() ? (DataType) QWORD : (DataType) DWORD;
	}
	PeUtils.createData(program, thunkAddress, dt, log);
}
 
Example #16
Source File: PefDebugAnalyzer.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public boolean added(Program program, AddressSetView functionSet, TaskMonitor monitor,
		MessageLog log) {
	Listing listing = program.getListing();
	FunctionIterator functions = listing.getFunctions(functionSet, true);
	while (functions.hasNext() && !monitor.isCancelled()) {
		Function function = functions.next();
		Address address = function.getBody().getMaxAddress().add(1);
		if (isEnoughSpaceForDebugSymbol(program, address)) {
			try {
				applyStructure(program, address);
			}
			catch (Exception e) {
				Msg.error(this, "Unexpected Exception: " + e.getMessage(), e);
			}
		}
	}
	return true;
}
 
Example #17
Source File: DyldCacheAccelerateInfo.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void markupAcceleratorDof(Program program, Address accelerateInfoAddr,
		TaskMonitor monitor, MessageLog log) throws CancelledException {
	monitor.setMessage("Marking up DYLD DOF sections...");
	monitor.initialize(acceleratorDofList.size());
	try {
		Address addr = accelerateInfoAddr.add(dofSectionsOffset);
		for (DyldCacheAcceleratorDof dof : acceleratorDofList) {
			Data d = DataUtilities.createData(program, addr, dof.toDataType(), -1, false,
				DataUtilities.ClearDataMode.CHECK_FOR_SPACE);
			addr = addr.add(d.getLength());
			monitor.checkCanceled();
			monitor.incrementProgress(1);
		}
	}
	catch (CodeUnitInsertionException | DuplicateNameException | IOException e) {
		log.appendMsg(DyldCacheAccelerateInfo.class.getSimpleName(),
			"Failed to markup dyld_cache_accelerator_dof.");
	}
}
 
Example #18
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 #19
Source File: DyldCacheLocalSymbolsInfo.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void markupLocalSymbols(Program program, Address localSymbolsInfoAddr,
		TaskMonitor monitor, MessageLog log) throws CancelledException {
	monitor.setMessage("Marking up DYLD local symbol entries...");
	monitor.initialize(entriesCount);
	try {
		Address addr = localSymbolsInfoAddr.add(entriesOffset);
		for (DyldCacheLocalSymbolsEntry localSymbolsEntry : localSymbolsEntryList) {
			Data d = DataUtilities.createData(program, addr, localSymbolsEntry.toDataType(), -1,
				false, DataUtilities.ClearDataMode.CHECK_FOR_SPACE);
			addr = addr.add(d.getLength());
			monitor.checkCanceled();
			monitor.incrementProgress(1);
		}
	}
	catch (CodeUnitInsertionException | DuplicateNameException | IOException e) {
		log.appendMsg(DyldCacheAccelerateInfo.class.getSimpleName(),
			"Failed to markup dyld_cache_local_symbols_entry.");
	}
}
 
Example #20
Source File: ObjectiveC2_MessageAnalyzer.java    From ghidra with Apache License 2.0 6 votes vote down vote up
public boolean added(Program program, AddressSetView set, TaskMonitor monitor, MessageLog log)
		throws CancelledException {
	AddressIterator iterator = set.getAddresses(true);
	while (iterator.hasNext()) {
		Address address = iterator.next();

		Function function = program.getListing().getFunctionAt(address);

		try {
			inspectFunction(program, function, monitor);
		}
		catch (Exception e) {
			// ignore
		}
	}

	return true;
}
 
Example #21
Source File: DyldCacheHeader.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void parseBranchPools(MessageLog log, TaskMonitor monitor) throws CancelledException {
	if (branchPoolsOffset == 0) {
		return;
	}
	monitor.setMessage("Parsing DYLD branch pool addresses...");
	monitor.initialize(branchPoolsCount);
	try {
		reader.setPointerIndex(branchPoolsOffset);
		for (int i = 0; i < branchPoolsCount; ++i) {
			branchPoolList.add(reader.readNextLong());
			monitor.checkCanceled();
			monitor.incrementProgress(1);
		}
	}
	catch (IOException e) {
		log.appendMsg(DyldCacheHeader.class.getSimpleName(), "Failed to parse pool addresses.");
	}
}
 
Example #22
Source File: MotorolaHexLoader.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Program> loadProgram(ByteProvider provider, String programName,
		DomainFolder programFolder, LoadSpec loadSpec, List<Option> options, MessageLog log,
		Object consumer, TaskMonitor monitor) throws IOException, CancelledException {
	LanguageCompilerSpecPair pair = loadSpec.getLanguageCompilerSpec();
	Language importerLanguage = getLanguageService().getLanguage(pair.languageID);
	CompilerSpec importerCompilerSpec =
		importerLanguage.getCompilerSpecByID(pair.compilerSpecID);

	Program prog = createProgram(provider, programName, null, getName(), importerLanguage,
		importerCompilerSpec, consumer);
	boolean success = false;
	try {
		success = loadInto(provider, loadSpec, options, log, prog, monitor);
		if (success) {
			createDefaultMemoryBlocks(prog, importerLanguage, log);
		}
	}
	finally {
		if (!success) {
			prog.release(consumer);
			prog = null;
		}
	}
	List<Program> results = new ArrayList<Program>();
	if (prog != null) {
		results.add(prog);
	}
	return results;
}
 
Example #23
Source File: SkeletonLoader.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options,
		Program program, TaskMonitor monitor, MessageLog log)
		throws CancelledException, IOException {

	// TODO: Load the bytes from 'provider' into the 'program'.
}
 
Example #24
Source File: AbstractLibrarySupportLoader.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * For each program in the programs list, fix up its external Library entries so
 * that they point to a path in the ghidra project.
 * <p>
 * Other programs in the programs list are matched first, then the
 * ghidraLibSearchFolders are searched for matches.
 *
 * @param programs the list of programs to resolve against each other.  Programs not saved
 * to the project will be considered as a valid external library.
 * @param domainFolder the {@link DomainFolder} folder within which imported libraries will
 * be searched.  This folder will be searched if a library is not found within the
 * list of programs supplied.  If null, only the list of programs will be considered.
 * @param saveIfModified flag to have this method save any programs it modifies
 * @param messageLog log for messages.
 * @param monitor the task monitor
 * @throws IOException if there was an IO-related problem resolving.
 * @throws CancelledException if the user cancelled the load.
 */
private void resolveExternalLibs(List<Program> programs, DomainFolder domainFolder,
		boolean saveIfModified, MessageLog messageLog, TaskMonitor monitor)
		throws CancelledException, IOException {

	Map<String, Program> progsByName = programs.stream().filter(Objects::nonNull).collect(
		Collectors.toMap((p) -> p.getDomainFile().getName(), (p) -> p));

	monitor.initialize(progsByName.size());
	for (Program program : progsByName.values()) {
		monitor.incrementProgress(1);
		if (monitor.isCancelled()) {
			return;
		}

		ExternalManager extManager = program.getExternalManager();
		String[] extLibNames = extManager.getExternalLibraryNames();
		if (extLibNames.length == 0 ||
			(extLibNames.length == 1 && Library.UNKNOWN.equals(extLibNames[0]))) {
			continue; // skip program if no libraries defined
		}

		monitor.setMessage("Resolving..." + program.getName());
		int id = program.startTransaction("resolving external references");
		try {
			resolveExternalLibs(program, progsByName, domainFolder, monitor, messageLog);
		}
		finally {
			program.endTransaction(id, true);
			if (saveIfModified && program.canSave() && program.isChanged()) {
				program.save("Resolve external references", monitor);
			}
		}
	}
}
 
Example #25
Source File: GccExceptionAnalyzer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public boolean added(Program program, AddressSetView addedLocationAddresses,
		TaskMonitor monitor, MessageLog log) throws CancelledException {

	if (visitedPrograms.contains(program)) {
		return true;
	}

	AutoAnalysisManager analysisManager = AutoAnalysisManager.getAnalysisManager(program);
	analysisManager.addListener(analysisListener);

	monitor.setMessage("Analyzing GCC exception-handling artifacts");
	monitor.setIndeterminate(true);
	monitor.setShowProgressValue(false);

	handleStandardSections(program, monitor, log);

	handleDebugFrameSection(program, monitor, log);

	// handleArmSections(program, monitor, log);

	visitedPrograms.add(program);
	monitor.setIndeterminate(false);
	monitor.setShowProgressValue(true);

	return true;
}
 
Example #26
Source File: CliStreamHeader.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, IOException, MemoryAccessException {
	if (stream != null) {
		stream.markup(program, isBinary, monitor, log, ntHeader);
	}
}
 
Example #27
Source File: RoutinesCommand.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void markup(MachHeader header, FlatProgramAPI api, Address baseAddress, boolean isBinary, ProgramModule parentModule, TaskMonitor monitor, MessageLog log) {
	updateMonitor(monitor);
	try {
		if (isBinary) {
			createFragment(api, baseAddress, parentModule);
			Address addr = baseAddress.getNewAddress(getStartIndex());
			api.createData(addr, toDataType());
		}
	}
	catch (Exception e) {
		log.appendMsg("Unable to create "+getCommandName()+" - "+e.getMessage());
	}
}
 
Example #28
Source File: OmfLoader.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Log a (hopefully) descriptive error, if we can't process a specific relocation
 * @param program is the Program
 * @param log will receive the error message
 * @param state is the relocation record that could not be processed
 */
private void relocationError(Program program, MessageLog log, OmfFixupRecord.FixupState state) {
	String message;
	if (state.locAddress != null) {
		message = "Unable to process relocation at " + state.locAddress + " with type 0x" +
			Integer.toHexString(state.locationType);
		program.getBookmarkManager().setBookmark(state.locAddress, BookmarkType.ERROR,
			"Relocations", message);
	}
	else {
		message = "Badly broken relocation";
	}
	log.appendMsg(message);
}
 
Example #29
Source File: BaseRelocationDataDirectory.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 CodeUnitInsertionException {

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

       for (BaseRelocation reloc : relocs) {
           if (monitor.isCancelled()) {
               return;
           }

		PeUtils.createData(program, addr, DWORD, log);
           addr = addr.add(DWORD.getLength());

		PeUtils.createData(program, addr, DWORD, log);
           addr = addr.add(DWORD.getLength());

           int count = reloc.getCount();
           for (int j = 0 ; j < count ; ++j) {
               if (monitor.isCancelled()) {
                   return;
               }
			PeUtils.createData(program, addr, WORD, log);
              	addr = addr.add(WORD.getLength());
           }
       }
}
 
Example #30
Source File: ExporterDialog.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void displaySummaryResults(Exporter exporter, DomainObject obj) {
	File outputFile = getSelectedOutputFile();
	StringBuffer resultsBuffer = new StringBuffer();

	resultsBuffer.append("Destination file:       " + outputFile.getAbsolutePath() + "\n\n");
	resultsBuffer.append("Destination file Size:  " + outputFile.length() + "\n");
	resultsBuffer.append("Format:                 " + exporter.getName() + "\n\n");

	MessageLog log = exporter.getMessageLog();
	if (log != null) {
		resultsBuffer.append(log.toString());
	}

	HelpLocation helpLocation = new HelpLocation(GenericHelpTopics.ABOUT, "About_Program");

	Object tmpConsumer = new Object();
	obj.addConsumer(tmpConsumer);
	Swing.runLater(() -> {
		try {
			AboutDomainObjectUtils.displayInformation(tool, obj.getDomainFile(),
				obj.getMetadata(), "Export Results Summary", resultsBuffer.toString(),
				helpLocation);
		}
		finally {
			obj.release(tmpConsumer);
		}
	});

}