Skip to content

Commit 8fc89ac

Browse files
committed
Update CLI to use this feature
1 parent d155da6 commit 8fc89ac

File tree

1 file changed

+59
-7
lines changed

1 file changed

+59
-7
lines changed

quark/cli.py

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@
1616
from quark.logo import logo
1717
from quark.utils.colors import yellow
1818
from quark.utils.graph import select_label_menu, show_comparison_graph
19-
from quark.utils.pprint import print_info, print_success, print_warning
19+
from quark.utils.pprint import (
20+
print_error,
21+
print_info,
22+
print_success,
23+
print_warning,
24+
)
2025
from quark.utils.weight import Weight
26+
from quark.utils.tools import find_rizin_instance, get_rizin_version
2127

2228
logo()
2329

@@ -125,11 +131,25 @@
125131
"--multi-process",
126132
"num_of_process",
127133
type=click.IntRange(min=1),
128-
help="Allow analyzing APK with N processes, where N doesn't exceeds" +
129-
" the number of usable CPUs - 1 to avoid memory exhaustion.",
134+
help="Allow analyzing APK with N processes, where N doesn't exceeds"
135+
+ " the number of usable CPUs - 1 to avoid memory exhaustion.",
130136
required=False,
131137
default=1,
132138
)
139+
@click.option(
140+
"--rizin-path",
141+
"rizin_path",
142+
type=click.Path(exists=True, file_okay=True, dir_okay=False),
143+
help="Specify a Rizin executable for Quark to perform analyses.",
144+
)
145+
@click.option(
146+
"--disable-rizin-installation",
147+
"disable_rizin_installation",
148+
default=False,
149+
is_flag=True,
150+
help="Don't install Rizin automatically when no Rizin instance with"
151+
+ " a compatible version is found."
152+
)
133153
def entry_point(
134154
summary,
135155
detail,
@@ -145,12 +165,39 @@ def entry_point(
145165
comparison,
146166
core_library,
147167
num_of_process,
168+
rizin_path,
169+
disable_rizin_installation,
148170
):
149171
"""Quark is an Obfuscation-Neglect Android Malware Scoring System"""
150172
# Load rules
151173
rule_buffer_list = []
152174
rule_filter = summary or detail
153175

176+
# Check Rizin version
177+
if core_library.lower() == "rizin":
178+
if not rizin_path:
179+
if disable_rizin_installation:
180+
print_info("Disable automatic Rizin installation.")
181+
182+
rizin_path = find_rizin_instance(
183+
disable_rizin_installation=disable_rizin_installation
184+
)
185+
186+
if not rizin_path:
187+
print_error(
188+
"No valid Rizin executable found. Please specify the path to the Rizin executable by using option --rizin-path."
189+
)
190+
return
191+
else:
192+
version = get_rizin_version(rizin_path)
193+
if rizin_path.startswith(config.HOME_DIR):
194+
print_info(f"Use the Rizin executable (version {version}) installed in the Quark directory.")
195+
else:
196+
print_info(f"Use the Rizin executable (version {version}) installed in the system PATH.")
197+
198+
else:
199+
print_info(f"Use the user-specified Rizin executable.")
200+
154201
# Determine the location of rules
155202
if rule_filter and rule_filter.endswith("json"):
156203
if not os.path.isfile(rule_filter):
@@ -205,9 +252,14 @@ def entry_point(
205252
malware_confidences = {}
206253
for apk_ in apk:
207254
data = (
208-
ParallelQuark(apk_, core_library, num_of_process)
255+
ParallelQuark(
256+
apk_,
257+
core_library,
258+
num_of_process,
259+
rizin_path,
260+
)
209261
if num_of_process > 1
210-
else Quark(apk_, core_library)
262+
else Quark(apk_, core_library, rizin_path)
211263
)
212264
all_labels = {}
213265
# dictionary containing
@@ -262,9 +314,9 @@ def entry_point(
262314

263315
# Load APK
264316
data = (
265-
ParallelQuark(apk[0], core_library, num_of_process)
317+
ParallelQuark(apk[0], core_library, num_of_process, rizin_path)
266318
if num_of_process > 1
267-
else Quark(apk[0], core_library)
319+
else Quark(apk[0], core_library, rizin_path)
268320
)
269321

270322
if label:

0 commit comments

Comments
 (0)