@@ -2256,29 +2256,84 @@ def try_mark_as_function(address):
2256
2256
2257
2257
if __name__ == "__main__" :
2258
2258
2259
+ #
2260
+ # interactive mode support
2261
+ #
2262
+
2263
+ architecture = None
2264
+ operating_system = None
2265
+ output_file_path = None
2266
+ log_file_path = None
2267
+ entry_point_list = []
2268
+
2269
+ if ida_kernwin .cvar .batch == 0 :
2270
+ print "Manual run detected; setting default parameters..."
2271
+
2272
+ # attempt to guess the architecture
2273
+ # todo: use idaapi.get_inf_structure().procName to determine which arch we are dealing with.
2274
+ # the 'bits' field is enough for the time being, since we only support x86 and amd64
2275
+
2276
+ if idaapi .get_inf_structure ().procName != 'metapc' :
2277
+ print "Unsupported architecture"
2278
+ exit (1 )
2279
+
2280
+ if idaapi .get_inf_structure ().is_64bit ():
2281
+ architecture = "amd64"
2282
+ elif idaapi .get_inf_structure ().is_32bit ():
2283
+ architecture = "x86"
2284
+ else :
2285
+ print "Only 32-bits and 64-bits targets are supported!"
2286
+ exit (1 )
2287
+
2288
+ # attempt to guess the file format
2289
+ loader_module_name = idaapi .get_file_type_name ()
2290
+ if "Portable executable" in loader_module_name :
2291
+ operating_system = "windows"
2292
+ elif "ELF" in loader_module_name :
2293
+ operating_system = "linux"
2294
+ else :
2295
+ print "Unsupported image type! Only PE and ELF executables are supported!"
2296
+ exit (1 )
2297
+
2298
+ # generate a default output path for both the cfg and the log file
2299
+ output_file_path = idc .GetIdbPath () + '-mcsema.cfg'
2300
+ log_file_path = idc .GetIdbPath () + '-mcsema.log'
2301
+
2302
+ # get the function name under the cursor and set it as the starting entry point
2303
+ entry_point_name = idc .GetFunctionName (idc .ScreenEA ())
2304
+ entry_point_list .append (entry_point_name )
2305
+
2306
+ print "Summary:"
2307
+ print 'Log file: ' + log_file_path
2308
+ print 'Architecture: ' + architecture
2309
+ print 'Operating system: ' + operating_system
2310
+ print 'Output file: ' + output_file_path
2311
+ print 'Entry point: ' + entry_point_name
2312
+
2313
+ #
2314
+ # parse the command line argument
2315
+ #
2316
+
2259
2317
parser = argparse .ArgumentParser ()
2260
2318
2261
2319
parser .add_argument ("--log_file" , type = argparse .FileType ('w' ),
2262
- default = sys . stderr ,
2320
+ default = log_file_path ,
2263
2321
help = "Log to a specific file. Default is stderr." )
2264
2322
2265
2323
parser .add_argument (
2266
- '--arch' ,
2267
- help = 'Name of the architecture. Valid names are x86, amd64.' ,
2268
- required = True )
2324
+ '--arch' , default = architecture ,
2325
+ help = 'Name of the architecture. Valid names are x86, amd64.' )
2269
2326
2270
2327
parser .add_argument (
2271
- '--os' ,
2272
- help = 'Name of the operating system. Valid names are linux, windows.' ,
2273
- required = True )
2328
+ '--os' , default = operating_system ,
2329
+ help = 'Name of the operating system. Valid names are linux, windows.' )
2274
2330
2275
2331
parser .add_argument (
2276
- "--output" , type = argparse .FileType ('wb' ), default = None ,
2277
- help = "The output control flow graph recovered from this file" ,
2278
- required = True )
2332
+ "--output" , type = argparse .FileType ('wb' ), default = output_file_path ,
2333
+ help = "The output control flow graph recovered from this file" )
2279
2334
2280
2335
parser .add_argument (
2281
- "--entrypoint" , nargs = '*' ,
2336
+ "--entrypoint" , nargs = '*' , default = entry_point_list ,
2282
2337
help = "Symbol(s) to start disassembling from" )
2283
2338
2284
2339
parser .add_argument ("--std-defs" , action = 'append' , type = str ,
@@ -2406,4 +2461,6 @@ def try_mark_as_function(address):
2406
2461
DEBUG (str (e ))
2407
2462
DEBUG (traceback .format_exc ())
2408
2463
2409
- idc .Exit (0 )
2464
+ # do not close IDA if we are not being run in batch mode
2465
+ if ida_kernwin .cvar .batch != 0 :
2466
+ idc .Exit (0 )
0 commit comments