From d05a57ae1a90ae11a9f196dbcd48c74ff7252b34 Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Fri, 22 Oct 2021 13:14:17 -0400 Subject: [PATCH] Removal of old deprecated methods --- .../DBTraceProgramViewSymbolTable.java | 32 ---- .../PropagateExternalParametersScript.java | 20 ++- .../program/flatapi/FlatProgramAPI.java | 122 ++++++++------- .../datamgr/DataTypeManagerPluginTest.java | 43 +----- .../component/DecompilerHighlightService.java | 37 ----- .../core/decompile/DecompilePlugin.java | 21 +-- .../core/decompile/DecompilerProvider.java | 16 +- .../ghidra_scripts/VxWorksSymTab_5_4.java | 26 +++- .../ghidra_scripts/VxWorksSymTab_6_1.java | 22 ++- .../ghidra_scripts/VxWorksSymTab_Finder.java | 18 ++- .../java/ghidra/app/util/NamespaceUtils.java | 30 +--- .../database/symbol/SymbolManager.java | 73 +++------ .../ghidra/program/model/listing/Data.java | 130 +++++++++------- .../ghidra/program/model/symbol/RefType.java | 23 +-- .../program/model/symbol/RefTypeFactory.java | 33 ++-- .../program/model/symbol/SymbolTable.java | 141 ++++++------------ 16 files changed, 287 insertions(+), 500 deletions(-) delete mode 100644 Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerHighlightService.java diff --git a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewSymbolTable.java b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewSymbolTable.java index 0720a58ba0..88be90a743 100644 --- a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewSymbolTable.java +++ b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewSymbolTable.java @@ -87,12 +87,6 @@ public class DBTraceProgramViewSymbolTable implements SymbolTable { return symbolManager.labels().create(program.snap, null, addr, name, global, source); } - @Override - public Symbol createSymbol(Address addr, String name, SourceType source) - throws InvalidInputException { - return createLabel(addr, name, source); - } - @Override public Symbol createLabel(Address addr, String name, Namespace namespace, SourceType source) throws InvalidInputException { @@ -101,12 +95,6 @@ public class DBTraceProgramViewSymbolTable implements SymbolTable { assertTraceNamespace(namespace), source); } - @Override - public Symbol createSymbol(Address addr, String name, Namespace namespace, SourceType source) - throws DuplicateNameException, InvalidInputException { - return createLabel(addr, name, namespace, source); - } - @Override public boolean removeSymbolSpecial(Symbol sym) { // TODO: I'm not sure I understand the point of this method... @@ -196,26 +184,6 @@ public class DBTraceProgramViewSymbolTable implements SymbolTable { return getSymbol(name, addr, global); } - @Override - public Symbol getSymbol(String name, Namespace namespace) { - try (LockHold hold = program.trace.lockRead()) { - for (TraceSymbol sym : symbolManager.allSymbols() - .getChildrenNamed(name, - assertTraceNamespace(namespace))) { - if (requireVisible(sym) == null) { - continue; - } - return sym; - } - return null; - } - } - - @Override - public Symbol getSymbol(String name) { - return getSymbol(name, global); - } - @Override public List getSymbols(String name, Namespace namespace) { TraceNamespaceSymbol parent = assertTraceNamespace(namespace); diff --git a/Ghidra/Features/Base/ghidra_scripts/PropagateExternalParametersScript.java b/Ghidra/Features/Base/ghidra_scripts/PropagateExternalParametersScript.java index 098e6afdf4..1eecf5918e 100644 --- a/Ghidra/Features/Base/ghidra_scripts/PropagateExternalParametersScript.java +++ b/Ghidra/Features/Base/ghidra_scripts/PropagateExternalParametersScript.java @@ -56,7 +56,7 @@ public class PropagateExternalParametersScript extends GhidraScript { } } - // use the 'results' to propagate param info to the local variables, data, and params of + // use the 'results' to propagate param info to the local variables, data, and params of // the calling function //println("Processing propagation results - count: " + results.size()); for (int i = 0; i < results.size(); i++) { @@ -68,7 +68,7 @@ public class PropagateExternalParametersScript extends GhidraScript { continue; } - //If operand of pushed parameter points to data make a symbol and comment at that location + //If operand of pushed parameter points to data make a symbol and comment at that location if (((opType & OperandType.ADDRESS) != 0) && (((opType & OperandType.DATA) != 0)) || ((opType & OperandType.SCALAR) != 0) || ((opType & OperandType.DYNAMIC) != 0)) { Reference[] refs = listing.getCodeUnitAt(ppi.getAddress()).getOperandReferences(0); @@ -88,7 +88,9 @@ public class PropagateExternalParametersScript extends GhidraScript { String newComment = new String( ppi.getName() + " parameter of " + ppi.getCalledFunctionName() + "\n"); - if ((getSymbol(symbolName, null) == null) && (isString == false)) { + List symbols = getSymbols(symbolName, null); + + if (symbols.isEmpty() && !isString) { createLabel(dataAddress, symbolName, true, SourceType.USER_DEFINED); } @@ -101,8 +103,10 @@ public class PropagateExternalParametersScript extends GhidraScript { } if ((data != null) && - (listing.getCodeUnitAt(dataAddress).getMnemonicString().startsWith( - "undefined"))) { + (listing.getCodeUnitAt(dataAddress) + .getMnemonicString() + .startsWith( + "undefined"))) { clearListing(dataAddress); } if (listing.isUndefined(dataAddress, dataAddress.add(dt.getLength() - 1))) { @@ -182,7 +186,7 @@ public class PropagateExternalParametersScript extends GhidraScript { * PUSH arg 2 to call func2 | * PUSH arg 1 to call func2 | -- want to bypass these * CALL func2 ___| - * PUSH arg 2 to call func1 ; put arg2 of func1 here + * PUSH arg 2 to call func1 ; put arg2 of func1 here * PUSH arg 1 to call func1 ; put arg1 of func1 here * CALL func1 */ @@ -272,7 +276,7 @@ public class PropagateExternalParametersScript extends GhidraScript { // need to take into account calls between the pushes and skip the pushes for those calls // skip pushes that are used for another call - // if label, then probably a branch, allow current push to be commented and + // if label, then probably a branch, allow current push to be commented and // next time through stop // can also be a branch if not label there but this case should still have parameters set // before it as long as not an unconditional jump - this wouldn't make sense so it shouldn't happen @@ -292,7 +296,7 @@ public class PropagateExternalParametersScript extends GhidraScript { else { setEOLComment(cu.getMinAddress(), params[index].getDataType().getDisplayName() + " " + params[index].getName() + " for " + extFuncName); - // add the following to the EOL comment to see the value of the optype + // add the following to the EOL comment to see the value of the optype // +" " + toHexString(currentProgram.getListing().getInstructionAt(cu.getMinAddress()).getOperandType(0), false, true) addResult(params[index].getName(), params[index].getDataType(), cu.getMinAddress(), extFuncName); diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/flatapi/FlatProgramAPI.java b/Ghidra/Features/Base/src/main/java/ghidra/program/flatapi/FlatProgramAPI.java index c178e39a09..33933b397e 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/program/flatapi/FlatProgramAPI.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/program/flatapi/FlatProgramAPI.java @@ -56,16 +56,14 @@ import ghidra.util.task.TaskMonitor; *

* NOTE: *

    - *
  1. NO METHODS SHOULD EVER BE REMOVED FROM THIS CLASS. - *
  2. NO METHOD SIGNATURES SHOULD EVER BE CHANGED IN THIS CLASS. + *
  3. NO METHODS *SHOULD* EVER BE REMOVED FROM THIS CLASS. + *
  4. NO METHOD SIGNATURES *SHOULD* EVER BE CHANGED IN THIS CLASS. *
*

* This class is used by GhidraScript. *

* Changing this class will break user scripts. *

- * That is bad. Don't do that. - *

*/ public class FlatProgramAPI { public static final int MAX_REFERENCES_TO = 0x1000; @@ -239,7 +237,7 @@ public class FlatProgramAPI { /** * Clears the code unit (instruction or data) defined at the address. * @param address the address to clear the code unit - * @throws CancelledException + * @throws CancelledException if cancelled */ public final void clearListing(Address address) throws CancelledException { clearListing(address, address); @@ -249,7 +247,7 @@ public class FlatProgramAPI { * Clears the code units (instructions or data) in the specified range. * @param start the start address * @param end the end address - * @throws CancelledException + * @throws CancelledException if cancelled */ public final void clearListing(Address start, Address end) throws CancelledException { currentProgram.getListing().clearCodeUnits(start, end, false, monitor); @@ -258,7 +256,7 @@ public class FlatProgramAPI { /** * Clears the code units (instructions or data) in the specified set * @param set the set to clear - * @throws CancelledException + * @throws CancelledException if cancelled */ public final void clearListing(AddressSetView set) throws CancelledException { AddressRangeIterator iter = set.getAddressRanges(); @@ -320,6 +318,7 @@ public class FlatProgramAPI { * @param length the size of the block * @param overlay true will create an overlay, false will not * @return the newly created memory block + * @throws Exception if there is any exception */ public final MemoryBlock createMemoryBlock(String name, Address start, InputStream input, long length, boolean overlay) throws Exception { @@ -340,6 +339,7 @@ public class FlatProgramAPI { * @param bytes the bytes of the memory block * @param overlay true will create an overlay, false will not * @return the newly created memory block + * @throws Exception if there is any exception */ public final MemoryBlock createMemoryBlock(String name, Address start, byte[] bytes, boolean overlay) throws Exception { @@ -384,6 +384,7 @@ public class FlatProgramAPI { * NOTE: ALL ANNOTATION (disassembly, comments, etc) defined in this * memory block will also be removed! * @param block the block to be removed + * @throws Exception if there is any exception */ public final void removeMemoryBlock(MemoryBlock block) throws Exception { currentProgram.getMemory().removeBlock(block, monitor); @@ -396,6 +397,7 @@ public class FlatProgramAPI { * @param name the name of the symbol * @param makePrimary true if the symbol should be made primary * @return the newly created code or function symbol + * @throws Exception if there is any exception */ public final Symbol createLabel(Address address, String name, boolean makePrimary) throws Exception { @@ -422,6 +424,7 @@ public class FlatProgramAPI { * @param makePrimary true if the symbol should be made primary * @param sourceType the source type. * @return the newly created code or function symbol + * @throws Exception if there is any exception */ public final Symbol createLabel(Address address, String name, boolean makePrimary, SourceType sourceType) throws Exception { @@ -439,6 +442,7 @@ public class FlatProgramAPI { * @param makePrimary true if the symbol should be made primary * @param sourceType the source type. * @return the newly created code or function symbol + * @throws Exception if there is any exception */ public final Symbol createLabel(Address address, String name, Namespace namespace, boolean makePrimary, SourceType sourceType) throws Exception { @@ -936,13 +940,16 @@ public class FlatProgramAPI { * Search for sequences of Ascii strings in program memory. See {@link AsciiCharSetRecognizer} * to see exactly what chars are considered ASCII for purposes of this search. * @param addressSet The address set to search. Use null to search all memory; - * @param minimumStringLength The smallest number of chars in a sequence to be considered a "string". - * @param alignment specifies any alignment requirements for the start of the string. An alignment - * of 1, means the string can start at any address. An alignment of 2 means the string must - * start on an even address and so on. Only allowed values are 1,2, and 4. + * @param minimumStringLength The smallest number of chars in a sequence to be considered a + * "string". + * @param alignment specifies any alignment requirements for the start of the string. An + * alignment of 1, means the string can start at any address. An alignment of 2 means the + * string must start on an even address and so on. Only allowed values are 1,2, and 4. * @param requireNullTermination If true, only strings that end in a null will be returned. - * @param includeAllCharWidths if true, UTF16 and UTF32 size strings will be included in addition to UTF8. - * @return a list of "FoundString" objects which contain the addresses, length, and type of possible strings. + * @param includeAllCharWidths if true, UTF16 and UTF32 size strings will be included in + * addition to UTF8. + * @return a list of "FoundString" objects which contain the addresses, length, and type of + * possible strings. */ public List findStrings(AddressSetView addressSet, int minimumStringLength, int alignment, boolean requireNullTermination, boolean includeAllCharWidths) { @@ -959,15 +966,18 @@ public class FlatProgramAPI { } /** - * Search for sequences of Pascal Ascii strings in program memory. See {@link AsciiCharSetRecognizer} - * to see exactly what chars are considered ASCII for purposes of this search. + * Search for sequences of Pascal Ascii strings in program memory. See + * {@link AsciiCharSetRecognizer} to see exactly what chars are considered ASCII for purposes + * of this search. * @param addressSet The address set to search. Use null to search all memory; - * @param minimumStringLength The smallest number of chars in a sequence to be considered a "string". - * @param alignment specifies any alignment requirements for the start of the string. An alignment - * of 1, means the string can start at any address. An alignment of 2 means the string must - * start on an even address and so on. Only allowed values are 1,2, and 4. + * @param minimumStringLength The smallest number of chars in a sequence to be considered a + * "string". + * @param alignment specifies any alignment requirements for the start of the string. An + * alignment of 1, means the string can start at any address. An alignment of 2 means the + * string must start on an even address and so on. Only allowed values are 1,2, and 4. * @param includePascalUnicode if true, UTF16 size strings will be included in addition to UTF8. - * @return a list of "FoundString" objects which contain the addresses, length, and type of possible strings. + * @return a list of "FoundString" objects which contain the addresses, length, and type of + * possible strings. */ public List findPascalStrings(AddressSetView addressSet, int minimumStringLength, int alignment, boolean includePascalUnicode) { @@ -1061,7 +1071,7 @@ public class FlatProgramAPI { return null; } Function func = iterator.next(); - // if the function found starts at the start addres, go to the next one. + // if the function found starts at the start address, go to the next one. if (address.equals(func.getEntryPoint())) { func = null; if (iterator.hasNext()) { @@ -1101,7 +1111,7 @@ public class FlatProgramAPI { return null; } Function func = iterator.next(); - // if the function found starts at the start addres, go to the next one. + // if the function found starts at the start address, go to the next one. if (address.equals(func.getEntryPoint())) { func = null; if (iterator.hasNext()) { @@ -1176,6 +1186,7 @@ public class FlatProgramAPI { /** * Returns the first instruction in the function. + * @param function the function * @return the first instruction in the function */ public final Instruction getFirstInstruction(Function function) { @@ -1633,6 +1644,7 @@ public class FlatProgramAPI { * @param address the address at which to create a new Data object. * @param datatype the Data Type that describes the type of Data object to create. * @return the newly created Data object + * @throws Exception if there is any exception */ public final Data createData(Address address, DataType datatype) throws Exception { Listing listing = currentProgram.getListing(); @@ -1650,6 +1662,7 @@ public class FlatProgramAPI { * Creates a byte datatype at the given address. * @param address the address to create the byte * @return the newly created Data object + * @throws Exception if there is any exception */ public final Data createByte(Address address) throws Exception { return createData(address, new ByteDataType()); @@ -1659,6 +1672,7 @@ public class FlatProgramAPI { * Creates a word datatype at the given address. * @param address the address to create the word * @return the newly created Data object + * @throws Exception if there is any exception */ public final Data createWord(Address address) throws Exception { return createData(address, new WordDataType()); @@ -1668,6 +1682,7 @@ public class FlatProgramAPI { * Creates a dword datatype at the given address. * @param address the address to create the dword * @return the newly created Data object + * @throws Exception if there is any exception */ public final Data createDWord(Address address) throws Exception { return createData(address, new DWordDataType()); @@ -1677,6 +1692,7 @@ public class FlatProgramAPI { * Creates a list of dword datatypes starting at the given address. * @param start the start address to create the dwords * @param count the number of dwords to create + * @throws Exception if there is any exception */ public final void createDwords(Address start, int count) throws Exception { for (int i = 0; i < count; ++i) { @@ -1689,6 +1705,7 @@ public class FlatProgramAPI { * Creates a qword datatype at the given address. * @param address the address to create the qword * @return the newly created Data object + * @throws Exception if there is any exception */ public final Data createQWord(Address address) throws Exception { return createData(address, new QWordDataType()); @@ -1698,6 +1715,7 @@ public class FlatProgramAPI { * Creates a float datatype at the given address. * @param address the address to create the float * @return the newly created Data object + * @throws Exception if there is any exception */ public final Data createFloat(Address address) throws Exception { return createData(address, new FloatDataType()); @@ -1707,6 +1725,7 @@ public class FlatProgramAPI { * Creates a double datatype at the given address. * @param address the address to create the double * @return the newly created Data object + * @throws Exception if there is any exception */ public final Data createDouble(Address address) throws Exception { return createData(address, new DoubleDataType()); @@ -1716,6 +1735,7 @@ public class FlatProgramAPI { * Creates a char datatype at the given address. * @param address the address to create the char * @return the newly created Data object + * @throws Exception if there is any exception */ public final Data createChar(Address address) throws Exception { return createData(address, new CharDataType()); @@ -1726,6 +1746,7 @@ public class FlatProgramAPI { * at the specified address. * @param address the address to create the string * @return the newly created Data object + * @throws Exception if there is any exception */ public final Data createAsciiString(Address address) throws Exception { return createData(address, new TerminatedStringDataType()); @@ -1733,12 +1754,11 @@ public class FlatProgramAPI { /** * Create an ASCII string at the specified address. - * @param address + * @param address the address * @param length length of string (a value of 0 or negative will force use * of dynamic null terminated string) * @return string data created - * @throws CodeUnitInsertionException - * @throws DataTypeConflictException + * @throws CodeUnitInsertionException if there is a data conflict */ public final Data createAsciiString(Address address, int length) throws CodeUnitInsertionException { @@ -1761,11 +1781,10 @@ public class FlatProgramAPI { } /** - * Creates a null terminated unicode string starting - * at the specified address. + * Creates a null terminated unicode string starting at the specified address. * @param address the address to create the string * @return the newly created Data object - * @throws Exception + * @throws Exception if there is any exception */ public final Data createUnicodeString(Address address) throws Exception { return createData(address, new TerminatedUnicodeDataType()); @@ -1774,6 +1793,7 @@ public class FlatProgramAPI { /** * Removes the given data from the current program. * @param data the data to remove + * @throws Exception if there is any exception */ public final void removeData(Data data) throws Exception { clearListing(data.getMinAddress(), data.getMaxAddress()); @@ -1782,6 +1802,7 @@ public class FlatProgramAPI { /** * Removes the data containing the given address from the current program. * @param address the address to remove data + * @throws Exception if there is any exception */ public final void removeDataAt(Address address) throws Exception { Data data = getDataContaining(address); @@ -1793,6 +1814,7 @@ public class FlatProgramAPI { /** * Removes the given instruction from the current program. * @param instruction the instruction to remove + * @throws Exception if there is any exception */ public final void removeInstruction(Instruction instruction) throws Exception { clearListing(instruction.getMinAddress(), instruction.getMaxAddress()); @@ -1801,6 +1823,7 @@ public class FlatProgramAPI { /** * Removes the instruction containing the given address from the current program. * @param address the address to remove instruction + * @throws Exception if there is any exception */ public final void removeInstructionAt(Address address) throws Exception { Instruction instruction = getInstructionContaining(address); @@ -2259,6 +2282,7 @@ public class FlatProgramAPI { * @param equateName the name of the equate * @return the newly created equate * @throws InvalidInputException if a scalar does not exist on the data + * @throws Exception if there is any exception */ public final Equate createEquate(Data data, String equateName) throws Exception { Object value = data.getValue(); @@ -2273,18 +2297,6 @@ public class FlatProgramAPI { "Unable to create equate on non-scalar value at " + data.getMinAddress()); } - /** - * Returns the equate defined at the operand index of the instruction. - * @param instruction the instruction - * @param operandIndex the operand index - * @return the equate defined at the operand index of the instruction - * @deprecated this form of getEquate is not supported and will throw a UnsupportedOperationException - */ - @Deprecated - public final Equate getEquate(Instruction instruction, int operandIndex) { - throw new UnsupportedOperationException("this form of getEquate is unsupported"); - } - /** * Returns the equate defined at the operand index of the instruction with the given value. * @param instruction the instruction @@ -2325,17 +2337,6 @@ public class FlatProgramAPI { return null; } - /** - * Removes the equate defined at the operand index of the instruction. - * @param instruction the instruction - * @param operandIndex the operand index - * @deprecated this form of getEquate is not supported and will throw a UnsupportedOperationException - */ - @Deprecated - public final void removeEquate(Instruction instruction, int operandIndex) { - throw new UnsupportedOperationException("this form of removeEquate is unsupported"); - } - /** * Removes the equate defined at the operand index of the instruction with the given value. * @param instruction the instruction @@ -2431,6 +2432,8 @@ public class FlatProgramAPI { * Opens a Data Type Archive * @param archiveFile the archive file to open * @param readOnly should file be opened read only + * @return the data type manager + * @throws Exception if there is any exception */ public final FileDataTypeManager openDataTypeArchive(File archiveFile, boolean readOnly) throws Exception { @@ -2445,7 +2448,7 @@ public class FlatProgramAPI { * If a program already exists with the specified * name, then a time stamp will be appended to the name to make it unique. * @param program the program to save - * @throws Exception + * @throws Exception if there is any exception */ public void saveProgram(Program program) throws Exception { saveProgram(program, null); @@ -2460,13 +2463,14 @@ public class FlatProgramAPI { * If path is NULL, the program will be saved into the root folder. If parts of the path are * missing, they will be created if possible. *

- * If a program already exists with the specified name, then a time stamp will be appended + * If a program already exists with the specified name, then a time stamp will be appended * to the name to make it unique. *

* @param program the program to save - * @param path list of string path elements (starting at the root of the project) that specify - * the project folder to save the program info. Example: { "folder1", "subfolder2", "finalfolder" } - * @throws Exception + * @param path list of string path elements (starting at the root of the project) that specify + * the project folder to save the program info. Example: { "folder1", "subfolder2", + * "final_folder" } + * @throws Exception if there is any exception */ public void saveProgram(Program program, List path) throws Exception { if (program == null) { @@ -2533,12 +2537,6 @@ public class FlatProgramAPI { return folder; } - /** - * - * @param type - * @param text - * @return - */ private Address findComment(int type, String text) { Listing listing = currentProgram.getListing(); Memory memory = currentProgram.getMemory(); diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/datamgr/DataTypeManagerPluginTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/datamgr/DataTypeManagerPluginTest.java index 10b5c3c543..6f854fec5f 100644 --- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/datamgr/DataTypeManagerPluginTest.java +++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/datamgr/DataTypeManagerPluginTest.java @@ -62,8 +62,8 @@ import ghidra.program.database.ProgramBuilder; import ghidra.program.database.ProgramDB; import ghidra.program.database.data.ProgramDataTypeManager; import ghidra.program.model.data.*; -import ghidra.test.*; -import ghidra.util.task.TaskMonitor; +import ghidra.test.AbstractGhidraHeadedIntegrationTest; +import ghidra.test.TestEnv; import util.CollectionUtils; import utilities.util.FileUtilities; @@ -1088,18 +1088,6 @@ public class DataTypeManagerPluginTest extends AbstractGhidraHeadedIntegrationTe waitForTree(); } - private void waitForActionToBeEnabled(DockingActionIf action) { - int numWaits = 0; - while (!action.isEnabled() && ++numWaits < 50) { - try { - Thread.sleep(100); - } - catch (InterruptedException e) { - // don't care; will try again - } - } - } - private void undo() throws Exception { runSwing(() -> { try { @@ -1204,33 +1192,6 @@ public class DataTypeManagerPluginTest extends AbstractGhidraHeadedIntegrationTe } } - private void compileJavaDataType() throws Exception { - - boolean success = false; - try { - File file = getTestDataTypeFile(); - File binDir = getClassesDirectory(); - if (!binDir.exists()) { - if (!binDir.mkdir()) { - Assert.fail("Could not create directory " + binDir.getAbsolutePath()); - } - } - - File javaFile = new File(binDir, "TestDataType.java"); - FileUtilities.copyFile(file, javaFile, false, TaskMonitor.DUMMY); - assertTrue(javaFile.exists()); - - JavaCompiler j = new JavaCompiler(); - j.compile(javaFile); - success = true; - } - finally { - if (!success) { - removeBinTestDir(); - } - } - } - private File getTestDataTypeFile() { URL url = getClass().getResource("TestDataType.txt"); try { diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerHighlightService.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerHighlightService.java deleted file mode 100644 index 0cede23117..0000000000 --- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerHighlightService.java +++ /dev/null @@ -1,37 +0,0 @@ -/* ### - * 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.decompiler.component; - -/** - * A poorly designed interface that does not correctly allow for modifying highlights - */ -@Deprecated // this will be removed after 9.2 -public interface DecompilerHighlightService { - - /** - * Returns the layout model of the Decompiler - * @return the layout model - */ - @Deprecated - public ClangLayoutController getLayoutModel(); - - /** - * Clears the primary highlights in the Decompiler - */ - @Deprecated - public void clearHighlights(); - -} diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilePlugin.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilePlugin.java index 6fd33a3913..9dd0eb1336 100644 --- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilePlugin.java +++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilePlugin.java @@ -20,7 +20,6 @@ import java.util.*; import org.jdom.Element; import ghidra.app.CorePluginPackage; -import ghidra.app.decompiler.component.DecompilerHighlightService; import ghidra.app.decompiler.component.hover.DecompilerHoverService; import ghidra.app.events.*; import ghidra.app.plugin.PluginCategoryNames; @@ -46,14 +45,13 @@ import ghidra.util.task.SwingUpdateManager; category = PluginCategoryNames.ANALYSIS, shortDescription = "Decompiler", description = "Plugin for producing high-level decompilation", - servicesRequired = { - GoToService.class, NavigationHistoryService.class, ClipboardService.class, + servicesRequired = { + GoToService.class, NavigationHistoryService.class, ClipboardService.class, DataTypeManagerService.class /*, ProgramManager.class */ - }, - servicesProvided = { DecompilerHighlightService.class }, - eventsConsumed = { - ProgramActivatedPluginEvent.class, ProgramOpenedPluginEvent.class, - ProgramLocationPluginEvent.class, ProgramSelectionPluginEvent.class, + }, + eventsConsumed = { + ProgramActivatedPluginEvent.class, ProgramOpenedPluginEvent.class, + ProgramLocationPluginEvent.class, ProgramSelectionPluginEvent.class, ProgramClosedPluginEvent.class } ) @@ -79,17 +77,10 @@ public class DecompilePlugin extends Plugin { }); public DecompilePlugin(PluginTool tool) { - super(tool); disconnectedProviders = new ArrayList<>(); connectedProvider = new PrimaryDecompilerProvider(this); - - registerServices(); - } - - private void registerServices() { - registerServiceProvided(DecompilerHighlightService.class, connectedProvider); } @Override diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java index cb1139c2f7..336cdbd07e 100644 --- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java +++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java @@ -55,8 +55,7 @@ import resources.ResourceManager; import utility.function.Callback; public class DecompilerProvider extends NavigatableComponentProviderAdapter - implements DomainObjectListener, OptionsChangeListener, DecompilerCallbackHandler, - DecompilerHighlightService { + implements DomainObjectListener, OptionsChangeListener, DecompilerCallbackHandler { final static String OPTIONS_TITLE = "Decompiler"; private static Icon REFRESH_ICON = Icons.REFRESH_ICON; @@ -1074,17 +1073,4 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter public void programClosed(Program closedProgram) { controller.programClosed(closedProgram); } - - @Deprecated // to be removed post 9.2; replace with an API to manipulate primary highlights - @Override - public ClangLayoutController getLayoutModel() { - return (ClangLayoutController) getDecompilerPanel().getLayoutModel(); - } - - @Deprecated // to be removed post 9.2; replace with an API to manipulate primary highlights - @Override - public void clearHighlights() { - getDecompilerPanel().clearPrimaryHighlights(); - } - } diff --git a/Ghidra/Features/GnuDemangler/ghidra_scripts/VxWorksSymTab_5_4.java b/Ghidra/Features/GnuDemangler/ghidra_scripts/VxWorksSymTab_5_4.java index 47af9fb626..f0af2fe43e 100644 --- a/Ghidra/Features/GnuDemangler/ghidra_scripts/VxWorksSymTab_5_4.java +++ b/Ghidra/Features/GnuDemangler/ghidra_scripts/VxWorksSymTab_5_4.java @@ -15,14 +15,14 @@ */ // VxWorksSymTab_5_4 is a copy of VxWorksSymTab_6_1 with a different value for SYM_ENTRY_SIZE // It was replaced at the request of a customer who tested that it worked with the slight modification -// VxWorksSymTab_6_1 is an adaptation of the vxWorksSymTab script. It was modified by a customer +// VxWorksSymTab_6_1 is an adaptation of the vxWorksSymTab script. It was modified by a customer // to use a single loop, instead of two. It also added demangling of C++ symbol names - at least // those that Ghidra knows how to demangle. // // Extracts all symbols in a VxWorks symbol table and disassembles // the global functions. Any existing symbols in the Ghidra symbol table // that collide with symbols defined in the VxWorks symbol table are deleted. -// +// // The VxWorks symbol table is an array of symbol table entries [0..n-1] // followed by a 32-bit value that is equal to n (number of sym tbl entries). // Each entry in the array has the following structure: @@ -48,6 +48,7 @@ import java.io.FileOutputStream; import java.io.PrintWriter; +import java.util.List; import ghidra.app.cmd.label.DemanglerCmd; import ghidra.app.script.GhidraScript; @@ -189,8 +190,11 @@ public class VxWorksSymTab_5_4 extends GhidraScript { createLabel(symLocAddr, symName, true); if (symDemangledName != null) { new DemanglerCmd(symLocAddr, symName).applyTo(currentProgram, monitor); - ghidraSymTbl.removeSymbolSpecial(getSymbol(symName, - currentProgram.getGlobalNamespace())); + List symbols = + getSymbols(symName, currentProgram.getGlobalNamespace()); + if (!symbols.isEmpty()) { + ghidraSymTbl.removeSymbolSpecial(symbols.get(0)); + } } break; case 4: // Local .text @@ -205,8 +209,11 @@ public class VxWorksSymTab_5_4 extends GhidraScript { if (symDemangledName != null) { new DemanglerCmd(symLocAddr, symName).applyTo(currentProgram, monitor); - ghidraSymTbl.removeSymbolSpecial(getSymbol(symName, - currentProgram.getGlobalNamespace())); + List symbols = + getSymbols(symName, currentProgram.getGlobalNamespace()); + if (!symbols.isEmpty()) { + ghidraSymTbl.removeSymbolSpecial(symbols.get(0)); + } } } else { @@ -216,8 +223,11 @@ public class VxWorksSymTab_5_4 extends GhidraScript { if (symDemangledName != null) { new DemanglerCmd(symLocAddr, symName).applyTo(currentProgram, monitor); - ghidraSymTbl.removeSymbolSpecial(getSymbol(symName, - currentProgram.getGlobalNamespace())); + List symbols = + getSymbols(symName, currentProgram.getGlobalNamespace()); + if (!symbols.isEmpty()) { + ghidraSymTbl.removeSymbolSpecial(symbols.get(0)); + } } } break; diff --git a/Ghidra/Features/GnuDemangler/ghidra_scripts/VxWorksSymTab_6_1.java b/Ghidra/Features/GnuDemangler/ghidra_scripts/VxWorksSymTab_6_1.java index a58aafd326..beeeab2a94 100644 --- a/Ghidra/Features/GnuDemangler/ghidra_scripts/VxWorksSymTab_6_1.java +++ b/Ghidra/Features/GnuDemangler/ghidra_scripts/VxWorksSymTab_6_1.java @@ -46,6 +46,7 @@ import java.io.FileOutputStream; import java.io.PrintWriter; +import java.util.List; import ghidra.app.cmd.label.DemanglerCmd; import ghidra.app.script.GhidraScript; @@ -185,8 +186,11 @@ public class VxWorksSymTab_6_1 extends GhidraScript { createLabel(symLocAddr, symName, true); if (symDemangledName != null) { new DemanglerCmd(symLocAddr, symName).applyTo(currentProgram, monitor); - ghidraSymTbl.removeSymbolSpecial( - getSymbol(symName, currentProgram.getGlobalNamespace())); + List symbols = + getSymbols(symName, currentProgram.getGlobalNamespace()); + if (!symbols.isEmpty()) { + ghidraSymTbl.removeSymbolSpecial(symbols.get(0)); + } } break; case 4: // Local .text @@ -201,8 +205,11 @@ public class VxWorksSymTab_6_1 extends GhidraScript { if (symDemangledName != null) { new DemanglerCmd(symLocAddr, symName).applyTo(currentProgram, monitor); - ghidraSymTbl.removeSymbolSpecial( - getSymbol(symName, currentProgram.getGlobalNamespace())); + List symbols = + getSymbols(symName, currentProgram.getGlobalNamespace()); + if (!symbols.isEmpty()) { + ghidraSymTbl.removeSymbolSpecial(symbols.get(0)); + } } } else { @@ -212,8 +219,11 @@ public class VxWorksSymTab_6_1 extends GhidraScript { if (symDemangledName != null) { new DemanglerCmd(symLocAddr, symName).applyTo(currentProgram, monitor); - ghidraSymTbl.removeSymbolSpecial( - getSymbol(symName, currentProgram.getGlobalNamespace())); + List symbols = + getSymbols(symName, currentProgram.getGlobalNamespace()); + if (!symbols.isEmpty()) { + ghidraSymTbl.removeSymbolSpecial(symbols.get(0)); + } } } break; diff --git a/Ghidra/Features/GnuDemangler/ghidra_scripts/VxWorksSymTab_Finder.java b/Ghidra/Features/GnuDemangler/ghidra_scripts/VxWorksSymTab_Finder.java index 4878c8a422..c54945ac70 100644 --- a/Ghidra/Features/GnuDemangler/ghidra_scripts/VxWorksSymTab_Finder.java +++ b/Ghidra/Features/GnuDemangler/ghidra_scripts/VxWorksSymTab_Finder.java @@ -23,13 +23,13 @@ // // Any existing Ghidra symbol table entries that collide with VxWorks symbol // table entries are deleted. Mangled C++ symbol names are demangled. -// +// // The VxWorks symbol table is an array [0..n-1] of (struct SYMBOL) entries. // The table may be immediately followed or preceeded by an (int) vxSymTblLen // value. // // Prerequisites: -// +// // - Program memory block(s) is(are) aligned with actual load addresses // (run something like MemAlignARM_LE.java) // @@ -41,6 +41,8 @@ // // @category VxWorks +import java.util.List; + import ghidra.app.cmd.disassemble.DisassembleCommand; import ghidra.app.cmd.label.DemanglerCmd; import ghidra.app.plugin.core.analysis.AutoAnalysisManager; @@ -593,7 +595,7 @@ public class VxWorksSymTab_Finder extends GhidraScript { * @param symTbl * @param vxSymbol * @param tableLen - * @throws Exception + * @throws Exception */ private void markSymbolTableLen(Address symTbl, VxSymbol vxSymbol, int symTblLen) throws Exception { @@ -651,9 +653,11 @@ public class VxWorksSymTab_Finder extends GhidraScript { if (demangled != null) { new DemanglerCmd(addr, mangled).applyTo(currentProgram, monitor); - currentProgram.getSymbolTable() - .removeSymbolSpecial( - getSymbol(mangled, currentProgram.getGlobalNamespace())); + List symbols = + getSymbols(mangled, currentProgram.getGlobalNamespace()); + if (!symbols.isEmpty()) { + currentProgram.getSymbolTable().removeSymbolSpecial(symbols.get(0)); + } } return; @@ -735,7 +739,7 @@ public class VxWorksSymTab_Finder extends GhidraScript { return; } - // Process VxWorks symbol table entries + // Process VxWorks symbol table entries println("Processing symbol table entries."); Address symEntry = symTbl; for (int i = 0; (i < symTblLen) && !monitor.isCancelled(); i++, symEntry = diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/NamespaceUtils.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/NamespaceUtils.java index 94e7613e0e..af09b57b7a 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/NamespaceUtils.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/util/NamespaceUtils.java @@ -36,7 +36,7 @@ import ghidra.util.exception.*; * Assumptions for creating namespaces from a path string: *