-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiskForensix.rb
More file actions
426 lines (343 loc) · 15 KB
/
DiskForensix.rb
File metadata and controls
426 lines (343 loc) · 15 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
require 'gtk3'
require 'shellwords'
require 'gdk_pixbuf2'
class SimpleEditor
def initialize
@window = Gtk::Window.new
@window.set_title("DiskForensix")
@window.set_default_size(800, 600)
@window.signal_connect("destroy") { Gtk.main_quit }
vbox = Gtk::Box.new(:vertical)
@window.add(vbox)
create_menu(vbox)
title_label = Gtk::Label.new("DiskForensix")
title_label.set_markup("<span font_desc='20'>DiskForensix</span>")
vbox.pack_start(title_label, expand: false, fill: false, padding: 10)
button_box = Gtk::Box.new(:horizontal, 10)
vbox.pack_start(button_box, expand: false, fill: false, padding: 10)
@create_image_button = Gtk::Button.new(label: "Create Image")
@create_image_button.set_size_request(150, 40) # Adjust button size
@create_image_button.signal_connect("clicked") { open_image_creation_dialog }
button_box.pack_start(@create_image_button, expand: false, fill: false, padding: 5)
button_box.set_halign(:center) # Center the button in the horizontal box
button_box.set_valign(:center)
@text_view = Gtk::TextView.new
@text_view.set_wrap_mode(:word)
@scrolled_window = Gtk::ScrolledWindow.new
@scrolled_window.add(@text_view)
@scrolled_window.set_policy(:automatic, :automatic)
vbox.pack_start(@scrolled_window, expand: true, fill: true, padding: 10)
# Open Image Button
@open_image_button = Gtk::Button.new(label: "Open Image")
@open_image_button.set_size_request(150, 40) # Adjust button size
@open_image_button.signal_connect("clicked") { open_image_dialog }
button_box.pack_start(@open_image_button, expand: false, fill: false, padding: 5)
version_label = Gtk::Label.new("Version 1.0.0")
version_label.set_margin_top(10)
vbox.pack_end(version_label, expand: false, fill: false, padding: 10)
@window.show_all
end
def create_menu(vbox)
menu_bar = Gtk::MenuBar.new
file_menu = Gtk::Menu.new
file_item = Gtk::MenuItem.new(label: "File")
file_item.set_submenu(file_menu)
exit_item = Gtk::MenuItem.new(label: "Exit")
exit_item.signal_connect("activate") { Gtk.main_quit }
file_menu.append(exit_item)
menu_bar.append(file_item)
# Tool Menu
tool_menu = Gtk::Menu.new
tool_item = Gtk::MenuItem.new(label: "Tool")
tool_item.set_submenu(tool_menu)
create_image_item = Gtk::MenuItem.new(label: "Create Image")
create_image_item.signal_connect("activate") { open_image_creation_dialog }
tool_menu.append(create_image_item)
show_hex_dump_item = Gtk::MenuItem.new(label: "Show Hex Dump")
show_hex_dump_item.signal_connect("activate") { open_image_dialog }
tool_menu.append(show_hex_dump_item)
menu_bar.append(tool_item)
# Help Menu
help_menu = Gtk::Menu.new
help_item = Gtk::MenuItem.new(label: "Help")
help_item.set_submenu(help_menu)
about_item = Gtk::MenuItem.new(label: "About")
about_item.signal_connect("activate") { open_about_dialog }
help_menu.append(about_item)
menu_bar.append(help_item)
vbox.pack_start(menu_bar, expand: false, fill: false, padding: 0)
end
def open_about_dialog
about_dialog = Gtk::AboutDialog.new
about_dialog.set_program_name("DiskForensix")
about_dialog.set_version("1.0.0")
about_dialog.set_license("GNU General Public License v3.0")
about_dialog.set_comments("A tool for forensic image creation and hex dumping.")
about_dialog.set_website("https://github.com/Ahmad-Rasheed-01/DiskForensix.git")
about_dialog.set_website_label("GitHub Repository")
logo_pixbuf_path = File.expand_path('/home/master_chief/Downloads/img.jpg') # Expand ~ to full path
if File.exist?(logo_pixbuf_path) # Check if the file exists
# Load the pixbuf from the file
original_pixbuf = GdkPixbuf::Pixbuf.new(file: logo_pixbuf_path)
scaled_pixbuf = original_pixbuf.scale_simple(100, 100, GdkPixbuf::InterpType::BILINEAR)
# Set the scaled pixbuf as the logo
about_dialog.set_logo(scaled_pixbuf)
else
puts "Logo file not found at #{logo_pixbuf_path}" # Debugging message if file is missing
end
about_dialog.run
about_dialog.destroy
end
def open_image_dialog
dialog = Gtk::FileChooserDialog.new(
title: "Select Image File",
parent: @window,
action: Gtk::FileChooserAction::OPEN,
buttons: [
[Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL],
[Gtk::Stock::OPEN, Gtk::ResponseType::ACCEPT]
]
)
if dialog.run == Gtk::ResponseType::ACCEPT
image_path = dialog.filename
# Properly escape the file path
escaped_image_path = Shellwords.escape(image_path)
# Run xxd command and capture output
xxd_output = `xxd #{escaped_image_path}`
show_xxd_output(xxd_output, image_path)
end
dialog.destroy
end
def show_xxd_output(xxd_output, image_path)
# Create a new window to show xxd output
xxd_window = Gtk::Window.new
xxd_window.set_title("xxd Output for #{image_path}")
xxd_window.set_default_size(600, 400)
vbox = Gtk::Box.new(:vertical)
xxd_window.add(vbox)
xxd_text_view = Gtk::TextView.new
xxd_text_view.set_wrap_mode(:word)
xxd_text_view.buffer.text = xxd_output
xxd_scrolled_window = Gtk::ScrolledWindow.new
xxd_scrolled_window.add(xxd_text_view)
xxd_scrolled_window.set_policy(:automatic, :automatic)
vbox.pack_start(xxd_scrolled_window, expand: true, fill: true, padding: 10)
close_button = Gtk::Button.new(label: "Close")
close_button.signal_connect("clicked") { xxd_window.destroy }
vbox.pack_start(close_button, expand: false, fill: false, padding: 10)
xxd_window.show_all
end
def open_image_creation_dialog
clear_paths
dialog = Gtk::Dialog.new(
title: "Create Forensic Image",
parent: @window,
flags: :modal
)
dialog.set_default_size(600, 400)
content_area = dialog.content_area
vbox = Gtk::Box.new(:vertical, 10)
content_area.add(vbox)
# Centered Evidence Item Information Button
info_button = Gtk::Button.new(label: "Add Evidence Item Information")
info_button.set_size_request(200, 40) # Adjust the width of the button
info_button.signal_connect("clicked") { open_evidence_info_dialog }
info_button_box = Gtk::Box.new(:horizontal)
info_button_box.pack_start(info_button, expand: false, fill: false, padding: 10)
info_button_box.set_halign(:start)
vbox.pack_start(info_button_box, expand: false, fill: false, padding: 10)
source_hbox = Gtk::Box.new(:horizontal, 10)
source_label = Gtk::Label.new("Image Source:")
@source_entry = Gtk::Entry.new
source_browse_button = Gtk::Button.new(label: "Browse")
source_browse_button.signal_connect("clicked") { select_source }
source_hbox.pack_start(source_label, expand: false, fill: false, padding: 5)
source_hbox.pack_start(@source_entry, expand: true, fill: true, padding: 5)
source_hbox.pack_start(source_browse_button, expand: false, fill: false, padding: 5)
vbox.pack_start(source_hbox, expand: false, fill: false, padding: 5)
destination_hbox = Gtk::Box.new(:horizontal, 10)
destination_label = Gtk::Label.new("Image Destination:")
@destination_entry = Gtk::Entry.new
destination_browse_button = Gtk::Button.new(label: "Browse")
destination_browse_button.signal_connect("clicked") { select_destination }
destination_hbox.pack_start(destination_label, expand: false, fill: false, padding: 5)
destination_hbox.pack_start(@destination_entry, expand: true, fill: true, padding: 5)
destination_hbox.pack_start(destination_browse_button, expand: false, fill: false, padding: 5)
vbox.pack_start(destination_hbox, expand: false, fill: false, padding: 5)
# Start Imaging Button
@start_button = Gtk::Button.new(label: "Start Imaging")
@start_button.set_size_request(150, 40) # Adjust button size
@start_button.sensitive = false
@start_button.signal_connect("clicked") do
dialog.response(Gtk::ResponseType::ACCEPT)
end
start_button_box = Gtk::Box.new(:horizontal)
start_button_box.pack_start(@start_button, expand: false, fill: false, padding: 10)
start_button_box.set_halign(:center)
start_button_box.set_valign(:center)
vbox.pack_start(start_button_box, expand: false, fill: false, padding: 10)
dialog.signal_connect("response") do |widget, response|
if response == Gtk::ResponseType::ACCEPT
@source_path = @source_entry.text
@destination_path = @destination_entry.text
# + " [raw/dd]"
create_forensic_image
end
dialog.destroy
end
dialog.signal_connect("destroy") do
clear_paths
end
dialog.show_all
end
def open_evidence_info_dialog
dialog = Gtk::Dialog.new(
title: "Evidence Item Information",
parent: @window,
flags: :modal
)
dialog.set_default_size(400, 300)
vbox = Gtk::Box.new(:vertical, 10)
dialog.content_area.add(vbox)
grid = Gtk::Grid.new
grid.set_row_spacing(10)
grid.set_column_spacing(10)
vbox.pack_start(grid, expand: false, fill: false, padding: 10)
# Case Number
case_number_hbox = Gtk::Box.new(:horizontal, 5)
case_number_label = Gtk::Label.new("Case Number:")
@case_number_entry = Gtk::Entry.new
case_number_hbox.pack_start(case_number_label, expand: false, fill: false, padding: 5)
case_number_hbox.pack_start(@case_number_entry, expand: true, fill: true, padding: 5)
grid.attach(case_number_hbox, 0, 0, 2, 1)
# Evidence Number
evidence_number_hbox = Gtk::Box.new(:horizontal, 5)
evidence_number_label = Gtk::Label.new("Evidence Number:")
@evidence_number_entry = Gtk::Entry.new
evidence_number_hbox.pack_start(evidence_number_label, expand: false, fill: false, padding: 5)
evidence_number_hbox.pack_start(@evidence_number_entry, expand: true, fill: true, padding: 5)
grid.attach(evidence_number_hbox, 0, 1, 2, 1)
# Examiner
examiner_hbox = Gtk::Box.new(:horizontal, 5)
examiner_label = Gtk::Label.new("Examiner:")
@examiner_entry = Gtk::Entry.new
examiner_hbox.pack_start(examiner_label, expand: false, fill: false, padding: 5)
examiner_hbox.pack_start(@examiner_entry, expand: true, fill: true, padding: 5)
grid.attach(examiner_hbox, 0, 2, 2, 1)
# Unique Description
description_hbox = Gtk::Box.new(:horizontal, 5)
description_label = Gtk::Label.new("Unique Description:")
@description_entry = Gtk::Entry.new
description_hbox.pack_start(description_label, expand: false, fill: false, padding: 5)
description_hbox.pack_start(@description_entry, expand: true, fill: true, padding: 5)
grid.attach(description_hbox, 0, 3, 2, 1)
# Notes
notes_hbox = Gtk::Box.new(:horizontal, 5)
notes_label = Gtk::Label.new("Notes:")
@notes_entry = Gtk::Entry.new
notes_hbox.pack_start(notes_label, expand: false, fill: false, padding: 5)
notes_hbox.pack_start(@notes_entry, expand: true, fill: true, padding: 5)
grid.attach(notes_hbox, 0, 4, 2, 1)
ok_button = Gtk::Button.new(label: "OK")
ok_button.set_size_request(100, -1) # Adjust the width to 100 pixels
ok_button_box = Gtk::Box.new(:horizontal)
ok_button_box.pack_start(ok_button, expand: false, fill: false, padding: 10)
# Center the ok_button_box within the dialog
ok_button_box.set_halign(:center)
ok_button_box.set_valign(:center)
ok_button.signal_connect("clicked") { dialog.response(Gtk::ResponseType::ACCEPT) }
vbox.pack_start(ok_button_box, expand: false, fill: false, padding: 10)
dialog.signal_connect("response") do |widget, response|
if response == Gtk::ResponseType::ACCEPT
# Handle the input data as needed
case_number = @case_number_entry.text
evidence_number = @evidence_number_entry.text
examiner = @examiner_entry.text
description = @description_entry.text
notes = @notes_entry.text
# Append evidence information to text view
@text_view.buffer.text = "Case Number: #{case_number}\n" \
"Evidence Number: #{evidence_number}\n" \
"Examiner: #{examiner}\n" \
"Unique Description: #{description}\n" \
"Notes: #{notes}\n" \
"---------------------------\n" \
"#{@text_view.buffer.text}"
# Reset the entries for next use
@case_number_entry.text = ""
@evidence_number_entry.text = ""
@description_entry.text = ""
@examiner_entry.text = ""
@notes_entry.text = ""
end
dialog.destroy
end
dialog.show_all
end
def select_source
source_dialog = Gtk::FileChooserDialog.new(
title: "Select Source",
parent: @window,
action: Gtk::FileChooserAction::OPEN,
buttons: [
[Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL],
[Gtk::Stock::OPEN, Gtk::ResponseType::ACCEPT]
]
)
if source_dialog.run == Gtk::ResponseType::ACCEPT
@source_path = source_dialog.filename
@source_entry.text = @source_path
check_paths
end
source_dialog.destroy
end
def select_destination
destination_dialog = Gtk::FileChooserDialog.new(
title: "Select Destination",
parent: @window,
action: Gtk::FileChooserAction::SAVE,
buttons: [
[Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL],
[Gtk::Stock::SAVE, Gtk::ResponseType::ACCEPT]
]
)
if destination_dialog.run == Gtk::ResponseType::ACCEPT
@destination_path = destination_dialog.filename
@destination_entry.text = @destination_path
check_paths
end
destination_dialog.destroy
end
def check_paths
if @source_path && @destination_path && !@start_button&.destroyed?
@start_button.sensitive = true
elsif @start_button && !@start_button.destroyed?
@start_button.sensitive = false
end
end
def clear_paths
@source_path = nil
@destination_path = nil
if @start_button && !@start_button.destroyed?
@start_button.sensitive = false
end
end
def create_forensic_image
if @source_path && @destination_path
create_image_command = "dd if='#{@source_path}' of='#{@destination_path}' bs=4M conv=sync,noerror"
@text_view.buffer.text = "Creating forensic image...\n\n" + @text_view.buffer.text
Thread.new do
system(create_image_command)
GLib::Idle.add do
@text_view.buffer.text = "Forensic image created successfully. #{@destination_path}\n" + @text_view.buffer.text
false
end
end
else
@text_view.buffer.text = "Source or destination path not selected.\n" + @text_view.buffer.text
end
end
end
Gtk.init
SimpleEditor.new
Gtk.main