-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexe2bin.py
More file actions
260 lines (210 loc) · 9.52 KB
/
Copy pathexe2bin.py
File metadata and controls
260 lines (210 loc) · 9.52 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import tkinter as tk
from tkinter import ttk, filedialog, messagebox
import base64
import os
import threading
class ExeToBinConverter:
def __init__(self, root):
self.root = root
self.root.title("Exe to Binary Converter")
self.root.geometry("800x600")
self.root.resizable(True, True)
self.file_path = None
self.output_mode = tk.StringVar(value="base64")
self.setup_ui()
def setup_ui(self):
main_frame = ttk.Frame(self.root, padding="20")
main_frame.pack(fill=tk.BOTH, expand=True)
title_label = ttk.Label(
main_frame,
text="Exe to Binary Converter",
font=("Helvetica", 18, "bold")
)
title_label.pack(pady=(0, 20))
file_frame = ttk.Frame(main_frame)
file_frame.pack(fill=tk.X, pady=(0, 15))
ttk.Label(file_frame, text="Selected File:", font=("Helvetica", 10)).pack(side=tk.LEFT, padx=(0, 10))
self.file_entry = ttk.Entry(file_frame, width=50)
self.file_entry.pack(side=tk.LEFT, fill=tk.X, expand=True, padx=(0, 10))
self.browse_btn = ttk.Button(file_frame, text="Browse", command=self.browse_file)
self.browse_btn.pack(side=tk.LEFT)
options_frame = ttk.LabelFrame(main_frame, text="Output Format", padding="10")
options_frame.pack(fill=tk.X, pady=(0, 15))
self.base64_rb = ttk.Radiobutton(
options_frame,
text="Base64",
variable=self.output_mode,
value="base64",
command=self.convert_file
)
self.base64_rb.pack(side=tk.LEFT, padx=(0, 20))
self.hex_rb = ttk.Radiobutton(
options_frame,
text="Hexadecimal",
variable=self.output_mode,
value="hex",
command=self.convert_file
)
self.hex_rb.pack(side=tk.LEFT)
self.raw_rb = ttk.Radiobutton(
options_frame,
text="Raw Bytes",
variable=self.output_mode,
value="raw",
command=self.convert_file
)
self.raw_rb.pack(side=tk.LEFT, padx=(20, 0))
self.format_label = ttk.Label(options_frame, text="Format: BASE64", font=("Helvetica", 9, "italic"))
self.format_label.pack(side=tk.RIGHT)
output_frame = ttk.LabelFrame(main_frame, text="Output", padding="10")
output_frame.pack(fill=tk.BOTH, expand=True, pady=(0, 15))
self.output_text = tk.Text(
output_frame,
wrap=tk.WORD,
font=("Consolas", 9),
bg="#1e1e1e",
fg="#00ff00",
insertbackground="white"
)
self.output_text.pack(fill=tk.BOTH, expand=True)
scrollbar = ttk.Scrollbar(self.output_text, command=self.output_text.yview)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
self.output_text.config(yscrollcommand=scrollbar.set)
self.status_label = ttk.Label(main_frame, text="Ready. Select a file to convert.", font=("Helvetica", 9))
self.status_label.pack(pady=(0, 5))
self.progress_frame = ttk.Frame(main_frame)
self.progress_frame.pack(fill=tk.X, pady=(0, 5))
self.progress_label = ttk.Label(self.progress_frame, text="", font=("Helvetica", 8))
self.progress_label.pack(side=tk.LEFT)
self.progress_bar = ttk.Progressbar(self.progress_frame, mode="indeterminate", length=200)
self.progress_bar.pack(side=tk.RIGHT)
buttons_frame = ttk.Frame(main_frame)
buttons_frame.pack(fill=tk.X)
self.copy_btn = ttk.Button(buttons_frame, text="Copy to Clipboard", command=self.copy_to_clipboard)
self.copy_btn.pack(side=tk.LEFT, padx=(0, 10))
self.save_btn = ttk.Button(buttons_frame, text="Save as File", command=self.save_to_file)
self.save_btn.pack(side=tk.LEFT, padx=(0, 10))
self.clear_btn = ttk.Button(buttons_frame, text="Clear", command=self.clear_output)
self.clear_btn.pack(side=tk.LEFT)
info_label = ttk.Label(
buttons_frame,
text="ExeBin by Wulcato", #pls dont remove my name
font=("Helvetica", 8, "italic"),
foreground="gray"
)
info_label.pack(side=tk.RIGHT)
def browse_file(self):
file_types = [("Executable files", "*.exe"), ("All files", "*.*")]
filename = filedialog.askopenfilename(
initialdir=os.path.expanduser("~"),
title="Select an Executable",
filetypes=file_types
)
if filename:
self.file_path = filename
self.file_entry.delete(0, tk.END)
self.file_entry.insert(0, filename)
self.convert_file()
def convert_file(self):
if not self.file_path:
self.status_label.config(text="Please select a file first!")
return
self._set_converting_state(True)
thread = threading.Thread(target=self._convert_in_thread)
thread.daemon = True
thread.start()
def _set_converting_state(self, converting):
if converting:
self.status_label.config(text="Converting...")
self.progress_bar.start(10)
self.progress_label.config(text="Reading file...")
self.browse_btn.config(state="disabled")
self.copy_btn.config(state="disabled")
self.save_btn.config(state="disabled")
self.clear_btn.config(state="disabled")
self.base64_rb.config(state="disabled")
self.hex_rb.config(state="disabled")
self.raw_rb.config(state="disabled")
else:
self.progress_bar.stop()
self.progress_label.config(text="")
self.browse_btn.config(state="normal")
self.copy_btn.config(state="normal")
self.save_btn.config(state="normal")
self.clear_btn.config(state="normal")
self.base64_rb.config(state="normal")
self.hex_rb.config(state="normal")
self.raw_rb.config(state="normal")
def _convert_in_thread(self):
try:
with open(self.file_path, "rb") as f:
data = f.read()
mode = self.output_mode.get()
if mode == "base64":
output = base64.b64encode(data).decode("ascii")
format_text = "Format: BASE64"
elif mode == "hex":
output = data.hex()
format_text = "Format: HEXADECIMAL"
else:
output = " ".join(f"{b:02x}" for b in data)
format_text = "Format: RAW BYTES"
file_size = len(data)
output_len = len(output)
status_text = f"Converted: {file_size:,} bytes -> {output_len:,} chars ({mode.upper()})"
self.root.after(0, lambda: self._update_ui(output, format_text, status_text))
except Exception as e:
self.root.after(0, lambda: messagebox.showerror("Error", f"Failed to convert file:\n{str(e)}"))
self.root.after(0, lambda: self.status_label.config(text="Conversion failed!"))
self.root.after(0, lambda: self._set_converting_state(False))
def _update_ui(self, output, format_text, status_text):
self._set_converting_state(False)
self.format_label.config(text=format_text)
self.output_text.delete("1.0", tk.END)
self.output_text.insert("1.0", output)
self.status_label.config(text=status_text)
def copy_to_clipboard(self):
content = self.output_text.get("1.0", tk.END).strip()
if content:
self.root.clipboard_clear()
self.root.clipboard_append(content)
self.status_label.config(text="Copied to clipboard!")
self.root.after(2000, lambda: self.status_label.config(
text=f"Converted: {len(content):,} chars" if self.file_path else "Ready."
))
else:
messagebox.showwarning("Warning", "No content to copy!")
def save_to_file(self):
content = self.output_text.get("1.0", tk.END).strip()
if not content:
messagebox.showwarning("Warning", "No content to save!")
return
mode = self.output_mode.get()
ext = ".b64" if mode == "base64" else ".hex" if mode == "hex" else ".raw"
filename = filedialog.asksaveasfilename(
initialdir=os.path.dirname(self.file_path) if self.file_path else os.path.expanduser("~"),
title="Save Output",
defaultextension=ext,
filetypes=[
("Text files", "*.txt"),
("All files", "*.*")
]
)
if filename:
try:
with open(filename, "w", encoding="utf-8") as f:
f.write(content)
messagebox.showinfo("Success", f"Saved to:\n{filename}")
except Exception as e:
messagebox.showerror("Error", f"Failed to save file:\n{str(e)}")
def clear_output(self):
self.output_text.delete("1.0", tk.END)
self.file_entry.delete(0, tk.END)
self.file_path = None
self.status_label.config(text="Ready. Select a file to convert.")
def main():
root = tk.Tk()
app = ExeToBinConverter(root)
root.mainloop()
if __name__ == "__main__":
main()