Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.

Commit 22287f7

Browse files
committed
use shlex for script path to args
1 parent 5ba9267 commit 22287f7

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

scripts/run_ida_script.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@
55
author: Willi Ballenthin
66
77
"""
8-
import re
9-
import sys
10-
import os.path
11-
import logging
12-
138
import argparse
149
import logging
1510
import os.path
11+
import shlex
1612
import sys
1713

1814
import idb
@@ -21,17 +17,6 @@
2117
logger = 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-
3520
def 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

Comments
 (0)