mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-26 03:46:08 +08:00
Merge remote-tracking branch 'origin/Ghidra_9.2'
This commit is contained in:
@@ -184,6 +184,13 @@
|
||||
<P>Shows all locations that reference the given symbol.</P>
|
||||
</BLOCKQUOTE>
|
||||
|
||||
<H2><A name="Convert_to_Class"></A>Convert Namespace to Class</H2>
|
||||
|
||||
<BLOCKQUOTE>
|
||||
<P>You can convert a <I>Namespace</I> to a <I>Class</I>.
|
||||
Right mouse click on a namespace and choose the <B>Convert To Class</B> option.</P>
|
||||
</BLOCKQUOTE>
|
||||
|
||||
<H2><A name="Create_Class"></A>Create a Class</H2>
|
||||
|
||||
<BLOCKQUOTE>
|
||||
|
||||
-2
@@ -316,8 +316,6 @@ public class StringTableProvider extends ComponentProviderAdapter implements Dom
|
||||
};
|
||||
|
||||
selectionNavigationAction = new SelectionNavigationAction(plugin, table);
|
||||
selectionNavigationAction.setHelpLocation(
|
||||
new HelpLocation(HelpTopics.SEARCH, "Strings_Selection_Navigation"));
|
||||
|
||||
addLocalAction(selectionNavigationAction);
|
||||
addLocalAction(selectAction);
|
||||
|
||||
+10
-2
@@ -206,8 +206,15 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
|
||||
DockingAction setExternalProgramAction = new SetExternalProgramAction(plugin, this);
|
||||
DockingAction createExternalLocationAction = new CreateExternalLocationAction(plugin);
|
||||
DockingAction editExternalLocationAction = new EditExternalLocationAction(plugin);
|
||||
DockingAction createClassAction = new CreateClassAction(plugin);
|
||||
DockingAction createNamespaceAction = new CreateNamespaceAction(plugin);
|
||||
|
||||
String createGroup = "0Create";
|
||||
int createGroupIndex = 0;
|
||||
DockingAction createNamespaceAction = new CreateNamespaceAction(plugin, createGroup,
|
||||
Integer.toString(createGroupIndex++));
|
||||
DockingAction createClassAction = new CreateClassAction(plugin, createGroup,
|
||||
Integer.toString(createGroupIndex++));
|
||||
DockingAction convertToClassAction = new ConvertToClassAction(plugin, createGroup,
|
||||
Integer.toString(createGroupIndex++));
|
||||
|
||||
DockingAction renameAction = new RenameAction(plugin);
|
||||
DockingAction cutAction = new CutAction(plugin, this);
|
||||
@@ -231,6 +238,7 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
|
||||
tool.addLocalAction(this, editExternalLocationAction);
|
||||
tool.addLocalAction(this, createClassAction);
|
||||
tool.addLocalAction(this, createNamespaceAction);
|
||||
tool.addLocalAction(this, convertToClassAction);
|
||||
tool.addLocalAction(this, renameAction);
|
||||
tool.addLocalAction(this, cutAction);
|
||||
tool.addLocalAction(this, pasteAction);
|
||||
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* 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.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ghidra.app.plugin.core.symboltree.actions;
|
||||
|
||||
import javax.swing.tree.TreePath;
|
||||
|
||||
import docking.action.MenuData;
|
||||
import docking.widgets.tree.GTreeNode;
|
||||
import ghidra.app.plugin.core.symboltree.*;
|
||||
import ghidra.app.plugin.core.symboltree.nodes.SymbolNode;
|
||||
import ghidra.app.util.NamespaceUtils;
|
||||
import ghidra.program.model.listing.Program;
|
||||
import ghidra.program.model.symbol.*;
|
||||
import ghidra.util.exception.AssertException;
|
||||
import ghidra.util.exception.InvalidInputException;
|
||||
|
||||
/**
|
||||
* Symbol tree action for converting a namespace to a class
|
||||
*/
|
||||
public class ConvertToClassAction extends SymbolTreeContextAction {
|
||||
|
||||
private static final String NAME = "Convert to Class";
|
||||
|
||||
public ConvertToClassAction(SymbolTreePlugin plugin, String group, String subGroup) {
|
||||
super(NAME, plugin.getName());
|
||||
MenuData menuData = new MenuData(new String[] { NAME }, group);
|
||||
menuData.setMenuSubGroup(subGroup);
|
||||
setPopupMenuData(menuData);
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabledForContext(SymbolTreeActionContext context) {
|
||||
TreePath[] selectionPaths = context.getSelectedSymbolTreePaths();
|
||||
if (selectionPaths.length != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object object = selectionPaths[0].getLastPathComponent();
|
||||
if (object instanceof SymbolNode) {
|
||||
SymbolNode symbolNode = (SymbolNode) object;
|
||||
Symbol symbol = symbolNode.getSymbol();
|
||||
return symbol.getSymbolType() == SymbolType.NAMESPACE;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(SymbolTreeActionContext context) {
|
||||
TreePath[] selectionPaths = context.getSelectedSymbolTreePaths();
|
||||
|
||||
Program program = context.getProgram();
|
||||
GTreeNode node = (GTreeNode) selectionPaths[0].getLastPathComponent();
|
||||
|
||||
SymbolGTree tree = context.getSymbolTree();
|
||||
GTreeNode root = tree.getViewRoot();
|
||||
GTreeNode classesNode = root.getChild(SymbolCategory.CLASS_CATEGORY.getName());
|
||||
|
||||
Symbol symbol = ((SymbolNode) node).getSymbol();
|
||||
Namespace namespace = (Namespace) symbol.getObject();
|
||||
if (namespace != null) {
|
||||
String name = namespace.getName();
|
||||
convertToClass(program, namespace);
|
||||
program.flushEvents();
|
||||
context.getSymbolTree().startEditing(classesNode, name);
|
||||
}
|
||||
}
|
||||
|
||||
private static void convertToClass(Program program, Namespace ns) {
|
||||
int id = program.startTransaction(NAME);
|
||||
boolean success = false;
|
||||
try {
|
||||
NamespaceUtils.convertNamespaceToClass(ns);
|
||||
success = true;
|
||||
}
|
||||
catch (InvalidInputException e) {
|
||||
// This is thrown when the provided namespace is a function
|
||||
// It was checked in isEnabledForContext and thus cannot occur
|
||||
throw new AssertException(e);
|
||||
}
|
||||
finally {
|
||||
program.endTransaction(id, success);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+22
-18
@@ -33,9 +33,11 @@ import ghidra.util.exception.InvalidInputException;
|
||||
|
||||
public class CreateClassAction extends SymbolTreeContextAction {
|
||||
|
||||
public CreateClassAction(SymbolTreePlugin plugin) {
|
||||
public CreateClassAction(SymbolTreePlugin plugin, String group, String subGroup) {
|
||||
super("Create Class", plugin.getName());
|
||||
setPopupMenuData(new MenuData(new String[] { "Create Class" }, "0Create"));
|
||||
MenuData menuData = new MenuData(new String[] { "Create Class" }, group);
|
||||
menuData.setMenuSubGroup(subGroup);
|
||||
setPopupMenuData(menuData);
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
@@ -54,23 +56,25 @@ public class CreateClassAction extends SymbolTreeContextAction {
|
||||
protected boolean isEnabledForContext(SymbolTreeActionContext context) {
|
||||
|
||||
TreePath[] selectionPaths = context.getSelectedSymbolTreePaths();
|
||||
if (selectionPaths.length == 1) {
|
||||
Object object = selectionPaths[0].getLastPathComponent();
|
||||
if (object instanceof ClassCategoryNode) {
|
||||
return true;
|
||||
}
|
||||
else if (object instanceof SymbolNode) {
|
||||
SymbolNode symbolNode = (SymbolNode) object;
|
||||
Symbol symbol = symbolNode.getSymbol();
|
||||
SymbolType symbolType = symbol.getSymbolType();
|
||||
if (symbolType == SymbolType.NAMESPACE) {
|
||||
// allow SymbolType to perform additional checks
|
||||
Namespace parentNamespace = (Namespace) symbol.getObject();
|
||||
return SymbolType.CLASS.isValidParent(context.getProgram(), parentNamespace,
|
||||
Address.NO_ADDRESS, parentNamespace.isExternal());
|
||||
}
|
||||
return (symbolType == SymbolType.CLASS || symbolType == SymbolType.LIBRARY);
|
||||
if (selectionPaths.length != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object object = selectionPaths[0].getLastPathComponent();
|
||||
if (object instanceof ClassCategoryNode) {
|
||||
return true;
|
||||
}
|
||||
else if (object instanceof SymbolNode) {
|
||||
SymbolNode symbolNode = (SymbolNode) object;
|
||||
Symbol symbol = symbolNode.getSymbol();
|
||||
SymbolType symbolType = symbol.getSymbolType();
|
||||
if (symbolType == SymbolType.NAMESPACE) {
|
||||
// allow SymbolType to perform additional checks
|
||||
Namespace parentNamespace = (Namespace) symbol.getObject();
|
||||
return SymbolType.CLASS.isValidParent(context.getProgram(), parentNamespace,
|
||||
Address.NO_ADDRESS, parentNamespace.isExternal());
|
||||
}
|
||||
return (symbolType == SymbolType.CLASS || symbolType == SymbolType.LIBRARY);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
+4
-2
@@ -32,9 +32,11 @@ import ghidra.util.exception.InvalidInputException;
|
||||
|
||||
public class CreateNamespaceAction extends SymbolTreeContextAction {
|
||||
|
||||
public CreateNamespaceAction(SymbolTreePlugin plugin) {
|
||||
public CreateNamespaceAction(SymbolTreePlugin plugin, String group, String subGroup) {
|
||||
super("Create Namespace", plugin.getName());
|
||||
setPopupMenuData(new MenuData(new String[] { "Create Namespace" }, "0Create"));
|
||||
MenuData menuData = new MenuData(new String[] { "Create Namespace" }, group);
|
||||
menuData.setMenuSubGroup(subGroup);
|
||||
setPopupMenuData(menuData);
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -1193,7 +1193,8 @@ public class HeadlessAnalyzer {
|
||||
// This can never happen because there is no user interaction in headless!
|
||||
}
|
||||
catch (Exception exc) {
|
||||
Msg.error(this, domFile.getPathname() + " Error during analysis: " + exc.getMessage());
|
||||
Msg.error(this, domFile.getPathname() + " Error during analysis: " + exc.getMessage(),
|
||||
exc);
|
||||
}
|
||||
finally {
|
||||
|
||||
|
||||
+1
-1
@@ -173,7 +173,7 @@ public class ImportBatchTask extends Task {
|
||||
Msg.debug(this, "Batch Import cancelled");
|
||||
}
|
||||
catch (DuplicateNameException | InvalidNameException | VersionException
|
||||
| IOException e) {
|
||||
| IOException | IllegalArgumentException e) {
|
||||
Msg.error(this, "Import failed for " + batchLoadConfig.getPreferredFileName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class GTreeEventTest extends AbstractDockingTest {
|
||||
|
||||
private DockingWindowManager winMgr;
|
||||
|
||||
private List<TreeEvent> events = new ArrayList<TreeEvent>();
|
||||
private List<TreeEvent> events = new ArrayList<>();
|
||||
private GTreeNode root;
|
||||
|
||||
@Before
|
||||
@@ -55,7 +55,7 @@ public class GTreeEventTest extends AbstractDockingTest {
|
||||
|
||||
@Test
|
||||
public void testNodeAdded() {
|
||||
root.addNode(new LeafNode("ABC"));
|
||||
root.addNode(new LeafNode("NEW ABC"));
|
||||
assertEquals(1, events.size());
|
||||
TreeEvent treeEvent = events.get(0);
|
||||
assertEquals(EventType.INSERTED, treeEvent.eventType);
|
||||
|
||||
+41
-31
@@ -62,6 +62,7 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
|
||||
private DockingActionIf selectionAction;
|
||||
private DockingActionIf createNamespaceAction;
|
||||
private DockingActionIf createClassAction;
|
||||
private DockingActionIf convertToClassAction;
|
||||
private ToggleDockingAction goToToggleAction;
|
||||
private SymbolTreeTestUtils util;
|
||||
private SymbolGTree tree;
|
||||
@@ -225,7 +226,7 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
|
||||
for (int i = 0; i < count - 1; i++) {
|
||||
GTreeNode n = ghidraNode.getChild(i);
|
||||
Symbol s = ((SymbolNode) n).getSymbol();
|
||||
assertTrue(!s.getName().equals("AnotherLocal"));
|
||||
assertFalse(s.getName().equals("AnotherLocal"));
|
||||
}
|
||||
|
||||
// test undo/redo
|
||||
@@ -254,7 +255,7 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
|
||||
for (int i = 0; i < count - 1; i++) {
|
||||
GTreeNode n = ghidraNode.getChild(i);
|
||||
Symbol s = ((SymbolNode) n).getSymbol();
|
||||
assertTrue(!s.getName().equals("AnotherLocal"));
|
||||
assertNotEquals("AnotherLocal", s.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,11 +296,21 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
|
||||
|
||||
}
|
||||
|
||||
private void performTreeAction(DockingActionIf action, ActionContext context) {
|
||||
assertTrue(action.isEnabledForContext(context));
|
||||
performAction(action, context, true);
|
||||
program.flushEvents();
|
||||
util.waitForTree();
|
||||
@Test
|
||||
public void testConvertNamespaceToClass() throws Exception {
|
||||
String classNodeName = "MyClass";
|
||||
GTreeNode nsNode = rootNode.getChild(SymbolCategory.NAMESPACE_CATEGORY.getName());
|
||||
GTreeNode classNode = util.createObject(
|
||||
nsNode, classNodeName, createNamespaceAction);
|
||||
|
||||
util.selectNode(classNode);
|
||||
ActionContext context = util.getSymbolTreeContext();
|
||||
performTreeAction(convertToClassAction, context);
|
||||
|
||||
GTreeNode classRootNode = rootNode.getChild(SymbolCategory.CLASS_CATEGORY.getName());
|
||||
classNode = classRootNode.getChild(classNodeName);
|
||||
assertNotNull(classNode);
|
||||
waitForCondition(tree::isEditing);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -313,13 +324,13 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
|
||||
util.selectNode(lNode);
|
||||
|
||||
ActionContext context = util.getSymbolTreeContext();
|
||||
assertTrue(!renameAction.isEnabledForContext(context));
|
||||
assertTrue(!cutAction.isEnabledForContext(context));
|
||||
assertTrue(!pasteAction.isEnabledForContext(context));
|
||||
assertTrue(!deleteAction.isEnabledForContext(context));
|
||||
assertTrue(!selectionAction.isEnabledForContext(context));
|
||||
assertTrue(!createNamespaceAction.isEnabledForContext(context));
|
||||
assertTrue(!createClassAction.isEnabledForContext(context));
|
||||
assertFalse(renameAction.isEnabledForContext(context));
|
||||
assertFalse(cutAction.isEnabledForContext(context));
|
||||
assertFalse(pasteAction.isEnabledForContext(context));
|
||||
assertFalse(deleteAction.isEnabledForContext(context));
|
||||
assertFalse(selectionAction.isEnabledForContext(context));
|
||||
assertFalse(createNamespaceAction.isEnabledForContext(context));
|
||||
assertFalse(createClassAction.isEnabledForContext(context));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -329,16 +340,11 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
|
||||
util.expandNode(lNode);
|
||||
|
||||
// add a label
|
||||
SymbolTable symTable = program.getSymbolTable();
|
||||
int transactionID = program.startTransaction("test");
|
||||
try {
|
||||
tx(program, () -> {
|
||||
SymbolTable symTable = program.getSymbolTable();
|
||||
symTable.createLabel(util.addr(0x010048a1L), "abcdefg", SourceType.USER_DEFINED);
|
||||
}
|
||||
finally {
|
||||
program.endTransaction(transactionID, true);
|
||||
}
|
||||
});
|
||||
|
||||
program.flushEvents();
|
||||
util.waitForTree();
|
||||
|
||||
lNode = rootNode.getChild(3);
|
||||
@@ -355,18 +361,13 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
|
||||
// verify that the tree updates
|
||||
|
||||
Function f = program.getFunctionManager().getFunctionAt(util.addr(0x01002cf5L));
|
||||
|
||||
Symbol s = getUniqueSymbol(program, "AnotherLocal", f);
|
||||
assertNotNull(s);
|
||||
int transactionID = program.startTransaction("test");
|
||||
try {
|
||||
|
||||
tx(program, () -> {
|
||||
s.setName("MyAnotherLocal", SourceType.USER_DEFINED);
|
||||
}
|
||||
finally {
|
||||
program.endTransaction(transactionID, true);
|
||||
}
|
||||
program.flushEvents();
|
||||
waitForSwing();
|
||||
});
|
||||
|
||||
util.waitForTree();
|
||||
|
||||
GTreeNode fNode = getFunctionsNode();
|
||||
@@ -421,11 +422,20 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
|
||||
assertNotNull(createClassAction);
|
||||
createNamespaceAction = getAction(plugin, "Create Namespace");
|
||||
assertNotNull(createNamespaceAction);
|
||||
convertToClassAction = getAction(plugin, "Convert to Class");
|
||||
assertNotNull(convertToClassAction);
|
||||
|
||||
goToToggleAction = (ToggleDockingAction) getAction(plugin, "Navigation");
|
||||
assertNotNull(goToToggleAction);
|
||||
}
|
||||
|
||||
private void performTreeAction(DockingActionIf action, ActionContext context) {
|
||||
assertTrue(action.isEnabledForContext(context));
|
||||
performAction(action, context, true);
|
||||
program.flushEvents();
|
||||
util.waitForTree();
|
||||
}
|
||||
|
||||
private void clickOnNode(GTreeNode node) throws Exception {
|
||||
JTree jTree = (JTree) AbstractGenericTest.getInstanceField("tree", tree);
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ Architecture::Architecture(void)
|
||||
commentdb = (CommentDatabase *)0;
|
||||
stringManager = (StringManager *)0;
|
||||
cpool = (ConstantPool *)0;
|
||||
symboltab = new Database(this);
|
||||
symboltab = (Database *)0;
|
||||
context = (ContextDatabase *)0;
|
||||
print = PrintLanguageCapability::getDefault()->buildLanguage(this);
|
||||
printlist.push_back(print);
|
||||
@@ -131,7 +131,8 @@ Architecture::~Architecture(void)
|
||||
for(int4 i=0;i<extra_pool_rules.size();++i)
|
||||
delete extra_pool_rules[i];
|
||||
|
||||
delete symboltab;
|
||||
if (symboltab != (Database *)0)
|
||||
delete symboltab;
|
||||
for(int4 i=0;i<(int4)printlist.size();++i)
|
||||
delete printlist[i];
|
||||
delete options;
|
||||
@@ -371,7 +372,7 @@ void Architecture::setPrintLanguage(const string &nm)
|
||||
void Architecture::globalify(void)
|
||||
|
||||
{
|
||||
Scope *scope = buildGlobalScope();
|
||||
Scope *scope = symboltab->getGlobalScope();
|
||||
int4 nm = numSpaces();
|
||||
|
||||
for(int4 i=0;i<nm;++i) {
|
||||
@@ -528,16 +529,16 @@ void Architecture::buildContext(DocumentStorage &store)
|
||||
context = new ContextInternal();
|
||||
}
|
||||
|
||||
/// If it does not already exist create the glocal Scope object
|
||||
/// Create the database object, which currently doesn't not depend on any configuration
|
||||
/// data. Then create the root (global) scope and attach it to the database.
|
||||
/// \param store is the storage for any configuration data
|
||||
/// \return the global Scope object
|
||||
Scope *Architecture::buildGlobalScope(void)
|
||||
Scope *Architecture::buildDatabase(DocumentStorage &store)
|
||||
|
||||
{
|
||||
Scope *globscope = symboltab->getGlobalScope();
|
||||
if (globscope == (Scope *)0) { // Make sure global scope exists
|
||||
globscope = new ScopeInternal("",this);
|
||||
symboltab->attachScope(globscope,(Scope *)0);
|
||||
}
|
||||
symboltab = new Database(this,true);
|
||||
Scope *globscope = new ScopeInternal(0,"",this);
|
||||
symboltab->attachScope(globscope,(Scope *)0);
|
||||
return globscope;
|
||||
}
|
||||
|
||||
@@ -802,7 +803,7 @@ void Architecture::parseDefaultProto(const Element *el)
|
||||
void Architecture::parseGlobal(const Element *el)
|
||||
|
||||
{
|
||||
Scope *scope = buildGlobalScope();
|
||||
Scope *scope = symboltab->getGlobalScope();
|
||||
const List &list(el->getChildren());
|
||||
List::const_iterator iter;
|
||||
|
||||
@@ -829,15 +830,15 @@ void Architecture::parseGlobal(const Element *el)
|
||||
void Architecture::addOtherSpace(void)
|
||||
|
||||
{
|
||||
Scope *scope = buildGlobalScope();
|
||||
Scope *scope = symboltab->getGlobalScope();
|
||||
AddrSpace *otherSpace = getSpaceByName("OTHER");
|
||||
symboltab->addRange(scope,otherSpace,0,otherSpace->getHighest());
|
||||
if (otherSpace->isOverlayBase()) {
|
||||
int4 num = numSpaces();
|
||||
for(int4 i=0;i<num;++i){
|
||||
OverlaySpace *ospc = (OverlaySpace *)getSpace(i);
|
||||
if (ospc->getBaseSpace() != otherSpace) continue;
|
||||
if (ospc->getBaseSpace() != otherSpace) continue;
|
||||
int4 num = numSpaces();
|
||||
for(int4 i=0;i<num;++i){
|
||||
AddrSpace *ospc = getSpace(i);
|
||||
if (!ospc->isOverlay()) continue;
|
||||
if (((OverlaySpace *)ospc)->getBaseSpace() != otherSpace) continue;
|
||||
symboltab->addRange(scope,ospc,0,otherSpace->getHighest());
|
||||
}
|
||||
}
|
||||
@@ -1279,9 +1280,11 @@ void Architecture::init(DocumentStorage &store)
|
||||
buildCommentDB(store);
|
||||
buildStringManager(store);
|
||||
buildConstantPool(store);
|
||||
buildDatabase(store);
|
||||
|
||||
restoreFromSpec(store);
|
||||
print->getCastStrategy()->setTypeFactory(types);
|
||||
symboltab->adjustCaches(); // In case the specs created additional address spaces
|
||||
postSpecFile(); // Let subclasses do things after translate is ready
|
||||
|
||||
buildInstructions(store); // Must be called after translate is built
|
||||
|
||||
@@ -206,7 +206,7 @@ protected:
|
||||
void addNoHighPtr(const Range &rng); ///< Add a new region where pointers do not exist
|
||||
|
||||
// Factory routines for building this architecture
|
||||
virtual Scope *buildGlobalScope(void); ///< Build the global scope for this executable
|
||||
virtual Scope *buildDatabase(DocumentStorage &store); ///< Build the database and global scope for this executable
|
||||
|
||||
/// \brief Build the Translator object
|
||||
///
|
||||
|
||||
@@ -4244,7 +4244,7 @@ Datatype *ActionInferTypes::propagateAddIn2Out(TypeFactory *typegrp,PcodeOp *op,
|
||||
int4 offset = propagateAddPointer(op,inslot);
|
||||
if (offset==-1) return op->getOut()->getTempType(); // Doesn't look like a good pointer add
|
||||
uintb uoffset = AddrSpace::addressToByte(offset,((TypePointer *)rettype)->getWordSize());
|
||||
if (tstruct->getSize() > 0)
|
||||
if (tstruct->getSize() > 0 && !tstruct->isVariableLength())
|
||||
uoffset = uoffset % tstruct->getSize();
|
||||
if (uoffset==0) {
|
||||
if (op->code() == CPUI_PTRSUB) // Go down at least one level
|
||||
@@ -4419,7 +4419,7 @@ bool ActionInferTypes::propagateTypeEdge(TypeFactory *typegrp,PcodeOp *op,int4 i
|
||||
}
|
||||
else if (alttype->getMetatype()==TYPE_PTR) {
|
||||
newtype = ((TypePointer *)alttype)->getPtrTo();
|
||||
if (newtype->getSize() != outvn->getTempType()->getSize()) // Size must be appropriate
|
||||
if (newtype->getSize() != outvn->getTempType()->getSize() || newtype->isVariableLength()) // Size must be appropriate
|
||||
newtype = outvn->getTempType();
|
||||
}
|
||||
else
|
||||
@@ -4432,7 +4432,7 @@ bool ActionInferTypes::propagateTypeEdge(TypeFactory *typegrp,PcodeOp *op,int4 i
|
||||
}
|
||||
else if (alttype->getMetatype()==TYPE_PTR) {
|
||||
newtype = ((TypePointer *)alttype)->getPtrTo();
|
||||
if (newtype->getSize() != outvn->getTempType()->getSize())
|
||||
if (newtype->getSize() != outvn->getTempType()->getSize() || newtype->isVariableLength())
|
||||
newtype = outvn->getTempType();
|
||||
}
|
||||
else
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -377,18 +377,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/// \brief A key for looking up child symbol scopes within a parent, based on name
|
||||
///
|
||||
/// A key for mapping from name to Scope. The class includes a deduplication component
|
||||
/// if Scopes with the same name are allowed.
|
||||
class ScopeKey {
|
||||
string name; ///< The name of the Scope
|
||||
uintb dedupId; ///< A duplication id for the Scope
|
||||
public:
|
||||
ScopeKey(const string &nm,uint4 id) { name = nm; dedupId = id; } ///< Construct given a name and id
|
||||
bool operator<(const ScopeKey &op2) const; ///< Comparison operator
|
||||
};
|
||||
typedef map<ScopeKey,Scope *> ScopeMap; ///< A map from ScopeKey to Scope
|
||||
typedef map<uint8,Scope *> ScopeMap; ///< A map from id to Scope
|
||||
|
||||
/// \brief A collection of Symbol objects within a single (namespace or functional) scope
|
||||
///
|
||||
@@ -420,12 +409,12 @@ class Scope {
|
||||
ScopeMap children; ///< Sorted list of child scopes
|
||||
void attachScope(Scope *child); ///< Attach a new child Scope to \b this
|
||||
void detachScope(ScopeMap::iterator iter); ///< Detach a child Scope from \b this
|
||||
void assignId(uint4 val) { uniqueId = val; } ///< Let the database assign a unique id to \b this scope
|
||||
static uint8 hashScopeName(uint8 baseId,const string &nm);
|
||||
protected:
|
||||
Architecture *glb; ///< Architecture of \b this scope
|
||||
string name; ///< Name of \b this scope
|
||||
Funcdata *fd; ///< (If non-null) the function which \b this is the local Scope for
|
||||
uint4 uniqueId; ///< Unique id for the scope, for deduping scope names, assigning symbol ids
|
||||
uint8 uniqueId; ///< Unique id for the scope, for deduping scope names, assigning symbol ids
|
||||
static const Scope *stackAddr(const Scope *scope1,
|
||||
const Scope *scope2,
|
||||
const Address &addr,
|
||||
@@ -460,9 +449,10 @@ protected:
|
||||
///
|
||||
/// This is a Scope object \e factory, intended to be called off of the global scope for building
|
||||
/// global namespace scopes. Function scopes are handled differently.
|
||||
/// \param id is the globally unique id associated with the scope
|
||||
/// \param nm is the name of the new scope
|
||||
/// \return the new Scope object
|
||||
virtual Scope *buildSubScope(const string &nm)=0;
|
||||
virtual Scope *buildSubScope(uint8 id,const string &nm)=0;
|
||||
|
||||
virtual void restrictScope(Funcdata *f); ///< Convert \b this to a local Scope
|
||||
|
||||
@@ -512,8 +502,8 @@ public:
|
||||
void turnOffDebug(void) const { debugon = false; }
|
||||
#endif
|
||||
/// \brief Construct an empty scope, given a name and Architecture
|
||||
Scope(const string &nm,Architecture *g,Scope *own) {
|
||||
name = nm; glb = g; parent = (Scope *)0; fd = (Funcdata *)0; uniqueId = 0; owner=own;
|
||||
Scope(uint8 id,const string &nm,Architecture *g,Scope *own) {
|
||||
uniqueId = id; name = nm; glb = g; parent = (Scope *)0; fd = (Funcdata *)0; owner=own;
|
||||
#ifdef OPACTION_DEBUG
|
||||
debugon = false;
|
||||
#endif
|
||||
@@ -530,6 +520,11 @@ public:
|
||||
virtual void clearUnlocked(void)=0; ///< Clear all unlocked symbols from \b this scope
|
||||
virtual void clearUnlockedCategory(int4 cat)=0; ///< Clear unlocked symbols of the given category from \b this scope
|
||||
|
||||
/// \brief Let scopes internally adjust any caches
|
||||
///
|
||||
/// This is called once after Architecture configuration is complete.
|
||||
virtual void adjustCaches(void)=0;
|
||||
|
||||
/// \brief Query if the given range is owned by \b this Scope
|
||||
///
|
||||
/// All bytes in the range must be owned, and ownership can be informed by
|
||||
@@ -680,6 +675,7 @@ public:
|
||||
const Address &addr,const Address &usepoint);
|
||||
|
||||
const string &getName(void) const { return name; } ///< Get the name of the Scope
|
||||
uint8 getId(void) const { return uniqueId; } ///< Get the globally unique id
|
||||
bool isGlobal(void) const { return (fd == (Funcdata *)0); } ///< Return \b true if \b this scope is global
|
||||
|
||||
// The main global querying routines
|
||||
@@ -695,7 +691,7 @@ public:
|
||||
Funcdata *queryExternalRefFunction(const Address &addr) const; ///< Look-up a function thru an \e external \e reference
|
||||
LabSymbol *queryCodeLabel(const Address &addr) const; ///< Look-up a code label by address
|
||||
|
||||
Scope *resolveScope(const string &name) const; ///< Find a child Scope of \b this
|
||||
Scope *resolveScope(const string &name, bool strategy) const; ///< Find a child Scope of \b this
|
||||
Scope *discoverScope(const Address &addr,int4 sz,const Address &usepoint); ///< Find the owning Scope of a given memory range
|
||||
ScopeMap::const_iterator childrenBegin() const { return children.begin(); } ///< Beginning iterator of child scopes
|
||||
ScopeMap::const_iterator childrenEnd() const { return children.end(); } ///< Ending iterator of child scopes
|
||||
@@ -705,7 +701,6 @@ public:
|
||||
void setThisPointer(Symbol *sym,bool val) { sym->setThisPointer(val); } ///< Toggle the given Symbol as the "this" pointer
|
||||
bool isSubScope(const Scope *scp) const; ///< Is this a sub-scope of the given Scope
|
||||
string getFullName(void) const; ///< Get the full name of \b this Scope
|
||||
void getNameSegments(vector<string> &vec) const; ///< Get the fullname of \b this in segments
|
||||
void getScopePath(vector<const Scope *> &vec) const; ///< Get the ordered list of scopes up to \b this
|
||||
const Scope *findDistinguishingScope(const Scope *op2) const; ///< Find first ancestor of \b this not shared by given scope
|
||||
Architecture *getArch(void) const { return glb; } ///< Get the Architecture associated with \b this
|
||||
@@ -735,7 +730,7 @@ class ScopeInternal : public Scope {
|
||||
void insertNameTree(Symbol *sym);
|
||||
SymbolNameTree::const_iterator findFirstByName(const string &name) const;
|
||||
protected:
|
||||
virtual Scope *buildSubScope(const string &nm); ///< Build an unattached Scope to be associated as a sub-scope of \b this
|
||||
virtual Scope *buildSubScope(uint8 id,const string &nm); ///< Build an unattached Scope to be associated as a sub-scope of \b this
|
||||
virtual void addSymbolInternal(Symbol *sym);
|
||||
virtual SymbolEntry *addMapInternal(Symbol *sym,uint4 exfl,const Address &addr,int4 off,int4 sz,const RangeList &uselim);
|
||||
virtual SymbolEntry *addDynamicMapInternal(Symbol *sym,uint4 exfl,uint8 hash,int4 off,int4 sz,
|
||||
@@ -747,13 +742,14 @@ protected:
|
||||
SymbolNameTree multiEntrySet; ///< Set of symbols with multiple entries
|
||||
uint8 nextUniqueId; ///< Next available symbol id
|
||||
public:
|
||||
ScopeInternal(const string &nm,Architecture *g); ///< Construct the Scope
|
||||
ScopeInternal(const string &nm,Architecture *g, Scope *own); ///< Construct as a cache
|
||||
ScopeInternal(uint8 id,const string &nm,Architecture *g); ///< Construct the Scope
|
||||
ScopeInternal(uint8 id,const string &nm,Architecture *g, Scope *own); ///< Construct as a cache
|
||||
virtual void clear(void);
|
||||
virtual void categorySanity(void); ///< Make sure Symbol categories are sane
|
||||
virtual void clearCategory(int4 cat);
|
||||
virtual void clearUnlocked(void);
|
||||
virtual void clearUnlockedCategory(int4 cat);
|
||||
virtual void adjustCaches(void);
|
||||
virtual ~ScopeInternal(void);
|
||||
virtual MapIterator begin(void) const;
|
||||
virtual MapIterator end(void) const;
|
||||
@@ -797,8 +793,6 @@ public:
|
||||
void assignDefaultNames(int4 &base); ///< Assign a default name (via buildVariableName) to any unnamed symbol
|
||||
set<Symbol *>::const_iterator beginMultiEntry(void) const { return multiEntrySet.begin(); } ///< Start of symbols with more than one entry
|
||||
set<Symbol *>::const_iterator endMultiEntry(void) const { return multiEntrySet.end(); } ///< End of symbols with more than one entry
|
||||
static void savePathXml(ostream &s,const vector<string> &vec); ///< Save a path with \<val> tags
|
||||
static void restorePathXml(vector<string> &vec,const Element *el); ///< Restore path from \<val> tags
|
||||
};
|
||||
|
||||
/// \brief An Address range associated with the symbol Scope that owns it
|
||||
@@ -850,19 +844,21 @@ typedef rangemap<ScopeMapper> ScopeResolve; ///< A map from address to the owni
|
||||
/// memory ranges. This allows important properties like \e read-only and \e volatile to
|
||||
/// be put down even if the Symbols aren't yet known.
|
||||
class Database {
|
||||
Architecture *glb; ///< The Architecture to which this symbol table is attached
|
||||
Scope *globalscope; ///< A quick reference to the \e global Scope
|
||||
ScopeResolve resolvemap; ///< The Address to \e namespace map
|
||||
Architecture *glb; ///< Architecture to which this symbol table is attached
|
||||
Scope *globalscope; ///< Quick reference to the \e global Scope
|
||||
ScopeResolve resolvemap; ///< Address to \e namespace map
|
||||
ScopeMap idmap; ///< Map from id to Scope
|
||||
partmap<Address,uint4> flagbase; ///< Map of global properties
|
||||
uint4 nextScopeId; ///< Id for next attached scope (0 reserved for global scope)
|
||||
bool idByNameHash; ///< True if scope ids are built from hash of name
|
||||
void clearResolve(Scope *scope); ///< Clear the \e ownership ranges associated with the given Scope
|
||||
void clearResolveRecursive(Scope *scope); ///< Clear the \e ownership ranges of a given Scope and its children
|
||||
void clearReferences(Scope *scope); ///< Clear any map references to the given Scope and its children
|
||||
void fillResolve(Scope *scope); ///< Add the \e ownership ranges of the given Scope to the map
|
||||
static void parseParentTag(const Element *el,string &name,vector<string> &parnames);
|
||||
Scope *parseParentTag(const Element *el); ///< Figure out parent scope given \<parent> tag.
|
||||
public:
|
||||
Database(Architecture *g) { glb=g; globalscope=(Scope *)0; flagbase.defaultValue()=0; nextScopeId=1; } ///< Constructor
|
||||
Database(Architecture *g,bool idByName); ///< Constructor
|
||||
~Database(void); ///< Destructor
|
||||
Architecture *getArch(void) const { return glb; } ///< Get the Architecture associate with \b this
|
||||
void adjustCaches(void); ///< Let scopes adjust after configuration is finished
|
||||
void attachScope(Scope *newscope,Scope *parent); ///< Register a new Scope
|
||||
void deleteScope(Scope *scope); ///< Delete the given Scope and all its sub-scopes
|
||||
void deleteSubScopes(Scope *scope); ///< Delete all sub-scopes of the given Scope
|
||||
@@ -871,9 +867,9 @@ public:
|
||||
void addRange(Scope *scope,AddrSpace *spc,uintb first,uintb last); ///< Add an address range to the \e ownership of a Scope
|
||||
void removeRange(Scope *scope,AddrSpace *spc,uintb first,uintb last); ///< Remove an address range from \e ownership of a Scope
|
||||
Scope *getGlobalScope(void) const { return globalscope; } ///< Get the global Scope
|
||||
Scope *resolveScope(const vector<string> &subnames) const; ///< Look-up a Scope by name
|
||||
Scope *resolveScope(uint8 id) const; ///< Look-up a Scope by id
|
||||
Scope *resolveScopeFromSymbolName(const string &fullname,const string &delim,string &basename,Scope *start) const;
|
||||
Scope *findCreateSubscope(const string &nm,Scope *parent); /// Find (and if not found create) a specific subscope
|
||||
Scope *findCreateScope(uint8,const string &nm,Scope *parent); /// Find (and if not found create) a specific subscope
|
||||
Scope *findCreateScopeFromSymbolName(const string &fullname,const string &delim,string &basename,Scope *start);
|
||||
const Scope *mapScope(const Scope *qpoint,const Address &addr,const Address &usepoint) const;
|
||||
Scope *mapScope(Scope *qpoint,const Address &addr,const Address &usepoint);
|
||||
@@ -883,7 +879,7 @@ public:
|
||||
const partmap<Address,uint4> &getProperties(void) const { return flagbase; } ///< Get the entire property map
|
||||
void saveXml(ostream &s) const; ///< Save the whole Database to an XML stream
|
||||
void restoreXml(const Element *el); ///< Recover the whole database from XML
|
||||
void restoreXmlScope(const Element *el,Scope *new_scope); ///< Register and fill out a single Scope from XML
|
||||
void restoreXmlScope(const Element *el,Scope *newScope); ///< Register and fill out a single Scope from an XML \<scope> tag
|
||||
};
|
||||
|
||||
/// \param sc is the scope containing the new symbol
|
||||
|
||||
@@ -16,18 +16,19 @@
|
||||
#include "database_ghidra.hh"
|
||||
#include "funcdata.hh"
|
||||
|
||||
Scope *ScopeGhidra::buildSubScope(const string &nm)
|
||||
Scope *ScopeGhidra::buildSubScope(uint8 id,const string &nm)
|
||||
|
||||
{
|
||||
return new ScopeGhidraNamespace(nm,ghidra);
|
||||
return new ScopeGhidraNamespace(id,nm,ghidra);
|
||||
}
|
||||
|
||||
/// \param g is the Architecture and connection to the Ghidra client
|
||||
///
|
||||
ScopeGhidra::ScopeGhidra(ArchitectureGhidra *g)
|
||||
: Scope("",g,this)
|
||||
: Scope(0,"",g,this)
|
||||
{
|
||||
ghidra = g;
|
||||
cache = new ScopeInternal("",g,this);
|
||||
cache = new ScopeInternal(0,"",g,this);
|
||||
cacheDirty = false;
|
||||
}
|
||||
|
||||
@@ -38,7 +39,7 @@ ScopeGhidra::~ScopeGhidra(void)
|
||||
}
|
||||
|
||||
/// The Ghidra client reports a \e namespace id associated with
|
||||
/// Symbol. Determine if a matching \e namespac Scope already exists in the cache and build
|
||||
/// Symbol. Determine if a matching \e namespace Scope already exists in the cache and build
|
||||
/// it if it isn't. This may mean creating a new \e namespace Scope.
|
||||
/// \param id is the ID associated with the Ghidra namespace
|
||||
/// \return the Scope matching the id.
|
||||
@@ -46,15 +47,16 @@ Scope *ScopeGhidra::reresolveScope(uint8 id) const
|
||||
|
||||
{
|
||||
if (id == 0) return cache;
|
||||
map<uint8,Scope *>::const_iterator miter = namespaceMap.find(id);
|
||||
if (miter != namespaceMap.end())
|
||||
return (*miter).second; // Scope was previously cached
|
||||
Database *symboltab = ghidra->symboltab;
|
||||
Scope *cacheScope = symboltab->resolveScope(id);
|
||||
if (cacheScope != (Scope *)0)
|
||||
return cacheScope; // Scope was previously cached
|
||||
|
||||
Document *doc = ghidra->getNamespacePath(id);
|
||||
if (doc == (Document *)0)
|
||||
throw LowlevelError("Could not get namespace info");
|
||||
|
||||
Scope *curscope = glb->symboltab->getGlobalScope(); // Get pointer to ourselves (which is not const)
|
||||
Scope *curscope = symboltab->getGlobalScope(); // Get pointer to ourselves (which is not const)
|
||||
try {
|
||||
const List &list(doc->getRoot()->getChildren());
|
||||
List::const_iterator iter = list.begin();
|
||||
@@ -66,16 +68,7 @@ Scope *ScopeGhidra::reresolveScope(uint8 id) const
|
||||
istringstream s(el->getAttributeValue("id"));
|
||||
s.unsetf(ios::dec | ios::hex | ios::oct);
|
||||
s >> scopeId;
|
||||
miter = namespaceMap.find(scopeId);
|
||||
if (miter == namespaceMap.end()) {
|
||||
curscope = glb->symboltab->findCreateSubscope(el->getContent(), curscope);
|
||||
ScopeGhidraNamespace *ghidraScope = (ScopeGhidraNamespace *)curscope;
|
||||
if (ghidraScope->getClientId() == 0)
|
||||
ghidraScope->setClientId(scopeId);
|
||||
namespaceMap[scopeId] = curscope;
|
||||
}
|
||||
else
|
||||
curscope = (*miter).second;
|
||||
curscope = symboltab->findCreateScope(scopeId, el->getContent(), curscope);
|
||||
}
|
||||
delete doc;
|
||||
}
|
||||
@@ -260,7 +253,6 @@ void ScopeGhidra::clear(void)
|
||||
{
|
||||
cache->clear();
|
||||
holes.clear();
|
||||
namespaceMap.clear();
|
||||
if (cacheDirty) {
|
||||
ghidra->symboltab->setProperties(flagbaseDefault); // Restore database properties to defaults
|
||||
cacheDirty = false;
|
||||
@@ -415,6 +407,6 @@ bool ScopeGhidraNamespace::isNameUsed(const string &nm,const Scope *op2) const
|
||||
if (ArchitectureGhidra::isDynamicSymbolName(nm))
|
||||
return false; // Just assume default FUN_ and DAT_ names don't collide
|
||||
const ScopeGhidraNamespace *otherScope = dynamic_cast<const ScopeGhidraNamespace *>(op2);
|
||||
uint8 otherId = (otherScope != (const ScopeGhidraNamespace *)0) ? otherScope->getClientId() : 0;
|
||||
return ghidra->isNameUsed(nm, scopeId, otherId);
|
||||
uint8 otherId = (otherScope != (const ScopeGhidraNamespace *)0) ? otherScope->getId() : 0;
|
||||
return ghidra->isNameUsed(nm, uniqueId, otherId);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ class ScopeGhidra : public Scope {
|
||||
ArchitectureGhidra *ghidra; ///< Architecture and connection to the Ghidra client
|
||||
mutable ScopeInternal *cache; ///< An internal cache of previously fetched Symbol objects
|
||||
mutable RangeList holes; ///< List of (queried) memory ranges with no Symbol in them
|
||||
mutable map<uint8,Scope *> namespaceMap; ///< Map from id to formal global namespace objects
|
||||
vector<int4> spacerange; ///< List of address spaces that are in the global range
|
||||
partmap<Address,uint4> flagbaseDefault; ///< Default boolean properties on memory
|
||||
mutable bool cacheDirty; ///< Is flagbaseDefault different from cache
|
||||
@@ -48,7 +47,7 @@ class ScopeGhidra : public Scope {
|
||||
virtual void removeRange(AddrSpace *spc,uintb first,uintb last) {
|
||||
throw LowlevelError("remove_range should not be performed on ghidra scope");
|
||||
}
|
||||
virtual Scope *buildSubScope(const string &nm);
|
||||
virtual Scope *buildSubScope(uint8 id,const string &nm);
|
||||
virtual void addSymbolInternal(Symbol *sym) { throw LowlevelError("add_symbol_internal unimplemented"); }
|
||||
virtual SymbolEntry *addMapInternal(Symbol *sym,uint4 exfl,const Address &addr,int4 off,int4 sz,
|
||||
const RangeList &uselim) { throw LowlevelError("addMap unimplemented"); }
|
||||
@@ -77,6 +76,7 @@ public:
|
||||
virtual void clearAttribute(Symbol *sym,uint4 attr) { cache->clearAttribute(sym,attr); }
|
||||
virtual void setDisplayFormat(Symbol *sym,uint4 attr) { cache->setDisplayFormat(sym,attr); }
|
||||
|
||||
virtual void adjustCaches(void) { cache->adjustCaches(); }
|
||||
virtual SymbolEntry *findAddr(const Address &addr,const Address &usepoint) const;
|
||||
virtual SymbolEntry *findContainer(const Address &addr,int4 size,
|
||||
const Address &usepoint) const;
|
||||
@@ -127,16 +127,13 @@ public:
|
||||
class ScopeGhidraNamespace : public ScopeInternal {
|
||||
friend class ScopeGhidra;
|
||||
ArchitectureGhidra *ghidra; ///< Connection to the Ghidra client
|
||||
uint8 scopeId; ///< Internal id allowing Ghidra client to reference formal namespaces
|
||||
void setClientId(uint8 id) { scopeId = id; }
|
||||
protected:
|
||||
virtual SymbolEntry *addMapInternal(Symbol *sym,uint4 exfl,const Address &addr,int4 off,int4 sz,
|
||||
const RangeList &uselim);
|
||||
public:
|
||||
ScopeGhidraNamespace(const string &nm,ArchitectureGhidra *g)
|
||||
: ScopeInternal(nm,g) { ghidra = g; scopeId = 0; } ///< Constructor
|
||||
ScopeGhidraNamespace(uint8 id,const string &nm,ArchitectureGhidra *g)
|
||||
: ScopeInternal(id,nm,g) { ghidra = g; } ///< Constructor
|
||||
|
||||
uint8 getClientId(void) const { return scopeId; } ///< Get the Ghidra specific id
|
||||
virtual bool isNameUsed(const string &nm,const Scope *op2) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -45,7 +45,15 @@ Funcdata::Funcdata(const string &nm,Scope *scope,const Address &addr,FunctionSym
|
||||
if (nm.size()==0)
|
||||
localmap = (ScopeLocal *)0; // Filled in by restoreXml
|
||||
else {
|
||||
ScopeLocal *newMap = new ScopeLocal(stackid,this,glb);
|
||||
uint8 id;
|
||||
if (sym != (FunctionSymbol *)0)
|
||||
id = sym->getId();
|
||||
else {
|
||||
// Missing a symbol, build unique id based on address
|
||||
id = 0x57AB12CD;
|
||||
id = (id << 32) | (addr.getOffset() & 0xffffffff);
|
||||
}
|
||||
ScopeLocal *newMap = new ScopeLocal(id,stackid,this,glb);
|
||||
glb->symboltab->attachScope(newMap,scope); // This may throw and delete newMap
|
||||
localmap = newMap;
|
||||
funcp.setScope(localmap,baseaddr+ -1);
|
||||
@@ -735,7 +743,7 @@ uint8 Funcdata::restoreXml(const Element *el)
|
||||
if ((*iter)->getName() == "localdb") {
|
||||
if (localmap != (ScopeLocal *)0)
|
||||
throw LowlevelError("Pre-existing local scope when restoring: "+name);
|
||||
ScopeLocal *newMap = new ScopeLocal(stackid,this,glb);
|
||||
ScopeLocal *newMap = new ScopeLocal(id,stackid,this,glb);
|
||||
glb->symboltab->restoreXmlScope(*iter,newMap); // May delete newMap and throw
|
||||
localmap = newMap;
|
||||
}
|
||||
@@ -750,7 +758,7 @@ uint8 Funcdata::restoreXml(const Element *el)
|
||||
else if ((*iter)->getName() == "prototype") {
|
||||
if (localmap == (ScopeLocal *)0) {
|
||||
// If we haven't seen a <localdb> tag yet, assume we have a default local scope
|
||||
ScopeLocal *newMap = new ScopeLocal(stackid,this,glb);
|
||||
ScopeLocal *newMap = new ScopeLocal(id,stackid,this,glb);
|
||||
Scope *scope = glb->symboltab->getGlobalScope();
|
||||
glb->symboltab->attachScope(newMap,scope); // May delete newMap and throw
|
||||
localmap = newMap;
|
||||
@@ -763,7 +771,7 @@ uint8 Funcdata::restoreXml(const Element *el)
|
||||
}
|
||||
if (localmap == (ScopeLocal *)0) { // Seen neither <localdb> or <prototype>
|
||||
// This is a function shell, so we provide default locals
|
||||
ScopeLocal *newMap = new ScopeLocal(stackid,this,glb);
|
||||
ScopeLocal *newMap = new ScopeLocal(id,stackid,this,glb);
|
||||
Scope *scope = glb->symboltab->getGlobalScope();
|
||||
glb->symboltab->attachScope(newMap,scope); // May delete newMap and throw
|
||||
localmap = newMap;
|
||||
|
||||
@@ -923,7 +923,7 @@ void Funcdata::overrideFlow(const Address &addr,uint4 type)
|
||||
else if (type == Override::CALL)
|
||||
op = findPrimaryBranch(iter,enditer,true,false,true);
|
||||
else if (type == Override::CALL_RETURN)
|
||||
op = findPrimaryBranch(iter,enditer,true,false,true);
|
||||
op = findPrimaryBranch(iter,enditer,true,true,true);
|
||||
else if (type == Override::RETURN)
|
||||
op = findPrimaryBranch(iter,enditer,true,true,false);
|
||||
|
||||
|
||||
@@ -325,14 +325,12 @@ Translate *ArchitectureGhidra::buildTranslator(DocumentStorage &store)
|
||||
return new GhidraTranslate(this);
|
||||
}
|
||||
|
||||
Scope *ArchitectureGhidra::buildGlobalScope(void)
|
||||
Scope *ArchitectureGhidra::buildDatabase(DocumentStorage &store)
|
||||
|
||||
{
|
||||
Scope *globalscope = symboltab->getGlobalScope();
|
||||
if (globalscope == (Scope *)0) { // Make sure global scope exists
|
||||
globalscope = new ScopeGhidra(this);
|
||||
symboltab->attachScope(globalscope,(Scope *)0);
|
||||
}
|
||||
symboltab = new Database(this,false);
|
||||
Scope *globalscope = new ScopeGhidra(this);
|
||||
symboltab->attachScope(globalscope,(Scope *)0);
|
||||
return globalscope;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class ArchitectureGhidra : public Architecture {
|
||||
bool sendsyntaxtree; ///< True if the syntax tree should be sent with function output
|
||||
bool sendCcode; ///< True if C code should be sent with function output
|
||||
bool sendParamMeasures; ///< True if measurements for argument and return parameters should be sent
|
||||
virtual Scope *buildGlobalScope(void);
|
||||
virtual Scope *buildDatabase(DocumentStorage &store);
|
||||
virtual Translate *buildTranslator(DocumentStorage &store);
|
||||
virtual void buildLoader(DocumentStorage &store);
|
||||
virtual PcodeInjectLibrary *buildPcodeInjectLibrary(void);
|
||||
|
||||
@@ -343,16 +343,8 @@ static bool maxmatch(string &res,const string &op1,const string &op2)
|
||||
{ // Set res to maximum characters in common
|
||||
// at the beginning of op1 and op2
|
||||
int4 len;
|
||||
bool equal;
|
||||
|
||||
if (op1.size() == op2.size()) {
|
||||
len = op1.size();
|
||||
equal = true;
|
||||
}
|
||||
else {
|
||||
equal = false;
|
||||
len = ( op1.size() < op2.size() ) ? op1.size() : op2.size();
|
||||
}
|
||||
len = ( op1.size() < op2.size() ) ? op1.size() : op2.size();
|
||||
|
||||
res.erase();
|
||||
for(int4 i=0;i<len;++i) {
|
||||
@@ -361,7 +353,7 @@ static bool maxmatch(string &res,const string &op1,const string &op2)
|
||||
else
|
||||
return false;
|
||||
}
|
||||
return equal;
|
||||
return true;
|
||||
}
|
||||
|
||||
int4 IfaceStatus::expandCom(vector<string> &expand,istream &s,
|
||||
|
||||
@@ -1670,21 +1670,7 @@ void PrintC::pushAnnotation(const Varnode *vn,const PcodeOp *op)
|
||||
void PrintC::pushSymbol(const Symbol *sym,const Varnode *vn,const PcodeOp *op)
|
||||
|
||||
{
|
||||
Datatype *ct = sym->getType();
|
||||
EmitXml::syntax_highlight tokenColor;
|
||||
if (((sym->getFlags()&Varnode::readonly)!=0)&&(ct->getMetatype()==TYPE_ARRAY)) {
|
||||
Datatype *subct = ((TypeArray *)ct)->getBase();
|
||||
if (subct->isCharPrint()) {
|
||||
SymbolEntry *entry = sym->getFirstWholeMap();
|
||||
if (entry != (SymbolEntry *)0) {
|
||||
ostringstream s;
|
||||
if (printCharacterConstant(s,entry->getAddr(),subct)) {
|
||||
pushAtom(Atom(s.str(),vartoken,EmitXml::const_color,op,vn));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sym->getScope()->isGlobal())
|
||||
tokenColor = EmitXml::global_color;
|
||||
else if (sym->getCategory() == 0)
|
||||
|
||||
@@ -5627,7 +5627,10 @@ AddTreeState::AddTreeState(Funcdata &d,PcodeOp *op,int4 slot)
|
||||
ptrsize = ptr->getSize();
|
||||
ptrmask = calc_mask(ptrsize);
|
||||
baseType = ct->getPtrTo();
|
||||
size = AddrSpace::byteToAddressInt(baseType->getSize(),ct->getWordSize());
|
||||
if (baseType->isVariableLength())
|
||||
size = 0; // Open-ended size being pointed to, there will be no "multiples" component
|
||||
else
|
||||
size = AddrSpace::byteToAddressInt(baseType->getSize(),ct->getWordSize());
|
||||
multsum = 0; // Sums start out as zero
|
||||
nonmultsum = 0;
|
||||
correct = 0;
|
||||
|
||||
@@ -46,7 +46,7 @@ class AddTreeState {
|
||||
const TypePointer *ct; ///< The pointer data-type
|
||||
const Datatype *baseType; ///< The base data-type being pointed at
|
||||
int4 ptrsize; ///< Size of the pointer
|
||||
int4 size; ///< Size of data-type being pointed to (in address units)
|
||||
int4 size; ///< Size of data-type being pointed to (in address units) or 0 for open ended pointer
|
||||
uintb ptrmask; ///< Mask for modulo calculations in ptr space
|
||||
uintb offset; ///< Number of bytes we dig into the base data-type
|
||||
uintb correct; ///< Number of bytes being double counted
|
||||
|
||||
@@ -1092,15 +1092,18 @@ void TypeStruct::restoreXml(const Element *el,TypeFactory &typegrp)
|
||||
}
|
||||
|
||||
/// Turn on the data-type's function prototype
|
||||
/// \param tfact is the factory that owns \b this
|
||||
/// \param model is the prototype model
|
||||
/// \param outtype is the return type of the prototype
|
||||
/// \param intypes is the list of input parameters
|
||||
/// \param dotdotdot is true if the prototype takes variable arguments
|
||||
/// \param voidtype is the reference "void" data-type
|
||||
void TypeCode::set(ProtoModel *model,
|
||||
void TypeCode::set(TypeFactory *tfact,ProtoModel *model,
|
||||
Datatype *outtype,const vector<Datatype *> &intypes,
|
||||
bool dotdotdot,Datatype *voidtype)
|
||||
{
|
||||
factory = tfact;
|
||||
flags |= variable_length;
|
||||
if (proto != (FuncProto *)0)
|
||||
delete proto;
|
||||
proto = new FuncProto();
|
||||
@@ -1123,6 +1126,7 @@ TypeCode::TypeCode(const TypeCode &op) : Datatype(op)
|
||||
|
||||
{
|
||||
proto = (FuncProto *)0;
|
||||
factory = op.factory;
|
||||
if (op.proto != (FuncProto *)0) {
|
||||
proto = new FuncProto();
|
||||
proto->copy(*op.proto);
|
||||
@@ -1133,6 +1137,7 @@ TypeCode::TypeCode(const string &nm) : Datatype(1,TYPE_CODE,nm)
|
||||
|
||||
{
|
||||
proto = (FuncProto *)0;
|
||||
factory = (TypeFactory *)0;
|
||||
}
|
||||
|
||||
TypeCode::~TypeCode(void)
|
||||
@@ -1204,6 +1209,14 @@ int4 TypeCode::compareBasic(const TypeCode *op) const
|
||||
return 2; // Carry on with comparison of parameters
|
||||
}
|
||||
|
||||
Datatype *TypeCode::getSubType(uintb off,uintb *newoff) const
|
||||
|
||||
{
|
||||
if (factory == (TypeFactory *)0) return (Datatype *)0;
|
||||
*newoff = 0;
|
||||
return factory->getBase(1, TYPE_CODE); // Return code byte unattached to function prototype
|
||||
}
|
||||
|
||||
int4 TypeCode::compare(const Datatype &op,int4 level) const
|
||||
|
||||
{
|
||||
@@ -1284,6 +1297,8 @@ void TypeCode::restoreXml(const Element *el,TypeFactory &typegrp)
|
||||
iter = list.begin();
|
||||
if (iter == list.end()) return; // No underlying prototype
|
||||
Architecture *glb = typegrp.getArch();
|
||||
factory = &typegrp;
|
||||
flags |= variable_length;
|
||||
proto = new FuncProto();
|
||||
proto->setInternal( glb->defaultfp, typegrp.getTypeVoid() );
|
||||
proto->restoreXml(*iter,glb);
|
||||
@@ -2107,7 +2122,7 @@ TypeCode *TypeFactory::getTypeCode(ProtoModel *model,Datatype *outtype,
|
||||
bool dotdotdot)
|
||||
{
|
||||
TypeCode tc(""); // getFuncdata type with no name
|
||||
tc.set(model,outtype,intypes,dotdotdot,getTypeVoid());
|
||||
tc.set(this,model,outtype,intypes,dotdotdot,getTypeVoid());
|
||||
return (TypeCode *) findAdd(tc);
|
||||
}
|
||||
|
||||
|
||||
@@ -342,7 +342,8 @@ class TypeCode : public Datatype {
|
||||
protected:
|
||||
friend class TypeFactory;
|
||||
FuncProto *proto; ///< If non-null, this describes the prototype of the underlying function
|
||||
void set(ProtoModel *model,
|
||||
TypeFactory *factory; ///< Factory owning \b this
|
||||
void set(TypeFactory *tfact,ProtoModel *model,
|
||||
Datatype *outtype,const vector<Datatype *> &intypes,
|
||||
bool dotdotdot,Datatype *voidtype); ///< Establish a function pointer
|
||||
virtual void restoreXml(const Element *el,TypeFactory &typegrp);
|
||||
@@ -354,6 +355,7 @@ public:
|
||||
void setProperties(bool isConstructor,bool isDestructor); ///< Set additional function properties
|
||||
virtual ~TypeCode(void);
|
||||
virtual void printRaw(ostream &s) const;
|
||||
virtual Datatype *getSubType(uintb off,uintb *newoff) const;
|
||||
virtual int4 compare(const Datatype &op,int4 level) const;
|
||||
virtual int4 compareDependency(const Datatype &op) const;
|
||||
virtual Datatype *clone(void) const { return new TypeCode(*this); }
|
||||
|
||||
@@ -262,10 +262,11 @@ int4 RangeHint::compare(const RangeHint &op2) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// \param id is the globally unique id associated with the function scope
|
||||
/// \param spc is the (stack) address space associated with this function's local variables
|
||||
/// \param fd is the function associated with these local variables
|
||||
/// \param g is the Architecture
|
||||
ScopeLocal::ScopeLocal(AddrSpace *spc,Funcdata *fd,Architecture *g) : ScopeInternal(fd->getName(),g)
|
||||
ScopeLocal::ScopeLocal(uint8 id,AddrSpace *spc,Funcdata *fd,Architecture *g) : ScopeInternal(id,fd->getName(),g)
|
||||
|
||||
{
|
||||
space = spc;
|
||||
|
||||
@@ -209,7 +209,7 @@ class ScopeLocal : public ScopeInternal {
|
||||
void addRecommendName(Symbol *sym); ///< Convert the given symbol to a name recommendation
|
||||
void collectNameRecs(void); ///< Collect names of unlocked Symbols on the stack
|
||||
public:
|
||||
ScopeLocal(AddrSpace *spc,Funcdata *fd,Architecture *g); ///< Constructor
|
||||
ScopeLocal(uint8 id,AddrSpace *spc,Funcdata *fd,Architecture *g); ///< Constructor
|
||||
virtual ~ScopeLocal(void) {} ///< Destructor
|
||||
|
||||
AddrSpace *getSpaceId(void) const { return space; } ///< Get the associated (stack) address space
|
||||
|
||||
+6
-3
@@ -500,7 +500,7 @@ public class DecompileCallback {
|
||||
}
|
||||
String res = getSymbolName(sym);
|
||||
if (debug != null) {
|
||||
debug.getSymbol(addr, res);
|
||||
debug.getCodeSymbol(addr, sym.getID(), res, sym.getParentNamespace());
|
||||
}
|
||||
|
||||
return res;
|
||||
@@ -563,7 +563,7 @@ public class DecompileCallback {
|
||||
int pathSize = 0;
|
||||
Namespace curspace = namespace;
|
||||
long curId = namespace.getID();
|
||||
while (curId != stopId && curId != 0 && !(curspace instanceof Library)) {
|
||||
while (curId != stopId && curId != 0 && !HighFunction.collapseToGlobal(curspace)) {
|
||||
pathSize += 1;
|
||||
curspace = curspace.getParentNamespace();
|
||||
curId = curspace.getID();
|
||||
@@ -610,7 +610,10 @@ public class DecompileCallback {
|
||||
public String getNamespacePath(long id) {
|
||||
Namespace namespace = getNameSpaceByID(id);
|
||||
StringBuilder buf = new StringBuilder();
|
||||
HighFunction.createNamespaceTag(buf, namespace, true);
|
||||
HighFunction.createNamespaceTag(buf, namespace);
|
||||
if (debug != null) {
|
||||
debug.getNamespacePath(namespace);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
|
||||
+81
-33
@@ -17,6 +17,7 @@ package ghidra.app.decompiler;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import ghidra.app.decompiler.DecompileCallback.StringData;
|
||||
import ghidra.app.plugin.processors.sleigh.ContextCache;
|
||||
@@ -49,7 +50,6 @@ public class DecompileDebug {
|
||||
private ArrayList<Namespace> dbscope; // Symbol query: scope
|
||||
private ArrayList<String> database; // description of the symbol
|
||||
private ArrayList<DataType> dtypes; // Data-types queried
|
||||
private ArrayList<String> symbol; // Names of code labels
|
||||
private ArrayList<String> context; // Tracked register values associated with an address
|
||||
private ArrayList<String> cpool; // Constant pool results
|
||||
private ArrayList<String> flowoverride; // Flow overrides associated with an address
|
||||
@@ -111,7 +111,6 @@ public class DecompileDebug {
|
||||
dbscope = new ArrayList<Namespace>();
|
||||
database = new ArrayList<String>();
|
||||
dtypes = new ArrayList<DataType>();
|
||||
symbol = new ArrayList<String>();
|
||||
context = new ArrayList<String>();
|
||||
cpool = new ArrayList<String>();
|
||||
byteset = new TreeSet<ByteChunk>();
|
||||
@@ -192,9 +191,6 @@ public class DecompileDebug {
|
||||
binimage += "\">\n";
|
||||
debugStream.write(binimage.getBytes());
|
||||
dumpBytes(debugStream);
|
||||
for (String element : symbol) {
|
||||
debugStream.write((element).getBytes());
|
||||
}
|
||||
debugStream.write("</binaryimage>\n".getBytes());
|
||||
}
|
||||
|
||||
@@ -511,50 +507,87 @@ public class DecompileDebug {
|
||||
debugStream.write("</injectdebug>\n".getBytes());
|
||||
}
|
||||
|
||||
private ArrayList<Namespace> orderNamespaces() {
|
||||
TreeMap<Long, Namespace> namespaceMap = new TreeMap<Long, Namespace>();
|
||||
for (Namespace namespace : dbscope) {
|
||||
namespaceMap.put(namespace.getID(), namespace);
|
||||
}
|
||||
ArrayList<Namespace> res = new ArrayList<Namespace>();
|
||||
while (!namespaceMap.isEmpty()) {
|
||||
Entry<Long, Namespace> entry = namespaceMap.firstEntry();
|
||||
Long curKey = entry.getKey();
|
||||
Namespace curSpace = entry.getValue();
|
||||
for (;;) {
|
||||
Long key;
|
||||
Namespace parent = curSpace.getParentNamespace();
|
||||
if (parent == null) {
|
||||
break;
|
||||
}
|
||||
if (HighFunction.collapseToGlobal(parent)) {
|
||||
key = Long.valueOf(Namespace.GLOBAL_NAMESPACE_ID);
|
||||
}
|
||||
else {
|
||||
key = Long.valueOf(parent.getID());
|
||||
}
|
||||
parent = namespaceMap.get(key);
|
||||
if (parent == null) {
|
||||
break;
|
||||
}
|
||||
curKey = key;
|
||||
curSpace = parent;
|
||||
}
|
||||
res.add(curSpace);
|
||||
namespaceMap.remove(curKey);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private void dumpDatabases(OutputStream debugStream) throws IOException {
|
||||
Namespace scopename = null;
|
||||
debugStream.write("<db>\n".getBytes());
|
||||
for (int i = 0; i < database.size(); ++i) {
|
||||
scopename = dbscope.get(i);
|
||||
if (scopename != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (scopename != null) {
|
||||
ArrayList<Namespace> spaceList = orderNamespaces();
|
||||
debugStream.write("<db scodeidbyname=\"false\">\n".getBytes());
|
||||
for (Namespace element : spaceList) {
|
||||
scopename = element;
|
||||
StringBuilder datahead = new StringBuilder();
|
||||
Namespace parentNamespace;
|
||||
datahead.append("<scope");
|
||||
// Force globalnamespace to have blank name
|
||||
if (scopename != globalnamespace && !(scopename instanceof Library)) {
|
||||
if (scopename != globalnamespace) {
|
||||
SpecXmlUtils.xmlEscapeAttribute(datahead, "name", scopename.getName());
|
||||
parentNamespace = scopename.getParentNamespace();
|
||||
SpecXmlUtils.encodeUnsignedIntegerAttribute(datahead, "id", scopename.getID());
|
||||
}
|
||||
else {
|
||||
SpecXmlUtils.encodeStringAttribute(datahead, "name", "");
|
||||
SpecXmlUtils.encodeUnsignedIntegerAttribute(datahead, "id",
|
||||
Namespace.GLOBAL_NAMESPACE_ID);
|
||||
parentNamespace = null;
|
||||
}
|
||||
datahead.append(">\n");
|
||||
HighFunction.createNamespaceTag(datahead, parentNamespace, false);
|
||||
if (parentNamespace != null) {
|
||||
long parentId =
|
||||
HighFunction.collapseToGlobal(parentNamespace) ? Namespace.GLOBAL_NAMESPACE_ID
|
||||
: parentNamespace.getID();
|
||||
datahead.append("<parent");
|
||||
SpecXmlUtils.encodeUnsignedIntegerAttribute(datahead, "id", parentId);
|
||||
datahead.append("/>\n");
|
||||
}
|
||||
if (scopename != globalnamespace) {
|
||||
datahead.append("<rangeequalssymbols/>\n");
|
||||
}
|
||||
datahead.append("<symbollist>\n");
|
||||
debugStream.write(datahead.toString().getBytes());
|
||||
for (int i = 0; i < database.size(); ++i) {
|
||||
Namespace namespc = dbscope.get(i);
|
||||
for (int j = 0; j < database.size(); ++j) {
|
||||
Namespace namespc = dbscope.get(j);
|
||||
if (namespc == scopename) {
|
||||
debugStream.write((database.get(i)).getBytes());
|
||||
dbscope.set(i, null);
|
||||
String entry = database.get(j);
|
||||
if (entry == null) {
|
||||
continue; // String may be null
|
||||
}
|
||||
debugStream.write(entry.getBytes());
|
||||
}
|
||||
}
|
||||
debugStream.write("</symbollist>\n</scope>\n".getBytes());
|
||||
scopename = null;
|
||||
for (Namespace element : dbscope) {
|
||||
scopename = element;
|
||||
if (scopename != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
debugStream.write("</db>\n".getBytes());
|
||||
}
|
||||
@@ -627,19 +660,34 @@ public class DecompileDebug {
|
||||
comments = comm; // Already in XML form
|
||||
}
|
||||
|
||||
public void getSymbol(Address addr, String name) {
|
||||
public void getCodeSymbol(Address addr, long id, String name, Namespace namespace) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("<symbol");
|
||||
AddressSpace space = addr.getAddressSpace();
|
||||
SpecXmlUtils.encodeStringAttribute(buf, "space", space.getPhysicalSpace().getName());
|
||||
SpecXmlUtils.encodeUnsignedIntegerAttribute(buf, "offset", addr.getOffset());
|
||||
buf.append("<mapsym>\n");
|
||||
buf.append(" <labelsym");
|
||||
SpecXmlUtils.xmlEscapeAttribute(buf, "name", name);
|
||||
SpecXmlUtils.encodeUnsignedIntegerAttribute(buf, "id", id);
|
||||
buf.append("/>\n");
|
||||
symbol.add(buf.toString());
|
||||
buf.append(" <addr");
|
||||
Varnode.appendSpaceOffset(buf, addr);
|
||||
buf.append("/>\n");
|
||||
buf.append(" <rangelist/>\n");
|
||||
buf.append("</mapsym>\n");
|
||||
getMapped(namespace, buf.toString());
|
||||
}
|
||||
|
||||
public void getNamespacePath(Namespace namespace) {
|
||||
while (namespace != null) {
|
||||
if (HighFunction.collapseToGlobal(namespace)) {
|
||||
break; // Treat library namespace as root
|
||||
}
|
||||
dbscope.add(namespace); // Add namespace to guarantee <scope> tag
|
||||
database.add(null); // Even if there isn't necessarily any symbols
|
||||
namespace = namespace.getParentNamespace();
|
||||
}
|
||||
}
|
||||
|
||||
public void getMapped(Namespace namespc, String res) {
|
||||
if (namespc == null) {
|
||||
if (namespc == null || HighFunction.collapseToGlobal(namespc)) {
|
||||
dbscope.add(globalnamespace);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -183,9 +183,7 @@ abstract class CoreGTreeNode implements Cloneable {
|
||||
* @param node the node to add as a child to this node
|
||||
*/
|
||||
protected synchronized void doAddNode(GTreeNode node) {
|
||||
children().add(node);
|
||||
node.setParent((GTreeNode) this);
|
||||
doFireNodeAdded(node);
|
||||
doAddNode(children().size(), node);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,6 +194,9 @@ abstract class CoreGTreeNode implements Cloneable {
|
||||
*/
|
||||
protected synchronized void doAddNode(int index, GTreeNode node) {
|
||||
List<GTreeNode> kids = children();
|
||||
if (kids.contains(node)) {
|
||||
return;
|
||||
}
|
||||
int insertIndex = Math.min(kids.size(), index);
|
||||
kids.add(insertIndex, node);
|
||||
node.setParent((GTreeNode) this);
|
||||
|
||||
@@ -456,6 +456,24 @@ public class GTreeNodeTest {
|
||||
assertNotEquals(nodeA.hashCode(), nodeB.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCantAddNodeTwice() {
|
||||
node0 = new TestNode("No Dups");
|
||||
|
||||
int childCount = root.getChildCount();
|
||||
root.addNode(node0);
|
||||
assertEquals(childCount + 1, root.getChildCount());
|
||||
|
||||
// now make sure the count doesn't grow again
|
||||
root.addNode(node0);
|
||||
assertEquals(childCount + 1, root.getChildCount());
|
||||
|
||||
// try adding it with an index, still shouldn't get added
|
||||
root.addNode(0, node0);
|
||||
assertEquals(childCount + 1, root.getChildCount());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneEquals() throws CloneNotSupportedException {
|
||||
GTreeNode nodeA = new TestNode("AAA");
|
||||
|
||||
+16
-7
@@ -615,22 +615,33 @@ public class HighFunction extends PcodeSyntaxTree {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The decompiler treats some namespaces as equivalent to the "global" namespace.
|
||||
* Return true if the given namespace is treated as equivalent.
|
||||
* @param namespace is the namespace
|
||||
* @return true if equivalent
|
||||
*/
|
||||
static final public boolean collapseToGlobal(Namespace namespace) {
|
||||
if (namespace instanceof Library) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append an XML <parent> tag to the buffer describing the formal path elements
|
||||
* from the root (global) namespace up to the given namespace
|
||||
* @param buf is the buffer to write to
|
||||
* @param namespace is the namespace being described
|
||||
* @param includeId is true if the XML tag should include namespace ids
|
||||
*/
|
||||
static public void createNamespaceTag(StringBuilder buf, Namespace namespace,
|
||||
boolean includeId) {
|
||||
static public void createNamespaceTag(StringBuilder buf, Namespace namespace) {
|
||||
buf.append("<parent>\n");
|
||||
if (namespace != null) {
|
||||
ArrayList<Namespace> arr = new ArrayList<Namespace>();
|
||||
Namespace curspc = namespace;
|
||||
while (curspc != null) {
|
||||
arr.add(0, curspc);
|
||||
if (curspc instanceof Library) {
|
||||
if (collapseToGlobal(curspc)) {
|
||||
break; // Treat library namespace as root
|
||||
}
|
||||
curspc = curspc.getParentNamespace();
|
||||
@@ -639,9 +650,7 @@ public class HighFunction extends PcodeSyntaxTree {
|
||||
for (int i = 1; i < arr.size(); ++i) {
|
||||
Namespace curScope = arr.get(i);
|
||||
buf.append("<val");
|
||||
if (includeId) {
|
||||
SpecXmlUtils.encodeUnsignedIntegerAttribute(buf, "id", curScope.getID());
|
||||
}
|
||||
SpecXmlUtils.encodeUnsignedIntegerAttribute(buf, "id", curScope.getID());
|
||||
buf.append('>');
|
||||
SpecXmlUtils.xmlEscape(buf, curScope.getName());
|
||||
buf.append("</val>\n");
|
||||
|
||||
+7
-1
@@ -338,7 +338,13 @@ public class LocalSymbolMap {
|
||||
resBuf.append("<scope");
|
||||
SpecXmlUtils.xmlEscapeAttribute(resBuf, "name", func.getFunction().getName());
|
||||
resBuf.append(">\n");
|
||||
HighFunction.createNamespaceTag(resBuf, namespace, false);
|
||||
resBuf.append("<parent");
|
||||
long parentid = Namespace.GLOBAL_NAMESPACE_ID;
|
||||
if (!HighFunction.collapseToGlobal(namespace)) {
|
||||
parentid = namespace.getID();
|
||||
}
|
||||
SpecXmlUtils.encodeUnsignedIntegerAttribute(resBuf, "id", parentid);
|
||||
resBuf.append("/>\n");
|
||||
resBuf.append("<rangelist/>\n"); // Empty address range
|
||||
resBuf.append("<symbollist>\n");
|
||||
Iterator<HighSymbol> iter = symbolMap.values().iterator();
|
||||
|
||||
@@ -2488,7 +2488,8 @@ buildVldmDdList: Dreg,buildVldmDdList is Dreg & buildVldmDdList [ counter=counte
|
||||
build buildVldmDdList;
|
||||
}
|
||||
|
||||
vldmDdList: "{"^buildVldmDdList^"}" is D22 & c1215 & c0007 & buildVldmDdList [ regNum=(D22<<4)+c1215 - 1; counter=c0007>>1; ] { }
|
||||
vldmDdList: "{"^buildVldmDdList^"}" is TMode=0 & D22 & c1215 & c0007 & buildVldmDdList [ regNum=(D22<<4)+c1215 - 1; counter=c0007>>1; ] { }
|
||||
vldmDdList: "{"^buildVldmDdList^"}" is TMode=1 & thv_D22 & thv_c1215 & thv_c0007 & buildVldmDdList [ regNum=(thv_D22<<4)+thv_c1215 - 1; counter=thv_c0007>>1; ] { }
|
||||
|
||||
:vldmia^COND vldmRn,vldmDdList is ( ($(AMODE) & COND & c2327=0x19 & c2121 & c2020=1 & c0811=11 & c0000=0) |
|
||||
($(TMODE_E) & thv_c2327=0x19 & thv_c2121 & thv_c2020=1 & thv_c0811=11 & thv_c0000=0) ) & vldmRn & vldmDdList & vldmOffset & vldmUpdate
|
||||
@@ -4540,7 +4541,8 @@ buildVstmDdList: Dreg,buildVstmDdList is Dreg & buildVstmDdList [ counter=counte
|
||||
build buildVstmDdList;
|
||||
}
|
||||
|
||||
vstmDdList: "{"^buildVstmDdList^"}" is D22 & c1215 & c0007 & buildVstmDdList [ regNum=(D22<<4)+c1215-1; counter=c0007>>1; ] { }
|
||||
vstmDdList: "{"^buildVstmDdList^"}" is TMode=0 & D22 & c1215 & c0007 & buildVstmDdList [ regNum=(D22<<4)+c1215-1; counter=c0007>>1; ] { }
|
||||
vstmDdList: "{"^buildVstmDdList^"}" is TMode=1 & thv_D22 & thv_c1215 & thv_c0007 & buildVstmDdList [ regNum=(thv_D22<<4)+thv_c1215-1; counter=thv_c0007>>1; ] { }
|
||||
|
||||
:vstmia^COND vldmRn,vstmDdList is ( ($(AMODE) & COND & c2327=0x19 & c2121 & c2020=0 & c0811=11 & c0000=0) |
|
||||
($(TMODE_E) & thv_c2327=0x19 & thv_c2121 & thv_c2020=0 & thv_c0811=11 & thv_c0000=0) ) & vldmRn & vstmDdList & vldmOffset & vldmUpdate
|
||||
|
||||
@@ -8,3 +8,4 @@ data/languages/superh.cspec||GHIDRA||||END|
|
||||
data/languages/superh.ldefs||GHIDRA||||END|
|
||||
data/languages/superh.pspec||GHIDRA||||END|
|
||||
data/languages/superh.sinc||GHIDRA||||END|
|
||||
data/languages/superh2a.cspec||GHIDRA||||END|
|
||||
|
||||
@@ -29,19 +29,6 @@
|
||||
<default_proto>
|
||||
<prototype name="__stdcall" extrapop="0" stackshift="0">
|
||||
<input>
|
||||
<pentry minsize="4" maxsize="4" metatype="float">
|
||||
<register name="fr4"/>
|
||||
</pentry>
|
||||
<pentry minsize="4" maxsize="4" metatype="float">
|
||||
<register name="fr5"/>
|
||||
</pentry>
|
||||
<pentry minsize="4" maxsize="4" metatype="float">
|
||||
<register name="fr6"/>
|
||||
</pentry>
|
||||
<pentry minsize="4" maxsize="4" metatype="float">
|
||||
<register name="fr7"/>
|
||||
</pentry>
|
||||
|
||||
<pentry minsize="1" maxsize="4" extension="inttype">
|
||||
<register name="r4"/>
|
||||
</pentry>
|
||||
@@ -59,9 +46,6 @@
|
||||
</pentry>
|
||||
</input>
|
||||
<output killedbycall="true">
|
||||
<pentry minsize="4" maxsize="4" metatype="float">
|
||||
<register name="fr0"/>
|
||||
</pentry>
|
||||
<pentry minsize="1" maxsize="4" extension="inttype">
|
||||
<register name="r0"/>
|
||||
</pentry>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
processorspec="superh.pspec"
|
||||
id="SuperH:BE:32:SH-2A">
|
||||
<description>SuperH SH-2A processor 32-bit big-endian</description>
|
||||
<compiler name="default" spec="superh.cspec" id="default"/>
|
||||
<compiler name="default" spec="superh2a.cspec" id="default"/>
|
||||
</language>
|
||||
<language processor="SuperH"
|
||||
endian="big"
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<compiler_spec>
|
||||
<data_organization> <!-- These tags were taken from https://gcc-renesas.com/manuals/SH-ABI-Specification.html-->
|
||||
<absolute_max_alignment value="0" />
|
||||
<machine_alignment value="2" />
|
||||
<default_alignment value="1" />
|
||||
<default_pointer_alignment value="4" />
|
||||
<pointer_size value="4" />
|
||||
<wchar_size value="2" />
|
||||
<short_size value="2" />
|
||||
<integer_size value="4" />
|
||||
<long_size value="4" />
|
||||
<long_long_size value="8" />
|
||||
<float_size value="4" />
|
||||
<double_size value="8" />
|
||||
<long_double_size value="8" />
|
||||
<size_alignment_map>
|
||||
<entry size="1" alignment="1" />
|
||||
<entry size="2" alignment="2" />
|
||||
<entry size="4" alignment="4" />
|
||||
<entry size="8" alignment="4" />
|
||||
</size_alignment_map>
|
||||
</data_organization>
|
||||
<global>
|
||||
<range space="ram"/>
|
||||
</global>
|
||||
<stackpointer register="r15" space="ram"/>
|
||||
<default_proto>
|
||||
<prototype name="__stdcall" extrapop="0" stackshift="0">
|
||||
<input>
|
||||
<pentry minsize="4" maxsize="4" metatype="float">
|
||||
<register name="fr4"/>
|
||||
</pentry>
|
||||
<pentry minsize="4" maxsize="4" metatype="float">
|
||||
<register name="fr5"/>
|
||||
</pentry>
|
||||
<pentry minsize="4" maxsize="4" metatype="float">
|
||||
<register name="fr6"/>
|
||||
</pentry>
|
||||
<pentry minsize="4" maxsize="4" metatype="float">
|
||||
<register name="fr7"/>
|
||||
</pentry>
|
||||
|
||||
<pentry minsize="1" maxsize="4" extension="inttype">
|
||||
<register name="r4"/>
|
||||
</pentry>
|
||||
<pentry minsize="1" maxsize="4" extension="inttype">
|
||||
<register name="r5"/>
|
||||
</pentry>
|
||||
<pentry minsize="1" maxsize="4" extension="inttype">
|
||||
<register name="r6"/>
|
||||
</pentry>
|
||||
<pentry minsize="1" maxsize="4" extension="inttype">
|
||||
<register name="r7"/>
|
||||
</pentry>
|
||||
<pentry minsize="1" maxsize="500" align="4">
|
||||
<addr offset="0" space="stack"/>
|
||||
</pentry>
|
||||
</input>
|
||||
<output killedbycall="true">
|
||||
<pentry minsize="4" maxsize="4" metatype="float">
|
||||
<register name="fr0"/>
|
||||
</pentry>
|
||||
<pentry minsize="1" maxsize="4" extension="inttype">
|
||||
<register name="r0"/>
|
||||
</pentry>
|
||||
<pentry minsize="5" maxsize="8">
|
||||
<addr space="join" piece1="r1" piece2="r0"/>
|
||||
</pentry>
|
||||
</output>
|
||||
<unaffected>
|
||||
<register name="r8"/>
|
||||
<register name="r9"/>
|
||||
<register name="r10"/>
|
||||
<register name="r11"/>
|
||||
<register name="r12"/>
|
||||
<register name="r13"/>
|
||||
<register name="r14"/>
|
||||
<register name="r15"/>
|
||||
</unaffected>
|
||||
<killedbycall>
|
||||
<register name="r2"/>
|
||||
<register name="r3"/>
|
||||
</killedbycall>
|
||||
</prototype>
|
||||
</default_proto>
|
||||
</compiler_spec>
|
||||
Reference in New Issue
Block a user