-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathScrambler.py
1398 lines (1115 loc) · 58.7 KB
/
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
#!/usr/bin/env python3
import os, platform, glob
import random
import tkinter as Tkinter
from tkinter import *
from tkinter import (Tk, messagebox)
from tkinter.filedialog import askopenfilename
from Engine import * #Import all the important classes I made haha
from Themes import *
'''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
and/or look pretty! Anyways, hopefully you'll find some enjoyment messing around with this corrupter. Have fun!'''
buildNumber = "22"
versionNumber = "v1.22"
goodIcon = "Assets/favi.ico" if (os.name == 'nt') else "@Assets/favi.xbm"
#os.getcwd() to get working directory
#Thank you Russel Dias from https://stackoverflow.com/questions/5137497
root = Tk()
root.title("Scares Scrambler Build "+buildNumber)
root.geometry("+100+100")
root.iconbitmap(goodIcon)
# root.resizable(width=False, height=False)
'''
Engines:
0 = Incrementer
1 = Randomizer
2 = Scrambler
3 = Copier
4 = Tilter
5 = Smoother
6 = Blender
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 = IntVar() #Haha
currentEngine.set(1) #Set to incrememnter
previousEngine = currentEngine.get() #So that we can clear the window
hexadecimalMode = False
fileName = ""
newFileName = ""
oldFileName = ""
newPresetName = ""
cnameLabel = ""
stopCorrupt = False #Variable to stop corrupting if needed
newFolder = False #Says whether a new folder is to be created for "Corrupt&Repeat"
nowCorrupting = False #Tells whether we're corrupting
def switch_algorithm(event=None):
'''The function that's called when the algorithm switches'''
global previousEngine
global engineLabel
whiteSpace = 25-len(algorithms[currentEngine.get()-1].name)
if whiteSpace < 0:
whiteSpace = 0
engineLabel["text"]=algorithms[currentEngine.get()-1].name+whiteSpace*" "
algorithms[previousEngine-1].hide_layout()
algorithms[currentEngine.get()-1].display_layout(colorList)
previousEngine = currentEngine.get() #Preparing for next switch
def auto_end_switch(event=None):
'''Calculates the end of the selected file automatically'''
if fileName != "":
size = os.path.getsize(fileName)
endValueEntry.delete(0, "end")
if hexadecimalMode:
size = hex_convert(size)
endValueEntry.insert(0, size)
def toggle_newFolder(event=None):
'''Toggles the value for newFolder'''
global newFolder
if newFolder:
newFolder = False
else:
newFolder = True
def get_value(entry, isInt=True):
'''Gets the value from an entry, and converts to decimal if necessary'''
if entry.get() != "": #Preventing erros while switching between hex and dec
if hexadecimalMode:
if isInt:
return int(float.fromhex(entry.get()))
else:
return float.fromhex(entry.get())
else:
if isInt:
try:
return int(entry.get())
except:
return float(entry.get()) #Fixing problems with exponential
else:
return float(entry.get())
else:
return ""
def hexadecimal_switch(event=None, switchTo=None):
global hexadecimalMode
'''Toggles the switch'''
#"Hex" or "Dec"
if switchTo == "Hex" and hexadecimalMode: #Prevents invalid values from going into functions
pass
elif switchTo == "Dec" and not hexadecimalMode:
pass
elif switchTo == "Dec":
for x in algorithms: #Converts hexes already in entries to decimals
x.hexadecimalMode = False #Changing each algorithm's internal switch
hexadecimalMode = False
elif switchTo == "Hex":
for x in algorithms: #Converts decimals in entries to hexes
x.hexadecimalMode = True #Changing each algorithm's internal switch
hexadecimalMode = True
elif hexadecimalMode and switchTo == None:
for x in algorithms: #Converts hexes already in entries to decimals
x.hexadecimalMode = False #Changing each algorithm's internal switch
for y in x.entries:
nonHex = get_value(y[1], isInt=False)
if nonHex != "": #Preventing errors when switching between hex and dec
if nonHex == int(nonHex): #Changing to ints if necessary
y[1].delete(0, END)
y[1].insert(0, int(nonHex))
else:
y[1].delete(0, END)
y[1].insert(0, nonHex)
nonHex = get_value(startValueEntry, isInt=True)
startValueEntry.delete(0, END)
startValueEntry.insert(0, nonHex)
nonHex = get_value(endValueEntry, isInt=True)
endValueEntry.delete(0, END)
endValueEntry.insert(0, nonHex)
nonHex = get_value(incValueEntry, isInt=True)
incValueEntry.delete(0, END)
incValueEntry.insert(0, nonHex)
hexadecimalMode = False
elif not hexadecimalMode and switchTo == None:
for x in algorithms: #Converts decimals in entries to hexes
x.hexadecimalMode = True #Changing each algorithm's internal switch
for y in x.entries:
coolHex = hex_convert(y[1].get())
y[1].delete(0, END)
y[1].insert(0, coolHex)
coolHex = hex_convert(startValueEntry.get())
startValueEntry.delete(0, END)
startValueEntry.insert(0, coolHex)
coolHex = hex_convert(endValueEntry.get())
endValueEntry.delete(0, END)
endValueEntry.insert(0, coolHex)
coolHex = hex_convert(incValueEntry.get())
incValueEntry.delete(0, END)
incValueEntry.insert(0, coolHex)
hexadecimalMode = True
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 = Toplevel()
userFileWindow.title("Enter filenames...")
userFileWindow.geometry("+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\n"
"(You may need to use the arrow keys to scroll the textbox):")
cfileLabel = Label(mainFrame, text="File To Corrupt:")
if fileName == "":
cnameLabel = Label(mainFrame, text="No File Selected")
else:
t = shorten_text(fileName, 25, "Front")
cnameLabel = Label(mainFrame, text=t)
userFileButton = Button(mainFrame, text="Select File")
nfileLabel2 = Label(mainFrame, text="New File Name:")
newFileButton = Button(mainFrame, text="Select Folder")
newFileText = Text(mainFrame)
if newFileName == "":
newFileText.insert(END, "Enter new file name...")
newFileText.bind("<Button-1>", lambda x: clear_textWidget(x, newFileText, "Enter new file name..."))
else:
newFileText.insert(END, newFileName)
applyButton = Button(applyFrame, text=" Apply ")
userFileWindow.config(bg=colorList[2])
mainFrame.config(bg=colorList[2])
applyFrame.config(bg=colorList[2])
instLabel.config(bg=colorList[2], fg=colorList[1])
cfileLabel.config(bg=colorList[2], fg=colorList[1])
cnameLabel.config(bg=colorList[2], fg=colorList[1])
userFileButton.config(bg=colorList[2], fg=colorList[1], activebackground=colorList[2], activeforeground=colorList[1])
nfileLabel2.config(bg=colorList[2], fg=colorList[1])
newFileText.config(bg=colorList[0], fg=colorList[1], insertbackground=colorList[1], selectbackground=colorList[5])
newFileButton.config(bg=colorList[2], fg=colorList[1], activebackground=colorList[2], activeforeground=colorList[1])
applyButton.config(bg=colorList[2], fg=colorList[1], activebackground=colorList[2], activeforeground=colorList[1])
userFileButton.bind("<Button-1>", select_file)
newFileButton.bind("<Button-1>", lambda _: folder_selector([newFileText]))
applyButton.bind("<Button-1>", lambda _: get_file_name(newFileText))
newFileText.config(width=25, height=1)
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)
newFileButton.grid(row=3, column=8, padx=5, pady=5)
nfileLabel2.grid(row=3, column=1, columnspan=2, padx=5, 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.bind("<Return>", lambda _: get_file_name(newFileText))
def select_file(event=None):
global fileName
'''Opens an 'open' window to select the file to corrupt'''
fileName = askopenfilename()
if not fileName:
return
cnameLabel["text"] = shorten_text(fileName, 25, "Front")
if autoEndVar.get() == 1: #If the user requests to always get auto ends
auto_end_switch()
def get_file_name(text, event=None):
global userFileWindow
global userFileLabel
#global newFileText
global newFileName
global oldFileName
global fileName
'''Gets the file name that the user entered'''
newFileName = text.get(1.0, END)[:-1]
if newFileName == ("Enter new file name..." or newFileName == "") and fileName == "":
newFileName = ""
elif newFileName == "Enter new file name..." or newFileName == "":
newFileName = "CorruptedFile" #Default file name
p = check_for_char(newFileName)
if p == False:
pp = check_for_char(fileName)
newFileName += fileName[pp:]
#print(newFileName)
p = check_for_char(newFileName, "\n")
if p != False:
if p == -1:
newFileName = newFileName[1:] #Removing any newlines from pressing enter
else:
newFileName = newFileName[:p] + newFileName[p+1:] #Removing any newlines from pressing enter
if fileName == "":
userFileLabel.config(text="No file loaded. Press Alt+F to load one!")
else:
hide_userFileLabel()
oldFileName = newFileName #Saving oldFileName so that it won't get lost
userFileWindow.destroy()
def about_program_window(event=None):
'''The about window'''
aboutWindow = Toplevel()
aboutWindow.title("About Scares Scrambler Build "+buildNumber+" "+"("+versionNumber+")")
aboutWindow.iconbitmap(goodIcon)
infoLabel = Label(aboutWindow, text="Program created by your man, Scares.\n"
"This is an open-source project, so feel free to mess around in the code and stuff.\n"
"If you want to release your own modified version of this project, just credit me and I'll be happy! :3\n\n"
"I'd also like to extend a huge thank you to anyone who bothered to try this thing!\n"
"It isn't the best piece of software out there, but I think it's pretty cool.")
infoLabel2 = Label(aboutWindow, text="Thank you for being a part of this project. Have fun!")
aboutWindow["bg"] = colorList[2]
goodLogo = PhotoImage(master=aboutWindow, file=colorList[4])
infoLabel.config(bg=colorList[2], fg=colorList[1])
infoLabel6 = Label(aboutWindow, image=goodLogo)
infoLabel2.config(bg=colorList[2], fg=colorList[1])
infoLabel.pack()
infoLabel6.pack()
infoLabel2.pack()
aboutWindow.mainloop()
def credits_window(event=None):
'''Window to credit bugtesters and any other contributors'''
creditsWindow = Toplevel()
creditsWindow.title("Scares Scrambler Build " +buildNumber+" "+"("+versionNumber+") Contributors")
creditsWindow.iconbitmap(goodIcon)
creditsWindow["bg"] = colorList[2]
label = Label(creditsWindow, text="Here's a list of people who've contributed to this project "
"in one way or another! \n Thank you to everyone for your support!",
bg=colorList[2], fg=colorList[1])
label2 = Label(creditsWindow, text="Dubby (Bugtester) \n"
"Ellestice (Bugtester) \n"
"Rare (Bugtester) \n"
"Tyler (Bugtester) \n"
"Scott (Bugtester, Moral Supporter) \n"
"Telic (Bugtester, Moral Supporter) \n"
"Ircluzar (Supporter, I think)", bg=colorList[2], fg=colorList[1])
goodLogo = PhotoImage(master=creditsWindow, file=colorList[4])
label3 = Label(creditsWindow, image=goodLogo)
label3.img = goodLogo
label.pack()
label2.pack()
label3.pack()
def corrupt_file(event=None, determinedVariables=[]):
global newFileName
global userFileLabel
global stopCorrupt
'''Corrupts the chosen file'''
tempIndex = 0 #Holds the index for specific variables
theEngine = algorithms[currentEngine.get()-1] #The current algorithm being used
try:
if determinedVariables == []: #If no values were given; standard Corrupt
startValue = get_value(startValueEntry)
endValue = get_value(endValueEntry)
#Mandatory stuff
tempIndex = find_engine_index(theEngine, "Block Size", "Entry")
blockSize = get_value(theEngine.entries[tempIndex][1])
if blockSize < 1:
blockSize = 1
tempIndex = find_engine_index(theEngine, "Block Space", "Alts") #Checking alts in case the label is different
#blockSpace = get_value(theEngine.entries[tempIndex][1])
blockSpaceState = theEngine.radioButtonVariables[tempIndex].get()
if blockSpaceState == 2: #Exponential
blockSpace = get_value(theEngine.entries[tempIndex][1], False)
else:
blockSpace = get_value(theEngine.entries[tempIndex][1])
corruptingVariables = theEngine.get_corruption_variables()
#print(corruptingVariables)
for x in range(0, len(corruptingVariables)): #Converting variables to usable stuff
if isinstance(corruptingVariables[x], list): #Making sure we're correcting the proper values
for y in range(0, len(corruptingVariables[x])):
if x == 0:
if not isinstance(corruptingVariables[x][y], str):
corruptingVariables[x][y] = get_value(corruptingVariables[x][y]) #Changing from hex if necessary
else:
if not isinstance(corruptingVariables[x][y], str):
corruptingVariables[x][y] = corruptingVariables[x][y].get()
#print(corruptingVariables)
else: #If values were given; Corrupt and Repeat
startValue = determinedVariables[0][1]
endValue = determinedVariables[1][1]
blockSpaceState = determinedVariables[-2][1]
determinedVariables = determinedVariables[2:-2] #Dumb formatting
for x in determinedVariables:
if x[0] == "Block Size":
if x[1] < 1:
x[1] = 1 #Preventing errors?
blockSize = x[1]
elif x[0] in ["Block Space", "Exponent", "Upper Bound"]:
blockSpace = x[1]
cVEntries = [x.copy()[1] for x in determinedVariables] #This should include all the remaining entries
cVRadios = []
cVChecks = []
for x in theEngine.radioButtonVariables: #All remaining radioButtons
if x != None:
cVRadios.append(x.get())
for x in theEngine.checkButtonVariables: #All remaining checkButtons
if x != None:
cVChecks.append(x.get())
if theEngine.name == "Blender Algorithm":
corruptingVariables = [cVEntries.copy(), cVRadios.copy(), cVChecks.copy(), open(theEngine.extraFile, "rb+")] #May not be rb+
else:
corruptingVariables = [cVEntries.copy(), cVRadios.copy(), cVChecks.copy()]
#print(corruptingVariables, "the cV")
if startValue < 0: #Fixing possible problems
startValue = 0
if endValue > os.path.getsize(fileName):
endValue = os.path.getsize(fileName)
elif endValue < 0:
endValue = 0
elif startValue > endValue:
startValue = endValue
if blockSpaceState == 2 and blockSpace < 1: #Fixing negative exponents and stuff
blockSpace = 1
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 == "" or newFileName == "Enter new file name...":
corruptedFile = open("CorruptedFile.txt", "wb+")
else:
#FULL FILE PATHS WORK I THINK :)
corruptedFile = open(newFileName, "wb+")
if theEngine.name == "Blender Algorithm":
if corruptingVariables[0][2] < 0:
corruptingVariables[0][2] = 0 #Making sure we don't go off the edge
corruptingVariables[3].seek(corruptingVariables[0][2]) #Setting proper offset
baseFile.seek(0) #Goto the start byte
copy_file_contents(baseFile, corruptedFile, startValue) #Add all stuff before start value
currentPos = 0 #Keeps track of where we are in the file currently
previousPos = 0 #Keeps track of the previous position in the file
exponentCounter = 1 #For exponential spacing
exponentCapValue = 1000000 #Fix this lovely hardcoding
tempSpace = blockSpace #BlockSpace used by the functions below (setting for linear)
corruptRange = endValue - startValue #Used for progress bar
nextUpdate = startValue + 100000 #Tells the window when to update (maybe fix hardcoded number later)
strCorruptRange = str(corruptRange)
userFileLabel["text"] = "0/"+strCorruptRange+" (0%) corrupted"
#print(blockSpace)
while True: #Main corruption loop
if blockSpaceState == 2: #Exponential
if tempSpace != exponentCapValue:
try: #Fixes the exponent from getting too big
if int(exponentCounter**blockSpace) > exponentCapValue: #If exponent is too big
tempSpace = exponentCapValue
else:
tempSpace = int(exponentCounter**blockSpace) #Check this if errors occur
exponentCounter += 1
except OverflowError:
tempSpace = exponentCapValue
elif blockSpaceState == 3: #Random
tempSpace = random.randrange(0, blockSpace+1)
theEngine.corrupt(corruptingVariables, tempSpace, baseFile, corruptedFile, endValue) #The thing that actually does the corrupting
currentPos = baseFile.tell() #Getting current pos
if theEngine.name == "Smoother Algorithm":
if currentPos+tempSpace+2*corruptingVariables[0][0] >= endValue:
userFileLabel["text"] = "Copying uncorrupted contents..."
root.update()
break
if theEngine.name == "Blender Algorithm": #Making sure we don't keep corrupting past the end of the file
if currentPos >= endValue:
userFileLabel["text"] = "Copying uncorrupted contents..."
root.update()
break
elif currentPos == previousPos:
userFileLabel["text"] = "Copying uncorrupted contents..."
root.update()
break
previousPos = currentPos
if currentPos > nextUpdate: #Prevents excess method calls
if currentPos <= endValue:
userFileLabel["text"] = str(currentPos-startValue)+"/"+strCorruptRange+" ("+str(
round(((currentPos-startValue)/corruptRange)*100))+"%) corrupted"
root.update() #Updates userFileLabel with progress bar
nextUpdate = currentPos + 100000
while True: #This finishes the uncorrupted part
currentByte = baseFile.read(100)
if currentByte == b"":
hide_userFileLabel() #Changing from progress bar to file name, if needed
break
corruptedFile.write(currentByte)
baseFile.close()
corruptedFile.close()
if theEngine.name == "Blender Algorithm":
corruptingVariables[3].close()
stopCorrupting = False
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.")
hide_userFileLabel() #Fixing any stuck progress bars
try:
baseFile.close()
corruptedFile.close()
except UnboundLocalError: #File was never opened
pass
root.update() #Updates userFileLabel with progress bar
if theEngine.name == "Blender Algorithm":
corruptingVariables[3].close()
stopCorrupt = True
except IndexError:
if baseFile.read() == b"": #Checking to see if endValue was too big
hide_userFileLabel() #Changing from progress bar to file name, if needed
baseFile.close()
corruptedFile.close()
if theEngine.name == "Blender Algorithm":
corruptingVariables[3].close()
else:
messagebox.showwarning("Woah there partner!", "Make sure to fill in the required values properly!")
hide_userFileLabel() #Fixing any stuck progress bars
baseFile.close()
corruptedFile.close()
if theEngine.name == "Blender Algorithm":
corruptingVariables[3].close()
root.update() #Updates userFileLabel with progress bar
stopCorrupt = True
except TypeError:
messagebox.showwarning("Woah there partner!", "Make sure to fill in the required values properly!")
hide_userFileLabel() #Fixing any stuck progress bars
try:
baseFile.close()
corruptedFile.close()
except UnboundLocalError: #File was never opened
pass
if theEngine.name == "Blender Algorithm":
corruptingVariables[3].close()
root.update() #Updates userFileLabel with progress bar'''
stopCorrupt = True
def corrupt_repeat_window(event=None):
'''Function to manage "Corrupt and Repeat"'''
global newFolder
global oldFileName
newFolder = False
repeatWindow = Toplevel()
if themeVar.get() == 3: #Dubby theme
repeatWindow.title("Dubby and Repeat")
else:
repeatWindow.title("Corrupt and Repeat")
repeatWindow.iconbitmap(goodIcon)
incFrame = Frame(repeatWindow, width=300, height=480)
entries = [] #Holds all the entries and labels
#oldValues = [] #Will hold the user's settings, in case they revert back after repeat
#currentValues = [] #Will hold the values used for repeat
entries.append([Label(incFrame, text="Start Value Inc:"), Entry(incFrame)])
entries.append([Label(incFrame, text="End Value Inc:"), Entry(incFrame)])
for x in algorithms[currentEngine.get()-1].entries: #Goes through all the entries
entries.append([Label(incFrame, text=x[0]["text"]+" Inc:"), Entry(incFrame)])
entries.append([Label(incFrame, text="Number of Files:"), Entry(incFrame)])
if themes[themeVar.get()-1].name == "Dubby": #Dubby theme
corruptButton = Button(repeatWindow, text="Dubby", font="Helvetica 25")
instructions = Label(repeatWindow, text='Insert the amount you\'d like the settings to be\n'
'incremented each time, then press "Dubby".')
else:
corruptButton = Button(repeatWindow, text="Corrupt", font="Helvetica 25")
instructions = Label(repeatWindow, text='Insert the amount you\'d like the settings to be\n'
'incremented each time, then press "Corrupt".')
newFolderCheck = Checkbutton(repeatWindow, text="Store files in new folder", command=toggle_newFolder)
#Checkbox to tell whether user wants a separate folder
corruptButton.bind("<Button-1>", lambda _: corrupt_repeat(entries))
repeatWindow["bg"] = colorList[2]
incFrame["bg"] = colorList[2]
instructions.config(bg=colorList[2], fg=colorList[1])
for x in entries:
x[0].config(bg=colorList[2], fg=colorList[1])
x[1].config(bg=colorList[0], fg=colorList[1], insertbackground=colorList[1], selectbackground=colorList[5])
corruptButton.config(bg=colorList[2], fg=colorList[1], activebackground=colorList[2], activeforeground=colorList[1])
newFolderCheck.config(bg=colorList[2], fg=colorList[1], selectcolor=colorList[0], activebackground=colorList[2],
activeforeground=colorList[1])
instructions.pack()
incFrame.pack(padx=17, pady=10)
for x in range(0, len(entries)):
entries[x][0].grid(row=x+1, column=0, pady=5, sticky=W)
entries[x][1].grid(row=x+1, column=1, columnspan=3, padx=10, sticky=W)
corruptButton.pack(side="bottom", pady=5)
newFolderCheck.pack(side="bottom", pady=5)
def corrupt_repeat(entries, event=None):
'''The function that manages the corrupt and repeat stuff'''
'''The random minuses in the range functions are to prevent errors with special corrupting values'''
global newFileName
global oldFileName
global stopCorrupt
if newFolder and ("newFolder" not in newFileName): #If we're making a new folder
p = check_for_char(newFileName, "\\")
# print(__file__[:q], "wow")
if p != False: #If the newFileName is a full path
if not os.path.exists(newFileName[:p]+"\\newFolder"):
os.mkdir(newFileName[:p]+"\\newFolder") #Make new directory if needed
newFileName = newFileName[:p] + "\\newFolder" + newFileName[p:]
else:
if not os.path.exists(os.getcwd()+"\\newFolder"):
os.mkdir(os.getcwd()+"\\newFolder") #Make new directory if needed
newFileName = os.getcwd() + "\\newFolder\\" + newFileName #Making sure the new folder gets added to path correctly
elif not newFolder:
newFileName = oldFileName
variables = []
ogFileName = newFileName
extraOffset = 0 #In case extra things are added to the variables; prevents incrementing errors
expo = algorithms[currentEngine.get()-1].radioButtonVariables[find_engine_index(
algorithms[currentEngine.get()-1], "Block Space", "Alts")].get()
blockSpaceAlts = algorithms[currentEngine.get()-1].entryAlts[find_engine_index(
algorithms[currentEngine.get()-1], "Block Space", "Alts")]
#Checking to see if exponential is on
for x in entries:
try:
if x[1].get() != "": #If there's actual data to collect
if x[0]["text"][:-5] in blockSpaceAlts and expo == 2:
variables.append([x[0]["text"][:-5], get_value(x[1], isInt=False)])
else:
variables.append([x[0]["text"][:-5], get_value(x[1], isInt=True)])
else:
variables.append([x[0]["text"][:-5], 0])
except:
messagebox.showwarning("Good job, Buddy.", "Make sure all entered values are valid numbers!")
variables.insert(-1, ["Block Space State", expo]) #Getting blockSpaceState; NO OTHER ADDITIONS CAN COME AFTER THIS
dotPos = check_for_char(newFileName) #Gets position of dot in newFileName
currentVariables = [x.copy() for x in variables] #Holds the variables to be used for corrupting
currentVariables[0][1] += get_value(startValueEntry) #Getting currentVariables ready for corrupting
currentVariables[1][1] += get_value(endValueEntry)
for x in range(0, len(algorithms[currentEngine.get()-1].entries)):
if algorithms[currentEngine.get()-1].entries[x][0]["text"] == "Exponent":
currentVariables[x+2][1] += get_value(algorithms[currentEngine.get()-1].entries[x][1], isInt=False)
else:
currentVariables[x+2][1] += get_value(algorithms[currentEngine.get()-1].entries[x][1], isInt=True)
for x in range(0, variables[-1][1]): #The actual "corrupt and repeat" part
corrupt_file(determinedVariables=currentVariables)
for y in range(0, len(variables)-2-extraOffset):
currentVariables[y][1] += variables[y][1] #This is what does the incrementing
newFileName = ogFileName[:dotPos] + "_" + str(x) + ogFileName[dotPos:]
if stopCorrupt: #If we need to stop corrupting
break
newFileName = ogFileName #Returning the fileName to normal
stopCorrupt = False
def save_presets_window(event=None):
global newPresetName
global newPresetEntry
global newPresetWindow
'''The UI for saving a preset'''
newPresetWindow = Toplevel()
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>", lambda _: save_presets(newPresetEntry)) #The _ is catching an usused argument
newPresetWindow.config(bg=colorList[2])
newPresetEntry.config(bg=colorList[0], fg=colorList[1], insertbackground=colorList[1], selectbackground=colorList[5])
newPresetLabel.config(bg=colorList[2], fg=colorList[1])
newPresetButton.config(bg=colorList[2], fg=colorList[1], activebackground=colorList[2], activeforeground=colorList[1])
newPresetLabel.pack()
newPresetEntry.pack(pady=5)
newPresetButton.pack()
newPresetWindow.bind("<Return>", lambda _: save_presets(newPresetEntry))
def save_presets(newPresetEntry, event=None):
'''Saves the presets to a text file'''
presetList = []
theEngine = algorithms[currentEngine.get()-1]
presetList.append("~~preset16~~")
presetList.append(fileName)
presetList.append(newFileName)
presetList.append(algorithms[currentEngine.get()-1].extraFile) #extraFile
presetList.append(startValueEntry.get())
presetList.append(endValueEntry.get())
presetList.append(incValueEntry.get())
presetList.append("~~"+theEngine.name+"~~") #Signifying the start of algorithm specific stuff
presetList.append("~~Entries~~") #Start of entry section
for x in range(0, len(theEngine.entries)): #Iterating through all entries
presetList.append(theEngine.entries[x][1].get())
presetList.append("~~Radiobuttons~~") #Start of radiobutton section
for x in theEngine.radioButtonVariables: #Iterating through all radiobutton variables
if x == None:
presetList.append("None")
else:
presetList.append(x.get())
presetList.append("~~Checkbuttons~~") #Start of checkbutton section
for x in theEngine.checkButtonVariables:
if x == None:
presetList.append("None")
else:
presetList.append(x.get())
presetList.append(hexadecimalMode) #Add hexadecimal mode
presetList.append(hideVar.get()) #Add hide file labels
name = newPresetEntry.get()
if name[-4:] == ".txt": #If there's a file extension
presetFile = open(name, "w")
else:
presetFile = open(name+".txt", "w")
for x in presetList:
presetFile.write(str(x)+"\n")
#presetFile.write("~~End~~")
presetFile.close()
newPresetWindow.destroy() #Close the preset window
def load_presets(event=None, coolName=""):
global fileName
global newFileName
global oldFileName
global startValueEntry
global endValueEntry
global incValueEntry
global hexadecimalMode
global hexVar
global userFileLabel
global currentEngine
'''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": #The preset used in Build 13 and below
fileName = presetFile.readline()[:-1]
newFileName = presetFile.readline()[:-1]
oldFileName = newFileName
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])
presetFile.readline() #Useless auto end toggle
blockSize = presetFile.readline()[:-1] #Getting blockSize
spaceType = presetFile.readline()[:-1] #Getting linear, exponential, random (blockSpaceState)
if spaceType == "Linear":
spaceType = 1
elif spaceType == "Exponential":
spaceType = 2
else:
spaceType = 3
blockSpace = presetFile.readline()[:-1] #Getting blockSpace
incEngine.entries[2][1].delete(0, END)
incEngine.entries[2][1].insert(0, presetFile.readline()[:-1]) #Add/subtract
blockGap = presetFile.readline()[:-1] #Getting blockGap
exclusiveBool = presetFile.readline()[:-1] #Exclusive switch
if exclusiveBool == "True":
tiltEngine.checkButtonVariables[3].set(1)
else:
tiltEngine.checkButtonVariables[3].set(0)
tiltEngine.entries[2][1].delete(0, END)
tiltEngine.entries[2][1].insert(0, presetFile.readline()[:-1]) #Replace
tiltEngine.entries[3][1].delete(0, END)
tiltEngine.entries[3][1].insert(0, presetFile.readline()[:-1]) #Replace with
if presetFile.readline()[:-1] == "True": #Hexadecimal mode
hexadecimal_switch(switchTo="Hex")
hexVar.set(1)
else:
hexadecimal_switch(switchTo="Dec")
hexVar.set(0)
for x in algorithms: #Setting variables found above
x.entries[0][1].delete(0, END)
x.entries[0][1].insert(0, blockSize)
x.radioButtonVariables[1].set(spaceType)
x.switch_entry_text(1)
x.entries[1][1].delete(0, END)
x.entries[1][1].insert(0, blockSpace)
for x in range(2, 4): #Scrambler, copier. Inserts blockGap
algorithms[x].entries[2][1].delete(0, END)
algorithms[x].entries[2][1].insert(0, blockGap)
hide_userFileLabel() #Making sure to hide userFileLabel if necessary
elif tag == "~~preset14~~\n" or tag == "~~preset16~~\n": #Preset for Build 14
fileName = presetFile.readline()[:-1]
newFileName = presetFile.readline()[:-1]
oldFileName = newFileName
if tag == "~~preset16~~\n":
extraFile = presetFile.readline()[:-1] #Extra file name
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])
theAlgo = presetFile.readline()[2:-3]
for x in range(0, len(algorithms)): #Getting the right algorithm
if algorithms[x].name == theAlgo:
currentEngine.set(x+1)
break
theEngine = algorithms[currentEngine.get()-1]
theEngine.extraFile = extraFile #Actually setting extraFile
switch_algorithm() #Making sure layout changes
presetFile.readline() #~~Entries~~
for x in range(0, len(theEngine.entries)): #Insert correct values for entries
theEngine.entries[x][1].delete(0, END)
theEngine.entries[x][1].insert(0, presetFile.readline()[:-1])
presetFile.readline() #~~Radiobuttons~~
for x in range(0, len(theEngine.radioButtonVariables)):
if theEngine.radioButtonVariables[x] != None:
theEngine.radioButtonVariables[x].set(presetFile.readline()[:-1])
theEngine.switch_entry_text(x)
else:
presetFile.readline() #Trashing the none values
presetFile.readline() #~~Checkbuttons~~
for x in range(0, len(theEngine.checkButtonVariables)):
if theEngine.checkButtonVariables[x] != None:
theEngine.checkButtonVariables[x].set(presetFile.readline()[:-1]) #Setting checkbuttons
else:
presetFile.readline() #Trashing none values
if presetFile.readline()[:-1] == "True": #Hexadecimal Mode
hexadecimal_switch(switchTo="Hex")
hexVar.set(1)
else:
hexadecimal_switch(switchTo="Dec")
hexVar.set(0)
if tag == "~~preset16~~\n":
hideVar.set(presetFile.readline()[:-1]) #Setting the hideVar variable
hide_userFileLabel()#Making sure to hide userFileLabel if necessary
else: #If the text file isn't a preset
if manualSelect:
messagebox.showwarning("Hold up!", "The file you selected isn't a preset file.")
'''except: #If the file doesn't have lines to read?
messagebox.showwarning("Hold up!", "The file you selected couldn't be read.")'''
presetFile.close()
except FileNotFoundError:
messagebox.showinfo("Hold it!", "The file you selected couldn't be found.")
def theme_switch(event=None):
global bannerLabel
global colorList
'''Changes the GUI to be dark, or light again'''
#SystemButtonFace - greyish bg
#SystemButtonText - text colour
#SystemWindow - Entry Colour (white) and black select colour for checks and radios
#print(themeVar.get())
colorList = themes[themeVar.get()-1].colorList #Changes the colors we're using
bannerLabel["image"] = colorList[3] #Changes the banner
logoFilename = colorList[4];
for x in range(0, len(algorithms)): #Prevents random buttons in other algorithms from changing color
algorithms[x].recolor(colorList) #Recolors the elements of the corrupter
for x in hardCodedWidgets: #Deal with it
if isinstance(x, Tkinter.Label):
x.config(bg=colorList[2], fg=colorList[1])
elif isinstance(x, Tkinter.Entry):
x.config(bg=colorList[0], fg=colorList[1], insertbackground=colorList[1], selectbackground=colorList[5])
elif isinstance(x, Tkinter.Button) or isinstance(x, Tkinter.Menubutton):
x.config(bg=colorList[2], fg=colorList[1], activebackground=colorList[0], activeforeground=colorList[1])
elif isinstance(x, Tkinter.Menu):
x.config(bg=colorList[2], fg=colorList[1], activebackground=colorList[5], activeforeground=colorList[1],
selectcolor=colorList[1])
else:
x["bg"] = colorList[2]
if logoFilename.upper().find("DUBBY") != -1: #Dubby theme
corruptButton["text"] = "Dubby"
corruptRepeatButton["text"] = "Dubby and Repeat"
elif logoFilename.upper().find("DEJAVU") != -1: #Dejavu theme
corruptButton["text"] = "Blast"
corruptButton.config(fg='orangered')
corruptButton.config(bg='#23303e')
corruptRepeatButton["text"] = "Blast and Repeat"
corruptRepeatButton.config(fg='orangered')
corruptRepeatButton.config(bg='#23303e')
else:
corruptButton["text"] = "Corrupt"
corruptRepeatButton["text"] = "Corrupt and Repeat"
# remember last used theme
with open("Assets/selectedTheme.txt", "w") as text_file:
text_file.write(str(themeVar.get()))
def select_listbox_item(listbox, pathList, tempFileName, curselection=":)", pathLabel=":)", event=None):
'''Returns an item within a given listbox'''