Re: Arbitrary code execution in Red/Blue using the "8F" item
Posted by: Stackout
Date: 2013-12-06 16:21:05
Major new finding:
8F should work in FR/ES/IT/DE R/B.
In all of these, item $5D points to $D168 which in these games is where "Number of Pokémon" is.
But of course, there's a catch.
Seeing as the offsets are different…
The bootstrap code for English R/B won't work!
So using them there will have to wait until me, TheZZAZZGlitch, or a 3rd party goes and plays around with GB asm and makes a nice payload that can jump to $D327 (3rd item type).
And for all you players of Japanese Blue.. 5kai should work there just as well as it works in Japanese R/G.
For Yellow:
In ES/DE/FR/IT Yellow, item $63 calls DA84 (I think this is Number of Pokémon in Current Box, i have yet to confirm this.)
Of course, different bootstrap code is needed here thanks to the offset differences.
In JP yellow, item $BB calls $DB21, which I think is something in the middle of current box pokémon 7. Either Status, or Type 1. I'm not sure which. UPDATE: if I have my calculations correct, it's Type 1. (Thanks Torchickens!) UPDATE 2: It's actually Type 1 of Pokémon 11 in the current box, not Pokémon 7. (Thanks again Torchickens!)
This would require whole new bootstrap code, it cannot be based on any of the others.
Another update:
Here's bootstrap code for European R/B. TheZZAZZGlitch, thanks a lot for using relative jumps and making my life easier, it only requires one byte change! Please note that I haven't tested this yet and probably won't have a chance to today, but if it doesn't work, I will probably update this post with the working code.
OK, here we go…
[tt]1. 6 Pokémon [0xD168 = 0x06]
2. Graveler as the first Pokémon [0xD169 = 0x27]
3. Pidgey as the second Pokémon [0xD16A = 0x24]
4. Tentacool as the third Pokémon [0xD16B = 0x18]
5. Meowth as the fourth Pokémon [0xD16C = 0x4D]
6. 24 PP left on the second Pokémon's second move [0xD1BA = 0x18]
7. 21 PP left on the second Pokémon's third move w/ 1 PP Up used [0xD1BB = 0x55]
8. 36 PP left on the fourth Pokémon's first move [0xD211 = 0x24]
9. 24 PP left on the fourth Pokémon's second move [0xD212 = 0x18]
10. 20 PP left on the fourth Pokémon's third move [0xD213 = 0x14]
11. Double Team as the fifth Pokémon's first move [0xD228 = 0x68]
12. Double Kick as the fifth Pokémon's second move [0xD229 = 0x18]
13. Strength as the fifth Pokémon's third move [0xD230 = 0x46]
14. Sixth Pokémon's attack stat has to be exactly 233 [0xD271 = 0xE9][/tt]
; -- EU R/B
; -- hl: D168
D168: 06 27 ld b,27 ; b=27
D16A: 24 inc h ; hl = D268
D16B: 18 4D jr D1BA
D1BA: 18 55 jr D211
D211: 24 inc h ; hl = D368
D212: 18 14 jr D228
D228: 68 ld l,b ; hl = D327
D229: 18 46 jr D271
D271: E9 jp hl
EDIT: Just tested, and this payload works totally fine on FR Blue.
Yet another update:
And here's payload code for FR/ES/DE/IT Yellow. Thanks again to TheZZAZZGlitch, again I only need to change one byte!
[tt]1. 20 Pokémon in your PC box [0xDA84 = 0x14]
2. Slowpoke as the 1st Pokémon in the current PC box [0xDA85 = 0x25]
3. Slowpoke as the 2nd Pokémon in the current PC box [0xDA86 = 0x25]
4. Slowpoke as the 3rd Pokémon in the current PC box [0xDA87 = 0x25]
5. Slowpoke as the 4th Pokémon in the current PC box [0xDA88 = 0x25]
6. Slowpoke as the 5th Pokémon in the current PC box [0xDA89 = 0x25]
7. Slowpoke as the 6th Pokémon in the current PC box [0xDA8A = 0x25]
8. Voltorb as the 7th Pokémon in the current PC box [0xDA8B = 0x06]
9. Scyther as the 8th Pokémon in the current PC box [0xDA8C = 0x26]
10. Jolteon as the 9th Pokémon in the current PC box [0xDA8D = 0x68]
11. Geodude as the 10th Pokémon in the current PC box [0xDA8E = 0xA9]
12. Geodude as the 11th Pokémon in the current PC box [0xDA8F = 0xA9]
13. Geodude as the 12th Pokémon in the current PC box [0xDA90 = 0xA9]
14. Geodude as the 13th Pokémon in the current PC box [0xDA91 = 0xA9]
15. Geodude as the 14th Pokémon in the current PC box [0xDA92 = 0xA9]
16. Geodude as the 16th Pokémon in the current PC box [0xDA93 = 0xA9]
17. Geodude as the 15th Pokémon in the current PC box [0xDA94 = 0xA9]
18. Geodude as the 17th Pokémon in the current PC box [0xDA95 = 0xA9]
19. Geodude as the 18th Pokémon in the current PC box [0xDA96 = 0xA9]
20. Geodude as the 19th Pokémon in the current PC box [0xDA97 = 0xA9]
21. Voltorb as the 20th Pokémon in the current PC box [0xDA98 = 0x06]
:: END OF LIST MARKER [0xFF] [0xDA99 = 0xFF]
22. Slowpoke as the 1st Pokémon in the current PC box [0xDA9A = 0x25]
23. First PC box Pokémon needs to have 233 HP -+- [0xDA9B = 0x00]
+- [0xDA9C = 0xE9][/tt]
; -- EU YELLOW
; initial value of hl = DA84
WRA1:DA84 14 inc d ; offset hack: 20 Pokémon in the box
WRA1:DA85 25 dec h ; hl = D984
WRA1:DA86 25 dec h ; hl = D884
WRA1:DA87 25 dec h ; hl = D784
WRA1:DA88 25 dec h ; hl = D684
WRA1:DA89 25 dec h ; hl = D584
WRA1:DA8A 25 dec h ; hl = D484
WRA1:DA8B 06 26 ld b,26
WRA1:DA8D 68 ld l,b ; hl = D426
WRA1:DA8E A9 xor c ; offset hack: do nothing until ip=DA93
WRA1:DA8F A9 xor c
WRA1:DA90 A9 xor c
WRA1:DA91 A9 xor c
WRA1:DA92 A9 xor c
WRA1:DA93 A9 xor c
WRA1:DA94 A9 xor c
WRA1:DA95 A9 xor c
WRA1:DA96 A9 xor c
WRA1:DA97 A9 xor c
WRA1:DA98 06 FF ld b,FF ; offset hack: making an end of list FF byte an operand so it doesn't translate to [rst 38]
WRA1:DA9A 25 dec h ; hl = D326
WRA1:DA9B 00 nop
WRA1:DA9C E9 jp hl
Tested working with FR Yellow. :)