Searching for instructions and opcodes is a basic necessity for security researchers, therefore to address this issue IDA Pro provides many search facilities, among them we list:
None of the existing search facilities allow us to readily search for instructions and opcodes. In order to do that, one has to assemble the instruction in question then use the Binary Search to find the pattern.
Each processor module in IDA can implement the assemble notification callback:
assemble, // Assemble an instruction // (display a warning if an error is found) // args: // ea_t ea - linear address of instruction // ea_t cs - cs of instruction // ea_t ip - ip of instruction // bool use32 - is 32bit segment? // const char *line - line to assemble // uchar *bin - pointer to output opcode buffer // returns size of the instruction in bytes
Once this callback is implemented by the processor module one can then assemble instructions by calling the ph.notify() with the assemble notification code (please check this forum discussion here).
Currently, only the pc processor module implements this callback and provides a very basic assembler.
We wrote a script that allows you to search for opcodes and assembly statements, so for example to find the “33 c0” (xor eax, eax), followed by “pop ebp” and followed by “ret” we could search like this:
find("33 c0;pop ebp;ret")
That’s the script operation in brief:
The script uses the Assemble() function (available in IdaPython r233 and above). Comments and suggestions are welcome.