-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRustDependencyStrings.py
More file actions
35 lines (26 loc) · 1003 Bytes
/
RustDependencyStrings.py
File metadata and controls
35 lines (26 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Extracts Rust crate dependency strings from a compiled Rust binary.
# @author Matt Ehrnschwender
# @category Search
import re
import string
import struct
from ghidra.program.database import *
unsigned_convert = lambda x: struct.unpack("B", struct.pack("b", x))[0]
regex_string = (
r".cargo(/|\\)registry(/|\\)src(/|\\).*?-[a-f0-9]{16}(/|\\)(.*?\d+.\d+.\d+)"
)
initialized_sections = filter(
lambda x: x.isInitialized(), currentProgram.getMemory().getBlocks()
)
rw_sections = filter(lambda x: x.getPermissions() & 1 == 0, initialized_sections)
string_data = ""
for section in rw_sections:
raw_bytes = [unsigned_convert(x) for x in section.getData().readAllBytes()]
printable_bytes = [chr(x) for x in raw_bytes if chr(x) in string.printable]
string_data += "".join(printable_bytes)
matches = sorted(set(re.findall(regex_string, string_data)))
if len(matches) > 0:
for match in matches:
print(match[-1])
else:
print("No Rust crate dependency strings found.")