-
Notifications
You must be signed in to change notification settings - Fork 0
/
CHStegano.py
220 lines (203 loc) · 7.5 KB
/
CHStegano.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
# Import built-in libraries
import time
import os
import sys
from PIL import Image
import argparse
import itertools
args = argparse.ArgumentParser(description="Script to extract and parse data from Clone Hero's screenshots")
args.add_argument('-i', '--input', action="store", dest="screenshot", type=str, help="Path to the screenshot")
args.add_argument('-o', '--output', action="store", dest="outf", type=str, help="Path to extract the extracted data")
# Define fancy classes cuz i wanna do print(CHScore.Player)
class CHPlayer:
def __init__(self, id):
self.Name = ""
self.Instrument = ""
self.Modifiers = []
self.Score = 0
self.NotesHit = 0
self.NotesTotal = 0
self.Accuracy = 0.0
self.SPPhases_Hit = 0
self.SPPhases_Total = 0
self.Streak = 0
self.FC = False
self.player = id
class CHScore:
SongChecksum = ""
SongName = ""
Artist = ""
Charter = ""
Score = 0
Speed = 100
Stars = ""
PlayersNum = 1
Players = []
if len(sys.argv) < 3:
args.print_help()
exit(0)
paths = args.parse_args()
def IdentifyInstrument(instrumentID: int=0):
if instrumentID == 0:
return "Guitar"
elif instrumentID == 1:
return "Bass"
elif instrumentID == 2:
return "Rhythm"
elif instrumentID == 3:
return "GuitarCoop"
elif instrumentID == 4:
return "GHLGuitar"
elif instrumentID == 5:
return "GHLBass"
elif instrumentID == 6:
return "Drums"
elif instrumentID == 7:
return "Keys"
elif instrumentID == 8:
return "Band"
def DetectModifiers(modifier: int=1):
Modifiers = []
AppendMod = Modifiers.append
if modifier - 2048 >= 0:
AppendMod("ModPrep")
modifier -= 2048
if modifier - 1024 >= 0:
AppendMod("ModLite")
modifier -= 1024
if modifier - 512 >= 0:
AppendMod("ModFull")
modifier -= 512
if modifier - 256 >= 0:
AppendMod("LightsOut")
modifier -= 256
if modifier - 128 >= 0:
AppendMod("HOPOsToTaps")
modifier -= 128
if modifier - 64 >= 0:
AppendMod("Shuffle")
modifier -= 64
if modifier - 32 >= 0:
AppendMod("MirrorMode")
modifier -= 32
if modifier - 16 >= 0:
AppendMod("AllOpens")
modifier -= 16
if modifier - 8 >= 0:
AppendMod("AllTaps")
modifier -= 8
if modifier - 4 >= 0:
AppendMod("AllHOPOs")
modifier -= 4
if modifier - 2 >= 0:
AppendMod("AllStrums")
if modifier == 1:
AppendMod("None")
return Modifiers
def AnalyseData(Data: bytes):
pos = 0x05 if Data[:5] == b'\x01\x00\x00\x00\x20' else 0x39 # Older versions didn't have ECC implemented
CHScore.SongChecksum = str(Data[pos:pos+0x20], 'utf-8')
pos += 0x20
CurLen = Data[pos]
pos += 0x01
CHScore.SongName = str(Data[pos:pos+CurLen], 'utf-8')
pos += CurLen
CurLen = Data[pos]
pos += 0x01
CHScore.Artist = str(Data[pos:pos+CurLen], 'utf-8')
pos += CurLen
CurLen = Data[pos]
pos += 0x01
CHScore.Charter = str(Data[pos:pos+CurLen], 'utf-8')
pos += CurLen
CHScore.Speed = int.from_bytes(Data[pos:pos+0x04], 'little')
pos += 0x0C
CHScore.Score = int.from_bytes(Data[pos:pos+0x04], 'little')
pos += 0x04
i = 0
if Data[pos] == 0:
CHScore.Stars = "None"
else:
while i < Data[pos]:
CHScore.Stars += '⭐'
i += 1
pos += 0x04
CHScore.PlayersNum = int.from_bytes(Data[pos:pos+0x04], 'little')
i=1
while(i <= CHScore.PlayersNum):
CHScore.Players.append(CHPlayer(i))
i += 1
pos += 0x04
CHScore.Instrument = IdentifyInstrument(Data[pos])
for CurPlayer in CHScore.Players:
pos += 0x08
CurLen = Data[pos]
pos += 0x01
CurPlayer.Name = str(Data[pos:pos+CurLen], 'utf-8')
pos += CurLen + 0x01
CurPlayer.Modifiers = DetectModifiers(int.from_bytes(Data[pos:pos+0x01], 'little'))
pos += 0x13
CurPlayer.Score = int.from_bytes(Data[pos:pos+0x04 if CurPlayer.player != 2 else pos+0x03], 'little')
pos += 0x0C if CurPlayer.player != 2 else 0x1C
CurPlayer.NotesHit = int.from_bytes(Data[pos:pos+0x04], 'little')
pos += 0x04
CurPlayer.NotesTotal = int.from_bytes(Data[pos:pos+0x04], 'little')
CurPlayer.Accuracy = (CurPlayer.NotesHit / CurPlayer.NotesTotal) * 100 if CurPlayer.NotesTotal != 0 else 0.0
pos += 4
CurPlayer.Streak = int.from_bytes(Data[pos:pos+0x04], 'little')
pos += 4
CurPlayer.SPPhases_Hit = int.from_bytes(Data[pos:pos+0x04], 'little')
pos += 4
CurPlayer.SPPhases_Total = int.from_bytes(Data[pos:pos+0x04], 'little')
pos += 4
CurPlayer.FC = bool(Data[pos] & 1)
pos += 1
print(f"Checksum: {CHScore.SongChecksum}")
print(f"SongName: {CHScore.SongName}")
print(f"Artist: {CHScore.Artist}")
print(f"Charter: {CHScore.Charter}")
print(f"Speed: {CHScore.Speed}%")
print(f"Score: {CHScore.Score}")
print(f"Stars: {CHScore.Stars}")
p = 1
for CurPlayer in CHScore.Players:
print(f"Player {p}: {CurPlayer.Name}")
print(f" Score: {CurPlayer.Score}")
print(f" Instrument: {CHScore.Instrument}")
print(f" Accuracy: {CurPlayer.NotesHit}/{CurPlayer.NotesTotal} ({CurPlayer.Accuracy}%)")
print(f" Longest streak: {CurPlayer.Streak}")
print(f" SP Phases: {CurPlayer.SPPhases_Hit}/{CurPlayer.SPPhases_Total}")
print(f" FC: {CurPlayer.FC}")
if len(CurPlayer.Modifiers) == 1:
if CurPlayer.Modifiers[0] == "None":
print(f" Modifiers: {CurPlayer.Modifiers[0]}")
else:
print(f" Modifier: {CurPlayer.Modifiers[0]}")
else:
i = 1
for Modifier in CurPlayer.Modifiers:
print(f" Modifier {i}: {Modifier}")
i += 1
p += 1
if paths.screenshot.lower().endswith(".png") == True:
StartTime = time.time()
EmbedScreenshot = Image.open(paths.screenshot, 'r').transpose(Image.FLIP_TOP_BOTTOM)
Pixels = itertools.islice(EmbedScreenshot.getdata(), 0x1000)
PixelData = [subpixel for pixel in Pixels for subpixel in pixel if subpixel != 0xFF] # Get Separated RGBA values for each pixels
LSBs = [SB & 1 for SB in PixelData] # Get least significant bits
EmbedData = [sum([byte[b] << b for b in range(0,8)])
for byte in zip(*(iter(LSBs),) * 8)
] # https://stackoverflow.com/questions/20541023/in-python-how-to-convert-array-of-bits-to-array-of-bytes
EmbedData = bytes(EmbedData)
if paths.outf != None and os.name == "nt":
os.write(os.open(paths.outf, os.O_CREAT | os.O_BINARY | os.O_WRONLY), EmbedData)
elif paths.outf != None and os.name == "posix":
os.write(os.open(paths.outf, os.O_CREAT | os.O_WRONLY), EmbedData)
print(f"It took {(time.time() - StartTime) * 1000} ms to extract the data from the screenshot")
elif os.name == "nt":
EmbedData = os.read(os.open(paths.screenshot, os.O_RDONLY | os.O_BINARY), os.path.getsize(paths.screenshot))
else:
EmbedData = os.read(os.open(paths.screenshot, os.O_RDONLY), os.path.getsize(paths.screenshot))
t = time.time()
AnalyseData(EmbedData)
print(f"\nIt took {(time.time() - t) * 1000}ms to parse the data" )