1

IDA Pro 6.95. From the menu I can use Edit... Export data... C unsigned char array (hex).

I want to do this in a Python script without rewriting what already works.

I have looked for a way to find a list of the commands I have performed through the GUI menus, but export data is not the sort of thing that appears in an IDC file.

3

Because this is a relatively basic functionality, there's not builtin way to call that command from IDAPython. You could do some Qt trickery to fake that GUI menu being clicked by the user, but that seems too much effort.

To me it seems as if the easiest and cleanest solution here is to simply call idaapi.get_many_bytes to get the buffer of data you're interesting in dumping, and then format it however you'd like.

for example, the following code snippet will output the binary data as a hexadecimal string:

buf = idaapi.get_many_bytes(start, end)
buf.encode('hex')

Or to get a c-like array:

buf = idaapi.get_many_bytes(start, end)
buf = buf.encode('hex')
two_hex_char_seq = map(operator.add, buf[::2], buf[1::2])
c_array = "{0x" + ", 0x".join(two_hex_char_seq) + "}"

Which will give an output similar to:

{0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30}
  • Perfect. This teaches me more IDA Python, and also lets me automate a whole load more stuff. – John Banks Feb 7 '17 at 17:55
  • @JohnBanks Can I interest you in accepting this answer if it suits your needs and provides the information you were looking for? :) – NirIzr Feb 8 '17 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.