diff --git a/.gitignore b/.gitignore index 04e661f556..c3fb9d3ddc 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ ghidra.repos.config **/dist repositories/ *.sla +**/data/build.xml # Misc files *.setting diff --git a/Ghidra/Features/FileFormats/data/build.xml b/Ghidra/Features/FileFormats/data/build.xml deleted file mode 100644 index 8f72019712..0000000000 --- a/Ghidra/Features/FileFormats/data/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Features/PDB/src/global/docs/README_PDB.html b/Ghidra/Features/PDB/src/global/docs/README_PDB.html index 7fff3b07c6..3b39a8ef11 100644 --- a/Ghidra/Features/PDB/src/global/docs/README_PDB.html +++ b/Ghidra/Features/PDB/src/global/docs/README_PDB.html @@ -75,9 +75,9 @@ of Visual Studio and DIA SDK.

First, check to see if you already have the msdia140.dll library installed on your system. It is generally installed installed with Microsoft Visual Studio 2017 when C/C++ development support -is included. +is included ( may be Community, Professional, or other VS 2017 distribution package name).

-        C:\\Program Files (x86)\Microsoft Visual Studio\2017\DIA SDK\bin\amd64\msdia140.dll
+        C:\Program Files (x86)\Microsoft Visual Studio\2017\\DIA SDK\bin\amd64\msdia140.dll
 

This file is commonly located here, although it may be installed in other locations as well. Any 64-bit copy may be registered provided it is the correct version. There is no need to register more than @@ -86,8 +86,8 @@ one.

Register 'msdia140.dll' in the Windows registry

