Skip to content

Commit 18f00f8

Browse files
committed
dex
Signed-off-by: Prabhu Subramanian <[email protected]>
1 parent de264a3 commit 18f00f8

File tree

2 files changed

+36
-45
lines changed

2 files changed

+36
-45
lines changed

blint/android.py

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ def collect_version_files_metadata(app_file, app_temp_dir):
140140
rel_path = os.path.relpath(vf, app_temp_dir)
141141
group = ""
142142
name = ""
143-
version_data = ""
144143
if "_" in file_name:
145144
parts = file_name.split("_")
146145
name = file_name
@@ -286,50 +285,40 @@ def collect_dex_files_metadata(app_file, parent_component, app_temp_dir):
286285
evidence=ComponentEvidence(
287286
identity=Identity(
288287
field=FieldModel.purl,
289-
confidence=0.5,
288+
confidence=0.2,
290289
methods=[
291290
Method(
292291
technique=Technique.binary_analysis,
293292
value=rel_path,
294-
confidence=0.5,
293+
confidence=0.2,
295294
)
296295
],
297296
)
298297
),
299298
properties=[
300299
Property(name="internal:srcFile", value=rel_path),
301300
Property(name="internal:appFile", value=app_file),
302-
Property(
303-
name="internal:header",
304-
value=", ".join(dex_metadata.get("header")),
305-
),
306301
Property(
307302
name="internal:functions",
308-
value=", ".join(dex_metadata.get("methods")),
303+
value=", ".join(
304+
set(
305+
[
306+
f"""{m.name}({','.join([_clean_type(p.underlying_array_type) for p in m.prototype.parameters_type])}):{_clean_type(m.prototype.return_type.underlying_array_type)}"""
307+
for m in dex_metadata.get("methods")
308+
]
309+
)
310+
),
309311
),
310312
Property(
311313
name="internal:classes",
312-
value=", ".join(dex_metadata.get("classes")),
313-
),
314-
Property(
315-
name="internal:fields",
316-
value=", ".join(dex_metadata.get("fields")),
317-
),
318-
Property(
319-
name="internal:strings",
320-
value=", ".join(dex_metadata.get("strings")),
321-
),
322-
Property(
323-
name="internal:types",
324-
value=", ".join(dex_metadata.get("types")),
325-
),
326-
Property(
327-
name="internal:prototypes",
328-
value=", ".join(dex_metadata.get("prototypes")),
329-
),
330-
Property(
331-
name="internal:map",
332-
value=", ".join(dex_metadata.get("map")),
314+
value=", ".join(
315+
set(
316+
[
317+
_clean_type(c.fullname)
318+
for c in dex_metadata.get("classes")
319+
]
320+
)
321+
),
333322
),
334323
],
335324
)
@@ -338,6 +327,10 @@ def collect_dex_files_metadata(app_file, parent_component, app_temp_dir):
338327
return file_components
339328

340329

330+
def _clean_type(t):
331+
return str(t).replace("/", ".").removeprefix("L").removesuffix(";")
332+
333+
341334
def collect_files_metadata(app_file, parent_component, deep_mode):
342335
"""
343336
Unzip the app and collect metadata

blint/binary.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,19 @@ def parse_relro(parsed_obj):
9494
now = False
9595
try:
9696
parsed_obj.get(lief.ELF.SEGMENT_TYPES.GNU_RELRO)
97-
except lief.not_found:
97+
except lief.lief_errors.not_found:
9898
return "no"
9999
try:
100100
dynamic_tags = parsed_obj.get(lief.ELF.DYNAMIC_TAGS.FLAGS)
101101
if dynamic_tags:
102102
bind_now = lief.ELF.DYNAMIC_FLAGS.BIND_NOW in dynamic_tags
103-
except lief.not_found:
103+
except lief.lief_errors.not_found:
104104
pass
105105
try:
106106
dynamic_tags = parsed_obj.get(lief.ELF.DYNAMIC_TAGS.FLAGS_1)
107107
if dynamic_tags:
108108
now = lief.ELF.DYNAMIC_FLAGS_1.NOW in dynamic_tags
109-
except lief.not_found:
109+
except lief.lief_errors.not_found:
110110
pass
111111
if bind_now or now:
112112
return "full"
@@ -597,19 +597,19 @@ def parse(exe_file):
597597
if parsed_obj.get_symbol(section):
598598
metadata["has_canary"] = True
599599
break
600-
except lief.not_found:
600+
except lief.lief_errors.not_found:
601601
metadata["has_canary"] = False
602602
# rpath check
603603
try:
604604
if parsed_obj.get(lief.ELF.DYNAMIC_TAGS.RPATH):
605605
metadata["has_rpath"] = True
606-
except lief.not_found:
606+
except lief.lief_errors.not_found:
607607
metadata["has_rpath"] = False
608608
# runpath check
609609
try:
610610
if parsed_obj.get(lief.ELF.DYNAMIC_TAGS.RUNPATH):
611611
metadata["has_runpath"] = True
612-
except lief.not_found:
612+
except lief.lief_errors.not_found:
613613
metadata["has_runpath"] = False
614614
static_symbols = parsed_obj.static_symbols
615615
if len(static_symbols):
@@ -762,9 +762,7 @@ def parse(exe_file):
762762
metadata["subsystem"] = str(optional_header.subsystem).rsplit(
763763
".", maxsplit=1
764764
)[-1]
765-
metadata["is_gui"] = (
766-
True if metadata["subsystem"] == "WINDOWS_GUI" else False
767-
)
765+
metadata["is_gui"] = metadata["subsystem"] == "WINDOWS_GUI"
768766
metadata["exe_type"] = (
769767
"PE32"
770768
if optional_header.magic == PE.PE_TYPE.PE32
@@ -1038,7 +1036,7 @@ def parse(exe_file):
10381036
metadata["has_main_command"] = True
10391037
if parsed_obj.thread_command:
10401038
metadata["has_thread_command"] = True
1041-
except lief.not_found:
1039+
except lief.lief_errors.not_found:
10421040
metadata["has_main"] = False
10431041
metadata["has_thread_command"] = False
10441042
try:
@@ -1116,12 +1114,12 @@ def parse_dex(dex_file):
11161114
dexfile_obj = DEX.parse(dex_file)
11171115
metadata["version"] = dexfile_obj.version
11181116
metadata["header"] = dexfile_obj.header
1119-
metadata["classes"] = dexfile_obj.classes
1120-
metadata["fields"] = dexfile_obj.fields
1121-
metadata["methods"] = dexfile_obj.methods
1122-
metadata["strings"] = dexfile_obj.strings
1123-
metadata["types"] = dexfile_obj.types
1124-
metadata["prototypes"] = dexfile_obj.prototypes
1117+
metadata["classes"] = [cls for cls in dexfile_obj.classes]
1118+
metadata["fields"] = [f for f in dexfile_obj.fields]
1119+
metadata["methods"] = [m for m in dexfile_obj.methods]
1120+
metadata["strings"] = list(dexfile_obj.strings)
1121+
metadata["types"] = [t for t in dexfile_obj.types]
1122+
metadata["prototypes"] = [p for p in dexfile_obj.prototypes]
11251123
metadata["map"] = dexfile_obj.map
11261124
except Exception as e:
11271125
LOG.exception(e)

0 commit comments

Comments
 (0)