Java Code Examples for ghidra.program.model.listing.Program#getLanguage()

The following examples show how to use ghidra.program.model.listing.Program#getLanguage() . 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: PowerPCDisassembleAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean isEnabledForContext(ListingActionContext context) {

	Address address = context.getAddress();
	if (address == null) {
		return false;
	}

	// Action only intended for use where PowerPC VLE instructions are available.
	// The presence of the VLE variant indicator in the language ID can be used for this 
	// determination.

	Program program = context.getProgram();
	Language lang = program.getLanguage();
	Processor proc = lang.getProcessor();

	if (!proc.equals(Processor.findOrPossiblyCreateProcessor("PowerPC")) ||
		lang.getLanguageID().toString().indexOf(":VLE") < 0) {
		return false;
	}

	return plugin.checkDisassemblyEnabled(context, address, true);
}
 
Example 2
Source File: MipsDisassembleAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isEnabledForContext(ListingActionContext context) {

	Address address = context.getAddress();
	if (address == null) {
		return false;
	}

	Program program = context.getProgram();
	Language lang = program.getLanguage();
	Processor proc = lang.getProcessor();

	if (!"MIPS".equals(proc.toString())) {
		return false;
	}

	Register register = context.getProgram().getProgramContext().getRegister("ISA_MODE");
	if (register == null) {
		return false;
	}

	return plugin.checkDisassemblyEnabled(context, address, true);

}
 
Example 3
Source File: ProgramXmlMgr.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void writeProcessor(Program program, XmlWriter writer, TaskMonitor monitor) {
	monitor.setMessage("Writing PROCESSOR ...");

	XmlAttributes attrs = new XmlAttributes();
	Language language = program.getLanguage();
	CompilerSpec compilerSpec = program.getCompilerSpec();

	attrs.addAttribute("NAME", language.getProcessor().toString());
	attrs.addAttribute("LANGUAGE_PROVIDER", language.getLanguageID().getIdAsString() + ":" +
		compilerSpec.getCompilerSpecID().getIdAsString());
	attrs.addAttribute("ENDIAN", language.isBigEndian() ? "big" : "little");

	writer.startElement("PROCESSOR", attrs);
	writer.endElement("PROCESSOR");
}
 
Example 4
Source File: ElfeBPFRelocationFixupHandler.java    From eBPF-for-Ghidra with MIT License 5 votes vote down vote up
@Override
public boolean handlesProgram(Program program) {
	if (!ElfLoader.ELF_NAME.equals(program.getExecutableFormat())) {
		return false;
	}
	Language language = program.getLanguage();
	if (language.getLanguageDescription().getSize() != 64) {
		return false;
	}
	Processor processor = language.getProcessor();
	return (processor.equals(Processor.findOrPossiblyCreateProcessor("eBPF")));
}
 
Example 5
Source File: ObjectiveC1_State.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public ObjectiveC1_State(Program program, TaskMonitor monitor, CategoryPath categoryPath) {
	this.program       =  program;
	this.pointerSize   =  program.getAddressFactory().getDefaultAddressSpace().getPointerSize();
	this.is32bit       =  pointerSize * 8 == 32;
	this.is64bit       =  pointerSize * 8 == 64;
	this.monitor       =  monitor;
	this.encodings     =  new ObjectiveC1_TypeEncodings(pointerSize, categoryPath);

	Language language = program.getLanguage();
	this.isARM     = language.getProcessor().equals(Processor.findOrPossiblyCreateProcessor("ARM"));
	this.isPowerPC = language.getProcessor().equals(Processor.findOrPossiblyCreateProcessor("PowerPC"));
	this.isX86     = language.getProcessor().equals(Processor.findOrPossiblyCreateProcessor("x86"));
}
 
Example 6
Source File: DWARFAnalyzer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getDefaultEnablement(Program program) {
	// TODO: DWARF implementation needs improvements to handle Harvard Architectures properly
	// Currently unable to produce addresses which should refer to data space resulting in
	// improperly placed symbols, etc.
	Language language = program.getLanguage();
	return language.getDefaultSpace() == language.getDefaultDataSpace();
}
 
