forked from KnightOS/KnightOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexploit.asm
More file actions
300 lines (287 loc) · 4.54 KB
/
exploit.asm
File metadata and controls
300 lines (287 loc) · 4.54 KB
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
; This is a somewhat modified version of BrandonW's fakesign exploit.
; It is this code's responsibility to:
; Restore sectors F0 and F4 from backup (E4 and EB).
; Erase sectors E4 and EB.
; Mark the OS as valid (both at 0056h and in the certificate).
; Reboot with RAM page 1 unhooked
; (as the boot code does, which tells the OS this is the initial boot).
.equ curRow 0x8459
.equ tempSwapArea 0x8B8C
.equ _dispBootVer 0x808A
.equ _WriteAByteSafe 0x80C6
.equ _WriteFlashSafe 0x80C9
.equ _EraseFlash 0x8024
.equ _MarkOSValid 0x8099
.org 0x0A60B
;Find the first "ret" on the boot page, for the flash writing/erasing routines
ld hl, 0x4000
ld a, 0xC9
ld b, h
ld c, l
cpir
dec hl
ld (location_ret), hl
;Clear LCD and display status message
ld hl, 0
ld (curRow), hl
ld bc, 10 * 26
clearLoop:
push bc
ld a, ' '
call PutC
pop bc
dec bc
ld a, b
or c
jr nz, clearLoop
ld hl, 0
ld (curRow), hl
ld hl, sCleaningUp
call PutS
;Erase sectors F0 and F4
#ifdef TI84pCSE
ld a, 0xF0
#else
ld a, 0x70
#endif
ld hl, 0x4000
call EraseFlash
call UpdateProgress
#ifdef TI84pCSE
ld a, 0xF4
#else
ld a, 0x74
#endif
ld hl, 0x4000
call EraseFlash
call UpdateProgress
;Copy data from pages E4-EB to F0-F7
#ifdef TI84pCSE
ld a, 0xE4
ld b, 0xF0
#else
ld a, 0x64
ld b, 0x70
#endif
ld c, 8
copyLoop:
push af
push bc
call CopyFlashPage
call UpdateProgress
pop bc
pop af
inc a
inc b
dec c
jr nz,copyLoop
call UpdateProgress
;Erase sectors E4 and E8
#ifdef TI84pCSE
ld a, 0xE4
#else
ld a, 0x74
#endif
ld hl, 0x4000
call EraseFlash
call UpdateProgress
#ifdef TI84pCSE
ld a, 0xE8
#else
ld a, 0x78
#endif
ld hl, 0x4000
call EraseFlash
call UpdateProgress
;Mark OS valid
xor a
ld de, 0x0056
ld b, 0x5A
call WriteAByte
call UpdateProgress
call MarkOSValid
call UpdateProgress
;Set final OS valid marker
;Any boot code display routines after this will relock flash back.
xor a
ld de, 0x0026
ld b, 0
call WriteAByte
;Boot
xor a
out (7), a
jp 0x0053
CopyFlashPage:
ld c, a
in a, (6)
push af
in a, (0xE)
push af
ld a, c
ld de, 0x4000
cfpLoop:
push af
push bc
bit 7, a
res 7, a
out (6), a
ld a, 1
jr nz, cfp1
xor a
cfp1:
out (0xE), a
ld hl, tempSwapArea
push hl
ex de, hl
push hl
ld bc, 128
push bc
ldir
pop bc
pop de
pop hl
ld a, 0x7F
out (6), a
ld a, 1
out (0xE), a
pop af
push af
push de
push bc
call WriteFlash
pop de
pop hl
add hl, de
ex de, hl
pop bc
pop af
bit 7, d
jr z, cfpLoop
pop af
out (0xE), a
pop af
out (6), a
ret
PutS:
ld a, (hl)
inc hl
or a
ret z
call PutC
jr PutS
UpdateProgress:
push af
push bc
push de
push hl
push ix
ld a, '.'
call PutC
pop ix
pop hl
pop de
pop bc
pop af
ret
ldhlind:
ld a, (hl)
inc hl
ld h, (hl)
ld l, a
ret
DispHexHL:
push af
ld a, h
call DispHexA
ld a, l
call DispHexA
pop af
ret
DispHexA:
push af
push hl
push bc
push af
rrca
rrca
rrca
rrca
call dispha
pop af
call dispha
pop bc
pop hl
pop af
ret
dispha:
and 15
cp 10
jp nc, dhlet
add a, 48
jp dispdh
dhlet:
add a, 55
dispdh:
jp PutC
PutC:
push hl
push af
ld hl, _dispBootVer - 0x4000
call ldhlind
ld de, 10
add hl, de
call ldhlind
ld a, 0xCD
ld b, a
ld c, a
cpir
call ldhlind
push hl
pop ix
pop af
pop hl
jp (ix)
WriteAByte:
ld ix, (location_ret)
push ix
push ix
ld ix, _WriteAByteSafe - 0x4000
ex (sp), hl
ld l, (ix + 0)
ld h, (ix + 1)
ex (sp), hl
ret
WriteFlash:
ld ix, (location_ret)
push ix
push ix
ld ix, _WriteFlashSafe - 0x4000
ex (sp), hl
ld l, (ix + 0)
ld h, (ix + 1)
ex (sp), hl
ret
EraseFlash:
ld ix, (location_ret)
push ix
push ix
ld ix, _EraseFlash - 0x4000
ex (sp), hl
ld l, (ix + 0)
ld h, (ix + 1)
ex (sp), hl
ret
MarkOSValid:
ld ix, (location_ret)
push ix
push ix
ld ix, _MarkOSValid - 0x4000
ex (sp), hl
ld l, (ix + 0)
ld h, (ix + 1)
ex (sp), hl
ret
sCleaningUp:
.db "Preparing, please wait...",0
location_ret:
.dw 0