mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 02:39:44 +02:00
GP-1073 updating uses of getSymbols(address) to be more efficient where possible
This commit is contained in:
parent
e2ea7320e1
commit
a8da2b761a
33 changed files with 530 additions and 550 deletions
|
@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue