Add ability to get list of instructions/lines from the current selection
What is the feature you'd like to have? I would like the ability to get the list of instructions/lines associated with the current selection. Based on the instruction type of the current view (e.g. disassembly, IL), the list should contain the appropriate instructions.
Is your feature request related to a problem? Currently, the current_selection returns a virtual address range in the form of a tuple (start_addr, end_addr). For some ILs, this address range seems to span the (min, max) of the addresses of the instructions contained in the selection, so it's unclear how to get instructions/lines using the address range since the linear view of IL instructions are not always ordered according to virtual address.
Use ui context to get more information regarding the selection.
The solution is to expose the m_SelectionStartPos in the Python API.
@kristopax How would you expect this to be implemented? Right now there is magic variable current_il_instruction, though it only refers to one instruction, rather than several. Do you want something like current_il_instructions? Besides, do you need this in the C++ API or Python API?
current_il_instructions does not work properly in some cases. In order to reproduce:
- Open the attached binary (httpd)
- Go to function sub_18fe8
- Highlight the HLIL lines shown in the screen shot below
- In the python console, enter
print(current_il_instructions) - Confirm that output is "None"
It would appear that getCurrentILInstructionIndex is incorrect.
Please resolve.
Also, if you output the following in the Python console, you should see the incorrect value that is taken from getCurrentILInstructionIndex()
>>> current_ui_action_context.instrIndex
18446744073709551615
It would appear that getCurrentILInstructionIndex() is invalid in some cases for unknown reasons. If you highlight just 0x1906c, current_ui_action_context.instrIndex is 18446744073709551615.
Actually, what we would really like to have is something along the lines of:
View.getCurrentLineNumber() and View.getSelectionStartLineNumber()
This will allow us to capture what we need.
This issue is more complicated than I have expected. I think the problem is the linear view incorrectly assigned address 0x1906c to the closing braces. In other places, the closing braces typically have the same address as the last instruction, e.g.,
00019098 if (r0_5 == 0 || (r0_5 != 0 && r0_7 == 0) || (r0_5 != 0 && r0_7 != 0 && r0_9 == 0)) {
000190a0 r1 = 0xf2a158
000190a4 r7_1 = data_199f78
000190a4 }
For the code snippet you showed, the address of the last two braces are all 0x1906c.
00019070 if (r0_5 != 0) {
0001907c r0_7 = strcmp(arg1, "securityquestions.cgi")
00019084 if (r0_7 != 0) {
00019090 r0_9 = strcmp(arg1, "passwordrecovered.cgi")
00019098 if (r0_9 != 0) {
000190b0 r1 = 0xf29f08
000190b4 r7_1 = data_199f74
000190b4 }
0001906c }
0001906c }
I guess the nesting is causing the issue.
Since there is no HLIL instruction at 0x1906c, the corresponding IL instruction index is -1. There is really not much I can do from the Python side. We will need to fix it in the linear view.
A workaround exists to only select the code in the if statement, shown in the below screenshot: