Glitch City Laboratories Forums

Lab δ: Tech => Programming/Scripting/Development/Web Design => Topic started by: Dandaman955 on July 20, 2016, 11:51:36 pm

Title: Another Crystal Disassembly?
Post by: Dandaman955 on July 20, 2016, 11:51:36 pm
Okay, so this is probably the most pointless thread, and I don't know how to make polls, so with that in mind:

I was looking through the current Pokemon Crystal disassembly by (I think?) pret, and I found a lot of it quite hard to read through. No disrespect to the work that was put through, but it was covered in equates and macros, with a lot of files split into sub-files which made following a lot of it difficult. Now in the Sonic scene, there are people who swear by two different types of disassemblies, often disagreeing on which is the best kind, with:-

- The up-to-date Git kind, where it is all macroed, equated and has code split into separate files, similar to how the Crystal disassembly is now. I think it's trying to be similar to how something like C handles it, with the includes and such?

- The one that isn't. Simple. :p

I personally believe that you can make a disassembly less cluttered by reducing the amount of equates, macros and file splits and replacing them with comments denoting what the instructions do in the grand scheme of things. Here's[1] an example of one disassembly I made (That isn't finished; Some instructions aren't commented and a lot of data isn't split into files yet, mainly the large block of data, from byte_100C to loc_6B48, with a few things otherwise. It should give an idea, though.) on the Action Replay ROM. I was thinking of making a disassembly with a similar structure to this one, but I don't think it's worth the effort if there isn't anyone who would actually find a use in it, so what I'm basically asking here is:

Would you be interested in/use a disassembly like this?

[1] - https://github.com/Dandaman955/Action-Replay-MD-Disasm/blob/master/Action%20Replay%20(Europe).asm (https://github.com/Dandaman955/Action-Replay-MD-Disasm/blob/master/Action%20Replay%20(Europe).asm)
Title: Re: Another Crystal Disassembly?
Post by: Yeniaul on July 20, 2016, 11:57:04 pm
In short? f**k yes.
This'd be perfect for an upcoming project of mine. (Hint, hint. :D)
Title: Re: Another Crystal Disassembly?
Post by: Dandaman955 on July 21, 2016, 12:16:28 am
Oh, you have to post to make the poll.

Anyways, I guess I can chalk one down for yes!
Title: Re: Another Crystal Disassembly?
Post by: TheZZAZZGlitch on July 21, 2016, 12:17:45 am
Definitely. A one-file disassembly is a lot easier to search through when you want to analyze a certain subroutine or check for certain behavior.
The current disasms of Pokemon games are formatted like "corporate quality code", which is good for ROM hacking, but not too good for reversing. A similar thing happened to the pokered disassembly. I circumvented the problem by getting an older version of the repository, where everything was still mostly in one file. But this old version has a lot of stuff undocumented, so later I need to search through the current version anyways.

An easy way to get a one-file disasm would be writing a quick script to expand all of the includes. Still, that wouldn't deal with macros and constants (looking through the code, minding my own business... f**k, what address is wWhichPokemon again? *scroll back to the top*)
Title: Re: Another Crystal Disassembly?
Post by: Wack0 on July 21, 2016, 02:41:34 am
I second TheZZAZZGlitch.
Title: Re: Another Crystal Disassembly?
Post by: ISSOtm on July 21, 2016, 05:56:20 am
It would also be nice if the same happened for Red and Yellow ; but, one thing at a time, so I heavily say YES to this one.
Title: Re: Another Crystal Disassembly?
Post by: Wack0 on July 21, 2016, 07:24:36 am
I just realised, compiling the disassembly would produce a symbol or map file, that I know that bgb at least can read to get symbol names (so you can ctrl+g <label> and it'll jump to the address etc).

That could be used instead of having an entirely new disasm.
Title: Re: Another Crystal Disassembly?
Post by: ISSOtm on July 21, 2016, 07:11:38 pm
I tried generating that file, but I didn't have rgbasm on my Debian system. When I tried to compile it, it required a package I didn't have.
That package didn't exist in the official repos, so I looked for an equivalent.
When running make on rbgasm, the equivalent produced seveal screens worth of synatx errors.

I uninstalled all out of discouragement.


If anyone could give me a link to such a .map file, I'd be ready to give them big, big hug. And a truck filled with Mews chocolate / candies / toffees / sweets.
Title: Re: Another Crystal Disassembly?
Post by: TheZZAZZGlitch on July 22, 2016, 12:51:55 am
I have a SYM file for Red/Blue, since I use it in bgb to get symbols for debugging.
But it doesn't seem to be of much help when creating a one-file disasm, using it by itself wouldn't preserve comments and differences between data and code. But I still included it as an attachment, since it's useful to have.

Instead, I randomly decided to do something stupid:

Code: [Select]
# coding: utf8
result = b''; counter = 0
with open('out.asm', 'rb') as f:
    for i in f.readlines():
        if i[0:9] == b'INCLUDE "':
            with open(i[9:-3], 'rb') as g: result += g.read()
            counter += 1
        else:
            result += i
with open('out.asm', 'wb') as f: f.write(result)
print("Eradicated includes: %i" % counter)
# run it multiple times to deal with nested includes

And the result looks surprisingly OK. https://aww.moe/u408xw.asm
It still lacks comments with function addresses (this could be done with the SYM file mentioned earlier), and has all the constants and macros (the problem of constants can be fixed by prefixing/suffixing each pointer constant with its effective address; still no idea how to approach the macros, does rgbasm have an command line option to only preprocess macros without compiling?)
Title: Re: Another Crystal Disassembly?
Post by: Yeniaul on July 22, 2016, 08:48:55 am
I tried generating that file, but I didn't have rgbasm on my Debian system. When I tried to compile it, it required a package I didn't have.
That package didn't exist in the official repos, so I looked for an equivalent.
When running make on rbgasm, the equivalent produced seveal screens worth of synatx errors.

I uninstalled all out of discouragement.


If anyone could give me a link to such a .map file, I'd be ready to give them big, big hug. And a truck filled with Mews chocolate / candies / toffees / sweets.
Search "rgbasm Debian" and find it on a repo. Look and see if any of the dependency names are links. Download those too, and any dependencies for those you don't have. Install the .deb files, starting with the lowest level of dependencies. (If rgbasm is the highest, and its dependencies are the next highest, what's the lowest level?)

This sounds and IS tedious, but try having to do this without ANY packages. You'd have to install EVERYTHING. If I can install GNUTools on Damn Small Linux, you can do the above process.

I hope you can figure out how to install them, considering all the documentation out there.
Title: Re: Another Crystal Disassembly?
Post by: IIMarckus on July 28, 2016, 01:16:38 am
Investing a little bit of time in learning how to effectively use tools like git grep and symfiles makes a big difference.