55author: Willi Ballenthin
6677"""
8- import re
9- import sys
10- import os .path
11- import logging
12-
138import argparse
149import logging
1510import os .path
11+ import shlex
1612import sys
1713
1814import idb
2117logger = logging .getLogger (__name__ )
2218
2319
24- def script_path_to_args (script_path ):
25- # Split based on spaces but preserve words inside double and single quotes
26- regex_extract_quoted = "[^\s\" ']+|\" ([^\" ]*)\" |'([^']*)'"
27- matches = re .finditer (regex_extract_quoted , script_path )
28- # Strip quotes away using groups
29- return [
30- m .group (2 ) if m .group (2 ) else m .group (1 ) if m .group (1 ) else m .group (0 )
31- for m in matches
32- ]
33-
34-
3520def main (argv = None ):
3621 # TODO: do version check for 3.x
3722
@@ -44,9 +29,10 @@ def main(argv=None):
4429 parser .add_argument (
4530 "script_path" ,
4631 type = str ,
47- help = 'Path to script file. \
48- Command line arguments can be passed using quotes: \
49- "myscrypt.py arg1 arg2 \\ "arg3 arg3\\ ""' ,
32+ help = """Path to script file.
33+ Command line arguments can be passed using quotes:
34+ "myscrypt.py arg1 arg2 "arg3 arg3""
35+ """ ,
5036 )
5137 parser .add_argument ("idbpath" , type = str , help = "Path to input idb file" )
5238 parser .add_argument (
@@ -83,7 +69,7 @@ def main(argv=None):
8369
8470 hooks = idb .shim .install (db , ScreenEA = screenea )
8571
86- script_args = script_path_to_args (args .script_path )
72+ script_args = shlex . split (args .script_path )
8773 # update sys.path to point to directory containing script.
8874 # so scripts can import .py files in the same directory.
8975 script_dir = os .path .dirname (script_args [0 ])
0 commit comments