Skip to content

Ghidra is a software reverse engineering (SRE) framework

Merge remote-tracking branch 'origin/GP-520_James_max_unique_varnode_size'

ghidra1a3f223619c9c
diff --cc Ghidra/Features/Decompiler/src/decompile/cpp/sleighbase.cc
index 1eb18a07a8,0d3107fabc..5eeca410f5
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/sleighbase.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/sleighbase.cc
@@@ -15,49 -15,9 +15,50 @@@
*/
#include "sleighbase.hh"
-const int4 SleighBase::SLA_FORMAT_VERSION = 2;
+const int4 SleighBase::SLA_FORMAT_VERSION = 3;
+
+ const uintb SleighBase::MAX_UNIQUE_SIZE = 128;
+
+int4 SourceFileIndexer::index(const string filename){
+ auto it = fileToIndex.find(filename);
+ if (fileToIndex.end() != it){
+ return it->second;
+ }
+ fileToIndex[filename] = leastUnusedIndex;
+ indexToFile[leastUnusedIndex] = filename;
+ return leastUnusedIndex++;
+}
+
+int4 SourceFileIndexer::getIndex(string filename){
+ return fileToIndex[filename];
+}
+
+string SourceFileIndexer::getFilename(int4 index){
+ return indexToFile[index];
+}
+
+void SourceFileIndexer::restoreXml(const Element *el){
+ const List &sourceFiles(el->getChildren());
+ List::const_iterator iter = sourceFiles.begin();
+ for (; iter != sourceFiles.end(); ++iter){
+ string filename = (*iter)->getAttributeValue("name");
+ int4 index = stoi((*iter)->getAttributeValue("index"),NULL,10);
+ fileToIndex[filename] = index;
+ indexToFile[index] = filename;
+ }
+}
+
+void SourceFileIndexer::saveXml(ostream& s) const {
+ s << "<sourcefiles>\n";
+ for (int4 i = 0; i < leastUnusedIndex; ++i){
+ s << ("<sourcefile name=\"");
+ const char *str = indexToFile.at(i).c_str();
+ xml_escape(s,str);
+ s << "\" index=\"" << dec << i << "\"/>\n";
+ }
+ s << "</sourcefiles>\n";
+}
+
-
SleighBase::SleighBase(void)
{
diff --cc Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguage.java
index b5a3be9dfd,f45f183e38..e86985a056
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguage.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguage.java
@@@ -33,6 -33,6 +33,7 @@@ import ghidra.app.plugin.processors.sle
import ghidra.app.plugin.processors.sleigh.expression.PatternValue;
import ghidra.app.plugin.processors.sleigh.symbol.*;
import ghidra.framework.Application;
++import ghidra.pcodeCPort.sleighbase.SleighBase;
import ghidra.pcodeCPort.slgh_compile.SleighCompileLauncher;
import ghidra.program.model.address.*;
import ghidra.program.model.lang.*;
@@@ -42,8 -42,7 +43,8 @@@ import ghidra.program.model.mem.MemoryA
import ghidra.program.model.symbol.SourceType;
import ghidra.program.model.util.AddressLabelInfo;
import ghidra.program.model.util.ProcessorSymbolType;
- import ghidra.sleigh.grammar.SourceFileIndexer;
import ghidra.sleigh.grammar.SleighPreprocessor;
++import ghidra.sleigh.grammar.SourceFileIndexer;
import ghidra.util.*;
import ghidra.util.task.TaskMonitor;
import ghidra.util.xml.SpecXmlUtils;
@@@ -53,18 -52,8 +54,15 @@@ import utilities.util.FileUtilities
public class SleighLanguage implements Language {
- public static final int SLA_FORMAT_VERSION = 2; // What format of the .sla file this expects
- // This value should always match SleighBase.SLA_FORMAT_VERSION
+ /**
- * NOTE: The value of {@link SleighLanguage#SLA_FORMAT_VERSION} must match that of
- * {@link ghidra.pcodeCPort.sleighbase.SleighBase#SLA_FORMAT_VERSION}!.
- * <p>
- * SLA_FORMAT_VERSION should be incremented whenever the format of the .sla
++ * SLA_FORMAT_VERSION will be incremented whenever the format of the .sla
+ * files change.
+ * <p>
- * Version 3: October 2020: added source file information for each constructor. <br>
++ * Version 3: January 2021: added source file information for each constructor. <br>
+ * Version 2: April 2019: Changed numbering of Overlay spaces.<br>
+ * Version 1: Initial version.<br>
+ */
- public static final int SLA_FORMAT_VERSION = 3;
++ public static final int SLA_FORMAT_VERSION = SleighBase.SLA_FORMAT_VERSION;
private Map<CompilerSpecID, SleighCompilerSpecDescription> compilerSpecDescriptions;
private HashMap<CompilerSpecID, BasicCompilerSpec> compilerSpecs;
private List<InjectPayloadSleigh> additionalInject = null;
diff --cc Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/sleighbase/SleighBase.java
index 8b0f02b056,ca99fc6cc2..7ff81c7e86
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/sleighbase/SleighBase.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/sleighbase/SleighBase.java
@@@ -34,11 -33,10 +34,15 @@@ public abstract class SleighBase extend
// NOTE: restoreXml method removed as it is only used by the decompiler's
// implementation
- public static final int SLA_FORMAT_VERSION = 2; // What format of the .sla file this produces
- // This value should always match SleighLanguage.SLA_FORMAT_VERSION
+ /**
- * Note: The value of {@link SleighBase#SLA_FORMAT_VERSION} must match
- * {@link ghidra.app.plugin.processors.sleigh.SleighLanguage#SLA_FORMAT_VERSION}.
++ * Note: The values of {@link #SLA_FORMAT_VERSION} and {@link #MAX_UNIQUE_SIZE}
++ * must match the corresponding values defined by sleighbase.cc
+ */
+ public static final int SLA_FORMAT_VERSION = 3;
++
+ public static final long MAX_UNIQUE_SIZE = 128; //Maximum size of a varnode in the unique space.
- //Should match value in sleighbase.cc
++ //Should match value in sleighbase.cc
++
private VectorSTL<String> userop = new VectorSTL<>();
private address_set varnode_xref = new address_set(); // Cross-reference registers by address
protected SubtableSymbol root;