Java Code Examples for ghidra.util.task.TaskMonitor#addCancelledListener()

The following examples show how to use ghidra.util.task.TaskMonitor#addCancelledListener() . 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: JadProcessController.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public void decompile(int timeoutSecs, TaskMonitor monitor) throws IOException {

		monitor.addCancelledListener(listener);

		GTimerMonitor timerMonitor = GTimer.scheduleRunnable(timeoutSecs * 1000, timeoutRunnable);

		try {
			String[] commands = wrapper.getCommands();

			// TODO: JAD will write its output files into its current directory.
			// following line should be changed to wrapper.getOutputDirectory()
			// TODO: JAD will output to file name taken from data inside the .class file.
			// TODO: use -p to force output to stdout.
			process = runtime.exec(commands, environment, wrapper.getWorkingDirectory());

			if (process == null) {
				System.out.println("native process is null");
				return;
			}

			stdin = process.getInputStream();
			stderr = process.getErrorStream();

			readMessagesFromProcess(stdin, "JAD STDOUT " + desc, monitor);
			readMessagesFromProcess(stderr, "JAD STDERR " + desc, monitor);

			waitForProcess();

			disposeState = DisposeState.ENDED_HAPPY;
		}
		finally {
			timerMonitor.cancel();
		}
	}
 
Example 2
Source File: DecompInterface.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public synchronized BlockGraph structureGraph(BlockGraph ingraph, AddressFactory factory,
		int timeoutSecs, TaskMonitor monitor) {
	decompileMessage = "";
	if (monitor != null && monitor.isCancelled()) {
		return null;
	}
	if (monitor != null) {
		monitor.addCancelledListener(monitorListener);
	}
	LimitedByteBuffer res = null;
	BlockGraph resgraph = null;
	try {
		StringWriter writer = new StringWriter();
		ingraph.saveXml(writer);
		verifyProcess();
		res = decompProcess.sendCommand1ParamTimeout("structureGraph", writer.toString(),
			timeoutSecs);
		decompileMessage = decompCallback.getNativeMessage();
		if (res != null) {
			XmlPullParser parser = HighFunction.stringTree(res.getInputStream(),
				HighFunction.getErrorHandler(this, "Results for structureGraph command"));
			resgraph = new BlockGraph();
			resgraph.restoreXml(parser, factory);
			resgraph.transferObjectRef(ingraph);
		}
	}
	catch (Exception ex) {
		decompileMessage = "Exception while graph structuring: " + ex.getMessage() + '\n';
	}
	finally {
		if (monitor != null) {
			monitor.removeCancelledListener(monitorListener);
		}
	}
	return resgraph;
}
 
Example 3
Source File: ConcurrentQ.java    From ghidra with Apache License 2.0 4 votes vote down vote up
QMonitorAdapter(TaskMonitor monitor, boolean cancelClearsAll) {
	this.monitor = monitor;
	cancelClearsAllJobs = cancelClearsAll;
	addProgressListener(this);
	monitor.addCancelledListener(this);
}
 
Example 4
Source File: DecompInterface.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Decompile function
 * @param func function to be decompiled
 * @param timeoutSecs if decompile does not complete in this time a null value
 * will be returned and a timeout error set.
 * @param monitor optional task monitor which may be used to cancel decompile
 * @return decompiled function text
 */
public synchronized DecompileResults decompileFunction(Function func, int timeoutSecs,
		TaskMonitor monitor) {

	decompileMessage = "";
	if (monitor != null && monitor.isCancelled()) {
		return null;
	}

	LimitedByteBuffer res = null;
	if (monitor != null) {
		monitor.addCancelledListener(monitorListener);
	}

	if (program == null) {
		return new DecompileResults(func, pcodelanguage, null, dtmanage, decompileMessage, null,
			DecompileProcess.DisposeState.DISPOSED_ON_CANCEL,
			false /* cancelled--doesn't matter */);
	}

	try {
		Address funcEntry = func.getEntryPoint();
		if (debug != null) {
			debug.setFunction(func);
		}
		decompCallback.setFunction(func, funcEntry, debug);
		String addrstring = Varnode.buildXMLAddress(funcEntry);
		verifyProcess();
		res = decompProcess.sendCommand1ParamTimeout("decompileAt", addrstring.toString(),
			timeoutSecs);
		decompileMessage = decompCallback.getNativeMessage();
	}
	catch (Exception ex) {
		decompileMessage = "Exception while decompiling " + func.getEntryPoint() + ": " +
			ex.getMessage() + '\n';
	}
	finally {
		if (monitor != null) {
			monitor.removeCancelledListener(monitorListener);
		}
	}
	if (debug != null) {
		debug.shutdown(pcodelanguage, xmlOptions.getXML(this));
		debug = null;
	}

	DecompileProcess.DisposeState processState;
	if (decompProcess != null) {
		processState = decompProcess.getDisposeState();
		if (decompProcess.getDisposeState() == DecompileProcess.DisposeState.NOT_DISPOSED) {
			flushCache();
		}
	}
	else {
		processState = DecompileProcess.DisposeState.DISPOSED_ON_CANCEL;
	}

	InputStream stream = null;
	if (res != null) {
		stream = res.getInputStream();
	}
	return new DecompileResults(func, pcodelanguage, compilerSpec, dtmanage, decompileMessage,
		stream, processState, isDisplayNamespace());
}