-
Notifications
You must be signed in to change notification settings - Fork 0
/
image-bytemasher.ps1
146 lines (133 loc) · 4.42 KB
/
image-bytemasher.ps1
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
param($path)
add-type -AssemblyName system.drawing
add-type -AssemblyName system.windows.forms
$global:origImageBytes = [System.IO.File]::ReadAllBytes( (&{if($path){echo $path}else{(read-host "Path to file to glitch").replace('"',"")}}))
$global:origImageImg = (new-object system.drawing.ImageConverter).ConvertFrom($global:origImageBytes);
$global:CorruptedBytes = $global:origImageBytes.clone();
$global:WorkingBytes = $global:CorruptedBytes.clone()
$global:Position = 0;
$global:Data = [byte[]]@(,0);
$global:LastError = "";
$global:command = ""
$global:Form = new-object system.windows.forms.form
$global:Form.width = 300;
$global:Form.height = 300;
$global:label = new-object system.windows.forms.label
$global:label.autosize = $false
$global:label.width = 290;
$global:label.height = 290;
$global:label.backgroundimagelayout = 4
$global:label.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom +[System.Windows.Forms.AnchorStyles]::top +[System.Windows.Forms.AnchorStyles]::Left +[System.Windows.Forms.AnchorStyles]::right
$global:editButton = new-object system.windows.forms.button
$global:editButton.width = 100;
$global:editButton.height = 30;
$global:editButton.top = 220;
$global:editButton.left = 10;
$global:editButton.text = "Edit";
$global:editButton.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom +[System.Windows.Forms.AnchorStyles]::left
$global:Form.Controls.Add($global:editButton)
$global:Form.Controls.Add($global:label)
$global:Form.width = 1000;
$global:Form.height = 600;
<#
$global:form.show();
$timer = new-object timers.timer
$action = {[System.Windows.Forms.Application]::DoEvents()}
$timer.Interval = 240 #0.1 seconds
unregister-Event *
Register-ObjectEvent -InputObject $timer -EventName elapsed –SourceIdentifier thetimer -Action $action
$timer.start();#>
function preview(){
param(
$img
)
$global:label.backgroundimage = $img
}
function showMenu(){
write-host ("Current position:"+$global:Position)
write-host ("Current Data:"+$global:data)
write-host ("Current Data (string):"+(-join [char[]]$global:data))
write-host ("File Length:"+($global:workingbytes.count))
write-host ""
$Percent = [int](($global:position/($global:workingbytes.count))*100)
write-host ("["+("X"*$percent)+(" "*(100-$percent))+"]")
write-host ""
write-host $global:LastError -foregroundcolor red
$global:LastError = ""
write-host ""
write-host "[+0]: Move forward; [-0]: Move back; [`"string]: Set data; [#]: HashString;[?] Apply/Preview; [>]: Confirm; [S]: Save"
$global:command = read-host "Enter command"
}
preview $origImageImg
$global:editButton.add_Click({
$Apply = $false
while(-not $Apply){
cls
showMenu
$commandTag = (-join ($global:command[1..($global:command.length-1)]))
switch(([string]$global:command[0]).toupper()){
"+" {
try{
if(($global:position+([int]$commandTag)+$global:data.count) -lt $global:workingbytes.count){
$global:Position +=[int]$commandTag
}
else{
$global:LastError = "Please enter an amount within bounds"
}
}
catch{
$global:LastError = "Please enter a valid amount"
}
}
"-" {
try{
if(($global:position-([int]$commandTag)) -gt 0){
$global:Position += 0-([int]$commandTag)
}
else{
$global:LastError = "Please enter an amount within bounds"
}
}
catch{
$global:LastError = "Please enter a valid amount"
}
}
"`"" {
$global:Data = [byte[]][char[]]$commandTag
}
"?"{
$global:WorkingBytes = $global:CorruptedBytes.clone()
try{
if(($global:position+$global:data.count) -lt $global:workingbytes.count){
for($i = $global:position; $i -lt ($global:position+$global:data.count); $i++){
$global:workingbytes[$i] = $global:data[$i-$global:position];
}
}
preview (new-object system.drawing.ImageConverter).ConvertFrom($global:WorkingBytes);
$apply = $true
}
catch{
$global:WorkingBytes = $global:CorruptedBytes.clone()
$global:LastError = "File too corrupt to open, reverted"
}
}
"#" {
$global:Data = [byte[]] -split ($commandTag -replace '..', '0x$& ')
}
">" {
$global:CorruptedBytes = $global:WorkingBytes.clone()
$apply = $true
}
"S" {
[System.IO.File]::WriteAllBytes((read-host "Enter a valid file path"),$global:CorruptedBytes)
$apply = $true
}
default {
$apply = $true
}
}
}
cls
write-host "Previewing" -foregroundcolor green
})
$global:form.showDialog();