

Flag: Tornado!
Hurricane!
|
 |
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?
|
Well, idapython wraps perfectly IDA's ask* functions, so you can easily prompt the user for the data you require.
|
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
|
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...
|
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?
|
|
thanks ero! but i guess i need a random access kind of ea-getting. then only the manual solution really works, i think
|
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!
|
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!
|
<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.
|
|