mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
Check original name in IsolateVariableTask
This commit is contained in:
parent
a3988a7db2
commit
cbcfaf54fa
4 changed files with 29 additions and 34 deletions
|
@ -115,7 +115,6 @@ void IfaceDecompCapability::registerCommands(IfaceStatus *status)
|
||||||
status->registerCom(new IfcRename(),"rename");
|
status->registerCom(new IfcRename(),"rename");
|
||||||
status->registerCom(new IfcRetype(),"retype");
|
status->registerCom(new IfcRetype(),"retype");
|
||||||
status->registerCom(new IfcRemove(),"remove");
|
status->registerCom(new IfcRemove(),"remove");
|
||||||
status->registerCom(new IfcIsolate(),"isolate");
|
|
||||||
status->registerCom(new IfcLockPrototype(),"prototype","lock");
|
status->registerCom(new IfcLockPrototype(),"prototype","lock");
|
||||||
status->registerCom(new IfcUnlockPrototype(),"prototype","unlock");
|
status->registerCom(new IfcUnlockPrototype(),"prototype","unlock");
|
||||||
status->registerCom(new IfcCommentInstr(),"comment","instruction");
|
status->registerCom(new IfcCommentInstr(),"comment","instruction");
|
||||||
|
@ -1058,32 +1057,6 @@ void IfcRetype::execute(istream &s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IfcIsolate::execute(istream &s)
|
|
||||||
|
|
||||||
{
|
|
||||||
string name;
|
|
||||||
|
|
||||||
s >> ws >> name;
|
|
||||||
if (name.size()==0)
|
|
||||||
throw IfaceParseError("Must specify name of symbol");
|
|
||||||
|
|
||||||
Symbol *sym;
|
|
||||||
vector<Symbol *> symList;
|
|
||||||
if (dcp->fd != (Funcdata *)0)
|
|
||||||
dcp->fd->getScopeLocal()->queryByName(name,symList);
|
|
||||||
else
|
|
||||||
dcp->conf->symboltab->getGlobalScope()->queryByName(name,symList);
|
|
||||||
|
|
||||||
if (symList.empty())
|
|
||||||
throw IfaceExecutionError("No symbol named: "+name);
|
|
||||||
if (symList.size() > 1)
|
|
||||||
throw IfaceExecutionError("More than one symbol named : "+name);
|
|
||||||
else
|
|
||||||
sym = symList[0];
|
|
||||||
|
|
||||||
sym->setIsolated(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Varnode *iface_read_varnode(IfaceDecompData *dcp,istream &s)
|
static Varnode *iface_read_varnode(IfaceDecompData *dcp,istream &s)
|
||||||
|
|
||||||
{ // Return varnode identified by input stream
|
{ // Return varnode identified by input stream
|
||||||
|
@ -1297,6 +1270,7 @@ void IfcTypeVarnode::execute(istream &s)
|
||||||
scope = dcp->fd->getScopeLocal(); // force it to be in function scope
|
scope = dcp->fd->getScopeLocal(); // force it to be in function scope
|
||||||
Symbol *sym = scope->addSymbol(name,ct,loc,pc)->getSymbol();
|
Symbol *sym = scope->addSymbol(name,ct,loc,pc)->getSymbol();
|
||||||
scope->setAttribute(sym,Varnode::typelock);
|
scope->setAttribute(sym,Varnode::typelock);
|
||||||
|
sym->setIsolated(true);
|
||||||
if (name.size() > 0)
|
if (name.size() > 0)
|
||||||
scope->setAttribute(sym,Varnode::namelock);
|
scope->setAttribute(sym,Varnode::namelock);
|
||||||
|
|
||||||
|
|
|
@ -304,11 +304,6 @@ public:
|
||||||
virtual void execute(istream &s);
|
virtual void execute(istream &s);
|
||||||
};
|
};
|
||||||
|
|
||||||
class IfcIsolate : public IfaceDecompCommand {
|
|
||||||
public:
|
|
||||||
virtual void execute(istream &s);
|
|
||||||
};
|
|
||||||
|
|
||||||
class IfcRemove : public IfaceDecompCommand {
|
class IfcRemove : public IfaceDecompCommand {
|
||||||
public:
|
public:
|
||||||
virtual void execute(istream &s);
|
virtual void execute(istream &s);
|
||||||
|
|
|
@ -1252,9 +1252,10 @@ void ScopeLocal::recoverNameRecommendationsForSymbols(void)
|
||||||
if (vn == (Varnode *)0) continue;
|
if (vn == (Varnode *)0) continue;
|
||||||
sym = vn->getHigh()->getSymbol();
|
sym = vn->getHigh()->getSymbol();
|
||||||
if (sym == (Symbol *)0) continue;
|
if (sym == (Symbol *)0) continue;
|
||||||
|
if ((sym->getFlags() & Varnode::addrtied)!=0)
|
||||||
|
continue; // Cannot use untied varnode as primary map for address tied symbol
|
||||||
SymbolEntry *entry = sym->getFirstWholeMap();
|
SymbolEntry *entry = sym->getFirstWholeMap();
|
||||||
if (entry->getAddr() != addr)
|
// entry->getAddr() does not need to match address of the recommendation
|
||||||
continue;
|
|
||||||
if (entry->getSize() != size) continue;
|
if (entry->getSize() != size) continue;
|
||||||
}
|
}
|
||||||
if (!sym->isNameUndefined()) continue;
|
if (!sym->isNameUndefined()) continue;
|
||||||
|
|
|
@ -33,6 +33,9 @@ public class IsolateVariableTask extends RenameTask {
|
||||||
private HighFunction highFunction;
|
private HighFunction highFunction;
|
||||||
private Function function;
|
private Function function;
|
||||||
private SourceType srcType;
|
private SourceType srcType;
|
||||||
|
private String originalName;
|
||||||
|
private boolean nameIsReserved;
|
||||||
|
private boolean instanceIsMapped;
|
||||||
|
|
||||||
public IsolateVariableTask(PluginTool tool, Program program, DecompilerPanel panel,
|
public IsolateVariableTask(PluginTool tool, Program program, DecompilerPanel panel,
|
||||||
ClangToken token, HighSymbol sym, SourceType st) {
|
ClangToken token, HighSymbol sym, SourceType st) {
|
||||||
|
@ -41,6 +44,21 @@ public class IsolateVariableTask extends RenameTask {
|
||||||
highFunction = highSymbol.getHighFunction();
|
highFunction = highSymbol.getHighFunction();
|
||||||
function = highFunction.getFunction();
|
function = highFunction.getFunction();
|
||||||
srcType = st;
|
srcType = st;
|
||||||
|
originalName = highSymbol.getName();
|
||||||
|
nameIsReserved = highSymbol.isNameLocked();
|
||||||
|
instanceIsMapped = false;
|
||||||
|
if (nameIsReserved) {
|
||||||
|
Varnode vn = token.getVarnode();
|
||||||
|
if (vn != null) {
|
||||||
|
instanceIsMapped =
|
||||||
|
(vn.getMergeGroup() == vn.getHigh().getRepresentative().getMergeGroup());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!nameIsReserved || instanceIsMapped) {
|
||||||
|
// We can keep the current name if
|
||||||
|
// either no locked symbol is using it, or if this instance is directly mapped to it
|
||||||
|
oldName = originalName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,6 +69,13 @@ public class IsolateVariableTask extends RenameTask {
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(String newNm) {
|
public boolean isValid(String newNm) {
|
||||||
newName = newNm;
|
newName = newNm;
|
||||||
|
if (newName.equals(originalName)) {
|
||||||
|
if (nameIsReserved && !instanceIsMapped) {
|
||||||
|
errorMsg = "The name \"" + originalName + "\" is attached to another instance";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
LocalSymbolMap localSymbolMap = highFunction.getLocalSymbolMap();
|
LocalSymbolMap localSymbolMap = highFunction.getLocalSymbolMap();
|
||||||
if (localSymbolMap.containsVariableWithName(newName) ||
|
if (localSymbolMap.containsVariableWithName(newName) ||
|
||||||
isSymbolInFunction(function, newName)) {
|
isSymbolInFunction(function, newName)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue