Skip to content

Commit 759d29f

Browse files
committed
Fix CI issues
1 parent 71dd744 commit 759d29f

File tree

5 files changed

+66
-60
lines changed

5 files changed

+66
-60
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: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import copy
66
import re
77
import shutil
8-
import subprocess
8+
from subprocess import STDOUT, CalledProcessError, Popen, PIPE, check_output
99
from ast import Str
1010
from os import F_OK, PathLike, access, mkdir
1111
from xmlrpc.client import Boolean
@@ -70,7 +70,7 @@ def descriptor_to_androguard_format(descriptor):
7070
return new_descriptor
7171

7272

73-
def execute_command(command, stderr=subprocess.PIPE, cwd=None):
73+
def _execute_command(command, stderr=PIPE, cwd=None):
7474
"""
7575
Execute a given command and yield the messages from the standard output.
7676
@@ -81,13 +81,13 @@ def execute_command(command, stderr=subprocess.PIPE, cwd=None):
8181
non-zero return code
8282
:yield: a string holding a line of message in the standard output
8383
"""
84-
process = subprocess.Popen(
84+
process = Popen(
8585
command,
8686
bufsize=1,
87-
stdout=subprocess.PIPE,
87+
stdout=PIPE,
8888
stderr=stderr,
8989
universal_newlines=True,
90-
cwd=cwd,
90+
cwd=cwd
9191
)
9292

9393
line = ""
@@ -109,29 +109,30 @@ def execute_command(command, stderr=subprocess.PIPE, cwd=None):
109109

110110
if return_code:
111111
error_messages = ""
112-
if stderr == subprocess.PIPE:
112+
if stderr == PIPE:
113113
for message in process.stderr.readlines():
114114
error_messages = error_messages + message
115115

116-
raise subprocess.CalledProcessError(
116+
raise CalledProcessError(
117117
return_code, command, stderr=error_messages
118118
)
119119

120-
if stderr == subprocess.PIPE:
120+
if stderr == PIPE:
121121
process.stderr.close()
122122

123123

124-
def get_rizin_version(rizin_path) -> Str:
124+
def _get_rizin_version(rizin_path) -> Str:
125125
"""
126126
Get the version number of the Rizin instance in the path.
127127
128128
:param rizin_path: a path to the Rizin executable
129129
:return: the version number of the Rizin instance
130130
"""
131131
try:
132-
result = subprocess.check_output(
133-
[rizin_path, "-v"], timeout=5, check=True, stdout=subprocess.PIPE
132+
result = check_output(
133+
[rizin_path, "-v"], timeout=5
134134
)
135+
result = str(result)
135136

136137
matched_versions = re.finditer(
137138
r"[0-9]+\.[0-9]+\.[0-9]+", result[: result.index("@")]
@@ -143,7 +144,7 @@ def get_rizin_version(rizin_path) -> Str:
143144
else:
144145
return None
145146

146-
except subprocess.CalledProcessError:
147+
except CalledProcessError:
147148
return None
148149

149150
except OSError:
@@ -166,21 +167,21 @@ def download_rizin(target_path) -> Boolean:
166167
try:
167168
print()
168169

169-
for line in execute_command(
170+
for line in _execute_command(
170171
[
171172
"git",
172173
"clone",
173174
"--progress",
174175
"https://github.com/rizinorg/rizin",
175176
target_path,
176177
],
177-
stderr=subprocess.STDOUT,
178+
stderr=STDOUT,
178179
):
179180
print_info(line)
180181

181182
return True
182183

183-
except subprocess.CalledProcessError:
184+
except CalledProcessError:
184185
print_error("An error occurred when downloading Rizin.\n")
185186

186187
except OSError:
@@ -205,48 +206,54 @@ def update_rizin(source_path, target_commit) -> Boolean:
205206
print()
206207

207208
# Checkout to target commit
208-
for line in execute_command(
209+
for line in _execute_command(
209210
["git", "checkout", target_commit], cwd=source_path
210211
):
211212
print_info(line)
212213

213214
# Remove the last build
214-
for line in execute_command(["rm", "-rf", "build"], cwd=source_path):
215+
for line in _execute_command(["rm", "-rf", "build"], cwd=source_path):
215216
print_info(line)
216217

217218
# Clean out old subproject
218-
for line in execute_command(
219+
for line in _execute_command(
219220
["git", "clean", "-dxff", "subprojects/"], cwd=source_path
220221
):
221222
print_info(line)
222223

223-
except subprocess.CalledProcessError as error:
224+
except CalledProcessError as error:
224225
print_error("An error occurred when updating Rizin.\n")
225226

226227
for line in error.stderr.decode().splitlines():
227228
print_error(line)
228229

229230
return False
231+
232+
except OSError as error:
233+
print_error("An error occurred when updating Rizin.\n")
234+
print_error(error)
235+
236+
return False
230237

231238
# Compile Rizin
232239
try:
233240
print()
234241

235242
# Configure
236-
for line in execute_command(
243+
for line in _execute_command(
237244
["meson", "--buildtype=release", "build"], cwd=source_path
238245
):
239246
print_info(line)
240247

241248
# Compile the source code
242-
for line in execute_command(
249+
for line in _execute_command(
243250
["meson", "compile", "-C", "build"], cwd=source_path
244251
):
245252
print_info(line)
246253

247254
return True
248255

249-
except subprocess.CalledProcessError as error:
256+
except CalledProcessError as error:
250257
pass
251258
except OSError:
252259
pass
@@ -286,13 +293,13 @@ def find_rizin_instance(
286293
# Search Rizin in PATH
287294
which_result = shutil.which("rizin")
288295
if which_result:
289-
version = get_rizin_version(which_result)
296+
version = _get_rizin_version(which_result)
290297
if version in COMPATIBLE_RAZIN_VERSIONS:
291298
return which_result
292299

293300
# Otherwise, search the home path
294301
rizin_executable_path = rizin_source_path + "build/binrz/rizin/rizin"
295-
current_version = get_rizin_version(rizin_executable_path)
302+
current_version = _get_rizin_version(rizin_executable_path)
296303

297304
if not current_version and not disable_rizin_installation:
298305
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)