mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
GP-4263 added Edit Signature Override action to decompiler (Help still needed)
This commit is contained in:
parent
ad7694a7a9
commit
a4f7bb24b9
8 changed files with 243 additions and 93 deletions
|
@ -21,10 +21,12 @@ import generic.hash.SimpleCRC32;
|
|||
import ghidra.program.model.address.Address;
|
||||
import ghidra.program.model.data.*;
|
||||
import ghidra.program.model.listing.FunctionSignature;
|
||||
import ghidra.program.model.listing.Program;
|
||||
import ghidra.program.model.symbol.*;
|
||||
import ghidra.util.InvalidNameException;
|
||||
import ghidra.util.exception.DuplicateNameException;
|
||||
import ghidra.util.exception.InvalidInputException;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
||||
public class DataTypeSymbol {
|
||||
private Symbol sym; // Traditional symbol object
|
||||
|
@ -105,14 +107,12 @@ public class DataTypeSymbol {
|
|||
public static void deleteSymbols(String nmroot, Address addr, SymbolTable symtab,
|
||||
Namespace space) throws InvalidInputException {
|
||||
ArrayList<Symbol> dellist = new ArrayList<Symbol>();
|
||||
SymbolIterator iter = symtab.getSymbols(space);
|
||||
while (iter.hasNext()) {
|
||||
Symbol sym = iter.next();
|
||||
for (Symbol sym : symtab.getSymbols(addr)) {
|
||||
if (!sym.getName().startsWith(nmroot))
|
||||
continue;
|
||||
if (sym.getSymbolType() != SymbolType.LABEL)
|
||||
continue;
|
||||
if (!addr.equals(sym.getAddress()))
|
||||
if (space.equals(sym.getParentNamespace()))
|
||||
continue;
|
||||
if (sym.hasReferences())
|
||||
throw new InvalidInputException("DataTypeSymbol has a reference");
|
||||
|
@ -123,6 +123,34 @@ public class DataTypeSymbol {
|
|||
}
|
||||
}
|
||||
|
||||
public void cleanupUnusedOverride() {
|
||||
if (sym == null) {
|
||||
throw new RuntimeException("not instantiated with readSymbol method");
|
||||
}
|
||||
|
||||
// NOTE: Although the symbol may have just been deleted its name will still be
|
||||
// be accesible within its retained DB record.
|
||||
String overrideName = sym.getName(); // override marker symbol
|
||||
|
||||
Program program = sym.getProgram();
|
||||
SymbolTable symbolTable = program.getSymbolTable();
|
||||
String prefix = nmroot + "_";
|
||||
String hashSuffix = "_" + extractHash(overrideName);
|
||||
for (Symbol s : symbolTable.scanSymbolsByName(prefix)) {
|
||||
String n = s.getName();
|
||||
if (!n.startsWith(prefix)) {
|
||||
break; // stop scan
|
||||
}
|
||||
if (s.getSymbolType() == SymbolType.LABEL && n.endsWith(hashSuffix) &&
|
||||
HighFunction.isOverrideNamespace(s.getParentNamespace())) {
|
||||
return; // do nothing if any symbol found
|
||||
}
|
||||
}
|
||||
|
||||
// remove unused override signature
|
||||
program.getDataTypeManager().remove(getDataType(), TaskMonitor.DUMMY);
|
||||
}
|
||||
|
||||
public static DataTypeSymbol readSymbol(String cat, Symbol s) {
|
||||
if (s.getSymbolType() != SymbolType.LABEL) {
|
||||
throw new IllegalArgumentException("Expected CODE symbol");
|
||||
|
|
|
@ -40,6 +40,8 @@ import ghidra.util.exception.InvalidInputException;
|
|||
*/
|
||||
public class HighFunction extends PcodeSyntaxTree {
|
||||
public final static String DECOMPILER_TAG_MAP = "decompiler_tags";
|
||||
public final static String OVERRIDE_NAMESPACE_NAME = "override";
|
||||
|
||||
private Function func; // The traditional function object
|
||||
private Language language;
|
||||
private CompilerSpec compilerSpec;
|
||||
|
@ -485,14 +487,22 @@ public class HighFunction extends PcodeSyntaxTree {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean isOverrideNamespace(Namespace namespace) {
|
||||
if (!OVERRIDE_NAMESPACE_NAME.equals(namespace.getName())) {
|
||||
return false;
|
||||
}
|
||||
Namespace parent = namespace.getParentNamespace();
|
||||
return (parent instanceof Function);
|
||||
}
|
||||
|
||||
public static Namespace findOverrideSpace(Function func) {
|
||||
SymbolTable symtab = func.getProgram().getSymbolTable();
|
||||
return findNamespace(symtab, func, "override");
|
||||
return findNamespace(symtab, func, OVERRIDE_NAMESPACE_NAME);
|
||||
}
|
||||
|
||||
public static Namespace findCreateOverrideSpace(Function func) {
|
||||
SymbolTable symtab = func.getProgram().getSymbolTable();
|
||||
return findCreateNamespace(symtab, func, "override");
|
||||
return findCreateNamespace(symtab, func, OVERRIDE_NAMESPACE_NAME);
|
||||
}
|
||||
|
||||
public static Namespace findNamespace(SymbolTable symtab, Namespace parent, String name) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue