From 1321b5bbec032ce16065eaa4e3f9f71053c67061 Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Tue, 29 Jun 2021 12:49:30 -0400 Subject: [PATCH] GP-1083 - removed outdated script Closes #1656 --- .../MakeFuncsAtLabelsScript.java | 67 --------- .../ReportDisassemblyStats.java | 132 ------------------ 2 files changed, 199 deletions(-) delete mode 100644 Ghidra/Features/Base/ghidra_scripts/MakeFuncsAtLabelsScript.java delete mode 100644 Ghidra/Features/Base/ghidra_scripts/ReportDisassemblyStats.java diff --git a/Ghidra/Features/Base/ghidra_scripts/MakeFuncsAtLabelsScript.java b/Ghidra/Features/Base/ghidra_scripts/MakeFuncsAtLabelsScript.java deleted file mode 100644 index c26621fdb3..0000000000 --- a/Ghidra/Features/Base/ghidra_scripts/MakeFuncsAtLabelsScript.java +++ /dev/null @@ -1,67 +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. - */ -// -// Calculates the percentage of instructions which are not in functions. -// -//@category Examples - -import ghidra.app.script.GhidraScript; -import ghidra.program.model.address.Address; -import ghidra.program.model.address.AddressSetView; -import ghidra.program.model.listing.Listing; -import ghidra.program.model.listing.Program; -import ghidra.program.model.symbol.*; - -public class MakeFuncsAtLabelsScript extends GhidraScript { - - int totalNumOfFunctions = 0; - - @Override - public void run() throws Exception { - - // find all the sections of memory marked as executable - Program prog = currentProgram; - AddressSetView execMemSet = prog.getMemory().getExecuteSet(); - SymbolTable sm = currentProgram.getSymbolTable(); - SymbolIterator textLabels = sm.getPrimarySymbolIterator(execMemSet, true); - Listing listing = prog.getListing(); - for (Symbol symbol : textLabels) { - if (symbol.getSource() == SourceType.IMPORTED && - (symbol.getSymbolType() == SymbolType.LABEL)) { - if (!this.isRunningHeadless()) { - printf("%s %s", symbol.getAddress().toString(), symbol.toString()); - } - Address labelAddress = symbol.getAddress(); - //don't declare to be functions if the symbol starts with .L or LAB - if (symbol.toString().startsWith(".L") || symbol.toString().startsWith("LAB")) { - continue; - } - if (listing.isUndefined(labelAddress, labelAddress)) { - if (!this.isRunningHeadless()) { - printf("Undefined: %s", labelAddress.toString()); - } - boolean result = disassemble(labelAddress); - if (result == false) { - printf("Disassembly failure at %s", labelAddress.toString()); - continue; //must be data - } - } - createFunction(labelAddress, symbol.toString()); - } - } - } - -} diff --git a/Ghidra/Features/Base/ghidra_scripts/ReportDisassemblyStats.java b/Ghidra/Features/Base/ghidra_scripts/ReportDisassemblyStats.java deleted file mode 100644 index 90403bbbb3..0000000000 --- a/Ghidra/Features/Base/ghidra_scripts/ReportDisassemblyStats.java +++ /dev/null @@ -1,132 +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. - */ -// -// Reports some basic information about how the binary was disassembled. If running in -// headless mode it also generates the signature file. -// -//@category Examples - -import java.io.*; -import java.util.Iterator; - -import ghidra.app.util.headless.HeadlessScript; -import ghidra.framework.options.Options; -import ghidra.program.model.address.AddressSetView; -import ghidra.program.model.listing.*; - -public class ReportDisassemblyStats extends HeadlessScript { - - int totalNumOfFunctions = 0; - double UNDEFINED_THRESHOLD = 50.0; - double NOT_IN_FUNC_THRESHOLD = 50.0; - - @Override - public void run() throws Exception { - - // find all the sections of memory marked as executable - - if (this.isRunningHeadless()) { - runScript("MakeFuncsAtLabelsScript.java"); - } - - AddressSetView execMemSet = currentProgram.getMemory().getExecuteSet(); - InstructionIterator instIter = - currentProgram.getListing().getInstructions(execMemSet, true); - FunctionManager fm = currentProgram.getFunctionManager(); - //calculate the number of instructions not in functions and the total number of instructions - int instCount = 0; - int instNotInFuncCount = 0; - int instByteCount = 0; - while (instIter.hasNext()) { - Instruction inst = instIter.next(); - instByteCount += inst.getBytes().length; - Function func = fm.getFunctionContaining(inst.getAddress()); - if (func == null) { - instNotInFuncCount++; - } - instCount++; - } - //count the number of defined data bytes - int dataByteCount = 0; - DataIterator dataIter = currentProgram.getListing().getData(execMemSet, true); - while (dataIter.hasNext()) { - Data data = dataIter.next(); - if (data.isDefined()) { - dataByteCount += data.getBytes().length; - } - } - - long numTotalBytes = execMemSet.getNumAddresses(); - double undefinedPercentage = - 100.0 - (100.0 * (instByteCount + dataByteCount) / numTotalBytes); - double notInFuncPercentage = instNotInFuncCount * 100.0 / instCount; - - printf("Name: %s", getProgramFile().toString()); - printf("Language: %s", currentProgram.getLanguageID()); - printf("CompilerSpec: %s", currentProgram.getCompilerSpec().getCompilerSpecID()); - printf("Number of functions: %d", fm.getFunctionCount()); - printf("Number of addresses: %d", numTotalBytes); - printf("Percentage of undefined addresses: %f", undefinedPercentage); - printf("Percentage of instructions not in functions: %f", notInFuncPercentage); - - Iterator bmi = currentProgram.getBookmarkManager().getBookmarksIterator("Error"); - int numConflicts = 0; - int numRelocationErrors = 0; - while (bmi.hasNext()) { - Bookmark bm = bmi.next(); - if (bm.toString().contains("conflicting")) { - numConflicts++; - continue; - } - if (bm.toString().contains("relocation")) { - numRelocationErrors++; - continue; - } - printf("!!%s", bm.toString()); - } - printf("Number of conflicts: %d", numConflicts); - printf("Number of relocation errors: %d", numRelocationErrors); - if (this.isRunningHeadless()) { - if ((undefinedPercentage <= UNDEFINED_THRESHOLD) && - (notInFuncPercentage <= NOT_IN_FUNC_THRESHOLD)) { - totalNumOfFunctions += fm.getFunctionCount(); - printf("Total number of functions: %d", totalNumOfFunctions); - //search for .siginfo file - File siginfoFile = new File(getProgramFile().getAbsolutePath() + ".siginfo"); - boolean siginfoExists = siginfoFile.exists(); - if (!siginfoExists) { - printf("No siginfo file found"); - } - else { - //read the .siginfo file and save the information to the project - BufferedReader br = new BufferedReader(new FileReader(siginfoFile)); - String verinfo = br.readLine(); - br.close(); - Options propList = currentProgram.getOptions("Signature Info"); - propList.setString("Version Name", verinfo); - printf("Saving version %s to project", verinfo); - } - } - else { - printf("Program not imported"); - setHeadlessContinuationOption(HeadlessContinuationOption.ABORT_AND_DELETE); - } - printf(""); - - } - - } -}