Skip to content

Commit f8e71a8

Browse files
committed
Fix CI issues
1 parent 71dd744 commit f8e71a8

File tree

5 files changed

+66
-58
lines changed

5 files changed

+66
-58
lines changed

quark/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
print_warning,
2424
)
2525
from quark.utils.weight import Weight
26-
from quark.utils.tools import find_rizin_instance, get_rizin_version
26+
from quark.utils.tools import find_rizin_instance, _get_rizin_version
2727

2828
logo()
2929

@@ -190,7 +190,7 @@ def entry_point(
190190
)
191191
return
192192
else:
193-
version = get_rizin_version(rizin_path)
193+
version = _get_rizin_version(rizin_path)
194194
if rizin_path.startswith(config.HOME_DIR):
195195
print_info(
196196
f"Use the Rizin executable (version {version})"

quark/core/rzapkinfo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from quark.core.struct.bytecodeobject import BytecodeObject
2020
from quark.core.struct.methodobject import MethodObject
2121
from quark.utils.tools import (descriptor_to_androguard_format,
22-
get_rizin_version, remove_dup_list)
22+
_get_rizin_version, remove_dup_list)
2323

2424
RizinCache = namedtuple("rizin_cache", "address dexindex is_imported")
2525

@@ -57,7 +57,7 @@ def __init__(
5757
super().__init__(apk_filepath, "rizin")
5858

5959
if rizin_path:
60-
if not get_rizin_version(rizin_path):
60+
if not _get_rizin_version(rizin_path):
6161
raise ValueError(
6262
f"The file in {rizin_path} is not a valid Rizin"
6363
+ " executable."

quark/utils/tools.py

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
import copy
66
import re
77
import shutil
8-
import subprocess
8+
from subprocess import ( # nosec
9+
STDOUT,
10+
CalledProcessError,
11+
Popen,
12+
PIPE,
13+
check_output,
14+
)
915
from ast import Str
1016
from os import F_OK, PathLike, access, mkdir
1117
from xmlrpc.client import Boolean
@@ -70,7 +76,7 @@ def descriptor_to_androguard_format(descriptor):
7076
return new_descriptor
7177

7278

73-
def execute_command(command, stderr=subprocess.PIPE, cwd=None):
79+
def _execute_command(command, stderr=PIPE, cwd=None):
7480
"""
7581
Execute a given command and yield the messages from the standard output.
7682
@@ -81,10 +87,10 @@ def execute_command(command, stderr=subprocess.PIPE, cwd=None):
8187
non-zero return code
8288
:yield: a string holding a line of message in the standard output
8389
"""
84-
process = subprocess.Popen(
90+
process = Popen( # nosec
8591
command,
8692
bufsize=1,
87-
stdout=subprocess.PIPE,
93+
stdout=PIPE,
8894
stderr=stderr,
8995
universal_newlines=True,
9096
cwd=cwd,
@@ -109,29 +115,26 @@ def execute_command(command, stderr=subprocess.PIPE, cwd=None):
109115

110116
if return_code:
111117
error_messages = ""
112-
if stderr == subprocess.PIPE:
118+
if stderr == PIPE:
113119
for message in process.stderr.readlines():
114120
error_messages = error_messages + message
115121

116-
raise subprocess.CalledProcessError(
117-
return_code, command, stderr=error_messages
118-
)
122+
raise CalledProcessError(return_code, command, stderr=error_messages)
119123

120-
if stderr == subprocess.PIPE:
124+
if stderr == PIPE:
121125
process.stderr.close()
122126

123127

124-
def get_rizin_version(rizin_path) -> Str:
128+
def _get_rizin_version(rizin_path) -> Str:
125129
"""
126130
Get the version number of the Rizin instance in the path.
127131
128132
:param rizin_path: a path to the Rizin executable
129133
:return: the version number of the Rizin instance
130134
"""
131135
try:
132-
result = subprocess.check_output(
133-
[rizin_path, "-v"], timeout=5, check=True, stdout=subprocess.PIPE
134-
)
136+
result = check_output([rizin_path, "-v"], timeout=5) # nosec
137+
result = str(result)
135138

136139
matched_versions = re.finditer(
137140
r"[0-9]+\.[0-9]+\.[0-9]+", result[: result.index("@")]
@@ -143,7 +146,7 @@ def get_rizin_version(rizin_path) -> Str:
143146
else:
144147
return None
145148

146-
except subprocess.CalledProcessError:
149+
except CalledProcessError:
147150
return None
148151

149152
except OSError:
@@ -166,21 +169,21 @@ def download_rizin(target_path) -> Boolean:
166169
try:
167170
print()
168171

169-
for line in execute_command(
172+
for line in _execute_command(
170173
[
171174
"git",
172175
"clone",
173176
"--progress",
174177
"https://github.com/rizinorg/rizin",
175178
target_path,
176179
],
177-
stderr=subprocess.STDOUT,
180+
stderr=STDOUT,
178181
):
179182
print_info(line)
180183

181184
return True
182185

183-
except subprocess.CalledProcessError:
186+
except CalledProcessError:
184187
print_error("An error occurred when downloading Rizin.\n")
185188

186189
except OSError:
@@ -205,48 +208,54 @@ def update_rizin(source_path, target_commit) -> Boolean:
205208
print()
206209

207210
# Checkout to target commit
208-
for line in execute_command(
211+
for line in _execute_command(
209212
["git", "checkout", target_commit], cwd=source_path
210213
):
211214
print_info(line)
212215

213216
# Remove the last build
214-
for line in execute_command(["rm", "-rf", "build"], cwd=source_path):
217+
for line in _execute_command(["rm", "-rf", "build"], cwd=source_path):
215218
print_info(line)
216219

217220
# Clean out old subproject
218-
for line in execute_command(
221+
for line in _execute_command(
219222
["git", "clean", "-dxff", "subprojects/"], cwd=source_path
220223
):
221224
print_info(line)
222225

223-
except subprocess.CalledProcessError as error:
226+
except CalledProcessError as error:
224227
print_error("An error occurred when updating Rizin.\n")
225228

226229
for line in error.stderr.decode().splitlines():
227230
print_error(line)
228231

229232
return False
230233

234+
except OSError as error:
235+
print_error("An error occurred when updating Rizin.\n")
236+
print_error(error)
237+
238+
return False
239+
231240
# Compile Rizin
232241
try:
233242
print()
234243

235244
# Configure
236-
for line in execute_command(
245+
for line in _execute_command(
237246
["meson", "--buildtype=release", "build"], cwd=source_path
238247
):
239248
print_info(line)
240249

241250
# Compile the source code
242-
for line in execute_command(
251+
for line in _execute_command(
243252
["meson", "compile", "-C", "build"], cwd=source_path
244253
):
245254
print_info(line)
246255

247256
return True
248257

249-
except subprocess.CalledProcessError as error:
258+
except CalledProcessError as error:
250259
pass
251260
except OSError:
252261
pass
@@ -286,13 +295,13 @@ def find_rizin_instance(
286295
# Search Rizin in PATH
287296
which_result = shutil.which("rizin")
288297
if which_result:
289-
version = get_rizin_version(which_result)
298+
version = _get_rizin_version(which_result)
290299
if version in COMPATIBLE_RAZIN_VERSIONS:
291300
return which_result
292301

293302
# Otherwise, search the home path
294303
rizin_executable_path = rizin_source_path + "build/binrz/rizin/rizin"
295-
current_version = get_rizin_version(rizin_executable_path)
304+
current_version = _get_rizin_version(rizin_executable_path)
296305

297306
if not current_version and not disable_rizin_installation:
298307
print_info("Cannot find a compatible Rizin instance.")

tests/test_report.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ def test_analysis_with_rule_directory(
131131
assert mock_run.call_count == num_of_rules
132132
assert mock_generate_report.call_count == num_of_rules
133133

134+
@staticmethod
134135
def test_analysis_without_specified_rizin_path(
135-
self, sample_apk_file, sample_rule_directory
136+
sample_apk_file, sample_rule_directory
136137
):
137138
expected_path = shutil.which("rizin")
138139

@@ -152,8 +153,9 @@ def test_analysis_without_specified_rizin_path(
152153
mock_run.assert_called_once()
153154
mock_generate_report.assert_called_once()
154155

156+
@staticmethod
155157
def test_analysis_with_specified_rizin_path(
156-
self, sample_apk_file, sample_rule_directory
158+
sample_apk_file, sample_rule_directory
157159
):
158160
rizin_path = shutil.which("rizin")
159161

@@ -179,8 +181,9 @@ def test_analysis_with_specified_rizin_path(
179181
mock_run.assert_called_once()
180182
mock_generate_report.assert_called_once()
181183

184+
@staticmethod
182185
def test_analysis_with_invalid_rizin_path(
183-
self, sample_report, sample_apk_file, sample_rule_directory
186+
sample_report, sample_apk_file, sample_rule_directory
184187
):
185188
invalid_path = "INVALID_PATH"
186189

0 commit comments

Comments
 (0)