Skip to content

Commit 918c9f4

Browse files
authored
Add a Shuriken-based core library (#697)
1 parent 178d72f commit 918c9f4

File tree

17 files changed

+1656
-274
lines changed

17 files changed

+1656
-274
lines changed

.github/workflows/pytest.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ jobs:
6060
sh install.sh -y
6161
cargo install project_ares
6262

63+
- name: Install Shuriken-Analyzer
64+
run: |
65+
pip install git+https://github.com/Fare9/Shuriken-Analyzer.git@main#subdirectory=shuriken/bindings/Python/
66+
6367
- name: Install Quark-Engine
6468
run: pip install .
6569

.github/workflows/smoke_test.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,17 @@ jobs:
4141
4242
# Install click <= 8.1.7 for CLI supports
4343
python -m pip install "click<=8.1.7"
44-
44+
45+
- name: Install Shuriken-Analyzer for Linux
46+
run: |
47+
pip install git+https://github.com/Fare9/Shuriken-Analyzer.git@main#subdirectory=shuriken/bindings/Python/
48+
if: matrix.os == 'ubuntu-latest'
49+
50+
- name: Install Shuriken-Analyzer for MacOS
51+
run: |
52+
pip install git+https://github.com/Fare9/Shuriken-Analyzer.git@main#subdirectory=shuriken/bindings/Python/
53+
if: matrix.os == 'macos-13'
54+
4555
- name: Install MacPorts
4656
uses: melusina-org/setup-macports@v1
4757
if: matrix.os == 'macos-13'

quark/cli.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@
133133
"--core-library",
134134
"core_library",
135135
help="Specify the core library used to analyze an APK",
136-
type=click.Choice(("androguard", "rizin", "radare2"), case_sensitive=False),
136+
type=click.Choice(
137+
("androguard", "rizin", "radare2", "shuriken"),
138+
case_sensitive=False
139+
),
137140
required=False,
138141
default="androguard",
139142
)

quark/core/apkinfo.py

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from androguard.core.bytecodes.dvm_types import Operand
1313
from androguard.misc import AnalyzeAPK, AnalyzeDex
1414

15-
from quark.core.interface.baseapkinfo import BaseApkinfo, XMLElement
15+
from quark.core.interface.baseapkinfo import BaseApkinfo
1616
from quark.core.struct.bytecodeobject import BytecodeObject
1717
from quark.core.struct.methodobject import MethodObject
1818
from quark.evaluator.pyeval import PyEval
@@ -21,7 +21,7 @@
2121
class AndroguardImp(BaseApkinfo):
2222
"""Information about apk based on androguard analysis"""
2323

24-
__slots__ = ("apk", "dalvikvmformat", "analysis")
24+
__slots__ = ("apk", "dalvikvmformat", "analysis", "_manifest")
2525

2626
def __init__(self, apk_filepath: Union[str, PathLike]):
2727
super().__init__(apk_filepath, "androguard")
@@ -32,55 +32,10 @@ def __init__(self, apk_filepath: Union[str, PathLike]):
3232
elif self.ret_type == "DEX":
3333
# return the sha256hash, DalvikVMFormat, and Analysis objects
3434
_, _, self.analysis = AnalyzeDex(apk_filepath)
35+
self._manifest = None
3536
else:
3637
raise ValueError("Unsupported File type.")
3738

38-
@property
39-
def permissions(self) -> List[str]:
40-
if self.ret_type == "APK":
41-
return self.apk.get_permissions()
42-
43-
if self.ret_type == "DEX":
44-
return []
45-
46-
@property
47-
def application(self) -> XMLElement:
48-
"""Get the application element from the manifest file.
49-
50-
:return: an application element
51-
"""
52-
if self.ret_type == "DEX":
53-
return []
54-
55-
manifest_root = self.apk.get_android_manifest_xml()
56-
57-
return manifest_root.find("application")
58-
59-
@property
60-
def activities(self) -> List[XMLElement]:
61-
if self.ret_type == "DEX":
62-
return []
63-
64-
manifest_root = self.apk.get_android_manifest_xml()
65-
application = manifest_root.find("application")
66-
67-
return application.findall("activity")
68-
69-
@property
70-
def receivers(self) -> List[XMLElement]:
71-
"""
72-
Return all receivers from the given APK.
73-
74-
:return: a list of all receivers
75-
"""
76-
if self.ret_type == "DEX":
77-
return []
78-
79-
manifest_root = self.apk.get_android_manifest_xml()
80-
application = manifest_root.find("application")
81-
82-
return application.findall("receiver")
83-
8439
@property
8540
def android_apis(self) -> Set[MethodObject]:
8641
apis = set()

quark/core/axmlreader/__init__.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# -*- coding: utf-8 -*-
2+
# This file is part of Quark-Engine - https://github.com/quark-engine/quark-engine
3+
# See the file 'LICENSE' for copying permission.
4+
15
import enum
26
import functools
37
import os.path
@@ -80,9 +84,9 @@ def __init__(self, message):
8084
super(AxmlException, self).__init__(message)
8185

8286

83-
class AxmlReader(object):
87+
class AxmlReader:
8488
"""
85-
A Class that parses the Android XML file
89+
A Class that parses the Android XML file using Rizin/Radare2
8690
"""
8791

8892
def __init__(self, file_path, core_library="rizin", structure_path=None):
@@ -205,6 +209,12 @@ def __init__(self, file_path, core_library="rizin", structure_path=None):
205209
if self._ptr >= self._axml_size:
206210
return
207211

212+
def __enter__(self):
213+
return self
214+
215+
def __exit__(self, exc_type, exc_val, exc_tb):
216+
pass
217+
208218
def __iter__(self) -> Iterator[ResChunkHeader]:
209219
"""Get an iterator that walks through the content of the Android XML
210220
binary.
@@ -373,7 +383,7 @@ def __convert_tag_to_xml_element(
373383

374384
return XMLElement(name, attributes)
375385

376-
def __find_manifest(
386+
def _find_manifest(
377387
self, chunk_iterator: Iterator[ResChunkHeader]
378388
) -> XMLElement:
379389
"""Find the resource chunk of the first XML label named manifest and
@@ -402,7 +412,7 @@ def get_xml_tree(self) -> XMLElementTree:
402412
:return: the content of the file
403413
"""
404414
file_iterator = iter(self)
405-
root = self.__find_manifest(file_iterator)
415+
root = self._find_manifest(file_iterator)
406416

407417
stack = [root]
408418
for tag in file_iterator:

0 commit comments

Comments
 (0)