Example 7
Source File: Pe32RelocationFixupHandler.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public boolean handlesProgram(Program program) {
	if (!PeLoader.PE_NAME.equals(program.getExecutableFormat())) {
		return false;
	}
	Language language = program.getLanguage();
	if (language.getLanguageDescription().getSize() != 32) {
		return false;
	}
	Processor processor = language.getProcessor();
	return (processor.equals(Processor.findOrPossiblyCreateProcessor("x86")));
}
 
Example 8
Source File: Pe64RelocationFixupHandler.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public boolean handlesProgram(Program program) {
	if (!PeLoader.PE_NAME.equals(program.getExecutableFormat())) {
		return false;
	}
	Language language = program.getLanguage();
	if (language.getLanguageDescription().getSize() != 64) {
		return false;
	}
	Processor processor = language.getProcessor();
	return (processor.equals(Processor.findOrPossiblyCreateProcessor("x86")));
}
 
Example 9
Source File: StackVariableAnalyzer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private boolean useOldStackAnalysisByDefault(Program program) {
	Language language = program.getLanguage();
	if (language.getProcessor().equals(Processor.findOrPossiblyCreateProcessor("x86"))) {
		if (language.getLanguageDescription().getSize() == 16) {
			// Prefer using old stack analysis for x86 16-bit with segmented addresses
			return true;
		}
	}
	return false;
}
 
Example 10
Source File: SharedReturnAnalyzer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getDefaultEnablement(Program program) {
	Language language = program.getLanguage();

	boolean sharedReturnEnabled = language.getPropertyAsBoolean(
		GhidraLanguagePropertyKeys.ENABLE_SHARED_RETURN_ANALYSIS, true);

	return sharedReturnEnabled;
}
 
Example 11
Source File: Hcs12DisassembleAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isEnabledForContext(ListingActionContext context) {

	// Action only intended for use where Xgate instructions are available.
	// The presence of the XGATE context register can be used for this 
	// determination.
	
	Address address = context.getAddress();
	if ( address == null ) {
	    return false;
	}
	
	Program program = context.getProgram();
	Language lang = program.getLanguage();
	Processor proc = lang.getProcessor();

	if (!"HCS12".equals(proc.toString())) {
		return false;
	}
	
	Register register = context.getProgram().getProgramContext().getRegister("XGATE");
	if (register == null) {
		return false;
	}

	return plugin.checkDisassemblyEnabled(context, address, true);
}
 
Example 12
Source File: ArmDisassembleAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isEnabledForContext(ListingActionContext context) {

	// Action only intended for use where ARM Thumb instructions are available.
	// The presence of the ARM TMode context register can be used for this 
	// determination.
	
	Address address = context.getAddress();
	if ( address == null ) {
	    return false;
	}
	
	Program program = context.getProgram();
	Language lang = program.getLanguage();
	Processor proc = lang.getProcessor();

	if (!"ARM".equals(proc.toString())) {
		return false;
	}
	
	Register register = context.getProgram().getProgramContext().getRegister("TMode");
	if (register == null) {
		return false;
	}

	return plugin.checkDisassemblyEnabled(context, address, true);
}
 
Example 13
Source File: Elfx86_64bitRelocationFixupHandler.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public boolean handlesProgram(Program program) {
	if (!ElfLoader.ELF_NAME.equals(program.getExecutableFormat())) {
		return false;
	}
	Language language = program.getLanguage();
	if (language.getLanguageDescription().getSize() != 64) {
		return false;
	}
	Processor processor = language.getProcessor();
	return (processor.equals(Processor.findOrPossiblyCreateProcessor("x86")));
}
 
Example 14
Source File: Elfx86_32bitRelocationFixupHandler.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public boolean handlesProgram(Program program) {
	if (!ElfLoader.ELF_NAME.equals(program.getExecutableFormat())) {
		return false;
	}
	Language language = program.getLanguage();
	if (language.getLanguageDescription().getSize() != 32) {
		return false;
	}
	Processor processor = language.getProcessor();
	return (processor.equals(Processor.findOrPossiblyCreateProcessor("x86")));
}
 
