GP-3952 Updated the script categories to simplify and reduce the number of folders.

This commit is contained in:
ghidra_blue
2025-06-13 15:00:15 +00:00
parent 7772d98143
commit 7db176b2bd
82 changed files with 885 additions and 981 deletions
@@ -4,9 +4,9 @@
* 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
// Adds a SourceFile with a user-defined path and name to the program.
//@category SourceMapping
//@category Source Mapping
import java.util.HexFormat;
import org.apache.commons.lang3.StringUtils;
@@ -4,9 +4,9 @@
* 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.
@@ -16,7 +16,7 @@
// Add a source map entry for the current selection.
// The current selection must consist of a single address range.
// If there is no selection, a length 0 entry will be added at the current address.
//@category SourceMapping
//@category Source Mapping
import java.util.*;
import ghidra.app.script.GhidraScript;
@@ -4,9 +4,9 @@
* 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.
@@ -14,12 +14,12 @@
* limitations under the License.
*/
//Converts an ascii hex file into binary file. Works for files with spaces and without. Assumes hex bytes are zero padded so all values are two bytes long.
//@category Conversion
import ghidra.app.script.GhidraScript;
//@category
import java.io.*;
import ghidra.app.script.GhidraScript;
public class AsciiToBinaryScript extends GhidraScript {
private static final String EMPTY_STRING = "";
@@ -37,8 +37,9 @@ public class AsciiToBinaryScript extends GhidraScript {
File outBinaryFile = askFile("Select Binary File", "Binary File");
if (outBinaryFile.equals(inAsciiFile)) {
popup("Input file and output file are the same. Please choose a different file for the output." +
inAsciiFile.getAbsolutePath());
popup(
"Input file and output file are the same. Please choose a different file for the output." +
inAsciiFile.getAbsolutePath());
return;
}
@@ -4,9 +4,9 @@
* 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
//Recursively finds a folder that matches a string and renames it to a new name.
//@category Project
//@category Program
//@menupath
import ghidra.app.script.GhidraScript;
@@ -26,7 +26,6 @@ public class BatchRename extends GhidraScript {
public BatchRename() {
}
@Override
public void run() throws Exception {
@@ -4,9 +4,9 @@
* 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
//Separates co-mingled n-bit and 64-bit binaries into two folder trees.
//@category Project
//@category Program
//@menupath
import java.io.IOException;
@@ -1,13 +1,12 @@
/* ###
* 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.
* 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.
@@ -15,13 +14,12 @@
* limitations under the License.
*/
//Converts a binary file into an ascii hex file.
//@category Conversion
import ghidra.app.script.GhidraScript;
import ghidra.util.Conv;
//@category
import java.io.*;
import ghidra.app.script.GhidraScript;
import ghidra.util.Conv;
public class BinaryToAsciiScript extends GhidraScript {
@@ -37,12 +35,13 @@ public class BinaryToAsciiScript extends GhidraScript {
File outAsciiFile = askFile("Select Ascii File", "Ascii File");
if (inputBinaryFile.equals(outAsciiFile)) {
popup("Input file and output file are the same. "+inputBinaryFile.getAbsolutePath());
popup("Input file and output file are the same. " + inputBinaryFile.getAbsolutePath());
return;
}
if (outAsciiFile.exists()) {
if (!askYesNo("Ascii File Already Exists", "The ascii file already exists.\nDo you want to overwrite it?")) {
if (!askYesNo("Ascii File Already Exists",
"The ascii file already exists.\nDo you want to overwrite it?")) {
return;
}
}
@@ -51,7 +50,7 @@ public class BinaryToAsciiScript extends GhidraScript {
if (bytesPerLine < 1) {
popup("Invalid bytes per line quantity: " + bytesPerLine + ".\n " +
"Value must be greater than zero.");
"Value must be greater than zero.");
return;
}
@@ -59,7 +58,7 @@ public class BinaryToAsciiScript extends GhidraScript {
PrintWriter out = new PrintWriter(outAsciiFile);
byte [] buffer = new byte[4096];
byte[] buffer = new byte[4096];
int bytesWritten = 0;
while (true) {
@@ -73,7 +72,7 @@ public class BinaryToAsciiScript extends GhidraScript {
break;
}
for (int i = 0 ; i < nRead ; ++i) {
for (int i = 0; i < nRead; ++i) {
if (monitor.isCancelled()) {
break;
}
@@ -82,7 +81,7 @@ public class BinaryToAsciiScript extends GhidraScript {
out.append('\n');
}
out.write( Conv.toHexString(buffer[i]) );
out.write(Conv.toHexString(buffer[i]));
++bytesWritten;
}
@@ -4,9 +4,9 @@
* 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.
@@ -16,7 +16,7 @@
// Produces a list of instructions whose pcode contains a CALLOTHER pcode op. The list is
// sorted by number of occurrences of an instruction. When run headlessly, the list is displayed
// each time a program is processed and the counts are cumulative.
// @category sleigh
// @category Sleigh
import java.util.HashMap;
import java.util.Map;
@@ -4,9 +4,9 @@
* 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.
@@ -15,14 +15,14 @@
*/
//Counts the number of defined strings in the current selection, or current program if no selection is made,
//and saves the results to a file.
//@category CustomerSubmission.Strings
//@category Customer Submission.Strings
import java.io.*;
import ghidra.app.script.GhidraScript;
import ghidra.program.model.listing.*;
import ghidra.program.util.ProgramSelection;
import java.io.*;
public class CountAndSaveStrings extends GhidraScript {
private Listing listing;
private File saveFile;
@@ -46,8 +46,8 @@ public class CountAndSaveStrings extends GhidraScript {
private File getSaveFile() throws Exception {
File file = askFile("Choose File Location", "Save");
if (file.exists()) {
if (!askYesNo("File Already Exists", "A file already exists with the name you "
+ "chose.\nDo you want to overwrite it?")) {
if (!askYesNo("File Already Exists", "A file already exists with the name you " +
"chose.\nDo you want to overwrite it?")) {
return null;
}
}
@@ -4,9 +4,9 @@
* 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.
@@ -21,7 +21,7 @@
//
// The name of the .exports file will be printed when the script finishes.
//
//@category Windows
//@category
//@keybinding
//@menupath
//@toolbar
@@ -4,9 +4,9 @@
* 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
//finds and creates strings that end with '\n'
//@category Memory
//@category Data Types
import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address;
@@ -4,9 +4,9 @@
* 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.
@@ -15,60 +15,62 @@
*/
// Attempt to parse single instruction from memory bytes at current location.
// Parse trace output written to Tool Console.
// @category sleigh
// @category Sleigh
import ghidra.app.plugin.processors.sleigh.SleighDebugLogger;
import ghidra.app.plugin.processors.sleigh.SleighDebugLogger.SleighDebugMode;
import ghidra.app.script.GhidraScript;
import ghidra.util.StringUtilities;
public class DebugSleighInstructionParse extends GhidraScript {
@Override
public void run() throws Exception {
if (currentProgram == null || currentAddress == null) {
return;
}
try {
SleighDebugLogger logger = new SleighDebugLogger(currentProgram, currentAddress, SleighDebugMode.VERBOSE);
SleighDebugLogger logger =
new SleighDebugLogger(currentProgram, currentAddress, SleighDebugMode.VERBOSE);
if (!logger.parseFailed()) {
logger.append("\n");
byte[] mask = logger.getInstructionMask();
byte[] value = logger.getMaskedBytes(mask);
logger.append("Instr Mask: ");
logger.append(mask, -1, -1);
logger.append("\nInstr Value: ");
logger.append(value, -1, -1);
for (int i = 0; i < logger.getNumOperands(); i++) {
mask = logger.getOperandValueMask(i);
logger.append("\nOp-" + i + " Mask: " + getFormattedBytes(mask));
logger.append("\nOp-" + i + " Value: " + getFormattedBytes(logger.getMaskedBytes(mask)));
logger.append(
"\nOp-" + i + " Value: " + getFormattedBytes(logger.getMaskedBytes(mask)));
}
}
println(logger.toString());
} catch (Exception e) {
}
catch (Exception e) {
println(e.getMessage());
}
}
private String getFormattedBytes(byte[] value) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < value.length; i++) {
private String getFormattedBytes(byte[] value) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < value.length; i++) {
String byteStr = StringUtilities.pad(Integer.toBinaryString(value[i] & 0xff), '0', 8);
buf.append(byteStr);
if (i < (value.length-1)) {
buf.append(".");
}
buf.append(byteStr);
if (i < (value.length - 1)) {
buf.append(".");
}
return buf.toString();
}
return buf.toString();
}
}
@@ -4,9 +4,9 @@
* 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
//Convenience script to quickly clear, edit, and recreate the code or data at the current cursor location.
//@category Memory
//@category Update
//@keybinding
//@menupath
//@toolbar
@@ -4,9 +4,9 @@
* 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.
@@ -15,7 +15,7 @@
*/
//Looks for already defined graphic image data in the program
//and writes all selected images to a directory.
//@category Images
//@category
import java.awt.image.BufferedImage;
import java.io.File;
@@ -4,9 +4,9 @@
* 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.
@@ -14,15 +14,15 @@
* limitations under the License.
*/
//Rid us of those pesky FF's that become bad instructions
//@category Cleanup
//@category
import java.util.Arrays;
import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.CategoryPath;
import ghidra.program.model.data.DataType;
import java.util.Arrays;
public class FFsBeGoneScript extends GhidraScript {
private Address addr;
byte[] bytes = new byte[10];
@@ -83,11 +83,17 @@ public class FFsBeGoneScript extends GhidraScript {
if (!isUndefinedData(addr)) {
if (currentProgram.getListing().getInstructionContaining(addr) != null) {
addr =
currentProgram.getListing().getInstructionContaining(addr).getMaxAddress().next();
currentProgram.getListing()
.getInstructionContaining(addr)
.getMaxAddress()
.next();
}
else if (currentProgram.getListing().getDefinedDataContaining(addr) != null) {
addr =
currentProgram.getListing().getDefinedDataContaining(addr).getMaxAddress().next();
currentProgram.getListing()
.getDefinedDataContaining(addr)
.getMaxAddress()
.next();
}
advance();
}
@@ -4,9 +4,9 @@
* 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
//Finds programs containing various audio resources such as WAV's
//@category Resources
//@category Search
import java.util.ArrayList;
import java.util.List;
@@ -109,7 +109,8 @@ public class FindAudioInProgramScript extends GhidraScript {
break;
}
found =
memory.findBytes(start, blocks[i].getEnd(), imageBytes, mask, true, monitor);
memory.findBytes(start, blocks[i].getEnd(), imageBytes, mask, true,
monitor);
if (found != null) {
foundImages.add(found);
start = found.add(1);
@@ -4,9 +4,9 @@
* 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.
@@ -14,7 +14,10 @@
* limitations under the License.
*/
//Finds PNG and GIF images and applies data type if not already applied
//@category Images
//@category Search
import java.util.ArrayList;
import java.util.List;
import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.GifDataType;
@@ -23,9 +26,6 @@ import ghidra.program.model.listing.Data;
import ghidra.program.model.mem.Memory;
import ghidra.program.model.mem.MemoryBlock;
import java.util.ArrayList;
import java.util.List;
public class FindImagesScript extends GhidraScript {
@Override
@@ -1,13 +1,12 @@
/* ###
* 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.
* 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.
@@ -26,7 +25,7 @@
// problems with it. Still, it did a pretty good job of cleaning up after
// FindUndefinedFunctionsScript.
//
//@category CustomerSubmission.Analysis.Repair
//@category Customer Submission.Analysis.Repair
import ghidra.app.script.GhidraScript;
import ghidra.app.util.PseudoDisassembler;
@@ -4,9 +4,9 @@
* 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.
@@ -27,7 +27,7 @@
//
// Script may be constrained by a selection.
//
//@category ELF Relocations
//@category DWARF
import java.util.Iterator;
import ghidra.app.script.GhidraScript;
@@ -82,18 +82,19 @@ public class FixElfExternalOffsetDataRelocationScript extends GhidraScript {
}
}
private boolean updateExternalDataRelocation(Bookmark relocErrorBookmark, MessageLog log) throws Exception {
private boolean updateExternalDataRelocation(Bookmark relocErrorBookmark, MessageLog log)
throws Exception {
Address address = relocErrorBookmark.getAddress();
String bookmarkComment = relocErrorBookmark.getComment();
int byteSize = address.getAddressSpace().getPointerSize();
int index = bookmarkComment.lastIndexOf("0x");
if (index < 0) {
return false;
}
char signChar = bookmarkComment.charAt(index - 1);
int offset;
try {
@@ -108,16 +109,18 @@ public class FixElfExternalOffsetDataRelocationScript extends GhidraScript {
else if (signChar != '+') {
return false;
}
Memory memory = currentProgram.getMemory();
DumbMemBufferImpl buf = new DumbMemBufferImpl(memory, address);
Address symbolAddr = PointerDataType.getAddressValue(buf, byteSize, address.getAddressSpace());
Address symbolAddr =
PointerDataType.getAddressValue(buf, byteSize, address.getAddressSpace());
if (symbolAddr == null) {
return false; // invalid pointer data
}
String symbolName = bookmarkComment.substring(EXT_RELO_BOOKMARK_TEXT_PREFIX.length(), index - 1).trim();
String symbolName =
bookmarkComment.substring(EXT_RELO_BOOKMARK_TEXT_PREFIX.length(), index - 1).trim();
if (currentProgram.getSymbolTable().getSymbol(symbolName, symbolAddr, null) == null) {
return false; // EXTERNAL block symbol not found at stored address
}
@@ -136,23 +139,24 @@ public class FixElfExternalOffsetDataRelocationScript extends GhidraScript {
!canFixupStructure(dt, componentOffset, address.getPointerSize())) {
return false; // unsupported datatype applied
}
long newValue = symbolAddr.getOffset() + offset;
GhidraDataConverter converter = GhidraDataConverter.getInstance(buf.isBigEndian());
byte[] bytes = new byte[byteSize];
converter.putValue(newValue, byteSize, bytes, 0);
memory.setBytes(address, bytes);
currentProgram.getBookmarkManager().removeBookmark(relocErrorBookmark);
ElfRelocationHandler.warnExternalOffsetRelocation(currentProgram, address, symbolAddr, symbolName, offset, log);
ElfRelocationHandler.warnExternalOffsetRelocation(currentProgram, address, symbolAddr,
symbolName, offset, log);
DataType offsetPtrDt =
currentProgram.getDataTypeManager()
.resolve(new PointerTypedef(null, null, -1, currentProgram.getDataTypeManager(),
offset), null);
if (isDefaultTypeApplied) {
// Replace undefined/default data with offset-pointer
DataUtilities.createData(currentProgram, address, offsetPtrDt, -1,
@@ -16,7 +16,7 @@
//
//Example script illustrating how to launch the Instruction Pattern Search dialog from a script.
//
//@category Search.InstructionPattern
//@category Search.Instruction Pattern
import java.util.List;
@@ -1,13 +1,12 @@
/* ###
* 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.
* 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.
@@ -15,7 +14,7 @@
* limitations under the License.
*/
//Iterates over all defined data in the current program.
//@category Iteration
//@category Examples
import ghidra.app.script.GhidraScript;
import ghidra.program.model.listing.Data;
@@ -4,9 +4,9 @@
* 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.
@@ -16,7 +16,7 @@
//Iterates over all functions in the current program
//starting at the minimum address of the program.
//
//@category Iteration
//@category Examples
import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address;
@@ -29,7 +29,8 @@ public class IterateFunctionsByAddressScript extends GhidraScript {
public void run() throws Exception {
boolean forward =
askYesNo("Iterate Function", "Do you want to iterate from low address to high address?");
askYesNo("Iterate Function",
"Do you want to iterate from low address to high address?");
if (forward) {
iterateForward();
@@ -1,13 +1,12 @@
/* ###
* 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.
* 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.
@@ -15,7 +14,7 @@
* limitations under the License.
*/
//Iterates over all functions in the current program.
//@category Iteration
//@category Examples
import ghidra.app.script.GhidraScript;
import ghidra.program.model.listing.Function;
@@ -26,7 +25,8 @@ public class IterateFunctionsScript extends GhidraScript {
public void run() throws Exception {
boolean forward =
askYesNo("Iterate Function", "Do you want to iterate from low address to high address?");
askYesNo("Iterate Function",
"Do you want to iterate from low address to high address?");
if (forward) {
iterateForward();
@@ -1,13 +1,12 @@
/* ###
* 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.
* 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.
@@ -15,7 +14,7 @@
* limitations under the License.
*/
//Iterates over all instructions in the current program.
//@category Iteration
//@category Examples
import ghidra.app.script.GhidraScript;
import ghidra.program.model.listing.Instruction;
@@ -46,7 +45,7 @@ public class IterateInstructionsScript extends GhidraScript {
int nOperands = instruction.getNumOperands();
for (int i = 0 ; i < nOperands ; ++i) {
for (int i = 0; i < nOperands; ++i) {
String operand = instruction.getDefaultOperandRepresentation(i);
buffer.append(operand);
buffer.append(' ');
@@ -4,9 +4,9 @@
* 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.
@@ -27,7 +27,7 @@
// /proc/ksyms eliminates the middle column, and may add the name of the module
// in square brackets at the end of the line.
//@category CustomerSubmission.Linux
//@category Customer Submission.Linux
import java.io.*;
@@ -1,13 +1,12 @@
/* ###
* 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.
* 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.
@@ -20,7 +19,7 @@
// specified data type and symbol name and converts all "offset(base_register)"
// references to "symbol_name(base_register)" references.
//
//@category CustomerSubmission.Analysis
//@category Customer Submission.Analysis
//@keybinding alt S
import ghidra.app.script.GhidraScript;
@@ -4,9 +4,9 @@
* 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.
@@ -16,7 +16,7 @@
// Generate WARNING Bookmarks at instructions whose pcode contains a CALLOTHER op.
// This is useful to find PseudoOps that need to be implemented to yield better
// emulation or decompilation.
// @category sleigh
// @category Sleigh
import ghidra.app.script.GhidraScript;
import ghidra.program.disassemble.Disassembler;
@@ -4,9 +4,9 @@
* 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.
@@ -16,7 +16,7 @@
// Generate WARNING Bookmarks on instructions which have unimplemented pcode.
// Similar to disassembler's built-in marking but allows for refresh after
// language update.
// @category sleigh
// @category Sleigh
import ghidra.app.script.GhidraScript;
import ghidra.program.disassemble.Disassembler;
import ghidra.program.model.address.AddressSetView;
@@ -60,8 +60,9 @@ public class MarkUnimplementedPcode extends GhidraScript {
}
private void markUnimplementedPcode(Instruction instr) {
currentProgram.getBookmarkManager().setBookmark(instr.getAddress(), BookmarkType.WARNING,
Disassembler.UNIMPL_BOOKMARK_CATEGORY,
"Instruction pcode is unimplemented: " + instr.getMnemonicString());
currentProgram.getBookmarkManager()
.setBookmark(instr.getAddress(), BookmarkType.WARNING,
Disassembler.UNIMPL_BOOKMARK_CATEGORY,
"Instruction pcode is unimplemented: " + instr.getMnemonicString());
}
}
@@ -4,9 +4,9 @@
* 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.
@@ -14,149 +14,158 @@
* limitations under the License.
*/
//This script applies labels and comments to the WallaceSrc.exe program for use with GhidraClass exercises
//@category Training.GhidraClass
//@category Training.Ghidra Class
import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.ArrayDataType;
import ghidra.program.model.data.BooleanDataType;
import ghidra.program.model.data.CharDataType;
import ghidra.program.model.data.IntegerDataType;
import ghidra.program.model.data.PointerDataType;
import ghidra.program.model.data.Structure;
import ghidra.program.model.data.StructureDataType;
import ghidra.program.model.listing.Function;
import ghidra.program.model.data.*;
import ghidra.program.model.listing.*;
import ghidra.program.model.listing.Function.FunctionUpdateType;
import ghidra.program.model.listing.Parameter;
import ghidra.program.model.listing.ParameterImpl;
import ghidra.program.model.symbol.Namespace;
import ghidra.program.model.symbol.SourceType;
import ghidra.program.model.symbol.SymbolTable;
import ghidra.program.model.symbol.*;
import ghidra.util.exception.InvalidInputException;
public class MarkupWallaceSrcScript extends GhidraScript {
@Override
public void run() throws Exception {
if(!currentProgram.getName().contains("WallaceSrc") || (!currentProgram.getExecutableMD5().equals("2527c463a079c81af7b3bc1d26bd3b5d"))) {
println("This script is only meant to work on the WallaceSrc executable with md5 hash 2527c463a079c81af7b3bc1d26bd3b5d.");
if (!currentProgram.getName().contains("WallaceSrc") ||
(!currentProgram.getExecutableMD5().equals("2527c463a079c81af7b3bc1d26bd3b5d"))) {
println(
"This script is only meant to work on the WallaceSrc executable with md5 hash 2527c463a079c81af7b3bc1d26bd3b5d.");
return;
}
}
//Create Person structure
Structure personStruct = new StructureDataType("Person", 0);
personStruct.add(new IntegerDataType(), "id", "");
personStruct.add(new IntegerDataType(), "id", "");
ArrayDataType adt = new ArrayDataType(new CharDataType(), 32, 1);
personStruct.add(adt, "name", "");
personStruct.add(new BooleanDataType(), "likesCheese", "");
PointerDataType ptrPersonStruct = new PointerDataType(personStruct);
personStruct.add(ptrPersonStruct, "next", "");
//Create Gadget structure
Structure gadgetStruct = new StructureDataType("Gadget", 0);
PointerDataType charPtr = new PointerDataType(new CharDataType());
gadgetStruct.add(charPtr,"name","");
gadgetStruct.add(new IntegerDataType(),"type", "");
gadgetStruct.add(new BooleanDataType(), "deployed","");
gadgetStruct.add(ptrPersonStruct, "workingOn","");
gadgetStruct.add(charPtr, "name", "");
gadgetStruct.add(new IntegerDataType(), "type", "");
gadgetStruct.add(new BooleanDataType(), "deployed", "");
gadgetStruct.add(ptrPersonStruct, "workingOn", "");
//apply data types to function parameters, locals, and returns
//Gadget::Gadget(Gadget * this, undefined4 param_1)
Function gadgetFunction = getFunctionAt(toAddr(0x00411440));
Parameter[] parameters = gadgetFunction.getParameters();
parameters[0] = new ParameterImpl("this", new PointerDataType(gadgetStruct), currentProgram);
gadgetFunction.replaceParameters(FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS,true, SourceType.USER_DEFINED, parameters);
parameters[0] =
new ParameterImpl("this", new PointerDataType(gadgetStruct), currentProgram);
gadgetFunction.replaceParameters(FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS, true,
SourceType.USER_DEFINED, parameters);
//deployGadget - return type = Gadget *
Function deployGadgetFunction = getFunctionAt(toAddr(0x004118f0));
deployGadgetFunction.setReturnType(new PointerDataType(gadgetStruct), SourceType.USER_DEFINED);
deployGadgetFunction.setReturnType(new PointerDataType(gadgetStruct),
SourceType.USER_DEFINED);
//initializePeople(Person *)
Function initPeopleFunction = getFunctionAt(toAddr(0x004117c0));
parameters = initPeopleFunction.getParameters();
parameters[0] = new ParameterImpl("people", new PointerDataType(personStruct), currentProgram);
initPeopleFunction.replaceParameters(FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS,true, SourceType.USER_DEFINED, parameters);
parameters[0] =
new ParameterImpl("people", new PointerDataType(personStruct), currentProgram);
initPeopleFunction.replaceParameters(FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS, true,
SourceType.USER_DEFINED, parameters);
//use(Gadget *this, Person *person)
Function useFunction = getFunctionAt(toAddr(0x00411570));
parameters = useFunction.getParameters();
parameters[0] = new ParameterImpl("this", new PointerDataType(gadgetStruct), currentProgram);
parameters[1] = new ParameterImpl("person", new PointerDataType(personStruct), currentProgram);
useFunction.replaceParameters(FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS,true, SourceType.USER_DEFINED, parameters);
parameters[0] =
new ParameterImpl("this", new PointerDataType(gadgetStruct), currentProgram);
parameters[1] =
new ParameterImpl("person", new PointerDataType(personStruct), currentProgram);
useFunction.replaceParameters(FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS, true,
SourceType.USER_DEFINED, parameters);
//addPerson(Person ** list, char * name)
Function addPersonFunction = getFunctionAt(toAddr(0x00411860));
parameters = addPersonFunction.getParameters();
parameters[0] = new ParameterImpl("list", new PointerDataType(new PointerDataType(personStruct)), currentProgram);
parameters[1] = new ParameterImpl("name", new PointerDataType(new CharDataType()), currentProgram);
addPersonFunction.replaceParameters(FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS,true, SourceType.USER_DEFINED, parameters);
parameters[0] = new ParameterImpl("list",
new PointerDataType(new PointerDataType(personStruct)), currentProgram);
parameters[1] =
new ParameterImpl("name", new PointerDataType(new CharDataType()), currentProgram);
addPersonFunction.replaceParameters(FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS, true,
SourceType.USER_DEFINED, parameters);
//addPeople(Person ** list)
Function addPeopleFunction = getFunctionAt(toAddr(0x00411700));
parameters = addPeopleFunction.getParameters();
parameters[0] = new ParameterImpl("list", new PointerDataType(new PointerDataType(personStruct)), currentProgram);
addPeopleFunction.replaceParameters(FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS,true, SourceType.USER_DEFINED, parameters);
parameters[0] = new ParameterImpl("list",
new PointerDataType(new PointerDataType(personStruct)), currentProgram);
addPeopleFunction.replaceParameters(FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS, true,
SourceType.USER_DEFINED, parameters);
//print(Gadget * pGadget)
Function printFunction = getFunctionAt(toAddr(0x004115d0));
parameters = printFunction.getParameters();
parameters[0] = new ParameterImpl("this", new PointerDataType(gadgetStruct), currentProgram);
printFunction.replaceParameters(FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS,true, SourceType.USER_DEFINED, parameters);
parameters[0] =
new ParameterImpl("this", new PointerDataType(gadgetStruct), currentProgram);
printFunction.replaceParameters(FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS, true,
SourceType.USER_DEFINED, parameters);
// Create labels for some of the functions
SymbolTable symbolTable = currentProgram.getSymbolTable();
//create the Class "Gadget" to put most function symbols in
Namespace namespace = null;
namespace = symbolTable.getNamespace("Gadget", null);
if(namespace == null) {
namespace = symbolTable.createClass(null, "Gadget", SourceType.USER_DEFINED);
if (namespace == null) {
namespace = symbolTable.createClass(null, "Gadget", SourceType.USER_DEFINED);
}
//Functions in Gadget class
createNewLabel(toAddr(0x00411440), "Gadget", namespace, SourceType.USER_DEFINED);
createNewLabel(toAddr(0x004115d0), "print", namespace, SourceType.USER_DEFINED);
createNewLabel(toAddr(0x00411570), "use", namespace, SourceType.USER_DEFINED);
createNewLabel(toAddr(0x004115d0), "print", namespace, SourceType.USER_DEFINED);
createNewLabel(toAddr(0x00411570), "use", namespace, SourceType.USER_DEFINED);
//Functions not in class
createNewLabel(toAddr(0x004117c0), "initializePeople", namespace, SourceType.USER_DEFINED);
createNewLabel(toAddr(0x004118f0), "deployGadget", namespace, SourceType.USER_DEFINED);
createNewLabel(toAddr(0x004118f0), "deployGadget", namespace, SourceType.USER_DEFINED);
createNewLabel(toAddr(0x00411700), "addPeople", namespace, SourceType.USER_DEFINED);
createNewLabel(toAddr(0x00411860), "addPerson", namespace, SourceType.USER_DEFINED);
createNewLabel(toAddr(0x00418138), "personList", namespace, SourceType.USER_DEFINED);
createNewLabel(toAddr(0x00411a30), "main", null, SourceType.USER_DEFINED);
createNewLabel(toAddr(0x00411a30), "main", null, SourceType.USER_DEFINED);
// Add other labels
Function function = currentProgram.getFunctionManager().getFunctionAt(toAddr(0x004117c0));
Function function = currentProgram.getFunctionManager().getFunctionAt(toAddr(0x004117c0));
createNewLabel(toAddr(0x004117e5), "LoopOverPeople", function, SourceType.USER_DEFINED);
if(getSymbolAt(toAddr(0x00418138)).getSource().equals(SourceType.DEFAULT)){
createLabel(toAddr(0x00418138),"personList", true);
if (getSymbolAt(toAddr(0x00418138)).getSource().equals(SourceType.DEFAULT)) {
createLabel(toAddr(0x00418138), "personList", true);
}
// Add comments
setPlateComment(toAddr(0x00411440), "This is the init method for the Gadget class");
setPlateComment(toAddr(0x004115d0), "This method prints the status of a Person -- whether they are deployed or not and who they are deployed on. ");
setPlateComment(toAddr(0x00411700), "This function adds all the people to the Person list.");
setPlateComment(toAddr(0x004117c0), "This function initializes each person's record with whether or not they like cheese, their id, and a pointer to the next person.");
setPlateComment(toAddr(0x00411860), "This function adds a person to the Person list.");
setPlateComment(toAddr(0x004118f0), "This function checks to see if the person on the list is Wallace and if so, it deploys the Infrared Garden Gnome.");
setEOLComment(toAddr(0x004117e7), "Randomly assign whether each person likes cheese or not.");
setPlateComment(toAddr(0x00411440), "This is the init method for the Gadget class");
setPlateComment(toAddr(0x004115d0),
"This method prints the status of a Person -- whether they are deployed or not and who they are deployed on. ");
setPlateComment(toAddr(0x00411700),
"This function adds all the people to the Person list.");
setPlateComment(toAddr(0x004117c0),
"This function initializes each person's record with whether or not they like cheese, their id, and a pointer to the next person.");
setPlateComment(toAddr(0x00411860), "This function adds a person to the Person list.");
setPlateComment(toAddr(0x004118f0),
"This function checks to see if the person on the list is Wallace and if so, it deploys the Infrared Garden Gnome.");
setEOLComment(toAddr(0x004117e7),
"Randomly assign whether each person likes cheese or not.");
}
void createNewLabel(Address address, String name, Namespace namespace, SourceType sourceType) {
SymbolTable symbolTable = currentProgram.getSymbolTable();
if(getSymbolAt(address).getSource().equals(SourceType.DEFAULT)){
if (getSymbolAt(address).getSource().equals(SourceType.DEFAULT)) {
try {
symbolTable.createLabel(address, name, namespace, sourceType);
} catch (InvalidInputException e) {
}
catch (InvalidInputException e) {
println("Invalid input to create label.");
}
}
}
}
@@ -25,7 +25,7 @@
// Edit -> Tool Options -> Eclipse Integration
//
// from the Ghidra Project Manager.
//@category SourceMapping
//@category Source Mapping
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
@@ -25,7 +25,7 @@
// Edit -> Tool Options -> Visual Studio Code Integration
//
// from the Ghidra Project Manager.
//@category SourceMapping
//@category Source Mapping
import java.io.File;
import java.io.FileNotFoundException;
@@ -4,9 +4,9 @@
* 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.
@@ -16,7 +16,7 @@
// This script displays data about Microsoft development tools (compilers, linkers, etc.)
// used to build objects within program as stored in the Rich header and table.
//
//@category Windows
//@category
//@keybinding
//@menupath
//@toolbar
@@ -81,8 +81,12 @@ public class PortableExecutableRichPrintScript extends GhidraScript {
MSProductType prodType = prod == null ? MSProductType.Unknown : prod.getProductType();
if (prodType != MSProductType.Unknown) {
sb.append(prodType).append(" from ").append(prodVersion).append(", build ").append(
compid.getBuildNumber());
sb.append(prodType)
.append(" from ")
.append(prodVersion)
.append(", build ")
.append(
compid.getBuildNumber());
}
else {
sb.append(prodVersion);
@@ -155,7 +159,7 @@ public class PortableExecutableRichPrintScript extends GhidraScript {
.filter(id -> id > LINKER_VERSION_5_PRODUCTID)
.collect(Collectors.counting());
// @formatter:on
return version5OrGreater != 0;
}
@@ -1,20 +1,20 @@
## ###
# 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.
# 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.
##
#Given a function, find all strings used within all called funtions.
# @category: Strings
# @category: Functions
# @runtime Jython
# Handles only functions, not subroutines, as of now. Hopefully this will change later
@@ -4,9 +4,9 @@
* 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
// Reloads the language specification associated with a program at runtime.
// @category sleigh
// @category Sleigh
import java.io.IOException;
import ghidra.app.script.GhidraScript;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
// Select and remove a source map entry at the current address.
//@category SourceMapping
//@category Source Mapping
import java.util.*;
import ghidra.app.script.GhidraScript;
@@ -4,9 +4,9 @@
* 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
//Script to allow repository admins the ability to terminate multiple file checkouts belonging to a single user.
//@category MultiUser
//@category Update
import java.io.IOException;
@@ -33,25 +33,25 @@ public class RemoveUserCheckoutsScript extends GhidraScript {
@Override
protected void run() throws Exception {
Project project = state.getProject();
ProjectData projectData = project.getProjectData();
RepositoryAdapter repository = projectData.getRepository();
if (repository == null) {
printerr("Project is not a shared project");
return;
}
User currentUser = repository.getUser();
if (!currentUser.isAdmin()) {
printerr("You are not a repository administrator for " + repository.getName());
return;
}
String uname = askString("Remove User Checkouts" , "Enter user ID to be cleared");
String uname = askString("Remove User Checkouts", "Enter user ID to be cleared");
boolean found = false;
for (User u : repository.getUserList()) {
if (uname.equals(u.getName())) {
@@ -61,31 +61,34 @@ public class RemoveUserCheckoutsScript extends GhidraScript {
}
if (!found) {
if (OptionDialog.showYesNoDialogWithNoAsDefaultButton(null, "User Name Confirmation",
"User '" + uname + "' not a registered server user.\nDo you still want to search for and remove checkouts for this user?") != OptionDialog.YES_OPTION) {
"User '" + uname +
"' not a registered server user.\nDo you still want to search for and remove checkouts for this user?") != OptionDialog.YES_OPTION) {
return;
}
}
if (projectData.getFileCount() > 1000) {
if (OptionDialog.showYesNoDialogWithNoAsDefaultButton(null, "Large Repository Confirmation",
"Repository contains a large number of failes and could be slow to search.\nDo you still want to search for and remove checkouts?") != OptionDialog.YES_OPTION) {
if (OptionDialog.showYesNoDialogWithNoAsDefaultButton(null,
"Large Repository Confirmation",
"Repository contains a large number of failes and could be slow to search.\nDo you still want to search for and remove checkouts?") != OptionDialog.YES_OPTION) {
return;
}
}
int count = removeCheckouts(repository, "/", uname, monitor);
popup("Removed " + count + " checkouts");
}
private String getPath(String folderPath, String childName) {
if (!folderPath.endsWith("/")) {
folderPath += "/";
}
return folderPath + childName;
}
private int removeCheckouts(RepositoryAdapter repository, String folderPath, String uid, TaskMonitor monitor) throws IOException, CancelledException {
private int removeCheckouts(RepositoryAdapter repository, String folderPath, String uid,
TaskMonitor monitor) throws IOException, CancelledException {
int count = 0;
for (RepositoryItem item : repository.getItemList(folderPath)) {
monitor.checkCancelled();
@@ -96,16 +99,20 @@ public class RemoveUserCheckoutsScript extends GhidraScript {
}
return count;
}
private int removeCheckouts(RepositoryAdapter repository, RepositoryItem item, String uid) throws IOException {
private int removeCheckouts(RepositoryAdapter repository, RepositoryItem item, String uid)
throws IOException {
int count = 0;
ItemCheckoutStatus[] checkouts = repository.getCheckouts(item.getParentPath(), item.getName());
ItemCheckoutStatus[] checkouts =
repository.getCheckouts(item.getParentPath(), item.getName());
for (ItemCheckoutStatus checkout : checkouts) {
if (uid.equals(checkout.getUser())) {
try {
repository.terminateCheckout(item.getParentPath(), item.getName(), checkout.getCheckoutId(), false);
repository.terminateCheckout(item.getParentPath(), item.getName(),
checkout.getCheckoutId(), false);
++count;
} catch (IOException e) {
}
catch (IOException e) {
printerr("Failed to remove checkout: " + e.getMessage());
}
}
@@ -1,13 +1,12 @@
/* ###
* 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.
* 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.
@@ -23,14 +22,14 @@
// Note: Script does not verify that no other member within the structure
// is already using the new name.
//
//@category CustomerSubmission.Search
//@category Customer Submission.Search
import java.util.Iterator;
import ghidra.app.script.GhidraScript;
import ghidra.program.model.data.DataTypeComponent;
import ghidra.program.model.data.Structure;
import java.util.Iterator;
public class RenameStructMembers extends GhidraScript {
@Override
@@ -1,13 +1,12 @@
/* ###
* 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.
* 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.
@@ -20,12 +19,10 @@
// Note: Script does not verify that no other variable within the
// function is already using the new name.
//
//@category CustomerSubmission.Search
//@category Customer Submission.Search
import ghidra.app.script.GhidraScript;
import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.FunctionIterator;
import ghidra.program.model.listing.Variable;
import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.SourceType;
public class RenameVariable extends GhidraScript {
@@ -1,13 +1,12 @@
/* ###
* 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.
* 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.
@@ -19,7 +18,10 @@
// Function Definition. This resolves variable size errors which
// result from this bad data state.
//
//@category Repair
//@category
import java.util.Arrays;
import java.util.Comparator;
import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.*;
@@ -28,9 +30,6 @@ import ghidra.program.model.symbol.SourceType;
import ghidra.util.Msg;
import ghidra.util.exception.InvalidInputException;
import java.util.Arrays;
import java.util.Comparator;
public class RepairFuncDefinitionUsageScript extends GhidraScript {
private static class MyVariableOffsetComparator implements Comparator<Variable> {
@@ -1,13 +1,12 @@
/* ###
* 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.
* 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.
@@ -30,13 +29,11 @@
// - Script scans every address within the program, so it is slow.
// - Script doesn't scan param comments.
//
//@category CustomerSubmission.Search
//@category Customer Submission.Search
import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.FunctionIterator;
import ghidra.program.model.listing.Variable;
import ghidra.program.model.listing.*;
import ghidra.program.model.mem.MemoryBlock;
public class ReplaceInComments extends GhidraScript {
@@ -4,9 +4,9 @@
* 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.
@@ -18,7 +18,7 @@
// the script will optionally list any existing checkouts prior to starting
// the batch upgrade.
//
//@category Upgrade
//@category Program
import java.io.IOException;
import ghidra.app.script.GhidraScript;
@@ -1,17 +1,17 @@
## ###
# 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.
# 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.
##
# This Ghidra script runs YARA on the file associated with the current program in the Ghidra Code Browser.
# The user supplies a YARA rule file. Upon a match, the YARA rule name is reported in the comment at
@@ -23,7 +23,7 @@
# 2. The user has imported the file into Ghidra and the user has since deleted the file. This Ghidra script attempts to
# generate the original bytes of the imported file and asks the user to provide a filename to store the bytes. YARA then runs on that file.
#@category Memory.YARA
#@category Search.YARA
#@runtime Jython
import os.path
@@ -4,9 +4,9 @@
* 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.
@@ -17,7 +17,7 @@
//that called it) and build a combined mask/value buffer.
//Memory is then searched looking for this combined value buffer that represents the selected instructions.
//This automates the process of searching through memory for a particular ordering of instructions by hand.
//@category Search.InstructionPattern
//@category Search.Instruction Pattern
import java.util.ArrayList;
import java.util.LinkedHashMap;
@@ -4,9 +4,9 @@
* 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.
@@ -16,7 +16,7 @@
//The script will use a selection of multiple instructions and build a combined mask/value buffer.
//Memory is then searched looking for this combined value buffer that represents the selected instructions.
//This automates the process of searching through memory for a particular ordering of instructions by hand.
//@category Search.InstructionPattern
//@category Search.Instruction Pattern
import java.awt.Color;
import java.awt.Component;
@@ -4,9 +4,9 @@
* 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.
@@ -16,7 +16,7 @@
//The script will use the first instructions in a selection and build a combined mask/value buffer.
//Memory is then searched looking for this combined value buffer that represents the selected instructions.
//This automates the process of searching through memory for a particular ordering of instructions by hand.
//@category Search.InstructionPattern
//@category Search.Instruction Pattern
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -56,11 +56,13 @@ public class SearchGuiSingle extends SearchBaseExtended {
GroupLayout jPanel1Layout = new GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 100,
Short.MAX_VALUE));
jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGap(0, 100,
Short.MAX_VALUE));
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 100,
Short.MAX_VALUE));
jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGap(0, 100,
Short.MAX_VALUE));
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
@@ -77,45 +79,51 @@ public class SearchGuiSingle extends SearchBaseExtended {
GroupLayout layout = new GroupLayout(frame.getContentPane());
frame.getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) //
.addGroup(layout.createSequentialGroup() //
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) //
.addGroup(layout.createSequentialGroup() //
.addContainerGap() //
.addGroup(layout.createSequentialGroup() //
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) //
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING) //
.addComponent(opTwoCheckBox) //
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) //
.addComponent(mnemonicCheckBox) //
.addComponent(opOneCheckBox) //
.addGroup(layout.createSequentialGroup() //
.addContainerGap() //
.addGroup(layout
.createParallelGroup(GroupLayout.Alignment.LEADING) //
.addGroup(layout
.createParallelGroup(
GroupLayout.Alignment.TRAILING) //
.addComponent(opTwoCheckBox) //
.addGroup(layout
.createParallelGroup(
GroupLayout.Alignment.LEADING) //
.addComponent(mnemonicCheckBox) //
.addComponent(opOneCheckBox) //
) //
) //
.addComponent(constCheckBox) //
.addComponent(jLabel1) //
) //
) //
.addGroup(layout.createSequentialGroup() //
.addGap(32, 32, 32) //
.addComponent(searchButton) //
) //
) //
.addComponent(constCheckBox) //
.addComponent(jLabel1) //
) //
) //
.addGroup(layout.createSequentialGroup() //
.addGap(32, 32, 32) //
.addComponent(searchButton) //
) //
.addContainerGap(12, Short.MAX_VALUE) //
) //
.addContainerGap(12, Short.MAX_VALUE) //
) //
);
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) //
.addGroup(layout.createSequentialGroup() //
.addContainerGap() //
.addComponent(jLabel1) //
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //
.addComponent(mnemonicCheckBox) //
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //
.addComponent(opOneCheckBox) //
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //
.addComponent(opTwoCheckBox) //
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //
.addComponent(constCheckBox) //
.addGap(18, 18, 18).addComponent(searchButton) //
.addContainerGap(27, Short.MAX_VALUE) //
) //
.addGroup(layout.createSequentialGroup() //
.addContainerGap() //
.addComponent(jLabel1) //
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //
.addComponent(mnemonicCheckBox) //
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //
.addComponent(opOneCheckBox) //
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //
.addComponent(opTwoCheckBox) //
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //
.addComponent(constCheckBox) //
.addGap(18, 18, 18)
.addComponent(searchButton) //
.addContainerGap(27, Short.MAX_VALUE) //
) //
);
frame.pack();
@@ -4,9 +4,9 @@
* 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.
@@ -16,7 +16,7 @@
//The script will use the selected instructions and build a combined mask/value buffer.
//Memory is then searched looking for this combined value buffer that represents the selected instructions.
//This automates the process of searching through memory for a particular ordering of instructions by hand.
//@category Search.InstructionPattern
//@category Search.Instruction Pattern
public class SearchMnemonicsNoOpsNoConstScript extends SearchBaseExtended {
@@ -4,9 +4,9 @@
* 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.
@@ -16,7 +16,7 @@
//The script will use the selected instructions and build a combined mask/value buffer.
//Memory is then searched looking for this combined value buffer that represents the selected instructions.
//This automates the process of searching through memory for a particular ordering of instructions by hand.
//@category Search.InstructionPattern
//@category Search.Instruction Pattern
public class SearchMnemonicsOpsConstScript extends SearchBaseExtended {
@Override
@@ -4,9 +4,9 @@
* 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.
@@ -16,7 +16,7 @@
//The script will use the selected instructions and build a combined mask/value buffer.
//Memory is then searched looking for this combined value buffer that represents the selected instructions.
//This automates the process of searching through memory for a particular ordering of instructions by hand.
//@category Search.InstructionPattern
//@category Search.Instruction Pattern
public class SearchMnemonicsOpsNoConstScript extends SearchBaseExtended {
@Override
@@ -14,7 +14,7 @@
* limitations under the License.
*/
// Sets the current selection based on source file and line number parameters
//@category SourceMapping
//@category Source Mapping
import java.util.*;
import ghidra.app.script.GhidraScript;
@@ -4,9 +4,9 @@
* 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.
@@ -15,27 +15,27 @@
*/
//Creates a selection in the current program consisting of the sum
//of all function bodies.
//@category Selection
//@category
import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.AddressSet;
import ghidra.program.model.listing.*;
public class SelectFunctionsScript extends GhidraScript {
@Override
public void run() {
monitor.setMessage("Selecting functions...");
AddressSet set = new AddressSet();
Listing listing = state.getCurrentProgram().getListing();
FunctionIterator iter = listing.getFunctions(true);
int functionCount = 0;
while (iter.hasNext() && !monitor.isCancelled()) {
functionCount++;
Function f = iter.next();
set.add(f.getBody());
println("Function Entry: "+f.getEntryPoint());
}
println("Function Count: "+functionCount);
createSelection(set);
}
@Override
public void run() {
monitor.setMessage("Selecting functions...");
AddressSet set = new AddressSet();
Listing listing = state.getCurrentProgram().getListing();
FunctionIterator iter = listing.getFunctions(true);
int functionCount = 0;
while (iter.hasNext() && !monitor.isCancelled()) {
functionCount++;
Function f = iter.next();
set.add(f.getBody());
println("Function Entry: " + f.getEntryPoint());
}
println("Function Count: " + functionCount);
createSelection(set);
}
}
@@ -16,7 +16,7 @@
// This script displays a table showing the base address of each source map entry
// in the program along with a count of the number of entries starting at the address.
// @category SourceMapping
// @category Source Mapping
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -28,7 +28,6 @@ import ghidra.program.model.sourcemap.SourceMapEntry;
import ghidra.program.model.sourcemap.SourceMapEntryIterator;
import ghidra.util.datastruct.Counter;
public class ShowSourceMapEntryStartsScript extends GhidraScript {
@Override

Some files were not shown because too many files have changed in this diff Show More