Re: Arbitrary code execution in Red/Blue using the "8F" item
Posted by: jfb1337
Date: 2016-09-22 15:49:42
The link in the description was broken, after trying to fix it it just led to the first post on this topic.
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.
The link in the description was broken, after trying to fix it it just led to the first post on this topic.
I just watched this video, and I don't really understand how it works - How does the code get executed from the save file? I'm assuming there's some kind of buffer overflow exploit in the load routine, I'd be interested to know the details.
The link in the description was broken, after trying to fix it it just led to the first post on this topic.
Recently, we had some maintaince.
I just watched this video, and I don't really understand how it works - How does the code get executed from the save file? I'm assuming there's some kind of buffer overflow exploit in the load routine, I'd be interested to know the details.
I semi-understand this.
8F executes code from somewhere around your party, then jumps to it, that's why you need a specific party, to form a jump instruction to jump to the third item data, then the code gets executed.
For larger codes you need to make a script I don't remember.
You can get stacks of items over 99 via 'M or Missingno. (all forms).
Yellow has w s m, which is equal to 8F.
However, to access SRAM, you must unlock it (write $0A in range 0000 - 1FFF). Plus, to prevent your save file from decaying, you should lock SRAM right after (either write any non-$0A to the memory range, or call some game code that just does that). Saving in any way (and accessing / updating the HoF too) should also lock SRAM.
Actually, none of that is necessary in Gen I. SRAM is permanently unlocked there and can be accessed at any time. The programmers didn't decide to take advantage of SRAM locking until Generation II.
The link in the description was broken, after trying to fix it it just led to the first post on this topic.
Recently, we had some maintaince.
I just watched this video, and I don't really understand how it works - How does the code get executed from the save file? I'm assuming there's some kind of buffer overflow exploit in the load routine, I'd be interested to know the details.
I semi-understand this.
8F executes code from somewhere around your party, then jumps to it, that's why you need a specific party, to form a jump instruction to jump to the third item data, then the code gets executed.
For larger codes you need to make a script I don't remember.
You can get stacks of items over 99 via 'M or Missingno. (all forms).
Yellow has w s m, which is equal to 8F.
I understand how 8F works, but I don't know how loading the save file after restarting caused arbitrary code to run (in order to display the text and stuff)
Hi, I'm new here. I've been trying to learn 8F asm programming and I mostly want something in yellow that gives me max ivs and evs and is easy to set up. So I was wondering if there was a way to use pc Pokémon as the program and then have it apply to the last Pokémon in the pc. That way I could deposit a Pokémon, use w sm, then withdraw the Pokémon. All I've used so far to learn is this website ( http://wahackforo.com/t-25791/gb-gbc-asm-lenguaje-ensamblador-en-gb-gbc ) that explains programming, but it's in Spanish so I'm not sure I'm getting some of the more complex things. Could someone explain like ld and jr and also if someone had a set up for the thing above that'd be great. Thanks.
ld a, FF [maximum value]
ld bc, 000C [copy hex:C i.e. 12 bytes]
ld hl, DBCF [destination]
inc d [useless; but used to represent the item as a Potion to avoid representing a CascadeBadge for the 16 later in the code]
call 166E [run the FillMemory routine]
ret [end of code]
3e ff 01 0c 00 21 cf db 14 cd 6e 16 c9
ld a,FF
ld h, DB
ld l, CF
ld (hli),a
ld (hli),a
ld (hli),a
ld (hli),a
ld (hli),a
ld (hli),a
ld (hli),a
ld (hli),a
ld (hli),a
ld (hli),a
ld (hli),a
ld (hli),a
ret
3e ff 26 db 2e cf 22 22 22 22 22 22 22 22 22 22 22 22 c9
Could someone explain like ld and jr and also if someone had a set up for the thing above that'd be great. Thanks.
ld a, 15 ; a=hex:15
ld (d058),a ; put a into d058
ret ; end of code, needed so the game doesn't execute anything below it
Ok, I have found what I was looking for. I decided to get my hands dirty and look directly into the disassembly tool. I looked at the address 3E48, as specified in the code for the R/B USA version, saw what the asm code looked like, and found one similar not far from this in the French Yellow version memory: in this version, the recipe for receiving a pokemon starts at 3E5C, which correspond to x92 instead of x72 for the TM05 quantity.
Now the code works wonder, I can receive the pokemon of my choice at lvl2 : )
Thanks again for having taken the time to answer my questions and my messages : ) !
I don't know how to post code in a neat box but I can just write it out. This is for the English Red using items:
Look at me in a Quote.
D322 21 C8 DA LD HL, DAC8
D325 7A LD A, D
D326 2F CPL
D327 22 LD (HL+), A
D328 04 INC B ; padding
D329 7D LD A, L
D32A EA 27 D3 LD (D327), A ; you assembled it the other way around. It takes practice to remember :)
D32D C9 RET
3e 01 3d 3d 01 0c 00 21 cf db 14 cd 6e 16 c9