<s> import idaapi <EOL> import idc <EOL> import idautils <EOL> import re <EOL> def find_imported_funcs ( dllname ) : <EOL> def imp_cb ( ea , name , ord ) : <EOL> if not name : <EOL> name = '<STR_LIT>' <EOL> imports . append ( [ ea , name , ord ] ) <EOL> return True <EOL> imports = [ ] <EOL> nimps = idaapi . get_import_module_qty ( ) <EOL> for i in xrange ( <NUM_LIT:0> , nimps ) : <EOL> name = idaapi . get_import_module_name ( i ) <EOL> if re . match ( dllname , name , re . IGNORECASE ) is None : <EOL> continue <EOL> idaapi . enum_import_names ( i , imp_cb ) <EOL> return imports <EOL> def find_import_ref ( dllname ) : <EOL> imports = find_imported_funcs ( dllname ) <EOL> R = dict ( ) <EOL> for i , ( ea , name , _ ) in enumerate ( imports ) : <EOL> for xref in idautils . XrefsTo ( ea ) : <EOL> ea = xref . frm <EOL> f = idaapi . get_func ( ea ) <EOL> if f and ( f . flags & idaapi . FUNC_THUNK ) != <NUM_LIT:0> : <EOL> imports . append ( [ f . startEA , idaapi . get_func_name ( f . startEA ) , <NUM_LIT:0> ] ) <EOL> continue <EOL> if not R . has_key ( i ) : <EOL> R [ i ] = [ ] <EOL> R [ i ] . append ( ea ) <EOL> return ( imports , R ) <EOL> def main ( ) : <EOL> dllname = idc . AskStr ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> if not dllname : <EOL> print ( "<STR_LIT>" ) <EOL> return <EOL> imports , R = find_import_ref ( dllname ) <EOL> for k , v in R . items ( ) : <EOL> print ( imports [ k ] [ <NUM_LIT:1> ] ) <EOL> for ea in v : <EOL> print ( "<STR_LIT>" % ea ) <EOL> main ( ) </s>
