Glitch City Laboratories Forums

Lab δ: Tech => Tech Help => Topic started by: Beppe1509 on November 23, 2019, 06:29:02 am

Title: Pokemon Crystal Remote Code Execution
Post by: Beppe1509 on November 23, 2019, 06:29:02 am
I was just casually looking at youtube and I found a video from TheZZAZZGlitch that showed me how I can use those ".bin" files with link cable to execute code, now I wanna make my own .bin files but I dont know how. Any suggestions?
Title: Re: How .bin files work?
Post by: Sherkel on November 23, 2019, 07:20:36 am
This one (https://www.youtube.com/watch?v=e8CO_e_rKd8)?

Just do what he does in the video. It's in the bottom left quarter of the screen. If I correctly understand what you're asking.

To clarify, there is no one common use of .bin files. It's short for "binary". So just use them in whatever way they're intended to be used, in this case the way they're used in the video.
Title: Re: How .bin files work?
Post by: Beppe1509 on November 23, 2019, 07:33:13 am
Yeah but if you see he does python and i managed to do that but the problem is i want to make my own bin file like make this : https://pastebin.com/LTmnYhTx into a pokemon red program executed like him
Title: Re: How .bin files work?
Post by: Sherkel on November 23, 2019, 08:19:21 am
Be more specific with your question next time; I almost asked if you knew what Python was. :P

Anyway, given that you do, this should speak for itself:
Code: [Select]
print("BINARY should be a headerless block of GB Z80 machine code, 256 bytes in size")
If you're wondering how to write GBz80 code and compile it, the forum section on ACE (https://forums.glitchcity.info/index.php?board=115.0) has plenty of links to help get you started.
Title: Re: How .bin files work?
Post by: Beppe1509 on November 23, 2019, 09:25:54 am
Thanks SO MUCH
Title: Re: How .bin files work?
Post by: Sherkel on November 23, 2019, 09:32:24 am
No problem!
Title: Re: How .bin files work?
Post by: Beppe1509 on November 23, 2019, 09:53:00 am
another question, what should i use for converting the gbz80 code into binary
Title: Re: Pokemon Crystal Remote Code Execution
Post by: Sherkel on November 23, 2019, 10:15:57 am
If it just needs machine code, running it through rgbasm (https://rednex.github.io/rgbds/rgbasm.1.html) should do it.

The GBDev Discord server (https://discord.gg/gpBxq85) might come in handy if you're interested in coding for the Game Boy. :)
Title: Re: Pokemon Crystal Remote Code Execution
Post by: Beppe1509 on November 24, 2019, 06:32:40 am
I have a question, how do I execute a gbz80 code into pokemon? I have seen a tread with the items but when i have all the items in place it just crashes, any help?
Title: Re: Pokemon Crystal Remote Code Execution
Post by: Sherkel on November 24, 2019, 08:57:31 am
Do you have the bootstrap part done? It's when you prepare your party for 8F, your PC for ws m, or your Safari Balls and Day Care for -gm, depending on which item you're using.
Title: Re: Pokemon Crystal Remote Code Execution
Post by: Beppe1509 on November 24, 2019, 11:16:26 am
I have prepared my 8F bootstrapper on pokemon red, i tested some premade ones and they worked fine but now the problem is "converting" the code
Title: Re: Pokemon Crystal Remote Code Execution
Post by: Sherkel on November 24, 2019, 12:38:45 pm
I have prepared my 8F bootstrapper on pokemon red, i tested some premade ones and they worked fine but now the problem is "converting" the code
Converting from what to what?

If it's assembly code to items, GBz80 to Items (https://eldred.fr/gbz80toitems3/) does exactly what it says on the tin. If you're on BGB, it's a good idea to just type them in to test the setup first before going through the trouble of doing it legitimately on an original system, if that's your goal.
Title: Re: Pokemon Crystal Remote Code Execution
Post by: Beppe1509 on November 27, 2019, 09:13:43 am
how can i convert Items to GBz80??
Title: Re: Pokemon Crystal Remote Code Execution
Post by: Parzival on November 27, 2019, 01:41:54 pm
how can i convert Items to GBz80??
write the items to your inventory then go to that area in a debugger. Should work.
Title: Re: Pokemon Crystal Remote Code Execution
Post by: Beppe1509 on November 28, 2019, 08:11:47 am
The Problem is that it does like that : https://ibb.co/pRmGYwH

any fix

CTRL + G works but on the code it just shows -
Title: Re: Pokemon Crystal Remote Code Execution
Post by: Evie the Bird Mother 🌸 ☽ on November 28, 2019, 11:43:53 am
The Problem is that it does like that : https://ibb.co/pRmGYwH

any fix

CTRL + G works but on the code it just shows -

As it's not automatic and sometimes BGB starts at the wrong place, the trick is to right click at the start of your code I think (i.e. D322 here) and access it via Go to; then BGB will update it.

Edit: In this case the display won't change because D321 was a one byte instruction (though if it was 2 bytes it would require right clicking method). Your code currently grabs FFD3, puts it into "a" and then puts "a" in D059 (instant encounter) (in contrast with e.g. 3E 15 at the start, which compiles as ld a,15 where 15 can be replaced with any value). When a is on the left side of the code it is storing something into the "a" register.

Additionally hope this may help https://iimarckus.org/etc/asmopcodes.txt
Title: Re: Pokemon Crystal Remote Code Execution
Post by: Parzival on November 28, 2019, 03:42:43 pm
The Problem is that it does like that : https://ibb.co/pRmGYwH

any fix

CTRL + G works but on the code it just shows -

As it's not automatic and sometimes BGB starts at the wrong place, the trick is to right click at the start of your code I think (i.e. D322 here) and access it via Go to; then BGB will update it.

Edit: In this case the display won't change because D321 was a one byte instruction (though if it was 2 bytes it would require right clicking method). Your code currently grabs FFD3, puts it into "a" and then puts "a" in D059 (instant encounter) (in contrast with e.g. 3E 15 at the start, which compiles as ld a,15 where 15 can be replaced with any value). When a is on the left side of the code it is storing something into the "a" register.

Additionally hope this may help https://iimarckus.org/etc/asmopcodes.txt
you missed the "CTRL + G works but on the code it just shows -" part
when it just shows a - it's an invalid opcode and will pop the debugger when hit.
Title: Re: Pokemon Crystal Remote Code Execution
Post by: Evie the Bird Mother 🌸 ☽ on November 28, 2019, 04:17:11 pm
Sorry about that, I didn't see the Ctrl+G part. Yeah Parzival is right, if there are any opcodes not on the opcodes text file they show as "-". That automatically brings up BGB debugger where other emulators e.g. VBA may act differently (invalid opcode at (address) message etc.) On a Game Boy this freezes, while on 3DS Virtual Console it skips them. (This actually makes me wonder if this is deeper technically/if invalid opcodes have separate effects that can only be understood on a hardware level/or if any obscure peripherals use them like what Shonumi is doing)
Title: Re: Pokemon Crystal Remote Code Execution
Post by: Parzival on November 28, 2019, 04:28:38 pm
Sorry about that, I didn't see the Ctrl+G part. Yeah Parzival is right, if there are any opcodes not on the opcodes text file they show as "-". That automatically brings up BGB debugger where other emulators e.g. VBA may act differently (invalid opcode at (address) message etc.) On a Game Boy this freezes, while on 3DS Virtual Console it skips them. (This actually makes me wonder if this is deeper technically/if invalid opcodes have separate effects that can only be understood on a hardware level/or if any obscure peripherals use them like what Shonumi is doing)
Nope. The CPU hangs as the silicon isn't built to handle that set of bits as an instruction anymore so it goes apeshit.
Title: Re: Pokemon Crystal Remote Code Execution
Post by: bbbbbbbbba on November 28, 2019, 05:27:42 pm
Sorry about that, I didn't see the Ctrl+G part. Yeah Parzival is right, if there are any opcodes not on the opcodes text file they show as "-". That automatically brings up BGB debugger where other emulators e.g. VBA may act differently (invalid opcode at (address) message etc.) On a Game Boy this freezes, while on 3DS Virtual Console it skips them. (This actually makes me wonder if this is deeper technically/if invalid opcodes have separate effects that can only be understood on a hardware level/or if any obscure peripherals use them like what Shonumi is doing)
Nope. The CPU hangs as the silicon isn't built to handle that set of bits as an instruction anymore so it goes apeshit.
My guess would be that, since each instruction takes a different number of cycles, there must be a signal that tells the CPU that the previous instruction has finished and the next instruction can begin. And whatever undefined behavior the invalid opcode triggers, it never emits that signal, so the CPU never gets to the next instruction.
Title: Re: Pokemon Crystal Remote Code Execution
Post by: Parzival on November 28, 2019, 09:12:19 pm
Sorry about that, I didn't see the Ctrl+G part. Yeah Parzival is right, if there are any opcodes not on the opcodes text file they show as "-". That automatically brings up BGB debugger where other emulators e.g. VBA may act differently (invalid opcode at (address) message etc.) On a Game Boy this freezes, while on 3DS Virtual Console it skips them. (This actually makes me wonder if this is deeper technically/if invalid opcodes have separate effects that can only be understood on a hardware level/or if any obscure peripherals use them like what Shonumi is doing)
Nope. The CPU hangs as the silicon isn't built to handle that set of bits as an instruction anymore so it goes apeshit.
My guess would be that, since each instruction takes a different number of cycles, there must be a signal that tells the CPU that the previous instruction has finished and the next instruction can begin. And whatever undefined behavior the invalid opcode triggers, it never emits that signal, so the CPU never gets to the next instruction.
The clock signal, the thing that only has power in and clock out? :P
Title: Re: Pokemon Crystal Remote Code Execution
Post by: Evie the Bird Mother 🌸 ☽ on March 07, 2020, 02:30:55 am
Might now be possible with https://forums.glitchcity.info/index.php?topic=9005.0 too? :)