Java Code Examples for ghidra.program.model.listing.Function#setCallingConvention()
The following examples show how to use
ghidra.program.model.listing.Function#setCallingConvention() .
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: HCS12ConventionAnalyzer.java From ghidra with Apache License 2.0 | 6 votes |
private void setPrototypeModel(Program program, Instruction instr, String convention) { if (convention == null) { return; } Function func = program.getFunctionManager().getFunctionContaining(instr.getMinAddress()); if (func == null) { return; } if (func.getSignatureSource() != SourceType.DEFAULT) { return; } try { func.setCallingConvention(convention); } catch (InvalidInputException e) { Msg.error(this, "Unexpected Exception: " + e.getMessage(), e); } }
Example 2
Source File: DecompilerParallelConventionAnalysisCmd.java From ghidra with Apache License 2.0 | 5 votes |
private SourceType updateCallingConvention(Function f, SourceType signatureSource, HighFunction highFunction, String modelName) throws InvalidInputException { // do the number of parameters disagree and decompiler says there is one more Namespace parentNamespace = f.getParentNamespace(); if (f.getParameterCount() + 1 == highFunction.getFunctionPrototype().getNumParams()) { // does it have a namespace if (parentNamespace.getID() != Namespace.GLOBAL_NAMESPACE_ID && // prevent accidental treatment of std namespace as class !parentNamespace.getName().equals(STD_NAMESPACE)) { // does it have a this call convention that is the equivalent of the stdcall PrototypeModel callingConvention = program.getCompilerSpec().getCallingConvention( CompilerSpec.CALLING_CONVENTION_thiscall); if (callingConvention != null) { modelName = CompilerSpec.CALLING_CONVENTION_thiscall; } } } // Then is __thiscall, create an object and new parameter if it doesn't have one yet. if (modelName.equals(CompilerSpec.CALLING_CONVENTION_stdcall) && f.getStackPurgeSize() == 0 && f.getParameterCount() > 0) { // if has parameters, and there is no purge, it can't be a stdcall, change it to cdecl if (program.getLanguageID().getIdAsString().startsWith("x86:LE:32")) { modelName = CompilerSpec.CALLING_CONVENTION_cdecl; // it could be a this call... } } if (parentNamespace.getSymbol().getSymbolType() == SymbolType.NAMESPACE && modelName.equals(CompilerSpec.CALLING_CONVENTION_thiscall)) { NamespaceUtils.convertNamespaceToClass(f.getParentNamespace()); } f.setCallingConvention(modelName); if (signatureSource == SourceType.DEFAULT) { signatureSource = SourceType.ANALYSIS; } return signatureSource; }