Example 15
Source File: ClassFileAnalysisState.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public ClassFileAnalysisState(Program program) throws IOException {
	this.program = program;
	AddressFactory factory = program.getAddressFactory();
	AddressSpace space = factory.getAddressSpace("constantPool");
	if (space == null) {
		throw new IllegalStateException("Not a valid class file");
	}
	Memory memory = program.getMemory();
	MemoryByteProvider provider = new MemoryByteProvider(memory, space);
	BinaryReader reader = new BinaryReader(provider, false);
	classFile = new ClassFileJava(reader);
	uniqueFactory =
		new UniqueAddressFactory(program.getAddressFactory(), program.getLanguage());
}
 
Example 16
Source File: ElfArmRelocationFixupHandler.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public boolean handlesProgram(Program program) {
	if (!ElfLoader.ELF_NAME.equals(program.getExecutableFormat())) {
		return false;
	}
	Language language = program.getLanguage();
	if (language.getLanguageDescription().getSize() != 32) {
		return false;
	}
	Processor processor = language.getProcessor();
	return (processor.equals(Processor.findOrPossiblyCreateProcessor("ARM")));
}
 
Example 17
Source File: DecompInterface.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * This call initializes a new decompiler process to do
 * decompilations for a new program. This method only
 * needs to be called once per program.  Even if the
 * underlying decompiler process crashes, the interface
 * will automatically restart and reinitialize a new
 * process when it needs it, and the openProgram call
 * does not need to be made again. The call can be made
 * multiple times, in which case, each call terminates
 * the process initialized the last time and starts a
 * new process
 * @param prog = the program on which to perform decompilations
 * @return true if the decompiler process is successfully initialized
 */
public synchronized boolean openProgram(Program prog) {
	decompileMessage = "";
	program = prog;
	Language lang = prog.getLanguage();
	if (!lang.supportsPcode()) {
		decompileMessage = "Language does not support PCode.";
		return false;
	}
	pcodelanguage = (SleighLanguage) lang;
	CompilerSpec spec = prog.getCompilerSpec();
	if (!(spec instanceof BasicCompilerSpec)) {
		decompileMessage =
			"Language has unsupported compiler spec: " + spec.getClass().getName();
		return false;
	}
	compilerSpec = (BasicCompilerSpec) spec;

	dtmanage = new PcodeDataTypeManager(prog);
	try {
		decompCallback =
			new DecompileCallback(prog, pcodelanguage, program.getCompilerSpec(), dtmanage);
		initializeProcess();
		if (!decompProcess.isReady()) {
			throw new IOException("Unable to start decompiler process");
		}
		decompileMessage = decompCallback.getNativeMessage();
		if (!isErrorMessage()) {
			return true;
		}
	}
	catch (Exception ex) {
		decompileMessage = ex.getMessage();
		if (decompProcess == null) {
			return false;
		}
		stopProcess();
	}
	program = null;
	decompCallback = null;

	return false;
}
 
Example 18
Source File: VarnodeTranslator.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public VarnodeTranslator(Program program) {
	this(program.getLanguage());
}
 
Example 19
Source File: PseudoDisassembler.java    From ghidra with Apache License 2.0 3 votes vote down vote up
/**
 * Create a pseudo disassembler for the given program.
 */
public PseudoDisassembler(Program program) {
	this.program = program;

	memory = program.getMemory();

	this.language = program.getLanguage();

	pointerSize = program.getDefaultPointerSize();

	this.programContext = program.getProgramContext();
}
 
Example 20
Source File: SleighDebugLogger.java    From ghidra with Apache License 2.0 2 votes vote down vote up
/**
 * Performs a parse debug at the specified memory location within program.
 * @param program the program the memory location is found in
 * @param start the start address of the memory location
 * @param mode the sleigh debug mode
 * @throws IllegalArgumentException if program language provider is not Sleigh
 */
public SleighDebugLogger(Program program, Address start, SleighDebugMode mode) {
	this(new MemoryBufferImpl(program.getMemory(), start), new MyProcessorContextView(
		program.getProgramContext(), start), program.getLanguage(), mode);
}