Last active
March 22, 2024 20:09
-
-
Save ultimateshadsform/49693e756cd544cb35e73bcce17b3d47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import idautils | |
import tkinter as tk | |
import pyperclip | |
import re | |
def filter_strings(filter_string, exclude_patterns): | |
searched_strings = idautils.Strings() | |
filtered_strings = [] | |
try: | |
pattern = re.compile(filter_string) | |
except re.error: | |
return [], 0 # Return empty list if there's a regex syntax error | |
for string_item in searched_strings: | |
string = str(string_item) | |
if all(not re.match(exclude_pattern, string) for exclude_pattern in exclude_patterns): | |
if re.search(pattern, string): | |
filtered_strings.append(string) | |
return filtered_strings, len(filtered_strings) | |
def get_total_strings(): | |
searched_strings = idautils.Strings() | |
return len(list(searched_strings)) | |
def update_filtered_strings(listbox, filter_entry, label, exclude_listbox): | |
filter_string = filter_entry.get() | |
exclude_patterns = [exclude_listbox.get(idx) for idx in range(exclude_listbox.size())] | |
filtered_strings, total_count = filter_strings(filter_string, exclude_patterns) | |
listbox.delete(0, tk.END) | |
for string in filtered_strings: | |
listbox.insert(tk.END, string) | |
label.config(text=f"Total Strings: {total_count}") | |
def sort_strings(listbox, filter_entry, label, order, exclude_listbox): | |
filter_string = filter_entry.get() | |
exclude_patterns = [exclude_listbox.get(idx) for idx in range(exclude_listbox.size())] | |
filtered_strings, _ = filter_strings(filter_string, exclude_patterns) | |
filtered_strings.sort(reverse=(order == "Descending")) | |
listbox.delete(0, tk.END) | |
for string in filtered_strings: | |
listbox.insert(tk.END, string) | |
def copy_to_clipboard(listbox): | |
selected_strings = listbox.curselection() | |
strings_to_copy = [listbox.get(idx) for idx in selected_strings] | |
all_strings = '\n'.join(strings_to_copy) | |
pyperclip.copy(all_strings) | |
def unselect_all(event): | |
event.widget.selection_clear(0, tk.END) | |
def add_to_exclude_list(exclude_listbox, exclude_entry, listbox, filter_entry, label): | |
exclude_pattern = exclude_entry.get() | |
if exclude_pattern: | |
exclude_listbox.insert(tk.END, exclude_pattern) | |
exclude_entry.delete(0, tk.END) | |
update_filtered_strings(listbox, filter_entry, label, exclude_listbox) | |
def delete_selected_exclude(exclude_listbox, listbox, filter_entry, label): | |
selected_indices = exclude_listbox.curselection() | |
for index in selected_indices[::-1]: # Reverse order to avoid shifting indices | |
exclude_listbox.delete(index) | |
update_filtered_strings(listbox, filter_entry, label, exclude_listbox) | |
def show_filtered_strings(filtered_strings, total_count): | |
root = tk.Tk() | |
root.title("Filtered Strings") | |
label = tk.Label(root, text=f"Total Strings: {total_count}") | |
label.pack(padx=10, pady=5) | |
listbox = tk.Listbox(root, width=50, selectmode=tk.MULTIPLE) | |
listbox.pack(fill=tk.BOTH, expand=True, padx=10, pady=5) | |
listbox.bind('<Escape>', unselect_all) | |
for string in filtered_strings: | |
listbox.insert(tk.END, string) | |
def sort_ascending(): | |
sort_strings(listbox, filter_entry, label, "Ascending", exclude_listbox) | |
def sort_descending(): | |
sort_strings(listbox, filter_entry, label, "Descending", exclude_listbox) | |
def copy_selected(): | |
copy_to_clipboard(listbox) | |
tk.Button(root, text="Sort Ascending", command=sort_ascending).pack(padx=5, pady=5) | |
tk.Button(root, text="Sort Descending", command=sort_descending).pack(padx=5, pady=5) | |
tk.Button(root, text="Copy Selected to Clipboard", command=copy_selected).pack(padx=5, pady=5) | |
root.resizable(True, True) # Allow resizing in both dimensions | |
filter_entry = tk.Entry(root) | |
filter_entry.pack(padx=10, pady=5) | |
filter_entry.bind('<KeyRelease>', lambda event: update_filtered_strings(listbox, filter_entry, label, exclude_listbox)) | |
exclude_listbox = tk.Listbox(root, selectmode=tk.MULTIPLE) | |
exclude_listbox.pack(padx=10, pady=5) | |
exclude_listbox.bind('<Escape>', unselect_all) | |
exclude_listbox.bind('<Delete>', lambda event: delete_selected_exclude(exclude_listbox, listbox, filter_entry, label)) | |
exclude_entry = tk.Entry(root) | |
exclude_entry.pack(padx=10, pady=5) | |
tk.Button(root, text="Add to Exclude", command=lambda: add_to_exclude_list(exclude_listbox, exclude_entry, listbox, filter_entry, label)).pack(padx=5, pady=5) | |
root.mainloop() | |
if __name__ == '__main__': | |
filtered_strings, total_count = filter_strings('', []) | |
show_filtered_strings(filtered_strings, total_count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment