This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathScares_Scrambler.py
1348 lines (1065 loc) · 49.5 KB
/
Scares_Scrambler.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
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!py -3.4
import tkinter as Tkinter
from tkinter import *
from tkinter import messagebox
from tkinter import ttk
from tkinter.filedialog import askopenfilename
import os
import random
'''Hello anyone reading this! Don't mind the disgusting code in some places. I'm not that good at coding, so don't expect it to work perfectly!
Anyways, hopefully you'll find some enjoyment messing around with this corrupter. Ciao!'''
buildNumber = "13"
versionNumber = "v1.1"
goodIcon = "favi16.ico"
root = Tk()
root.title("Scares Scrambler Build "+buildNumber)
root.geometry("310x600+100+100")
root.iconbitmap(goodIcon)
#root.resizable(width=False, height=False)
'''
Engines:
0 = Incrementer
1 = Randomizer
2 = Scrambler
3 = Copier
4 = Tilter
6 = Sentence Mixer (Text Only)
Unbinding is apparently possible: foo.unbind("<Button-1>")
showerror, showinfo, showwarning, _show? ~These are all message box types.
http://wiki.tcl.tk/37701 ~Hex codes work as well
font="Times"'''
currentEngine = 0
autoEndBool = False
exclusiveBool = False
hexadecimalMode = False
darkMode = False
blockSpaceState = "Linear"
fileName = ""
newFileName = ""
newPresetName = ""
cnameLabel = ""
allWidgets = []
dynamicWidgets = []
listOfEngines = ["Incrementer Algorithm", "Randomizer Algorithm", "Scrambler Algorithm ",
"Copier Algorithm ", "Tilter Algorithm ", "Mixer Algorithm "]
class entry_function_class:
def __init__(self, entryBox):
self.entryBox = entryBox
def left_click_function(self, event=None):
'''Increments the entries'''
try:
if hexadecimalMode:
incValue = incValueEntry.get()
entryBoxValue = self.entryBox.get()
incValue = hex_convert(incValue)
entryBoxValue = hex_convert(entryBoxValue)
entryBoxValue = int(entryBoxValue)
entryBoxValue += int(incValue)
self.entryBox.delete(0, "end")
if entryBoxValue < 0:
entryBoxValue = 0
entryBoxValue = hex_convert(entryBoxValue, hexMode=False)
else:
incValue = int(incValueEntry.get()) #Getting values
entryBoxValue = int(self.entryBox.get())
entryBoxValue += incValue #Setting values
self.entryBox.delete(0, "end")
if entryBoxValue < 0:
entryBoxValue = 0
self.entryBox.insert(0, entryBoxValue)
except ValueError:
messagebox.showwarning("What are you doing?", "Please use a whole number for"
" the increment value, thanks!")
def right_click_function(self, event=None):
'''Decrements the values'''
try:
if hexadecimalMode:
incValue = incValueEntry.get()
entryBoxValue = self.entryBox.get()
incValue = hex_convert(incValue)
entryBoxValue = hex_convert(entryBoxValue)
entryBoxValue = int(entryBoxValue)
entryBoxValue -= int(incValue)
self.entryBox.delete(0, "end")
if entryBoxValue < 0:
entryBoxValue = 0
entryBoxValue = hex_convert(entryBoxValue, hexMode=False)
else:
incValue = int(incValueEntry.get()) #Getting values
entryBoxValue = int(self.entryBox.get())
entryBoxValue -= incValue #Setting values
self.entryBox.delete(0, "end")
if entryBoxValue < 0:
entryBoxValue = 0
self.entryBox.insert(0, entryBoxValue)
except ValueError:
messagebox.showwarning("What are you doing?", "Please use a whole number for"
" the increment value, thanks!")
def generate_random_byte(self, event=None):
'''Generates a number between 1 and 255'''
self.entryBox.delete(0, "end")
if hexadecimalMode:
ran1 = random.randint(0, 15)
ran2 = random.randint(0, 15)
ran1 = singular_hex_convert(ran1)
ran2 = singular_hex_convert(ran2)
self.entryBox.insert(0, str(ran1)+str(ran2))
else:
self.entryBox.insert(0, random.randint(0, 255))
def change_engine_right(event=None):
global currentEngine
'''Changes the engine label'''
currentEngine += 1
if currentEngine > (len(listOfEngines)-1):
currentEngine = 0
engineLabel.config(text=listOfEngines[currentEngine])
update_layout()
def change_engine_left(event=None):
global currentEngine
'''Changes the engine label'''
currentEngine -= 1
if currentEngine < 0:
currentEngine = len(listOfEngines)-1
engineLabel.config(text=listOfEngines[currentEngine])
update_layout()
def hide_dynamic_widgets():
global dynamicWidgets
'''Hides dynamic widgets, dummy'''
for x in dynamicWidgets:
x.grid_forget()
def update_layout():
'''Updates the layout, dummy'''
#Do something with the allWidgets list later
hide_dynamic_widgets()
if currentEngine == 0: #Incrementer
blockSizeLabel.grid(row=5, column=0, pady=5, padx=5, sticky=E)
blockSizeEntry.grid(row=5, column=1, columnspan=2, pady=5)
blockSizeButton.grid(row=5, column=3, pady=5)
linearRadio.grid(row=6, column=0, pady=5)
exponentialRadio.grid(row=6, column=1, pady=5, sticky=E)
randomRadio.grid(row=6, column=3, pady=5, sticky=E)
blockSpaceLabel.grid(row=7, column=0, pady=5, padx=5, sticky=E)
blockSpaceEntry.grid(row=7, column=1, columnspan=2, pady=5)
blockSpaceButton.grid(row=7, column=3, pady=5)
addValueLabel.grid(row=8, column=0, pady=5, padx=5, sticky=E)
addValueEntry.grid(row=8, column=1, columnspan=2, pady=5)
addValueButton.grid(row=8, column=3, pady=5)
elif currentEngine == 1: #Randomizer
blockSizeLabel.grid(row=5, column=0, pady=5, padx=5, sticky=E)
blockSizeEntry.grid(row=5, column=1, columnspan=2, pady=5)
blockSizeButton.grid(row=5, column=3, pady=5)
linearRadio.grid(row=6, column=0, pady=5)
exponentialRadio.grid(row=6, column=1, pady=5, sticky=E)
randomRadio.grid(row=6, column=3, pady=5, sticky=E)
blockSpaceLabel.grid(row=7, column=0, pady=5, padx=5, sticky=E)
blockSpaceEntry.grid(row=7, column=1, columnspan=2, pady=5)
blockSpaceButton.grid(row=7, column=3, pady=5)
elif currentEngine == 2: #Scrambler
blockSizeLabel.grid(row=5, column=0, pady=5, padx=5, sticky=E)
blockSizeEntry.grid(row=5, column=1, columnspan=2, pady=5)
blockSizeButton.grid(row=5, column=3, pady=5)
linearRadio.grid(row=6, column=0, pady=5)
exponentialRadio.grid(row=6, column=1, pady=5, sticky=E)
randomRadio.grid(row=6, column=3, pady=5, sticky=E)
blockSpaceLabel.grid(row=7, column=0, pady=5, padx=5, sticky=E)
blockSpaceEntry.grid(row=7, column=1, columnspan=2, pady=5)
blockSpaceButton.grid(row=7, column=3, pady=5)
blockGapLabel.grid(row=8, column=0, pady=5, padx=5, sticky=E)
blockGapEntry.grid(row=8, column=1, columnspan=2, pady=5)
blockGapButton.grid(row=8, column=3, pady=5)
elif currentEngine == 3: #Copier
blockSizeLabel.grid(row=5, column=0, pady=5, padx=5, sticky=E)
blockSizeEntry.grid(row=5, column=1, columnspan=2, pady=5)
blockSizeButton.grid(row=5, column=3, pady=5)
linearRadio.grid(row=6, column=0, pady=5)
exponentialRadio.grid(row=6, column=1, pady=5, sticky=E)
randomRadio.grid(row=6, column=3, pady=5, sticky=E)
blockSpaceLabel.grid(row=7, column=0, pady=5, padx=5, sticky=E)
blockSpaceEntry.grid(row=7, column=1, columnspan=2, pady=5)
blockSpaceButton.grid(row=7, column=3, pady=5)
blockGapLabel.grid(row=8, column=0, pady=5, padx=5, sticky=E)
blockGapEntry.grid(row=8, column=1, columnspan=2, pady=5)
blockGapButton.grid(row=8, column=3, pady=5)
elif currentEngine == 4: #Tilter
blockSizeLabel.grid(row=5, column=0, pady=5, padx=5, sticky=E)
blockSizeEntry.grid(row=5, column=1, columnspan=2, pady=5)
blockSizeButton.grid(row=5, column=3, pady=5)
linearRadio.grid(row=6, column=0, pady=5)
exponentialRadio.grid(row=6, column=1, pady=5, sticky=E)
randomRadio.grid(row=6, column=3, pady=5, sticky=E)
blockSpaceLabel.grid(row=7, column=0, pady=5, padx=5, sticky=E)
blockSpaceEntry.grid(row=7, column=1, columnspan=2, pady=5)
blockSpaceButton.grid(row=7, column=3, pady=5)
replaceLabel.grid(row=8, column=0, pady=5, padx=5, sticky=E)
replaceEntry.grid(row=8, column=1, columnspan=2, pady=5)
replaceButton.grid(row=8, column=3, pady=5)
replaceWithLabel.grid(row=9, column=0, pady=5, padx=5, sticky=E)
replaceWithEntry.grid(row=9, column=1, columnspan=2, pady=5)
replaceWithButton.grid(row=9, column=3, pady=5)
replaceXCheck.grid(row=10, column=1, pady=5, padx=30, sticky=W, columnspan=2)
elif currentEngine == 5: #Mixer
mixerLabel.grid(row=5, column=0)
def auto_end_switch(event=None):
global autoEndBool
'''Yes'''
if autoEndBool:
autoEndBool = False
else:
autoEndBool = True
def exclusive_switch(event=None):
global exclusiveBool
'''Toggles the switch'''
if exclusiveBool:
exclusiveBool = False
else:
exclusiveBool = True
def hexadecimal_switch(event=None):
global hexadecimalMode
'''Toggles the switch'''
if hexadecimalMode:
hexadecimalMode = False
else:
hexadecimalMode = True
def check_for_period(text):
'''Checks to see if there's a period in the given text'''
isDot = False
for x in text:
if x == ".":
isDot = True
if isDot:
return True
else:
return False
def clear_newFileText(event):
'''Clears newFileText when it's clicked'''
global newFileText
newFileText.delete("1.0", END)
def enter_file(event=None):
global fileName
global userFileWindow
global userFileEntry
global newFileText
global fileName
global newFileName
global cnameLabel
'''Chooses the files to use during corrupting'''
userFileWindow = Tk()
userFileWindow.title("Enter filenames...")
userFileWindow.geometry("450x175+250+250")
userFileWindow.iconbitmap(goodIcon)
userFileWindow.resizable(width=False, height=False)
mainFrame = Frame(userFileWindow)
applyFrame = Frame(userFileWindow)
instLabel = Label(mainFrame, text="Select the file you wish to corrupt, and enter the name of the new file:")
cfileLabel = Label(mainFrame, text="File To Corrupt:")
if fileName == "":
cnameLabel = Label(mainFrame, text="No File Selected")
else:
cnameLabel = Label(mainFrame, text="..."+fileName[len(fileName)-25:])
userFileButton = Button(mainFrame, text="Select File")
nfileLabel = Label(mainFrame, text="New File:")
newFileText = Text(mainFrame)
applyButton = Button(applyFrame, text=" Apply ")
if darkMode:
userFileWindow.config(bg="#1c1c1c")
mainFrame.config(bg="#1c1c1c")
applyFrame.config(bg="#1c1c1c")
instLabel.config(bg="#1c1c1c", fg="#c8c8c8")
cfileLabel.config(bg="#1c1c1c", fg="#c8c8c8")
cnameLabel.config(bg="#1c1c1c", fg="#c8c8c8")
userFileButton.config(bg="#1c1c1c", fg="#c8c8c8", activebackground="#1c1c1c", activeforeground="#c8c8c8")
nfileLabel.config(bg="#1c1c1c", fg="#c8c8c8")
newFileText.config(bg="#1c1c1c", fg="#c8c8c8")
applyButton.config(bg="#1c1c1c", fg="#c8c8c8", activebackground="#1c1c1c", activeforeground="#c8c8c8")
userFileButton.bind("<Button-1>", select_file)
applyButton.bind("<Button-1>", get_file_name)
newFileText.config(width=25, height=1)
if newFileName == "":
newFileText.insert(END, "Enter new file name...")
else:
newFileText.insert(END, newFileName)
newFileText.bind("<Button-1>", clear_newFileText)
mainFrame.pack()
applyFrame.pack()
instLabel.grid(row=1, column=1, columnspan=10, padx=40, pady=10)
cfileLabel.grid(row=2, column=1, columnspan=2, padx=0, pady=5)
cnameLabel.grid(row=2, column=3, columnspan=5, padx=10, pady=5)
userFileButton.grid(row=2, column=8, padx=20, pady=5)
nfileLabel.grid(row=3, column=1, columnspan=2, padx=0, pady=5)
newFileText.grid(row=3, column=3, columnspan=5, padx=28, pady=5)
applyButton.grid(row=4, column=1, columnspan=1, padx=10, pady=15)
userFileWindow.mainloop()
def select_file(event=None):
global fileName
'''Opens an 'open' window to select the file to corrupt'''
fileName = askopenfilename()
cnameLabel.config(text="..."+fileName[len(fileName)-25:])
def get_file_name(event=None):
global userFileWindow
global userFileLabel
global newFileText
global newFileName
global fileName
'''Gets the file name that the user entered'''
newFileName = newFileText.get(1.0, END)
newFileName = newFileName[:-1]
if not check_for_period(newFileName):
for x in range(0, len(fileName)): #Getting the file extension
if fileName[len(fileName)-x-1] == ".":
newFileName += fileName[(-x-1):]
break
if len(fileName) <= 40:
userFileLabel.config(text=fileName)
else:
userFileLabel.config(text="..."+fileName[len(fileName)-40:])
userFileWindow.destroy()
def blockSpaceState_to_linear(event=None): #Now this is good coding
global blockSpaceState
global blockStateVar
'''Changes blockSpaceState to Linear'''
blockSpaceState = "Linear"
blockStateVar.set(1)
blockSpaceLabel.config(text="Block Space")
def blockSpaceState_to_exponential(event=None):
global blockSpaceState
global blockStateVar
'''Changes blockSpaceState to Exponential'''
blockSpaceState = "Exponential"
blockStateVar.set(2)
blockSpaceLabel.config(text="Exponent")
def blockSpaceState_to_random(event=None):
global blockSpaceState
global blockStateVar
'''Changes blockSpaceState to Random'''
blockSpaceState = "Random"
blockStateVar.set(3)
blockSpaceLabel.config(text="Upper Bound")
def about_program_window(event=None):
'''The about window'''
aboutWindow = Tk()
aboutWindow.title("About Scares Scrambler Build "+buildNumber+" "+"("+versionNumber+")")
aboutWindow.iconbitmap(goodIcon)
infoLabel = Label(aboutWindow, text="Program created by your man, Scares. Bugtested by only Telic.")
infoLabel2 = Label(aboutWindow, text="This is an open-source project, so feel free to mess around in the code and stuff.")
infoLabel3 = Label(aboutWindow, text="If you want to release your own modified version of this project, just credit me! :3")
infoLabel4 = Label(aboutWindow, text="I'd also like to extend a huge thank you to anyone who bothered to try this thing!")
infoLabel5 = Label(aboutWindow, text="I know this isn't the best corrupter out there, but I tried to make it as special as I could.")
infoLabel7 = Label(aboutWindow, text="Thank you for being a part of this project. Here's to another year of crappy software!")
if darkMode:
infoLabel.config(bg="#1c1c1c", fg="#c8c8c8")
infoLabel2.config(bg="#1c1c1c", fg="#c8c8c8")
infoLabel3.config(bg="#1c1c1c", fg="#c8c8c8")
infoLabel4.config(bg="#1c1c1c", fg="#c8c8c8")
infoLabel5.config(bg="#1c1c1c", fg="#c8c8c8")
infoLabel7.config(bg="#1c1c1c", fg="#c8c8c8")
aboutWindow.config(bg="#1c1c1c")
goodLogo = PhotoImage(master=aboutWindow, file="darkLogo.png")
infoLabel6 = Label(aboutWindow, image=goodLogo)
else:
goodLogo = PhotoImage(master=aboutWindow, file="logo.png")
infoLabel6 = Label(aboutWindow, image=goodLogo)
infoLabel.pack()
infoLabel2.pack()
infoLabel3.pack()
infoLabel4.pack()
infoLabel5.pack()
infoLabel6.pack()
infoLabel7.pack()
aboutWindow.mainloop()
def add_corrupt_engine(baseFile, corruptedFile, blockSpace, blockSize, addValue):
'''Does adding and subtracting'''
for y in range(0, blockSize): #Corrupting part
currentByte = baseFile.read(1) #Gets the byte
if currentByte == b"":
break
currentByte = int.from_bytes(currentByte, byteorder="big")
currentByte += addValue
if currentByte > 255 or currentByte < 0: #If it's bigger than a byte OR if it's a negative
currentByte = currentByte % 256
currentByte = (currentByte).to_bytes(1, byteorder="big")
corruptedFile.write(currentByte)
copy_file_contents(baseFile, corruptedFile, blockSpace) #The gap in between - Shoutout to Jason
def random_corrupt_engine(baseFile, corruptedFile, blockSpace, blockSize):
'''Does random byte changes'''
for y in range(0, blockSize): #Corrupting part
currentByte = baseFile.read(1) #Gets the byte
if currentByte == b"":
break
currentByte = int.from_bytes(currentByte, byteorder="big")
currentByte += random.randrange(0, 255)
if currentByte > 255: #If it's bigger than a byte
currentByte = currentByte % 256
currentByte = (currentByte).to_bytes(1, byteorder="big")
corruptedFile.write(currentByte)
copy_file_contents(baseFile, corruptedFile, blockSpace) #The gap in between
def scrambler_corrupt_engine(baseFile, corruptedFile, blockSpace, blockSize, blockGap):
'''Does scrambles to bytes'''
currentByteList1 = []
bufferList = []
currentByteList2 = []
for y in range(0,blockSize): #Corrupting part
currentByte = baseFile.read(1)
if currentByte == b"":
break
currentByteList1.append(currentByte) #Gets the bytes
for z in range(0, blockGap): #The gap in between
currentByte = baseFile.read(1)
if currentByte == b"":
break
bufferList.append(currentByte)
for y in range(0, blockSize): #Corrupting part
currentByte = baseFile.read(1)
if currentByte == b"":
break
currentByteList2.append(currentByte) #Gets the bytes
for x in currentByteList2:
corruptedFile.write(x)
for x in bufferList:
corruptedFile.write(x)
for x in currentByteList1:
corruptedFile.write(x)
copy_file_contents(baseFile, corruptedFile, blockSpace) #The gap in between
def copier_corrupt_engine(baseFile, corruptedFile, blockSpace, corruptEndByte, blockSize, blockGap):
'''Does copying stuff'''
currentByteList1 = []
bufferList = []
currentByteList2 = []
counter = 0
for y in range(0, blockSize):
currentByte = baseFile.read(1)
if currentByte == b"":
break
currentByteList1.append(currentByte)
for z in range(0, blockGap):
currentByte = baseFile.read(1)
if currentByte == b"":
break
bufferList.append(currentByte)
for y in range(0, blockSize):
currentByte = baseFile.read(1)
if currentByte == b"":
break
currentByteList2.append(currentByte)
if (blockGap * -1) > blockGap: #Negative
for x in currentByteList2:
if corruptedFile.tell() >= corruptEndByte:
break
corruptedFile.write(x)
for x in bufferList:
if corruptedFile.tell() >= corruptEndByte:
break
corruptedFile.write(x)
for x in currentByteList2:
if corruptedFile.tell() >= corruptEndByte:
break
corruptedFile.write(x)
else: #Positive
for x in currentByteList1:
if corruptedFile.tell() >= corruptEndByte:
break
corruptedFile.write(x)
for x in bufferList:
if corruptedFile.tell() >= corruptEndByte:
break
corruptedFile.write(x)
for x in currentByteList1:
if corruptedFile.tell() >= corruptEndByte:
break
corruptedFile.write(x)
copy_file_contents(baseFile, corruptedFile, blockSpace)
def tilter_corrupt_engine(baseFile, corruptedFile, blockSpace, blockSize, replace, replaceWith):
'''You know what it does by now'''
for y in range(0, blockSize): #Corrupting part
currentByte = baseFile.read(1) #Gets the byte
if currentByte == b"":
break
currentByte = int.from_bytes(currentByte, byteorder="big")
if exclusiveBool:
compareByte = replace
if currentByte == compareByte:
currentByte = replaceWith
else:
currentByte = replaceWith
currentByte = (currentByte).to_bytes(1, byteorder="big")
corruptedFile.write(currentByte)
copy_file_contents(baseFile, corruptedFile, blockSpace)
def copy_file_contents(baseFile, corruptedFile, endValue):
'''For copying uncorrupted parts of a file'''
for z in range(0, endValue): #The gap in between
currentByte = baseFile.read(1)
corruptedFile.write(currentByte) #The gap in between
def hex_convert(number, isFloat=False, hexMode=True):
'''Converts the input to hexadecimal, or to a number'''
newNum = ""
if not hexMode: #Convert number to hex
keepGoing = True
counter = 0
while keepGoing: #Checking to see the highest power of 16 that can go into the number
if number//16**counter == 0:
keepGoing = False
else:
counter += 1
keepGoing = True
counter = counter - 1
tempNum = 0
number2 = number
while keepGoing: #Subtract multiples of powers of 16 to get the hex representation
tempNum = number2//16**counter
tempNum = singular_hex_convert(tempNum)
newNum += str(tempNum)
tempNum2 = hex_convert(str(tempNum))
number2 -= 16**counter*tempNum2
counter -= 1 #Fuck you
if counter == -1:
keepGoing = False
else: #Convert hex to number
if number[0] == "-":
newNum = "-0x" + number[1:]
else:
newNum = "0x" + number
newNum = float.fromhex(newNum)
if not isFloat:
newNum = int(newNum)
return newNum
def singular_hex_convert(n):
'''Converts the numbers 10 to 16 to hex'''
newN = n
if n == 10:
newN = "a"
elif n == 11:
newN = "b"
elif n == 12:
newN = "c"
elif n == 13:
newN = "d"
elif n == 14:
newN = "e"
elif n == 15:
newN = "f"
return newN
def corrupt_file(event=None):
global newFileName
'''Corrupts the chosen file'''
nullCounter2 = 0
try:
if hexadecimalMode: #Changing hexadecimal values to ints
startValue = hex_convert(startValueEntry.get())
if not autoEndBool:
endValue = hex_convert(endValueEntry.get())
blockSize = hex_convert(blockSizeEntry.get())
if blockSpaceState == "Exponential":
blockSpace = hex_convert(blockSpaceEntry.get(), True)
else:
blockSpace = hex_convert(blockSpaceEntry.get())
blockSize = hex_convert(blockSizeEntry.get())
if currentEngine == 0:
addValue = hex_convert(addValueEntry.get())
elif currentEngine == 2 or currentEngine == 3:
blockGap = hex_convert(blockGapEntry.get())
elif currentEngine == 4:
replace = hex_convert(replaceEntry.get())
replaceWith = hex_convert(replaceWithEntry.get())
else:
startValue = int(startValueEntry.get())
if not autoEndBool:
endValue = int(endValueEntry.get())
blockSize = int(blockSizeEntry.get())
if blockSpaceState == "Exponential":
blockSpace = float(blockSpaceEntry.get())
else:
blockSpace = int(float(blockSpaceEntry.get()))
blockSize = int(blockSizeEntry.get())
if currentEngine == 0:
addValue = int(addValueEntry.get())
if currentEngine == 2 or currentEngine == 3:
blockGap = int(blockGapEntry.get())
if currentEngine == 4:
replace = int(replaceEntry.get())
replaceWith = int(replaceWithEntry.get())
if fileName == "":
messagebox.showinfo("Woah there buddy!", "You need to select a file first before"
" you corrupt it! Press Alt+F to select a file.")
else:
baseFile = open(fileName, "rb+")
if newFileName == "":
corruptedFile = open("CorruptedFile.txt", "wb+")
else:
corruptedFile = open(newFileName, "wb+")
baseFile.seek(startValue) #Goto the start byte
if not autoEndBool: #If auto end is turned off
corruptEndByte = endValue
else: #If auto end is on
nullCounter = startValue
while True:
nullTester = baseFile.read(1)
if nullTester != b"": #If the byte isn't empty
nullCounter = baseFile.tell()
else:
break
corruptEndByte = nullCounter
baseFile.seek(0) #Goto the start byte
if currentEngine <= 5: #All current engines
copy_file_contents(baseFile, corruptedFile, startValue)
if blockSpaceState == "Linear":
corruptStepSize = blockSize + blockSpace
for x in range(startValue, corruptEndByte, corruptStepSize): #Through the file
if currentEngine == 0:
add_corrupt_engine(baseFile, corruptedFile, blockSpace, blockSize, addValue)
elif currentEngine == 1:
random_corrupt_engine(baseFile, corruptedFile, blockSpace, blockSize)
elif currentEngine == 2:
scrambler_corrupt_engine(baseFile, corruptedFile, blockSpace, blockSize, blockGap)
elif currentEngine == 3:
copier_corrupt_engine(baseFile, corruptedFile, blockSpace, corruptEndByte, blockSize, blockGap)
elif currentEngine == 4:
tilter_corrupt_engine(baseFile, corruptedFile, blockSpace, blockSize, replace, replaceWith)
elif blockSpaceState == "Exponential":
nullCounter = baseFile.tell()
exponentPower = blockSpace
exponentCounter = 1
exponentCap = False
exponentCapValue = 1000000
while nullCounter < corruptEndByte: #Through the file
try: #Fixes the exponent from getting too big
if int(exponentCounter**exponentPower) > exponentCapValue: #If exponent is too big
exponentCap = True
except OverflowError:
exponentCap = True
if not exponentCap:
if currentEngine == 0:
add_corrupt_engine(baseFile, corruptedFile, int(exponentCounter**exponentPower), blockSize, addValue)
elif currentEngine == 1:
random_corrupt_engine(baseFile, corruptedFile, int(exponentCounter**exponentPower), blockSize)
elif currentEngine == 2:
scrambler_corrupt_engine(baseFile, corruptedFile, int(exponentCounter**exponentPower), blockSize, blockGap)
elif currentEngine == 3:
copier_corrupt_engine(baseFile, corruptedFile, int(exponentCounter**exponentPower), corruptEndByte, blockSize, blockGap)
elif currentEngine == 4:
tilter_corrupt_engine(baseFile, corruptedFile, int(exponentCounter**exponentPower), blockSize, replace, replaceWith)
else:
if currentEngine == 0:
add_corrupt_engine(baseFile, corruptedFile, exponentCapValue, blockSize, addValue)
elif currentEngine == 1:
random_corrupt_engine(baseFile, corruptedFile, exponentCapValue, blockSize)
elif currentEngine == 2:
scrambler_corrupt_engine(baseFile, corruptedFile, exponentCapValue, blockSize, blockGap)
elif currentEngine == 3:
copier_corrupt_engine(baseFile, corruptedFile, exponentCapValue, corruptEndByte, blockSize, blockGap)
elif currentEngine == 4:
tilter_corrupt_engine(baseFile, corruptedFile, exponentCapValue, blockSize, replace, replaceWith)
if exponentCap:
nullCounter += exponentCapValue
else:
nullCounter += int(exponentCounter**exponentPower)
exponentCounter += 1
elif blockSpaceState == "Random":
nullCounter = startValue
if blockSpace == 0: #Prevents random number from being zero
blockSpace = 1
while nullCounter < corruptEndByte: #Through the file
tempRand = random.randrange(0, blockSpace+1)
if currentEngine == 0:
add_corrupt_engine(baseFile, corruptedFile, tempRand, blockSize, addValue)
elif currentEngine == 1:
random_corrupt_engine(baseFile, corruptedFile, tempRand, blockSize)
elif currentEngine == 2:
scrambler_corrupt_engine(baseFile, corruptedFile, tempRand, blockSize, blockGap)
elif currentEngine == 3:
copier_corrupt_engine(baseFile, corruptedFile, tempRand, corruptEndByte, blockSize, blockGap)
elif currentEngine == 4:
tilter_corrupt_engine(baseFile, corruptedFile, tempRand, blockSize, replace, replaceWith)
nullCounter += tempRand
while True: #This finishes the uncorrupted part
currentByte = baseFile.read(1)
if currentByte == b"":
break
corruptedFile.write(currentByte)
baseFile.close()
corruptedFile.close()
except ValueError:
messagebox.showwarning("Woah there partner!", "The values you entered were not valid. Make sure that all the values were entered correctly. "
"Some values can't be decimals, so uh... check that as well.")
except IndexError:
messagebox.showwarning("Woah there partner!", "Make sure to fill in the required values!")
def save_presets_window(event=None):
global newPresetName
global newPresetEntry
global newPresetWindow
'''The UI for saving a preset'''
newPresetWindow = Tk()
newPresetWindow.title("Enter preset name...")
newPresetWindow.geometry("300x100+250+250")
newPresetWindow.iconbitmap(goodIcon)
newPresetWindow.resizable(width=False, height=False)
newPresetName = ""
newPresetLabel = Label(newPresetWindow, text="Enter the name of the new preset file:")
newPresetEntry = Entry(newPresetWindow)
newPresetButton = Button(newPresetWindow, text=" Ok ")
newPresetButton.bind("<Button-1>", save_presets)
if darkMode:
newPresetWindow.config(bg="#1c1c1c")
newPresetEntry.config(bg="#1c1c1c", fg="#c8c8c8")
newPresetLabel.config(bg="#1c1c1c", fg="#c8c8c8")
newPresetButton.config(bg="#1c1c1c", fg="#c8c8c8", activebackground="#1c1c1c", activeforeground="#c8c8c8")
newPresetLabel.pack()
newPresetEntry.pack()
newPresetButton.pack()
newPresetWindow.mainloop()
def save_presets(event=None):
global newPresetEntry
'''Saves the presets to a text file'''
presetList = []
presetList.append("~~preset~~")
presetList.append(fileName)
presetList.append(newFileName)
presetList.append(startValueEntry.get())
presetList.append(endValueEntry.get())
presetList.append(incValueEntry.get())
presetList.append(autoEndBool)
presetList.append(blockSizeEntry.get())
presetList.append(blockSpaceState)
presetList.append(blockSpaceEntry.get())
presetList.append(addValueEntry.get())
presetList.append(blockGapEntry.get())
presetList.append(exclusiveBool)
presetList.append(replaceEntry.get())
presetList.append(replaceWithEntry.get())
presetList.append(hexadecimalMode)
name = newPresetEntry.get()
if name[-4:] == ".txt": #If there's a file extension
presetFile = open(name, "w")
for x in presetList:
presetFile.write(str(x))
presetFile.write("\n")
presetFile.close()
else:
presetFile = open(name+".txt", "w")
for x in presetList:
presetFile.write(str(x))
presetFile.write("\n")
presetFile.close()
newPresetWindow.destroy()
def load_presets(event=None, coolName=""):
global fileName
global newFileName
global startValueEntry
global endValueEntry
global incValueEntry
global autoEndBool
global autoEndVar
global autoEndCheck
global blockSizeEntry
global blockSpaceState
global blockSpaceEntry
global addValueEntry
global blockGapEntry
global exclusiveBool
global exclusiveVar
global replaceEntry
global replaceWithEntry
global hexadecimalMode
global hexVar
global userFileLabel
'''Loads the presets from the text file'''
#Fix all the try/excepts later
manualSelect = False
try:
if coolName == "": #If no name was entered
presetFile = askopenfilename()
presetFile = open(presetFile, "r")
manualSelect = True
else: #Use the name given
presetFile = open(coolName, "r")
try:
tempVar = ""
tag = presetFile.readline()
if tag == "~~preset~~\n":
fileName = presetFile.readline()[:-1]
newFileName = presetFile.readline()[:-1]
startValueEntry.delete(0, END)
startValueEntry.insert(0, presetFile.readline()[:-1])
endValueEntry.delete(0, END)
endValueEntry.insert(0, presetFile.readline()[:-1])
incValueEntry.delete(0, END)
incValueEntry.insert(0, presetFile.readline()[:-1])
tempVar = presetFile.readline()
if tempVar[:len(tempVar)-1] == "True":
autoEndBool = True
autoEndVar.set(1)
elif tempVar[:len(tempVar)-1] == "False":
autoEndBool = False
autoEndVar.set(0)
blockSizeEntry.delete(0, END)
blockSizeEntry.insert(0, presetFile.readline()[:-1])
blockSpaceState = presetFile.readline()[:-1]
if blockSpaceState == "Linear":
blockSpaceState_to_linear()
elif blockSpaceState == "Exponential":
blockSpaceState_to_exponential()
elif blockSpaceState == "Random":
blockSpaceState_to_random()
blockSpaceEntry.delete(0, END)
blockSpaceEntry.insert(0, presetFile.readline()[:-1])
addValueEntry.delete(0, END)
addValueEntry.insert(0, presetFile.readline()[:-1])
blockGapEntry.delete(0, END)
blockGapEntry.insert(0, presetFile.readline()[:-1])
tempVar = presetFile.readline()
if tempVar[:len(tempVar)-1] == "True":
exclusiveBool = True
exclusiveVar.set(1)
elif tempVar[:len(tempVar)-1] == "False":
exclusiveBool = False
exclusiveVar.set(0)