mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-27 13:06:55 +08:00
Merge remote-tracking branch 'origin/GP-1073_ghidravore_checking_uses_of_getSymbols_address--SQUASHED'
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,58 +25,49 @@ import ghidra.program.model.symbol.*;
|
||||
|
||||
public class AutoRenameLabelsScript extends GhidraScript {
|
||||
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
if (currentSelection == null || currentSelection.isEmpty()) {
|
||||
println("No selection exists.");
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
if (currentSelection == null || currentSelection.isEmpty()) {
|
||||
println("No selection exists.");
|
||||
return;
|
||||
}
|
||||
|
||||
String base = askString("Auto Rename Labels", "Enter label base name:");
|
||||
if (base == null) {
|
||||
println("No base value entered.");
|
||||
return;
|
||||
}
|
||||
String base = askString("Auto Rename Labels", "Enter label base name:");
|
||||
if (base == null) {
|
||||
println("No base value entered.");
|
||||
return;
|
||||
}
|
||||
|
||||
int num = 1;
|
||||
int num = 1;
|
||||
|
||||
AddressSetView view = currentSelection;
|
||||
if ((view == null) || (view.isEmpty())) return;
|
||||
AddressSetView view = currentSelection;
|
||||
if ((view == null) || (view.isEmpty()))
|
||||
return;
|
||||
|
||||
// Obtain the symbol table and listing from program
|
||||
SymbolTable symbolTable = currentProgram.getSymbolTable();
|
||||
// Obtain the symbol table and listing from program
|
||||
SymbolTable symbolTable = currentProgram.getSymbolTable();
|
||||
|
||||
// Get the addresses in the set.
|
||||
AddressIterator it = view.getAddresses(true);
|
||||
|
||||
CompoundCmd cmd = new CompoundCmd("Auto Rename Labels");
|
||||
while(it.hasNext()) {
|
||||
Address address = it.next();
|
||||
Symbol[] symbols = symbolTable.getSymbols(address);
|
||||
Symbol defaultSymbol = getDynamicSymbol( symbols );
|
||||
if ( defaultSymbol != null ) {
|
||||
cmd.add(new RenameLabelCmd(address, null, base+num++, SourceType.USER_DEFINED));
|
||||
}
|
||||
}
|
||||
if (cmd.size() > 0) {
|
||||
if (!cmd.applyTo(currentProgram)) {
|
||||
String msg = cmd.getStatusMsg();
|
||||
if (msg != null && msg.length() > 0) {
|
||||
setToolStatusMessage(msg, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
println("No default labels found in selection.");
|
||||
}
|
||||
}
|
||||
// Get the addresses in the set.
|
||||
AddressIterator it = view.getAddresses(true);
|
||||
|
||||
private Symbol getDynamicSymbol( Symbol[] symbols ) {
|
||||
for (int i=0;i<symbols.length;i++) {
|
||||
if ( symbols[i].getSource() == SourceType.DEFAULT ) {
|
||||
return symbols[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
CompoundCmd cmd = new CompoundCmd("Auto Rename Labels");
|
||||
while (it.hasNext()) {
|
||||
Address address = it.next();
|
||||
Symbol primary = symbolTable.getPrimarySymbol(address);
|
||||
if (primary != null && primary.getSource() == SourceType.DEFAULT) {
|
||||
cmd.add(new RenameLabelCmd(address, null, base + num++, SourceType.USER_DEFINED));
|
||||
}
|
||||
}
|
||||
if (cmd.size() > 0) {
|
||||
if (!cmd.applyTo(currentProgram)) {
|
||||
String msg = cmd.getStatusMsg();
|
||||
if (msg != null && msg.length() > 0) {
|
||||
setToolStatusMessage(msg, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
println("No default labels found in selection.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class GccRttiAnalysisScript extends GhidraScript {
|
||||
symbolTable = currentProgram.getSymbolTable();
|
||||
|
||||
globalNamespace = (GlobalNamespace) currentProgram.getGlobalNamespace();
|
||||
|
||||
|
||||
// create the path for the data type manager root/ClassDataTypes folder
|
||||
classDataTypesCategoryPath =
|
||||
createDataTypeCategoryPath(CategoryPath.ROOT, DTM_CLASS_DATA_FOLDER_NAME);
|
||||
@@ -201,7 +201,7 @@ public class GccRttiAnalysisScript extends GhidraScript {
|
||||
// find the three special vtables and replace the incorrectly made array with
|
||||
// data types found in vtable
|
||||
boolean continueProcessing = createSpecialVtables();
|
||||
if(!continueProcessing) {
|
||||
if (!continueProcessing) {
|
||||
return;
|
||||
}
|
||||
// find all typeinfo symbols and get their class namespace and create RecoveredClass object
|
||||
@@ -264,9 +264,11 @@ public class GccRttiAnalysisScript extends GhidraScript {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(class_type_info_vtable == null && si_class_type_info_vtable == null && vmi_class_type_info_vtable == null) {
|
||||
println("Since there are no class typeinfo tables this program does not appear to have RTTI.");
|
||||
|
||||
if (class_type_info_vtable == null && si_class_type_info_vtable == null &&
|
||||
vmi_class_type_info_vtable == null) {
|
||||
println(
|
||||
"Since there are no class typeinfo tables this program does not appear to have RTTI.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -378,7 +380,7 @@ public class GccRttiAnalysisScript extends GhidraScript {
|
||||
|
||||
// Except for the first one which should have a symbol, if there is a symbol at the
|
||||
// address, stop making longs because it there are no references into the vtable longs
|
||||
if (offset > 0 && symbolTable.getSymbols(address).length > 0) {
|
||||
if (offset > 0 && symbolTable.getPrimarySymbol(address) != null) {
|
||||
return numLongs;
|
||||
}
|
||||
|
||||
@@ -499,8 +501,11 @@ public class GccRttiAnalysisScript extends GhidraScript {
|
||||
private void setIsGcc() {
|
||||
|
||||
isGcc =
|
||||
currentProgram.getCompilerSpec().getCompilerSpecID().getIdAsString().equalsIgnoreCase(
|
||||
"gcc");
|
||||
currentProgram.getCompilerSpec()
|
||||
.getCompilerSpecID()
|
||||
.getIdAsString()
|
||||
.equalsIgnoreCase(
|
||||
"gcc");
|
||||
}
|
||||
|
||||
private void createTypeinfoStructs(List<Symbol> typeinfoSymbols) throws CancelledException {
|
||||
@@ -684,7 +689,6 @@ public class GccRttiAnalysisScript extends GhidraScript {
|
||||
*/
|
||||
private void processVtables() throws Exception {
|
||||
|
||||
|
||||
// find all vtable symbols
|
||||
List<Symbol> listOfVtableSymbols = getListOfSymbolsInAddressSet(
|
||||
currentProgram.getAddressFactory().getAddressSet(), VTABLE_LABEL, false);
|
||||
@@ -700,7 +704,6 @@ public class GccRttiAnalysisScript extends GhidraScript {
|
||||
|
||||
processVtable(vtableAddress, vtableNamespace, true);
|
||||
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -756,7 +759,6 @@ public class GccRttiAnalysisScript extends GhidraScript {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int numFunctionPointers = getNumFunctionPointers(vftableAddress, true, true);
|
||||
|
||||
// if at least one function pointer make vftable label - the createVftable method will
|
||||
@@ -791,7 +793,6 @@ public class GccRttiAnalysisScript extends GhidraScript {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// check for an internal vtable and make a symbol there if there is one
|
||||
// will process them later
|
||||
Address possibleInternalVtableAddress =
|
||||
@@ -1160,7 +1161,6 @@ public class GccRttiAnalysisScript extends GhidraScript {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Address findNextTypeinfoRef(Address startAddress) {
|
||||
|
||||
int offset = 0;
|
||||
@@ -1275,4 +1275,3 @@ public class GccRttiAnalysisScript extends GhidraScript {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user