show Dialog Changes Order of Provided Addresses
See original GitHub issueI have an instruction trace and I’m particularly interested in generating a Ghidra dialogue that lists each address I give it in the order given. I managed to nearly accomplish this with the show
dialog. However, the address array I give the show
function is implicitly sorted by Ghidra and that is not the behavior I want.
Here is a simple example. The addresses provided are arbitrary, the point is 0x10a09c
is the second item in the array and 0x10a098
is the third item in the array. You can replace these addresses with any valid addresses for your binary, just make sure they are not sorted.
import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.*;
public class TraceGoTo extends GhidraScript {
private static String addresses[] = new String[] {"0x10a094", "0x10a09c", "0x10a098"};
public void run() throws Exception {
Address addrs[] = new Address[3];
for (int i = 0; i < 1000 && i < addresses.length; i++) {
addrs[i] = toAddr(addresses[i]);
}
show(addrs);
}
}
The show
dialog should display a table with the addresses given in the exact order they are given. It should not automatically sort the results. I believe what is happening is the table is automatically sorting by address, which again is not what I want.
Issue Analytics
- State:
- Created a year ago
- Comments:7
There are much crazier things than this.
There are many ways to do this, but not via scripting.
That depends on you use case. It used to be that all tables were always sorted. In those ancient times we would have simply added an ordinal column to go a long with the addresses, with the sort being on the ordinal column. We added the ability to have tables be unsorted some years back. The code below uses this ability.
Below is a script that shows a table with unsorted addresses with relatively few lines of code, taken from what the script code does internally.
Note: there are no ‘Next’ and ‘Previous’ buttons in this example. However, you can simply use the arrow keys in the table to accomplish the equivalent behavior. You could certainly build a more complicated custom dialog if you really wanted such buttons.
That is a fairly old version of Ghidra. Perhaps there is a related bug. I verified that changing the order of addresses in the list works as expected for me in Ghidra 10.1.5.
Glad to hear it worked!