2

I'm looking for a way, to make programmatically change of data type. This is the same as you press 'C' or 'D'.

For example convert this:

.text:00401008 unk_401008      db  55h ; U             ; CODE XREF: start↑p
.text:00401009                 db  8Bh ; ‹
.text:0040100A                 db 0ECh ; ì
.text:0040100B                 db  83h ; ƒ
.text:0040100C                 db 0ECh ; ì

to this:

.text:00401008 loc_401008:                             ; CODE XREF: start↑p
.text:00401008                 push    ebp
.text:00401009                 mov     ebp, esp
.text:0040100B                 sub     esp, 0Ch

and vice versa.

These functions should be listed here https://www.hex-rays.com/products/ida/support/idapython_docs/ but I can't find it.

So far I found only this:

generate_disasm_line(here(), GENDSM_FORCE_CODE)

but it only prints data to output, and does not change the "IDA View" window content.

Thanks

0

2 Answers 2

4

ah, to create code there is:

create_insn(here())

The last question, when I'm trying to create data from code I'm getting False:

Python>create_byte(here())
False
Python>create_data(here(), FF_BYTE, 0x79, 0)
False

This is because I need previously del_items()

2
  • If you want to ask another question, ask new question. Don't "bundle" it together with an answer. It's confusing.
    – user202729
    Aug 22, 2018 at 15:44
  • ok, next time I will, this is my first experience of using this platform, sorry
    – eXp
    Aug 22, 2018 at 19:49
1

To create code, there is:

create_insn(here())

To create data:

ida_bytes.create_byte(here()) # create byte at the specified address
ida_bytes.create_data(here(), ida_bytes.dword_flag(), 4, ida_netnode.BADNODE) # create a dword variable at the specified address

ida_bytes.create_data documentation.

If you already have something defined there at that address, or something defined before it that spans through that address, for example, variable at address 0x100 that spans 8 bytes and you want to create a variable at address 0x104, use ida_bytes.del_items to undefine bytes first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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