Re: Arbitrary code execution in Red/Blue using the "8F" item
Posted by: Azarokkusu
Date: 2017-11-28 04:54:18
Glitch City Laboratories closed on 1 September 2020 (announcement). This is an archived copy of a thread from Glitch City Laboratories Forums.
You can join Glitch City Research Institute to ask questions or discuss current developments.
You may also download the archive of this forum in .tar.gz, .sql.gz, or .sqlite.gz formats.
Hmm, that's a very interesting idea…
I guess we could use OAM DMA Hijacking? OAM DMA routine is FF80-FF89. Using the item setup to modify this routine to jump, at each frame, to other items, and writing a code with these items that affect DA40 to DA45 may work. I could try that to be sure…
X Accuracy x65
Carbos x218
Poké Ball x175
Repel x5
Water Stone x29
Fire Stone x252
Lemonade x195
Awakening x70
TM01 x1
[any items past here if you want, doesn't matter]
8F
[any item] x[any qty]
Lemonade x201
X Accuracy x128
Carbos x255
Water Stone x201
(or Water Stone x3 then TM01 x[any])
Lemonade x2
X Accuracy x50
Carbos x218
Water Stone x201
Um, no, it doesn't. (We discussed, and it was because his DMA hijacking setup was a little bit dirty. The one I use is 100% clean.)
Anyways ; to do this "setting play time to 0" using DMA hijacking, I have made a setup that almost works.
Almost, because it sets your play time to 0 hours 0 minutes 0 seconds and one frame. This can be fixed, at the cost of an extra
So, we'll be setting up your PC items first.
X Accuracy x65
Carbos x218
Poké Ball x175
Repel x5
Water Stone x29
Fire Stone x252
Lemonade x195
Awakening x70
TM01 x1
[any items past here if you want, doesn't matter]
Save, just to be sure.
Then, set up your item pack :
8F
[any item] x[any qty]
Lemonade x201
X Accuracy x128
Carbos x255
Water Stone x201
(or Water Stone x3 then TM01 x[any])
Use 8F. Now, sprites on-screen should stop updating. If not, then you didn't use the proper quantities, reset the game.
Otherwise, this means you successfully disabled the OAM DMA routine, which is a key component of updating sprites. Since that function is executed on every frame, and we're going to hijack it to run our own code, we need to disable it.
Now, we're going to set it up to hijack its exec.
Get yourself 131 X Accuracies and 226 Lemonades. (By that I mean, set the quantities of the corresponding stacks to the corresponding value)
Use 8F.
Toss 1 X Accuracy and 13 Lemonades. (You have 213)
Use 8F.
Toss 1 X Accuracy and 154 Lemonades. (You have 59)
Use 8F.
Toss 1 X Accuracy and set your number of Lemonades to 205.
Use 8F, and hopefully you won't crash. If you don't, your play time will now be stuck ! (0 hours 0 minutes 0 seconds 1 frame)
Memory editor alternative, starting after saving after setting up the PC items.
Go to FF80, and write CD 3B D5 E2 in one go (notably, this will NOT work with offgao's memory editor).
Now, if you're reeeeally picky, you can set the play time to 0 frames instead. Just run the following 8F script.
Lemonade x2
X Accuracy x50
Carbos x218
Water Stone x201
This will tell the game to stop counting play time, which will freeze the counter to 0 frames instead of 1.
About persistence of the hijack… the hijack is destroyed by saving and resetting. Basically, you should resume from where I recommended to save ; obviously the payload stored using your PC items will have survived, but the final step of the hijack (the five 8F uses, and optionally the sixth one to freeze at 0 frames) must be started over every time you reset the game, even if you saved.
Could some thing like the game memory hacking itself rom hack be done with 8f it would be cool to see the game glitching itself on a real cartridge.
Yeah, it adds some register mixing to VBlank. That's not RAMable.
Could some thing like the game memory hacking itself rom hack be done with 8f it would be cool to see the game glitching itself on a real cartridge.
…
????????
I'm going to assume you're reffering to a ROM hack that alters data pseudo-randomly, in which case, no, that cannot be done with 8f under any circumstances. If you want to make a ROM hack, use pokered.
ld hl, sp+X
ld [hl], Y
ld a, $C3
ld c, $46
ret
di ; Prevent the game from prematurely executing the other game's interrupts
inc b ; Filler
.loop
ld a,$10 ; a = $10
ld h,$ff ; hl = $FF22
ld l,$01 ; hl = $FF01
dec c ; Filler
dec l ; hl = $FF00, hardware register responsible for Joypad input
inc c ; Filler
ld (hl),a ; Enable polling for button inputs
ld d,d ; Filler
ld a,(hl) ; Grab current button inputs
and $0f ; Filter out unrelated upper nibble
ld c,$07 ; c = $07
inc d ; Filler
cp c ; compare a with c. In binary, this would check for %0111, as bit 3 is reset if START is pressed
jr nz,.loop ; Not Equal? Go to loop
ld b,c ; Filler
ld h,l ; hl = $0000
inc h ; hl = $0100 (GB booting point)
ld c,1 ; c = 1
ld a,c ; a = 1
jp hl ; Reboot
ld a, $20 ; Select dpad
ldh [$FF00], a
ld a, $10 ; Joypad interrupt
ldh [$FFFF], a
stop ; $10, makes the Game Boy "deep sleep" until an interrupt occurs
XX ; Any byte
xor a
ld [$FF0F], a
inc a
ld [$FFFF], a
halt ; Wait for a VBlank interrupt, this helps stabilize the state
It'd probably help if we spent about 1/4 of a second wasting time in this setup so we have time to compensate for user reaction time and button bounce.
A CartSwap setup had been made (by Cryo, IIRC), which used the joypad to wake up the Game Boy. It did this, plus fillers :
ld a, $20 ; Select dpad
ldh [$FF00], a
ld a, $10 ; Joypad interrupt
ldh [$FFFF], a
stop ; $10, makes the Game Boy "deep sleep" until an interrupt occurs
XX ; Any byte
xor a
ld [$FF0F], a
inc a
ld [$FFFF], a
halt ; Wait for a VBlank interrupt, this helps stabilize the state
The user should simply run the code, swap carts, and press the D-Pad.
(Note : if the D-Pad is already held when the setup is ran, it will fail.)