This repository has been archived by the owner on May 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMake_Splash_Image_src.au3
219 lines (182 loc) · 6.76 KB
/
Make_Splash_Image_src.au3
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
#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=Make_Splash_Image.exe
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.14.5
Author: CosmicDan
Script Function:
Generate splash.img of all five images for tissot (Mi A1)
#ce ----------------------------------------------------------------------------
#include <File.au3>
#include "bin\Binary.au3"
#include "bin\IsPressed_UDF.au3"
; ------------------------------ Constants
Global Const $aInFiles[] = [ _
@ScriptDir & "\input\01.png", _
@ScriptDir & "\input\02.png", _
@ScriptDir & "\input\03.png", _
@ScriptDir & "\input\04.png", _
@ScriptDir & "\input\05.png" _
]
Global $aInMaxSizesBytes[] = [ _
"100864", _
"613888", _
"101888", _
"153088", _
"204800" _
]
Global $aInMaxSizesBytes_HackLarger03[] = [ _
"100864", _
"613888", _
"183808", _
"71168", _
"204800" _
]
Global Const $sLogPath = @ScriptDir & "\last_log.txt"
Global Const $sTempDir = @ScriptDir & "\temp\"
Global Const $sBinDir = @ScriptDir & "\bin\"
Global Const $sSplashOut = $sTempDir & "splash.img"
Global Const $iSectorSize = 512
Global Const $iSplashImgHeaderSize = 1024
; ------------------------------ Functions
Func LogEcho($sMessage)
ConsoleWrite($sMessage & @CRLF)
; It's a bit crap to keep opening/closing a file handle but we don't want to contest with e.g. python script STDOUT
Local $hFile = FileOpen($sLogPath, $FO_APPEND)
FileWrite($hFile, $sMessage & @CRLF)
FileClose($hFile)
EndFunc
Func ExitWait()
If @Compiled Then
ConsoleWrite("[i] Press any key to close." & @CRLF)
While 1
If _IsAnyKeyPressed() Then
ExitLoop
EndIf
WEnd
EndIf
Exit
EndFunc
; ------------------------------ Main
If $CmdLine[0] >= 1 Then
If $CmdLine[1] = "-hack03" Then
LogEcho("[!] Using 'larger 03 splash' hack. Make sure splash 04 is reduced to a tiny size (it likely won't work anymore anyway).")
$aInMaxSizesBytes = $aInMaxSizesBytes_HackLarger03
EndIf
EndIf
If FileExists(@ScriptDir & "\splash.img") Then
ConsoleWrite("[!] A splash.img already exists in the current folder. Please delete or move it first." & @CRLF)
ExitWait()
EndIf
FileDelete($sLogPath)
DirCreate(@ScriptDir & "\input")
; check all PNG's are there
For $sInFile In $aInFiles
If Not FileExists($sInFile) Then
LogEcho("[!] One or more input PNG's are missing. Please put 01.png to 05.png in the 'input' folder.")
ExitWait()
EndIf
Next
DirRemove($sTempDir, 1)
DirCreate($sTempDir)
; write out header
Global $hSplashOut = FileOpen($sSplashOut, $FO_APPEND + $FO_BINARY)
For $l = 1 To $iSplashImgHeaderSize
FileWrite($hSplashOut, Chr(0x00))
Next
FileFlush($hSplashOut)
Local $iCount = 1
For $iIndex = 0 To UBound($aInFiles) - 1
Local $sInFile = $aInFiles[$iIndex]
Local $sInSize = $aInMaxSizesBytes[$iIndex]
; Build current PNG file/path info
Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = ""
_PathSplit($sInFile, $sDrive, $sDir, $sFileName, $sExtension)
; Copy current png file to temp
FileCopy($sInFile, $sTempDir)
FileMove($sTempDir & $sFileName & $sExtension, $sTempDir & "input.png")
; Convert to RLE
LogEcho("[#] Converting file " & $iCount & " of " & UBound($aInFiles) &"...")
RunWait(@ComSpec & ' /c ""' & $sBinDir & 'Python2.7\python2.7.exe" "' & $sBinDir & 'code.py" >> "' & $sLogPath & '" 2>&1"', $sTempDir, @SW_HIDE)
If Not FileExists($sTempDir & "output.rle") Then
LogEcho("[!] Error creating RLE file!")
ExitWait()
EndIf
FileMove($sTempDir & "output.rle", $sTempDir & $sFileName & ".rle")
FileDelete($sTempDir & "input.png")
Local $sSplashFile = $sTempDir & $sFileName & ".rle"
; Do padding to next sector boundary
Local $iSplashSizeBytes = FileGetSize($sSplashFile)
LogEcho(" [i] File size is " & $iSplashSizeBytes & " bytes")
If $iSplashSizeBytes > $sInSize Then
LogEcho(" [!] RLE image file is too big. Must be smaller than " & $sInSize & " bytes. Try reducing the image complexity.")
ExitWait()
EndIf
Local $iSplashSizeSectors = 0
; pad the file to the required size
Local $hSplashRleFile = FileOpen($sSplashFile, $FO_APPEND + $FO_BINARY)
LogEcho(" [#] Padding RLE file...")
For $l = 1 To $sInSize - $iSplashSizeBytes
If Mod($iSplashSizeBytes + $l, $iSectorSize) = 0 And $iSplashSizeSectors = 0 Then
; remember the sector size of image for header
Local $iSplashSizeSectors = ($iSplashSizeBytes + $l) / 512
LogEcho(" [i] RLE length detected at " & $iSplashSizeBytes + $l & " bytes (" & $iSplashSizeSectors & " sectors).")
EndIf
FileWrite($hSplashRleFile, Chr(0x00))
Next
If $iSplashSizeSectors = 0 Then
LogEcho("[!] Could not calculate RLE size for header. It's probably too large. Try reducing the image complexity.")
ExitWait()
EndIf
FileFlush($hSplashRleFile)
FileClose($hSplashRleFile)
; calculate new size
$iChunkSizeBytes = FileGetSize($sSplashFile)
Local $iChunkSizeSectors = $iSplashSizeBytes / $iSectorSize
LogEcho(" [i] Full chunk size is " & $iChunkSizeBytes & " bytes")
; Do header
LogEcho(" [#] Calculating and adding header...")
Local $sSplashHeader = $sTempDir & $sFileName & ".header"
FileCopy($sBinDir & "splash_rle_header.img", $sSplashHeader)
Local $bSplashLength = _BinaryFromInt32($iSplashSizeSectors)
Local $hSplashHeaderFile = FileOpen($sSplashHeader, $FO_APPEND + $FO_BINARY)
FileWrite($hSplashHeaderFile, $bSplashLength)
LogEcho(" [i] Wrote '" & $bSplashLength & "' to header. Now padding to 512 bytes...")
; recalculate the size
FileFlush($hSplashHeaderFile)
Local $iSplashHeaderSizeBytes = FileGetSize($sSplashHeader)
For $l = 1 To $iSectorSize - $iSplashHeaderSizeBytes
FileWrite($hSplashRleFile, Chr(0x00))
Next
FileFlush($hSplashHeaderFile)
FileClose($hSplashHeaderFile)
LogEcho(" ...done")
LogEcho(" [#] Writing-out chunk...")
Local $hFileInput = FileOpen($sSplashHeader, $FO_READ + $FO_BINARY)
FileWrite($hSplashOut, FileRead($hFileInput))
FileFlush($hSplashOut)
FileClose($hFileInput)
$hFileInput = FileOpen($sSplashFile, $FO_READ + $FO_BINARY)
FileWrite($hSplashOut, FileRead($hFileInput))
FileFlush($hSplashOut)
FileClose($hFileInput)
FileDelete($sSplashFile)
FileDelete($sSplashHeader)
LogEcho(" ... done")
$iCount = $iCount + 1
Next
FileClose($hSplashOut)
LogEcho("")
If Not FileExists($sSplashOut) Then
LogEcho("[!] splash.img build failed. Check log for details.")
Else
FileMove($sSplashOut, @ScriptDir)
LogEcho("[i] splash.img done!")
EndIf
LogEcho("")
; cleanup
DirRemove($sTempDir, 1)
ExitWait()