diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/EditFunctionSignatureDialog.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/EditFunctionSignatureDialog.java index ee87361506..f0b5b26922 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/EditFunctionSignatureDialog.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/EditFunctionSignatureDialog.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,11 +22,9 @@ import ghidra.app.cmd.function.ApplyFunctionSignatureCmd; import ghidra.app.cmd.function.FunctionRenameOption; import ghidra.framework.cmd.Command; import ghidra.framework.cmd.CompoundCmd; -import ghidra.framework.model.DomainObject; import ghidra.framework.plugintool.PluginTool; import ghidra.program.model.data.*; -import ghidra.program.model.listing.Function; -import ghidra.program.model.listing.FunctionSignature; +import ghidra.program.model.listing.*; import ghidra.program.model.symbol.SourceType; import ghidra.util.Msg; import ghidra.util.exception.CancelledException; @@ -148,7 +146,7 @@ public class EditFunctionSignatureDialog extends AbstractEditFunctionSignatureDi @Override protected boolean applyChanges() throws CancelledException { // create the command - Command command = createCommand(); + Command command = createCommand(); if (command == null) { return false; @@ -164,9 +162,9 @@ public class EditFunctionSignatureDialog extends AbstractEditFunctionSignatureDi return true; } - private Command createCommand() throws CancelledException { + private Command createCommand() throws CancelledException { - Command cmd = null; + Command cmd = null; if (isSignatureChanged() || isCallingConventionChanged() || (function.getSignatureSource() == SourceType.DEFAULT)) { @@ -179,20 +177,20 @@ public class EditFunctionSignatureDialog extends AbstractEditFunctionSignatureDi FunctionRenameOption.RENAME); } - CompoundCmd compoundCommand = new CompoundCmd("Update Function Signature"); + CompoundCmd compoundCommand = new CompoundCmd<>("Update Function Signature"); - compoundCommand.add(new Command() { + compoundCommand.add(new Command() { String errMsg = null; @Override - public boolean applyTo(DomainObject obj) { + public boolean applyTo(Program p) { try { String conventionName = getCallingConvention(); function.setCallingConvention(conventionName); return true; } catch (InvalidInputException e) { - errMsg = "Invalid calling convention. " + e.getMessage(); + errMsg = e.getMessage(); Msg.error(this, "Unexpected Exception: " + e.getMessage(), e); return false; } @@ -209,9 +207,9 @@ public class EditFunctionSignatureDialog extends AbstractEditFunctionSignatureDi } }); if (allowInLine) { - compoundCommand.add(new Command() { + compoundCommand.add(new Command() { @Override - public boolean applyTo(DomainObject obj) { + public boolean applyTo(Program p) { function.setInline(isInlineSelected()); return true; } @@ -228,9 +226,9 @@ public class EditFunctionSignatureDialog extends AbstractEditFunctionSignatureDi }); } if (allowNoReturn) { - compoundCommand.add(new Command() { + compoundCommand.add(new Command() { @Override - public boolean applyTo(DomainObject obj) { + public boolean applyTo(Program p) { function.setNoReturn(hasNoReturnSelected()); return true; } @@ -247,9 +245,9 @@ public class EditFunctionSignatureDialog extends AbstractEditFunctionSignatureDi }); } if (allowCallFixup) { - compoundCommand.add(new Command() { + compoundCommand.add(new Command() { @Override - public boolean applyTo(DomainObject obj) { + public boolean applyTo(Program p) { function.setCallFixup(getCallFixupSelection()); return true; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/util/FunctionUtility.java b/Ghidra/Features/Base/src/main/java/ghidra/program/util/FunctionUtility.java index 7f5d780013..01e101a9fa 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/program/util/FunctionUtility.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/program/util/FunctionUtility.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -380,7 +380,17 @@ public class FunctionUtility { if (CompilerSpec.CALLING_CONVENTION_thiscall.equals(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(); } diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/cmd/function/DecompilerParameterIdCmd.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/cmd/function/DecompilerParameterIdCmd.java index 74d8b210ad..b91b95d2f3 100644 --- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/cmd/function/DecompilerParameterIdCmd.java +++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/cmd/function/DecompilerParameterIdCmd.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -314,8 +314,8 @@ public class DecompilerParameterIdCmd extends BackgroundCommand { func.setCallingConvention(CompilerSpec.CALLING_CONVENTION_cdecl); } catch (InvalidInputException e) { - setStatusMsg("Invalid Calling Convention " + CompilerSpec.CALLING_CONVENTION_cdecl + - " : " + e); + setStatusMsg( + "Unknown calling convention: " + CompilerSpec.CALLING_CONVENTION_cdecl); } } } diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeManagerDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeManagerDB.java index 6cddc3457d..5c5a69cf6b 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeManagerDB.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeManagerDB.java @@ -4144,10 +4144,9 @@ abstract public class DataTypeManagerDB implements DataTypeManager { if (restrictive && GenericCallingConvention .getGenericCallingConvention(name) == GenericCallingConvention.unknown && - !getKnownCallingConventionNames().contains(name) && - getCallingConvention(name) == null) { + !getKnownCallingConventionNames().contains(name)) { - throw new InvalidInputException("Invalid calling convention name: " + name); + throw new InvalidInputException("Unknown calling convention name: " + name); } return callingConventionAdapter.getCallingConventionId(name, diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/FunctionDefinitionDataType.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/FunctionDefinitionDataType.java index 99cfc04ccc..f4ca1e0168 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/FunctionDefinitionDataType.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/FunctionDefinitionDataType.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -188,17 +188,9 @@ public class FunctionDefinitionDataType extends GenericDataType implements Funct } if (GenericCallingConvention - .getGenericCallingConvention(conventionName) != GenericCallingConvention.unknown) { - ProgramArchitecture arch = dataMgr != null ? dataMgr.getProgramArchitecture() : null; - if (arch != null) { - CompilerSpec compilerSpec = arch.getCompilerSpec(); - PrototypeModel callingConvention = - compilerSpec.getCallingConvention(conventionName); - if (callingConvention == null) { - throw new InvalidInputException( - "Invalid calling convention name: " + conventionName); - } - } + .getGenericCallingConvention(conventionName) == GenericCallingConvention.unknown && + !dataMgr.getKnownCallingConventionNames().contains(name)) { + throw new InvalidInputException("Unknown calling convention name: " + conventionName); } this.callingConventionName = conventionName;