📚 OpenRCE is preserved as a read-only archive. Launched at RECon Montreal in 2005. Registration and posting are disabled.








Flag: Tornado! Hurricane!

 Forums >>  IDA Pro  >>  Interactive IDA Python Script

Topic created on: May 23, 2007 07:39 CDT by stahl .

Hello everyone

i want to create a idapython script that offers some interactivity. The goal is to feed the script the addresses of several assembler lines and the indices of several operands. so the script should ask the user how many eas to fetch. (lets say three) so the user should be able to select a assembler line in ida and hit a button "grab" to get_screen_ea the selected ea. The script should now ask "which operand" and the user should type in a number. Then this should be repeated 2 times...

at the end of this, there should be a list of three (ea,index) pairs available.

is this interactivity possible to achive? how?

  Paolo     May 23, 2007 07:50.39 CDT
Well, idapython wraps perfectly IDA's ask* functions, so you can easily prompt the user for the data you require.

  ero     May 23, 2007 07:59.59 CDT
Look into idaapi.Choose and idc.AskStr (and the other Ask*). I think those will be enough for what you want to do.

The following is a chunk of code from ida2sql that queries the user for database information, I hope it gives and idea of how to use those functions, as it might not be too obvious from just looking at the docs.

It first shows a dropdown menu and then asks for four strings.

def query_configuration():

    # Set the default values to None
    db_engine, db_host, db_name, db_user, db_password = (None,)*5
    
    class ExportChoose(idaapi.Choose):
        def __init__(self, engines = []):
            idaapi.Choose.__init__(self, engines, 'Select Database Type', 1)
            self.width = 30
            
        def sizer(self):
            return len(self.list)-1
            
    engines = [
        DB_ENGINE.MYSQL, DB_ENGINE.POSTGRESQL,
        DB_ENGINE.MYSQLDUMP, 'Export Method']
    dlg = ExportChoose(engines)
    
    chosen_one = dlg.choose()
    if chosen_one>0:
        db_engine = engines[chosen_one-1]
    
        if db_engine == DB_ENGINE.MYSQLDUMP:
            # If a SQL dump is going to be generated, no DB
            # parameters are needed
            #
            return db_engine, '', '', '' ,''
    
        db_host = idc.AskStr('localhost', '[1/4] Enter database host:')
        if not db_host is None:
            db_name = idc.AskStr('db_name', '[2/4] Enter database(schema) name:')
            if not db_name is None:
                db_user = idc.AskStr('root', '[3/4] Enter database user:')
                if not db_user is None:
                    db_password = idc.AskStr('', '[4/4] Enter password for user:')
    
    return db_engine, db_host, db_name, db_user, db_password

  stahl   May 23, 2007 08:25.24 CDT
thanks for the replies.

i know that the user could prepare (on a piece of paper) a list of eas and the corresponding ops. then i could use the ask functions for example to read in that list.

but that is not interactive enough to be really useful.

i want that the user doen't has to type in any ea. i would love to get the eas by get_screen_ea. The Problem is that when i show a dialog with ask* i cannpt position the cursor anywhere.Like:

asklong(0,"Please move cursor on favorite line and please type in number of desired operand")

does not work!

of course positioning the cursor first and then asking for the op number works. but only one time. when used in a loop of ask* windows ("do you want to add more?") the cursor could not be moved any more...

i hope this makes my problem more clearly.

i figured out that collecting some screen_ea manually with the script box is possible. but WAY to unhandy...

  ero     May 23, 2007 08:46.26 CDT
If you want to retrieve more operands sequentially, you could do, for instance a NextHead() to move to the next instruction.  And prompt the user whether he wants to grab that one.
Otherwise, as long as you have a dialog open it's not really possible to have the user interact with the disassembly. Maybe you could prompt for an address range?

  stahl   May 23, 2007 09:27.18 CDT
thanks ero! but i guess i need a random access kind of ea-getting. then only the manual solution really works, i think

  gera     May 23, 2007 12:22.03 CDT
so... I've been wanting to try this for some time now, and I'm glad you are going to try it now :-)

You can try starting a new thread in python. This new thread does all the interaction, and the original thread just returns. Returning from that thread should (probably) make IDA continue with what it was doing, and the other thread could still do things from python. Hopefully.

How stable will this be? no idea, let me know.
How to know when the user has selected a new line? No real idea either... An ugly hack would be to bind a hotkey to an idc script (can't bind hotkeys to python, right?), then from that idc script you have to do something that lets the python code continue. You can create a file, or write to a pipe (if possible from IDC), or... you figure out :-)

good luck! and please share!

  stahl   May 24, 2007 07:49.01 CDT
hi gera,


this really is a nice idea. but i need a solution quick. and i have no experience with threads. thats why i think to chose a xml reader solution. so a xml file containing eas and ops must be prepared and is read in by python. not so nice but i need a quick solution.

if you want to take action now yourself, i would like to stay informed by your progress!

  Dyce     May 28, 2007 05:57.52 CDT
<snip>
> of course positioning the cursor first and then asking for the op number works. but only one time. when used in a loop of ask* windows (\"do you want to add more?\") the cursor could not be moved any more...

You can jump around in the disassembly from a script. This will loop through the consecutive heads until you press Esc in AskLong:


while True:
    ea = here()
    foo = AskLong(0, "Tell me about 0x%x (Press Esc to quit)" % ea)
    if foo == None: break
    Jump(NextHead(ea, ea+16))

Note: Registration is required to post to the forums.

There are 31,328 total registered users.


Recently Created Topics
[help] Unpacking VMP...
Mar/12
Reverse Engineering ...
Jul/06
let 'IDAPython' impo...
Sep/24
set 'IDAPython' as t...
Sep/24
GuessType return une...
Sep/20
About retrieving the...
Sep/07
How to find specific...
Aug/15
How to get data depe...
Jul/07
Identify RVA data in...
May/06
Question about memor...
Dec/12


Recent Forum Posts
Finding the procedur...
rolEYder
Question about debbu...
rolEYder
Identify RVA data in...
sohlow
let 'IDAPython' impo...
sohlow
How to find specific...
hackgreti
Problem with ollydbg
sh3dow
How can I write olly...
sh3dow
New LoadMAP plugin v...
mefisto...
Intel pin in loaded ...
djnemo
OOP_RE tool available?
Bl4ckm4n


Recent Blog Entries
halsten
Mar/14
Breaking IonCUBE VM

oleavr
Oct/24
Anatomy of a code tracer

hasherezade
Sep/24
IAT Patcher - new tool for ...

oleavr
Aug/27
CryptoShark: code tracer ba...

oleavr
Jun/25
Build a debugger in 5 minutes

More ...


Recent Blog Comments
nieo on:
Mar/22
IAT Patcher - new tool for ...

djnemo on:
Nov/17
Kernel debugger vs user mod...

acel on:
Nov/14
Kernel debugger vs user mod...

pedram on:
Dec/21
frida.github.io: scriptable...

capadleman on:
Jun/19
Using NtCreateThreadEx for ...

More ...


Imagery
SoySauce Blueprint
Jun 6, 2008

[+] expand

View Gallery (11) / Submit