Please register 64-bit msdia140.dll even if you already had a copy of it on your computer -since it is not registered by the Visual Studio installation process. You will need administrative rights/privileges in order to register the DLL in the Windows -registry. +since it is not registered by the Visual Studio installation process. You will need administrative +rights/privileges in order to register the DLL in the Windows registry.

  1. Start a command prompt as an administrator:
  2. diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbParserNEW.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbParserNEW.java index 9a446da18d..6adbba1967 100644 --- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbParserNEW.java +++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbParserNEW.java @@ -576,6 +576,9 @@ public class PdbParserNEW { } catch (Exception e) { if (!isXML) { + if (hasErrors()) { + throw new PdbException(getErrorAndWarningMessages()); + } throw new PdbException("PDB Execution failure of " + PDB_EXE + ".\n" + "This was likely caused by severe execution failure which can occur if executed\n" + "on an unsupported platform. It may be neccessary to rebuild the PDB executable\n" + diff --git a/Ghidra/Features/PDB/src/pdb/cpp/err.cpp b/Ghidra/Features/PDB/src/pdb/cpp/err.cpp index 47bc2d14f1..bf22cc23bf 100644 --- a/Ghidra/Features/PDB/src/pdb/cpp/err.cpp +++ b/Ghidra/Features/PDB/src/pdb/cpp/err.cpp @@ -1,6 +1,5 @@ /* ### * IP: GHIDRA - * REVIEWED: YES * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,9 +25,7 @@ void warning( const char * msg ) void fatal( const char * msg ) { - fprintf( stderr, "ERROR:\n" ); - fprintf( stderr, msg ); - fprintf( stderr, "\n" ); + fprintf( stderr, "ERROR: %s\n", msg ); exit( -1 ); } diff --git a/Ghidra/Features/PDB/src/pdb/cpp/pdb.cpp b/Ghidra/Features/PDB/src/pdb/cpp/pdb.cpp index 4aedf4c8c6..b08daa7b14 100644 --- a/Ghidra/Features/PDB/src/pdb/cpp/pdb.cpp +++ b/Ghidra/Features/PDB/src/pdb/cpp/pdb.cpp @@ -46,9 +46,8 @@ int init(const char * szFilename, const char * szSignature, const char * szAge) if (hr < 0) { switch (hr) { case REGDB_E_CLASSNOTREG: - fatal("Unable to locate the DIA SDK. It is required to load PDB files.\n\n" \ - "* Open {Ghidra install root}/docs/README_PDB.html\n" - " and follow the instructions therein.\n"); + fatal("Unable to locate the DIA SDK. It is required to load PDB files.\n" \ + "* See docs/README_PDB.html for DLL registration instructions.\n"); break; default: char msg[256]; diff --git a/Ghidra/Features/PDB/src/pdb/pdb.vcxproj b/Ghidra/Features/PDB/src/pdb/pdb.vcxproj index 002c8a5723..500065d27c 100644 --- a/Ghidra/Features/PDB/src/pdb/pdb.vcxproj +++ b/Ghidra/Features/PDB/src/pdb/pdb.vcxproj @@ -72,7 +72,7 @@ rem copy /y /v /b "$(VSInstallDir)DIA SDK\bin\amd64\msdia*.dll" "$(OutDir)" -set OS_DIR="$(SolutionDir)..\..\os" +set OS_DIR=$(SolutionDir)..\..\os if exist "%OS_DIR%\win64" ( mkdir "%OS_DIR%" mkdir "%OS_DIR%\win64" @@ -104,7 +104,7 @@ if exist "%OS_DIR%\win64" ( rem copy /y /v /b "$(VSInstallDir)DIA SDK\bin\amd64\msdia*.dll" "$(OutDir)" -set OS_DIR="$(SolutionDir)..\..\os" +set OS_DIR=$(SolutionDir)..\..\os if exist "%OS_DIR%\win64" ( mkdir "%OS_DIR%" mkdir "%OS_DIR%\win64" diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Application.java b/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Application.java index e6f02965f7..09572b2b80 100644 --- a/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Application.java +++ b/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Application.java @@ -460,18 +460,19 @@ public class Application { if (module == null) { return null; } - - File file = getModuleFile(module, "build/os/" + Platform.CURRENT_PLATFORM.getDirectoryName(), - exactFilename); + + File file = getModuleFile(module, + "build/os/" + Platform.CURRENT_PLATFORM.getDirectoryName(), exactFilename); if (file == null) { file = getModuleFile(module, "os/" + Platform.CURRENT_PLATFORM.getDirectoryName(), exactFilename); } - + // Allow win32 to be used for win64 as fallback if (file == null && Platform.CURRENT_PLATFORM == Platform.WIN_64) { - file = getModuleFile(module, "build/os/" + Platform.WIN_32.getDirectoryName(), exactFilename); + file = getModuleFile(module, "build/os/" + Platform.WIN_32.getDirectoryName(), + exactFilename); } if (file == null && Platform.CURRENT_PLATFORM == Platform.WIN_64) { file = getModuleFile(module, "os/" + Platform.WIN_32.getDirectoryName(), exactFilename); @@ -492,12 +493,13 @@ public class Application { private File getOSFileInAnyModule(String path) throws FileNotFoundException { - File file = findModuleFile("build/os/" + Platform.CURRENT_PLATFORM.getDirectoryName(), path); - + File file = + findModuleFile("build/os/" + Platform.CURRENT_PLATFORM.getDirectoryName(), path); + if (file == null) { file = findModuleFile("os/" + Platform.CURRENT_PLATFORM.getDirectoryName(), path); } - + // Allow win32 to be used for win64 as fallback if (file == null && Platform.CURRENT_PLATFORM == Platform.WIN_64) { file = findModuleFile("build/os/" + Platform.WIN_32.getDirectoryName(), path); @@ -657,7 +659,7 @@ public class Application { /** * Return the module root directory for the module with the given name. * @param moduleName the name of the module. - * @return the module root directory for the module with the given name. + * @return the module root directory for the module with the given name or null if not found. */ public static ResourceFile getModuleRootDir(String moduleName) { checkAppInitialized(); diff --git a/Ghidra/Framework/SoftwareModeling/Sleigh.launch b/Ghidra/Framework/SoftwareModeling/Sleigh.launch index b4f8e30e41..b8273f84bc 100644 --- a/Ghidra/Framework/SoftwareModeling/Sleigh.launch +++ b/Ghidra/Framework/SoftwareModeling/Sleigh.launch @@ -1,19 +1,27 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Ghidra/Framework/SoftwareModeling/build.gradle b/Ghidra/Framework/SoftwareModeling/build.gradle index ea5e731db3..afcc62f929 100644 --- a/Ghidra/Framework/SoftwareModeling/build.gradle +++ b/Ghidra/Framework/SoftwareModeling/build.gradle @@ -23,6 +23,10 @@ dependencies { antlr "org.antlr:antlr:3.5.2" } +// Define classpath needed to execute sleigh compiler during development +// (see gradleScripts/processorUtils.gradle) +ext.sleighDevClasspath = project.sourceSets.main.runtimeClasspath.collect { it.absolutePath }.join(':') + def genSrcDir = 'generated-src/antlr/main' generateGrammarSource { diff --git 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 index a0cf138fdb..8c12ac945a 100644 --- 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 @@ -412,11 +412,39 @@ public class SleighLanguage implements Language { String languageName = specName + ".slaspec"; ResourceFile languageFile = new ResourceFile(slaFile.getParentFile(), languageName); + // see gradleScripts/processorUtils.gradle for sleighArgs.txt generation + ResourceFile sleighArgsFile = null; + ResourceFile languageModule = Application.getModuleContainingResourceFile(languageFile); + if (languageModule != null) { + if (SystemUtilities.isInReleaseMode()) { + sleighArgsFile = new ResourceFile(languageModule, "data/sleighArgs.txt"); + } + else { + sleighArgsFile = new ResourceFile(languageModule, "build/data/sleighArgs.txt"); + } + } + + Map defineMap; + String[] args; + if (sleighArgsFile != null && sleighArgsFile.isFile()) { + args = new String[] { "-i", sleighArgsFile.getAbsolutePath(), + languageFile.getAbsolutePath(), description.getSlaFile().getAbsolutePath() }; + defineMap = new HashMap<>(); + } + else { + args = new String[] { languageFile.getAbsolutePath(), + description.getSlaFile().getAbsolutePath() }; + defineMap = ModuleDefinitionsMap.getModuleMap(); + } + try { - int returnCode = SleighCompileLauncher.runMain( - new String[] { languageFile.getAbsolutePath(), - description.getSlaFile().getAbsolutePath() }, - ModuleDefinitionsMap.getModuleMap()); + StringBuilder buf = new StringBuilder(); + for (String str : args) { + buf.append(str); + buf.append(" "); + } + Msg.debug(this, "Sleigh compile: " + buf); + int returnCode = SleighCompileLauncher.runMain(args, defineMap); if (returnCode != 0) { throw new SleighException("Errors compiling " + languageFile.getAbsolutePath() + " -- please check log messages for details"); diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/SleighCompile.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/SleighCompile.java index cd3f56fad9..895c894be6 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/SleighCompile.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/SleighCompile.java @@ -963,10 +963,9 @@ public class SleighCompile extends SleighBase { continue; } if (firstContextField != null && sym.getId() == firstContextField) { - reportError(location, - sym.getName() + - " cannot be used to attach variables because it occurs at the lowest bit position in context at " + - sym.getLocation()); + reportError(location, sym.getName() + + " cannot be used to attach variables because it occurs at the lowest bit position in context at " + + sym.getLocation()); continue; } PatternValue patval = sym.getPatternValue(); @@ -1569,7 +1568,9 @@ public class SleighCompile extends SleighBase { } /** - * Run the sleigh compiler. + * Run the sleigh compiler. This provides a direct means of invoking the + * compiler without using the launcher. The full SoftwareModeling classpath + * must be established including any dependencies. * @param args compiler command line arguments * @throws JDOMException * @throws IOException @@ -1578,5 +1579,4 @@ public class SleighCompile extends SleighBase { public static void main(String[] args) throws JDOMException, IOException, RecognitionException { System.exit(SleighCompileLauncher.runMain(args, new HashMap())); } - } diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/SleighCompileLauncher.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/SleighCompileLauncher.java index 299ffdc938..c678b37ef7 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/SleighCompileLauncher.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/SleighCompileLauncher.java @@ -21,17 +21,18 @@ import java.util.Map.Entry; import org.antlr.runtime.*; import org.antlr.runtime.tree.CommonTreeNodeStream; -import org.jdom.*; -import org.jdom.input.SAXBuilder; +import org.jdom.JDOMException; +import generic.jar.ResourceFile; import generic.stl.IteratorSTL; import ghidra.GhidraApplicationLayout; import ghidra.GhidraLaunchable; +import ghidra.framework.Application; +import ghidra.framework.ApplicationConfiguration; import ghidra.pcodeCPort.context.SleighError; -import ghidra.pcodeCPort.translate.XmlError; import ghidra.sleigh.grammar.*; import ghidra.util.Msg; -import ghidra.util.xml.XmlUtilities; +import ghidra.util.SystemUtilities; import utilities.util.FileResolutionResult; import utilities.util.FileUtilities; @@ -63,6 +64,11 @@ public class SleighCompileLauncher implements GhidraLaunchable { @Override public void launch(GhidraApplicationLayout layout, String[] args) throws JDOMException, IOException, RecognitionException { + + // Initialize the application + ApplicationConfiguration configuration = new ApplicationConfiguration(); + Application.initializeApplication(layout, configuration); + System.exit(runMain(args, new HashMap())); } @@ -87,17 +93,24 @@ public class SleighCompileLauncher implements GhidraLaunchable { if (args.length < 1) { // @formatter:off - Msg.info(SleighCompile.class, "USAGE: sleigh [-x] [-dNAME=VALUE] inputfile outputfile"); - Msg.info(SleighCompile.class, " -x turns on parser debugging"); - Msg.info(SleighCompile.class, " -u print warnings for unnecessary pcode instructions"); - Msg.info(SleighCompile.class, " -l report pattern conflicts"); - Msg.info(SleighCompile.class, " -n print warnings for all NOP constructors"); - Msg.info(SleighCompile.class, " -t print warnings for dead temporaries"); - Msg.info(SleighCompile.class, " -e enforce use of 'local' keyword for temporaries"); - Msg.info(SleighCompile.class, " -f print warnings for unused token fields"); - Msg.info(SleighCompile.class, " -DNAME=VALUE defines a preprocessor macro NAME with value VALUE"); - Msg.info(SleighCompile.class, " OR sleigh -a directory-root"); - Msg.info(SleighCompile.class, " compiles all .slaspec files to .sla files anywhere under directory-root"); + Msg.info(SleighCompile.class, "Usage: sleigh [options...] [ [] | -a ]"); + Msg.info(SleighCompile.class, " sleigh [options...] []"); + Msg.info(SleighCompile.class, " source slaspec file to be compiled"); + Msg.info(SleighCompile.class, " optional output sla file (infile.sla assumed)"); + Msg.info(SleighCompile.class, " or"); + Msg.info(SleighCompile.class, " sleigh [options...] -a "); + Msg.info(SleighCompile.class, " directory to have all slaspec files compiled"); + Msg.info(SleighCompile.class, " options:"); + Msg.info(SleighCompile.class, " -x turns on parser debugging"); + Msg.info(SleighCompile.class, " -u print warnings for unnecessary pcode instructions"); + Msg.info(SleighCompile.class, " -l report pattern conflicts"); + Msg.info(SleighCompile.class, " -n print warnings for all NOP constructors"); + Msg.info(SleighCompile.class, " -t print warnings for dead temporaries"); + Msg.info(SleighCompile.class, " -e enforce use of 'local' keyword for temporaries"); + Msg.info(SleighCompile.class, " -f print warnings for unused token fields"); + Msg.info(SleighCompile.class, " -DNAME=VALUE defines a preprocessor macro NAME with value VALUE (option may be repeated)"); + Msg.info(SleighCompile.class, " -dMODULE defines a preprocessor macro MODULE with a value of its module path (option may be repeated)"); + Msg.info(SleighCompile.class, " -i inject options from specified file"); // @formatter:on return 2; } @@ -114,6 +127,13 @@ public class SleighCompileLauncher implements GhidraLaunchable { if (args[i].charAt(0) != '-') { break; } + else if (args[i].charAt(1) == 'i') { + // inject options from file specified by next argument + args = injectOptionsFromFile(args, ++i); + if (args == null) { + return 1; + } + } else if (args[i].charAt(1) == 'D') { String preproc = args[i].substring(2); int pos = preproc.indexOf('='); @@ -125,6 +145,18 @@ public class SleighCompileLauncher implements GhidraLaunchable { String value = preproc.substring(pos + 1); preprocs.put(name, value); // Preprocessor macro definitions } + else if (args[i].charAt(1) == 'd') { + String moduleName = args[i].substring(2); + ResourceFile module = Application.getModuleRootDir(moduleName); + if (module == null || !module.isDirectory()) { + Msg.error(SleighCompile.class, + "Failed to resolve module reference: " + args[i]); + return 1; + } + Msg.debug(SleighCompile.class, + "Sleigh resolved module: " + moduleName + "=" + module.getAbsolutePath()); + preprocs.put(moduleName, module.getAbsolutePath()); // Preprocessor macro definitions + } else if (args[i].charAt(1) == 'u') { unnecessaryPcodeWarning = true; } @@ -155,7 +187,16 @@ public class SleighCompileLauncher implements GhidraLaunchable { } } + if (i < args.length - 2) { + Msg.error(SleighCompile.class, "Too many parameters"); + return 1; + } + if (allMode) { + if (i == args.length) { + Msg.error(SleighCompile.class, "Missing input directory path"); + return 1; + } String directory = args[i]; File dir = new File(directory); if (!dir.exists() || !dir.isDirectory()) { @@ -195,6 +236,7 @@ public class SleighCompileLauncher implements GhidraLaunchable { return -totalFailures; } + // single file compile SleighCompile compiler = new SleighCompile(); initCompiler(compiler, preprocs, unnecessaryPcodeWarning, lenientConflict, allNopWarning, deadTempWarning, unusedFieldWarning, enforceLocalKeyWord); @@ -202,60 +244,71 @@ public class SleighCompileLauncher implements GhidraLaunchable { Msg.error(SleighCompile.class, "Missing input file name"); return 1; } - if (i < args.length - 2) { - Msg.error(SleighCompile.class, "Too many parameters"); - return 1; - } filein = args[i]; if (i < args.length - 1) { fileout = args[i + 1]; } - String fileinExamine = filein; - int extInPos = fileinExamine.indexOf(FILE_IN_DEFAULT_EXT); - boolean autoExtInSet = false; - String fileinPreExt = ""; - if (extInPos == -1) {// No Extension Given... - // cout << "No Ext Given" << endl; - fileinPreExt = fileinExamine; - fileinExamine += FILE_IN_DEFAULT_EXT; - filein = fileinExamine; - // cout << "filein = " << filein << endl; - autoExtInSet = true; + String baseName = filein; + if (filein.toLowerCase().endsWith(FILE_IN_DEFAULT_EXT)) { + baseName = filein.substring(0, filein.length() - FILE_IN_DEFAULT_EXT.length()); } - else { - fileinPreExt = fileinExamine.substring(0, extInPos); - } - // cout << "fileinPreExt = " << fileinPreExt << endl; + filein = baseName + FILE_IN_DEFAULT_EXT; - if (fileout != null) { - String fileoutExamine = fileout; - int extOutPos = fileoutExamine.indexOf(FILE_OUT_DEFAULT_EXT); - if (extOutPos == -1) {// No Extension Given... - // cout << "No Ext Given" << endl; - fileoutExamine += FILE_OUT_DEFAULT_EXT; - fileout = fileoutExamine; - // cout << "fileout = " << fileout << endl; - } - retval = run_compilation(filein, fileout, compiler); + String baseOutName = fileout; + if (fileout == null) { + baseOutName = baseName; } - else { - // First determine whether or not to use Run_XML... - if (autoExtInSet) {// Assumed format of at least "sleigh file" . - // "sleigh file.slaspec file.sla" - String fileoutSTR = fileinPreExt; - fileoutSTR += FILE_OUT_DEFAULT_EXT; - fileout = fileoutSTR; - // cout << "generated fileout = " << fileout << endl; - retval = run_compilation(filein, fileout, compiler); - } - else { - retval = run_xml(filein, compiler); - } + else if (fileout.toLowerCase().endsWith(FILE_OUT_DEFAULT_EXT)) { + baseOutName = fileout.substring(0, fileout.length() - FILE_OUT_DEFAULT_EXT.length()); + } + fileout = baseOutName + FILE_OUT_DEFAULT_EXT; + return run_compilation(filein, fileout, compiler); + } + + private static String[] injectOptionsFromFile(String[] args, int index) { + if (index >= args.length) { + Msg.error(SleighCompile.class, "Missing options input file name"); + return null; } - return retval; + + File optionsFile = new File(args[index]); + if (!optionsFile.isFile()) { + Msg.error(SleighCompile.class, + "Options file not found: " + optionsFile.getAbsolutePath()); + if (SystemUtilities.isInDevelopmentMode()) { + Msg.error(SleighCompile.class, + "Eclipse language module must be selected and 'gradle prepdev' prevously run"); + } + return null; + } + ArrayList list = new ArrayList<>(); + for (int i = 0; i <= index; i++) { + list.add(args[i]); + } + + try (BufferedReader r = new BufferedReader(new FileReader(optionsFile))) { + String option = r.readLine(); + while (option != null) { + option = option.trim(); + if (option.length() != 0 && !option.startsWith("#")) { + list.add(option); + } + option = r.readLine(); + } + } + catch (IOException e) { + Msg.error(SleighCompile.class, + "Reading options file failed (" + optionsFile.getName() + "): " + e.getMessage()); + return null; + } + + for (int i = index + 1; i < args.length; i++) { + list.add(args[i]); + } + return list.toArray(new String[list.size()]); } private static int run_compilation(String filein, String fileout, SleighCompile compiler) @@ -384,64 +437,4 @@ public class SleighCompileLauncher implements GhidraLaunchable { return 0; } - private static int run_xml(String filein, SleighCompile compiler) - throws JDOMException, IOException, RecognitionException { - FileInputStream s = new FileInputStream(new File(filein)); - Document doc = null; - String specfileout = ""; - String specfilein = ""; - - try { - SAXBuilder builder = XmlUtilities.createSecureSAXBuilder(false, false); - doc = builder.build(s); - } - catch (XmlError err) { - Msg.error(SleighCompile.class, - "Unable to parse single input file as XML spec: " + filein, err); - return 1; - } - s.close(); - - Element el = doc.getRootElement(); - for (;;) { - List list = el.getChildren(); - Iterator iter = list.iterator(); - while (iter.hasNext()) { - el = (Element) iter.next(); - if (el.getName().equals("processorfile")) { - specfileout = el.getText(); - List atts = el.getAttributes(); - Iterator i = atts.iterator(); - while (i.hasNext()) { - Attribute att = (Attribute) i.next(); - if (att.getName().equals("slaspec")) { - specfilein = att.getValue(); - } - else { - compiler.setPreprocValue(att.getName(), att.getValue()); - } - } - } - else if (el.getName().equals("language_spec")) { - break; - } - else if (el.getName().equals("language_description")) { - break; - } - } - if (!iter.hasNext()) { - break; - } - } - - if (specfilein.length() == 0) { - Msg.error(SleighCompile.class, "Input slaspec file was not specified in " + filein); - return 1; - } - if (specfileout.length() == 0) { - Msg.error(SleighCompile.class, "Output sla file was not specified in " + filein); - return 1; - } - return run_compilation(specfilein, specfileout, compiler); - } } diff --git a/Ghidra/Processors/6502/data/build.xml b/Ghidra/Processors/6502/data/build.xml deleted file mode 100644 index 8f72019712..0000000000 --- a/Ghidra/Processors/6502/data/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/68000/data/build.xml b/Ghidra/Processors/68000/data/build.xml deleted file mode 100644 index 8f72019712..0000000000 --- a/Ghidra/Processors/68000/data/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/6805/data/build.xml b/Ghidra/Processors/6805/data/build.xml deleted file mode 100644 index 8f72019712..0000000000 --- a/Ghidra/Processors/6805/data/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/8051/data/build.xml b/Ghidra/Processors/8051/data/build.xml deleted file mode 100644 index 8f72019712..0000000000 --- a/Ghidra/Processors/8051/data/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/8085/data/build.xml b/Ghidra/Processors/8085/data/build.xml deleted file mode 100644 index 2164d961ae..0000000000 --- a/Ghidra/Processors/8085/data/build.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/AARCH64/data/build.xml b/Ghidra/Processors/AARCH64/data/build.xml deleted file mode 100644 index 7c1d69306c..0000000000 --- a/Ghidra/Processors/AARCH64/data/build.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/ARM/data/build.xml b/Ghidra/Processors/ARM/data/build.xml deleted file mode 100644 index 8f72019712..0000000000 --- a/Ghidra/Processors/ARM/data/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/Atmel/data/build.xml b/Ghidra/Processors/Atmel/data/build.xml deleted file mode 100644 index 8f72019712..0000000000 --- a/Ghidra/Processors/Atmel/data/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/CR16/data/build.xml b/Ghidra/Processors/CR16/data/build.xml deleted file mode 100644 index 8f72019712..0000000000 --- a/Ghidra/Processors/CR16/data/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/DATA/data/build.xml b/Ghidra/Processors/DATA/data/build.xml deleted file mode 100644 index 8f72019712..0000000000 --- a/Ghidra/Processors/DATA/data/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/JVM/data/build.xml b/Ghidra/Processors/JVM/data/build.xml deleted file mode 100644 index 8f72019712..0000000000 --- a/Ghidra/Processors/JVM/data/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/MIPS/data/build.xml b/Ghidra/Processors/MIPS/data/build.xml deleted file mode 100644 index a6301d23ca..0000000000 --- a/Ghidra/Processors/MIPS/data/build.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/PA-RISC/data/build.xml b/Ghidra/Processors/PA-RISC/data/build.xml deleted file mode 100644 index 8f72019712..0000000000 --- a/Ghidra/Processors/PA-RISC/data/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/PIC/data/build.xml b/Ghidra/Processors/PIC/data/build.xml deleted file mode 100644 index 8f72019712..0000000000 --- a/Ghidra/Processors/PIC/data/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/PowerPC/data/build.xml b/Ghidra/Processors/PowerPC/data/build.xml deleted file mode 100644 index 8f72019712..0000000000 --- a/Ghidra/Processors/PowerPC/data/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/Sparc/data/build.xml b/Ghidra/Processors/Sparc/data/build.xml deleted file mode 100644 index 8f72019712..0000000000 --- a/Ghidra/Processors/Sparc/data/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/TI_MSP430/data/build.xml b/Ghidra/Processors/TI_MSP430/data/build.xml deleted file mode 100644 index 8f72019712..0000000000 --- a/Ghidra/Processors/TI_MSP430/data/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/Toy/data/build.xml b/Ghidra/Processors/Toy/data/build.xml deleted file mode 100644 index 8f72019712..0000000000 --- a/Ghidra/Processors/Toy/data/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/Z80/data/build.xml b/Ghidra/Processors/Z80/data/build.xml deleted file mode 100644 index 8f72019712..0000000000 --- a/Ghidra/Processors/Z80/data/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ghidra/Processors/x86/data/build.xml b/Ghidra/Processors/x86/data/build.xml deleted file mode 100644 index b80b6d91fa..0000000000 --- a/Ghidra/Processors/x86/data/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/GhidraBuild/BuildFiles/certification.manifest b/GhidraBuild/BuildFiles/certification.manifest index 40d82f7a77..95930675a6 100644 --- a/GhidraBuild/BuildFiles/certification.manifest +++ b/GhidraBuild/BuildFiles/certification.manifest @@ -6,3 +6,5 @@ JsonDoclet/.project||GHIDRA||||END| JsonDoclet/Module.manifest||GHIDRA||||END| JsonDoclet/build.gradle||GHIDRA||||END| build.gradle||GHIDRA||||END| +sleighDevBuild.template||GHIDRA||||END| +sleighDistBuild.template||GHIDRA||||END| diff --git a/GhidraBuild/BuildFiles/sleighDevBuild.template b/GhidraBuild/BuildFiles/sleighDevBuild.template new file mode 100644 index 0000000000..d81928bd61 --- /dev/null +++ b/GhidraBuild/BuildFiles/sleighDevBuild.template @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GhidraBuild/BuildFiles/sleighDistBuild.template b/GhidraBuild/BuildFiles/sleighDistBuild.template new file mode 100644 index 0000000000..ec9976b7c3 --- /dev/null +++ b/GhidraBuild/BuildFiles/sleighDistBuild.template @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GhidraBuild/Skeleton/certification.manifest b/GhidraBuild/Skeleton/certification.manifest index 25a6ffeb28..89c984df68 100644 --- a/GhidraBuild/Skeleton/certification.manifest +++ b/GhidraBuild/Skeleton/certification.manifest @@ -12,6 +12,7 @@ data/languages/skel.opinion||GHIDRA||||END| data/languages/skel.pspec||GHIDRA||||END| data/languages/skel.sinc||GHIDRA||||END| data/languages/skel.slaspec||GHIDRA||||END| +data/sleighArgs.txt||GHIDRA||||END| extension.properties||GHIDRA||||END| ghidra_scripts/README.txt||GHIDRA||||END| lib/README.txt||GHIDRA||||END| diff --git a/GhidraBuild/Skeleton/data/build.xml b/GhidraBuild/Skeleton/data/build.xml deleted file mode 100644 index b83278c5e4..0000000000 --- a/GhidraBuild/Skeleton/data/build.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/GhidraBuild/Skeleton/data/sleighArgs.txt b/GhidraBuild/Skeleton/data/sleighArgs.txt new file mode 100644 index 0000000000..ce06926358 --- /dev/null +++ b/GhidraBuild/Skeleton/data/sleighArgs.txt @@ -0,0 +1,6 @@ +# Add sleigh compiler options to this file (one per line) which will +# be used when compiling each language within this module. +# All options should start with a '-' character. +# +# IMPORTANT: The -a option should NOT be specified +# \ No newline at end of file diff --git a/gradleScripts/distribution.gradle b/gradleScripts/distribution.gradle index 69df51a986..7aaf03b2f4 100644 --- a/gradleScripts/distribution.gradle +++ b/gradleScripts/distribution.gradle @@ -223,6 +223,7 @@ task assembleCommon (type: Copy) { from (p.projectDir.toString() + "/data") { into { getZipPath(p) + "/data" } + exclude 'build.xml' // associated with language modules (dev use only) } from (BIN_REPO + '/' + getZipPath(p) + "/data") { @@ -697,6 +698,7 @@ subprojects { p -> exclude 'bin/**' exclude 'src/**' exclude 'test/**' + exclude 'data/build.xml' exclude 'developer_scripts' // general place where extension modules can put files that won't get diff --git a/gradleScripts/ip.gradle b/gradleScripts/ip.gradle index 16b0c91b08..18a778c275 100644 --- a/gradleScripts/ip.gradle +++ b/gradleScripts/ip.gradle @@ -120,6 +120,7 @@ def Map> getIpForModule(Project p) { exclude "build.gradle" exclude "**/Misc/Tips.htm" exclude "**/*.sla" + exclude "**/data/build.xml" // language build file (generated for dev only) exclude "**/.gradle/**" exclude "**/.settings/**" exclude "**/.vs/**" diff --git a/gradleScripts/processorUtils.gradle b/gradleScripts/processorUtils.gradle index 99bb843875..7d83c68ccc 100644 --- a/gradleScripts/processorUtils.gradle +++ b/gradleScripts/processorUtils.gradle @@ -1,4 +1,3 @@ - /***************************************************************************************** * * Create a configuration so the a dependency can be declared on the the software modeling @@ -14,6 +13,64 @@ dependencies { sleighConfig project(':SoftwareModeling') } +/***************************************************************************************** + * + * Task to write sleigh compiler args to build/data/sleighArgs.txt for use with sleigh + * external sleigh compiler. + * + *****************************************************************************************/ +task saveSleighArgs { + def sleighArgsFile = file("build/data/sleighArgs.txt") + outputs.files sleighArgsFile + outputs.upToDateWhen { false } + doLast { + sleighArgsFile.withWriter { out-> + project.sleighCompile.args.each { a-> + // don't save -a option + if (!"-a".equals(a)) { + out.println a + } + } + } + } +} + +prepDev.dependsOn(saveSleighArgs) + +/***************************************************************************************** + * + * Task to write sleigh build.xml file for use is development mode only. + * + *****************************************************************************************/ +task writeSleighDevBuild { + def templateFilePath = project(':BuildFiles').projectDir.toString() + "/sleighDevBuild.template" + doLast { + // Generate build.xml with injected classpath for running sleigh compiler + copy { + into "data" + from (templateFilePath) { + rename { "build.xml" } + expand ( [ 'gradleSleighDevClasspath': project(':SoftwareModeling').sleighDevClasspath ] ) + } + } + } +} + +prepDev.dependsOn(writeSleighDevBuild) + +/***************************************************************************************** + * + * Write sleigh build.xml file for each language module into assembleCommon + * + *****************************************************************************************/ +rootProject.assembleCommon { + into (getZipPath(this.project) + "/data") { + from (rootProject.projectDir.toString() + "/GhidraBuild/BuildFiles/sleighDistBuild.template") { + rename { "build.xml" } + } + } +} + /***************************************************************************************** * * Task to compile language files using the sleigh compiler. @@ -22,17 +79,16 @@ dependencies { task sleighCompile (type: JavaExec) { group = rootProject.GHIDRA_GROUP description " Compiles all the sleigh languages. [processorUtils.gradle]\n" - + // define standard parameters for JavaExec classpath configurations.sleighConfig main = 'ghidra.pcodeCPort.slgh_compile.SleighCompile' - args '-a' - // Delay adding the directory argument until the first part of the execution phase, so // that any extra args added by a project override will be added to the arg list before - // this argument. + // these arguments. doFirst { + args '-a' args './data/languages' } @@ -40,8 +96,9 @@ task sleighCompile (type: JavaExec) { } // The task that copies the common files to the distribution folder must depend on -// this sleigh task before executing. +// the sleigh tasks before executing. rootProject.assembleCommon.dependsOn(sleighCompile) +rootProject.assembleCommon.dependsOn(saveSleighArgs) // For all tasks of type:Test (i.e., integrationTest, cunitTest, etc.), add a task dependency to // sleighCompile. The sleighCompile task inputs and outputs are defined such that the *.slaspec @@ -52,8 +109,9 @@ rootProject.assembleCommon.dependsOn(sleighCompile) // modules as seen in the use of ghidra.test.ToyProgramBuilder. // The tasks of type:Test do not know about sleighCompile during their configuration phase, so the // dependency must be done in this gradle file. -rootProject.subprojects.findAll { subproject -> - if (!isSupportModule(subproject)) { +rootProject.subprojects.findAll { subproject -> + boolean isSupporProject = subproject.findProperty("isSupportProject") ?: false; + if (!isSupporProject) { subproject.tasks.withType(Test).all { it.dependsOn(sleighCompile) } @@ -91,26 +149,9 @@ def taskOutputs = fileTree(dir: 'data/languages', include: '**/*.sla') sleighCompile.inputs.files (taskInputs) sleighCompile.outputs.files (taskOutputs) -task eclipseSleighLauncher(type: WriteEclipseLauncher) { - dest = forName("Sleigh $project.name") - isRunFave = true - isDbgFave = false - - classpath = configurations.sleighConfig - main 'ghidra.pcodeCPort.slgh_compile.SleighCompile' - - args '-a' - - // Delay adding the directory argument until the first part of the execution phase, so - // that any extra args added by a project override will be added to the arg list before - // this argument. - doFirst { - args './data/languages' - } - - jvmArgs '-Xmx2048M' -} +// define the sleigh compile inputs to saveSleighArgs to limit task creation to language modules +saveSleighArgs.inputs.files (taskInputs) def isSupportModule(Project p) { return p.findProperty("isSupportProject") ?: false -} \ No newline at end of file +}