mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 02:09:44 +02:00
Changed data structure that holds addresses from Set to List.
This commit is contained in:
parent
a40e75da90
commit
18c8e5b8d6
3 changed files with 19 additions and 19 deletions
|
@ -22,7 +22,7 @@
|
||||||
//Ghidra comment)
|
//Ghidra comment)
|
||||||
//@category Examples
|
//@category Examples
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.List;
|
||||||
|
|
||||||
import ghidra.app.script.GhidraScript;
|
import ghidra.app.script.GhidraScript;
|
||||||
import ghidra.program.model.address.Address;
|
import ghidra.program.model.address.Address;
|
||||||
|
@ -36,12 +36,12 @@ public class LocateMemoryAddressesForFileOffset extends GhidraScript {
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
long myFileOffset = getFileOffset();
|
long myFileOffset = getFileOffset();
|
||||||
Memory mem = currentProgram.getMemory();
|
Memory mem = currentProgram.getMemory();
|
||||||
Set<Address> addressSet = mem.locateAddressesForFileOffset(myFileOffset);
|
List<Address> addressList = mem.locateAddressesForFileOffset(myFileOffset);
|
||||||
if (addressSet.isEmpty()) {
|
if (addressList.isEmpty()) {
|
||||||
println("No memory address found for: " + Long.toHexString(myFileOffset));
|
println("No memory address found for: " + Long.toHexString(myFileOffset));
|
||||||
}
|
}
|
||||||
else if (addressSet.size() == 1) {
|
else if (addressList.size() == 1) {
|
||||||
Address address = addressSet.iterator().next();
|
Address address = addressList.get(0);
|
||||||
processAddress(address, mem.getBlock(address).getName(), myFileOffset);
|
processAddress(address, mem.getBlock(address).getName(), myFileOffset);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ public class LocateMemoryAddressesForFileOffset extends GhidraScript {
|
||||||
//Let the user decide which address they want.
|
//Let the user decide which address they want.
|
||||||
else {
|
else {
|
||||||
println("Possible memory block:address are:");
|
println("Possible memory block:address are:");
|
||||||
for (Address addr : addressSet) {
|
for (Address addr : addressList) {
|
||||||
println(mem.getBlock(addr).getName() + ":" + addr.toString());
|
println(mem.getBlock(addr).getName() + ":" + addr.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,14 +51,14 @@ def processAddress(addr, memBlockName, fileOffset):
|
||||||
|
|
||||||
myFileOffset = getFileOffset()
|
myFileOffset = getFileOffset()
|
||||||
mem = currentProgram.getMemory()
|
mem = currentProgram.getMemory()
|
||||||
addressSet = mem.locateAddressesForFileOffset(myFileOffset)
|
addressList = mem.locateAddressesForFileOffset(myFileOffset)
|
||||||
if addressSet.isEmpty():
|
if addressList.isEmpty():
|
||||||
println('No memory address found for: ' + hex(myFileOffset))
|
println('No memory address found for: ' + hex(myFileOffset))
|
||||||
elif addressSet.size() == 1:
|
elif addressList.size() == 1:
|
||||||
address = addressSet.iterator().next()
|
address = addressList.get(0)
|
||||||
processAddress(address, mem.getBlock(address).getName(), myFileOffset)
|
processAddress(address, mem.getBlock(address).getName(), myFileOffset)
|
||||||
#file offset matches to multiple addresses. Let the user decide which address they want.
|
#file offset matches to multiple addresses. Let the user decide which address they want.
|
||||||
else:
|
else:
|
||||||
println('Possible memory block:address are:')
|
println('Possible memory block:address are:')
|
||||||
for addr in addressSet:
|
for addr in addressList:
|
||||||
println(mem.getBlock(addr).getName() + ":" + addr.toString())
|
println(mem.getBlock(addr).getName() + ":" + addr.toString())
|
||||||
|
|
|
@ -17,7 +17,8 @@ package ghidra.program.model.mem;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import ghidra.framework.store.LockException;
|
import ghidra.framework.store.LockException;
|
||||||
import ghidra.program.database.mem.*;
|
import ghidra.program.database.mem.*;
|
||||||
|
@ -829,22 +830,21 @@ public interface Memory extends AddressSetView {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a {@link Set} of {@link Address addresses} that correspond to the given file offset.
|
* Gets a {@link List} of {@link Address addresses} that correspond to the given file offset.
|
||||||
*
|
|
||||||
* @param fileOffset the file offset that will be used to locate the corresponding memory
|
* @param fileOffset the file offset that will be used to locate the corresponding memory
|
||||||
* addresses
|
* addresses
|
||||||
* @return a {@link Set} of {@link Address}es that are associated with the provided file offset
|
* @return a {@link List} of {@link Address}es that are associated with the provided file offset
|
||||||
*/
|
*/
|
||||||
public default Set<Address> locateAddressesForFileOffset(long fileOffset) {
|
public default List<Address> locateAddressesForFileOffset(long fileOffset) {
|
||||||
Set<Address> set = new HashSet<>();
|
List<Address> list = new ArrayList<>();
|
||||||
for (MemoryBlock memBlock : getBlocks()) {
|
for (MemoryBlock memBlock : getBlocks()) {
|
||||||
for (MemoryBlockSourceInfo info : memBlock.getSourceInfos()) {
|
for (MemoryBlockSourceInfo info : memBlock.getSourceInfos()) {
|
||||||
Address addr = info.locateAddressForFileOffset(fileOffset);
|
Address addr = info.locateAddressForFileOffset(fileOffset);
|
||||||
if (addr != null) {
|
if (addr != null) {
|
||||||
set.add(addr);
|
list.add(addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return set;
|
return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue