mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 17:59:46 +02:00
Merge remote-tracking branch 'origin/GP-5216_ghidra1_BSimApplySignature'
(Closes #7310)
This commit is contained in:
commit
87666d830b
5 changed files with 40 additions and 41 deletions
|
@ -22,11 +22,9 @@ import ghidra.app.cmd.function.ApplyFunctionSignatureCmd;
|
||||||
import ghidra.app.cmd.function.FunctionRenameOption;
|
import ghidra.app.cmd.function.FunctionRenameOption;
|
||||||
import ghidra.framework.cmd.Command;
|
import ghidra.framework.cmd.Command;
|
||||||
import ghidra.framework.cmd.CompoundCmd;
|
import ghidra.framework.cmd.CompoundCmd;
|
||||||
import ghidra.framework.model.DomainObject;
|
|
||||||
import ghidra.framework.plugintool.PluginTool;
|
import ghidra.framework.plugintool.PluginTool;
|
||||||
import ghidra.program.model.data.*;
|
import ghidra.program.model.data.*;
|
||||||
import ghidra.program.model.listing.Function;
|
import ghidra.program.model.listing.*;
|
||||||
import ghidra.program.model.listing.FunctionSignature;
|
|
||||||
import ghidra.program.model.symbol.SourceType;
|
import ghidra.program.model.symbol.SourceType;
|
||||||
import ghidra.util.Msg;
|
import ghidra.util.Msg;
|
||||||
import ghidra.util.exception.CancelledException;
|
import ghidra.util.exception.CancelledException;
|
||||||
|
@ -148,7 +146,7 @@ public class EditFunctionSignatureDialog extends AbstractEditFunctionSignatureDi
|
||||||
@Override
|
@Override
|
||||||
protected boolean applyChanges() throws CancelledException {
|
protected boolean applyChanges() throws CancelledException {
|
||||||
// create the command
|
// create the command
|
||||||
Command command = createCommand();
|
Command<Program> command = createCommand();
|
||||||
|
|
||||||
if (command == null) {
|
if (command == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -164,9 +162,9 @@ public class EditFunctionSignatureDialog extends AbstractEditFunctionSignatureDi
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Command createCommand() throws CancelledException {
|
private Command<Program> createCommand() throws CancelledException {
|
||||||
|
|
||||||
Command cmd = null;
|
Command<Program> cmd = null;
|
||||||
if (isSignatureChanged() || isCallingConventionChanged() ||
|
if (isSignatureChanged() || isCallingConventionChanged() ||
|
||||||
(function.getSignatureSource() == SourceType.DEFAULT)) {
|
(function.getSignatureSource() == SourceType.DEFAULT)) {
|
||||||
|
|
||||||
|
@ -179,20 +177,20 @@ public class EditFunctionSignatureDialog extends AbstractEditFunctionSignatureDi
|
||||||
FunctionRenameOption.RENAME);
|
FunctionRenameOption.RENAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
CompoundCmd compoundCommand = new CompoundCmd("Update Function Signature");
|
CompoundCmd<Program> compoundCommand = new CompoundCmd<>("Update Function Signature");
|
||||||
|
|
||||||
compoundCommand.add(new Command() {
|
compoundCommand.add(new Command<Program>() {
|
||||||
String errMsg = null;
|
String errMsg = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applyTo(DomainObject obj) {
|
public boolean applyTo(Program p) {
|
||||||
try {
|
try {
|
||||||
String conventionName = getCallingConvention();
|
String conventionName = getCallingConvention();
|
||||||
function.setCallingConvention(conventionName);
|
function.setCallingConvention(conventionName);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (InvalidInputException e) {
|
catch (InvalidInputException e) {
|
||||||
errMsg = "Invalid calling convention. " + e.getMessage();
|
errMsg = e.getMessage();
|
||||||
Msg.error(this, "Unexpected Exception: " + e.getMessage(), e);
|
Msg.error(this, "Unexpected Exception: " + e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -209,9 +207,9 @@ public class EditFunctionSignatureDialog extends AbstractEditFunctionSignatureDi
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (allowInLine) {
|
if (allowInLine) {
|
||||||
compoundCommand.add(new Command() {
|
compoundCommand.add(new Command<Program>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean applyTo(DomainObject obj) {
|
public boolean applyTo(Program p) {
|
||||||
function.setInline(isInlineSelected());
|
function.setInline(isInlineSelected());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -228,9 +226,9 @@ public class EditFunctionSignatureDialog extends AbstractEditFunctionSignatureDi
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (allowNoReturn) {
|
if (allowNoReturn) {
|
||||||
compoundCommand.add(new Command() {
|
compoundCommand.add(new Command<Program>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean applyTo(DomainObject obj) {
|
public boolean applyTo(Program p) {
|
||||||
function.setNoReturn(hasNoReturnSelected());
|
function.setNoReturn(hasNoReturnSelected());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -247,9 +245,9 @@ public class EditFunctionSignatureDialog extends AbstractEditFunctionSignatureDi
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (allowCallFixup) {
|
if (allowCallFixup) {
|
||||||
compoundCommand.add(new Command() {
|
compoundCommand.add(new Command<Program>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean applyTo(DomainObject obj) {
|
public boolean applyTo(Program p) {
|
||||||
function.setCallFixup(getCallFixupSelection());
|
function.setCallFixup(getCallFixupSelection());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -380,7 +380,17 @@ public class FunctionUtility {
|
||||||
if (CompilerSpec.CALLING_CONVENTION_thiscall.equals(sourceConv)) {
|
if (CompilerSpec.CALLING_CONVENTION_thiscall.equals(sourceConv)) {
|
||||||
return sourceConv;
|
return sourceConv;
|
||||||
}
|
}
|
||||||
return sameLanguageAndCompilerSpec ? sourceFunction.getCallingConventionName()
|
boolean applyConventionName = sameLanguageAndCompilerSpec;
|
||||||
|
if (applyConventionName) {
|
||||||
|
DataTypeManager dtMgr = destinationFunction.getProgram().getDataTypeManager();
|
||||||
|
String name = destinationFunction.getCallingConventionName();
|
||||||
|
if (GenericCallingConvention
|
||||||
|
.getGenericCallingConvention(name) == GenericCallingConvention.unknown &&
|
||||||
|
!dtMgr.getKnownCallingConventionNames().contains(name)) {
|
||||||
|
applyConventionName = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return applyConventionName ? sourceFunction.getCallingConventionName()
|
||||||
: destinationFunction.getCallingConventionName();
|
: destinationFunction.getCallingConventionName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -314,8 +314,8 @@ public class DecompilerParameterIdCmd extends BackgroundCommand<Program> {
|
||||||
func.setCallingConvention(CompilerSpec.CALLING_CONVENTION_cdecl);
|
func.setCallingConvention(CompilerSpec.CALLING_CONVENTION_cdecl);
|
||||||
}
|
}
|
||||||
catch (InvalidInputException e) {
|
catch (InvalidInputException e) {
|
||||||
setStatusMsg("Invalid Calling Convention " + CompilerSpec.CALLING_CONVENTION_cdecl +
|
setStatusMsg(
|
||||||
" : " + e);
|
"Unknown calling convention: " + CompilerSpec.CALLING_CONVENTION_cdecl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4144,10 +4144,9 @@ abstract public class DataTypeManagerDB implements DataTypeManager {
|
||||||
if (restrictive &&
|
if (restrictive &&
|
||||||
GenericCallingConvention
|
GenericCallingConvention
|
||||||
.getGenericCallingConvention(name) == GenericCallingConvention.unknown &&
|
.getGenericCallingConvention(name) == GenericCallingConvention.unknown &&
|
||||||
!getKnownCallingConventionNames().contains(name) &&
|
!getKnownCallingConventionNames().contains(name)) {
|
||||||
getCallingConvention(name) == null) {
|
|
||||||
|
|
||||||
throw new InvalidInputException("Invalid calling convention name: " + name);
|
throw new InvalidInputException("Unknown calling convention name: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return callingConventionAdapter.getCallingConventionId(name,
|
return callingConventionAdapter.getCallingConventionId(name,
|
||||||
|
|
|
@ -188,17 +188,9 @@ public class FunctionDefinitionDataType extends GenericDataType implements Funct
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GenericCallingConvention
|
if (GenericCallingConvention
|
||||||
.getGenericCallingConvention(conventionName) != GenericCallingConvention.unknown) {
|
.getGenericCallingConvention(conventionName) == GenericCallingConvention.unknown &&
|
||||||
ProgramArchitecture arch = dataMgr != null ? dataMgr.getProgramArchitecture() : null;
|
!dataMgr.getKnownCallingConventionNames().contains(name)) {
|
||||||
if (arch != null) {
|
throw new InvalidInputException("Unknown calling convention name: " + conventionName);
|
||||||
CompilerSpec compilerSpec = arch.getCompilerSpec();
|
|
||||||
PrototypeModel callingConvention =
|
|
||||||
compilerSpec.getCallingConvention(conventionName);
|
|
||||||
if (callingConvention == null) {
|
|
||||||
throw new InvalidInputException(
|
|
||||||
"Invalid calling convention name: " + conventionName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.callingConventionName = conventionName;
|
this.callingConventionName = conventionName;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue