-
Notifications
You must be signed in to change notification settings - Fork 3
/
ExtractStrings.py
29 lines (24 loc) · 1.04 KB
/
ExtractStrings.py
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
def extract_strings(filename):
# Open the output file for writing
with open(filename, "w") as f:
# Iterate through all segments
for seg_ea in Segments():
# Get segment name
seg_name = SegName(seg_ea)
# Check if segment is readable
if IsSegmentReadable(seg_ea):
# Iterate through each head (instruction or data) within the segment
for head_ea in Heads(seg_ea, SEARCH_ALL):
# Get string information
str_type = idc.GetStringType(head_ea)
str_len = idc.GetStringLength(head_ea)
# Check if it's a valid string type
if str_type in [ASCIISTR_TYPE, UNICODE_STR_TYPE, UTF16_STR_TYPE]:
# Read the string data
str_data = idc.GetString(head_ea)
# Write the string with segment name (optional)
f.write(f"{seg_name}: {str_data}\n") # Modify formatting as needed
# Example usage:
filename = "extracted_strings.txt" # Replace with your desired filename
extract_strings(filename)
print(f"Extracted strings written to: {filename}")