From 2e9caa75d77d368ead271268406a24a1052b9d85 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 3 Aug 2013 13:44:03 -0500 Subject: Move extras/ into a git submodule. --- extras | 1 + extras/graph.py | 169 -------------------------------------------------------- 2 files changed, 1 insertion(+), 169 deletions(-) create mode 160000 extras delete mode 100644 extras/graph.py (limited to 'extras/graph.py') diff --git a/extras b/extras new file mode 160000 index 000000000..13dfbba8d --- /dev/null +++ b/extras @@ -0,0 +1 @@ +Subproject commit 13dfbba8d21b843cc3bb871ed06088ca72cde8c3 diff --git a/extras/graph.py b/extras/graph.py deleted file mode 100644 index 47087e5cf..000000000 --- a/extras/graph.py +++ /dev/null @@ -1,169 +0,0 @@ -# -*- coding: utf-8 -*- - -import networkx as nx - -from romstr import ( - RomStr, - relative_jumps, - call_commands, - relative_unconditional_jumps, -) - -class RomGraph(nx.DiGraph): - """ - Graphs various functions pointing to each other. - - TODO: Bank switches are nasty. They should be detected. Otherwise, - functions will point to non-functions within the same bank. Another way - to detect bankswitches is retroactively. By disassembling one function - after another within the function banks, it can be roughly assumed that - anything pointing to something else (within the same bank) is really - actually a bankswitch. An even better method to handle bankswitches - would be to just detect those situations in the asm (but I presently - forget how bankswitches are performed in pokecrystal). - """ - - # some areas shouldn't be parsed as asm - exclusions = [] - - # where is the first function located? - start_address = 0x150 - - # and where is a good place to stop? - end_address = 0x4000 * 0x03 # only do the first bank? sure.. - - # where is the rom stored? - rompath = "../baserom.gbc" - - def __init__(self, rom=None, **kwargs): - """ - Loads and parses the ROM into a function graph. - """ - # continue the initialization - nx.DiGraph.__init__(self, **kwargs) - - # load the graph - if rom == None: - self.load_rom() - else: - self.rom = rom - - # start parsing the ROM - self.parse() - - def load_rom(self): - """ - Creates a RomStr from rompath. - """ - file_handler = open(self.rompath, "r") - self.rom = RomStr(file_handler.read()) - file_handler.close() - - def parse(self): - """ - Parses the ROM starting with the first function address. Each - function is disassembled and parsed to find where else it leads to. - """ - functions = {} - - address = self.start_address - - other_addresses = set() - - count = 0 - - while True: - if count > 3000: - break - - if address < self.end_address and (address not in functions.keys()) and address >= 0x150: - # address is okay to parse at, keep going - pass - elif len(other_addresses) > 0: - # parse some other address possibly in a remote bank - address = other_addresses.pop() - else: - # no more addresses detected- exit loop - break - - # parse the asm - func = self.rom.to_asm(address) - - # check if there are any nops (probably not a function) - nops = 0 - for (id, command) in func.asm_commands.items(): - if command.has_key("id") and command["id"] == 0x0: - nops += 1 - - # skip this function - if nops > 1: - address = 0 - continue - - # store this parsed function - functions[address] = func - - # where does this function jump to? - used_addresses = set(func.used_addresses()) - - # add this information to the graph - for used_address in used_addresses: - # only add this remote address if it's not yet parsed - if used_address not in functions.keys(): - other_addresses.update([used_address]) - - # add this other address to the graph - if used_address > 100: - self.add_node(used_address) - - # add this as an edge between the two nodes - self.add_edge(address, used_address) - - # setup the next function to be parsed - address = func.last_address - - count += 1 - - self.functions = functions - - def pretty_printer(self): - """ - Shows some text output describing which nodes point to which other - nodes. - """ - print self.edges() - - def to_d3(self): - """ - Exports to d3.js because we're gangster like that. - """ - import networkx.readwrite.json_graph as json_graph - content = json_graph.dumps(self) - fh = open("crystal/crystal.json", "w") - fh.write(content) - fh.close() - - def to_gephi(self): - """ - Generates a gexf file. - """ - nx.write_gexf(self, "graph.gexf") - -class RedGraph(RomGraph): - """ - Not implemented. Go away. - """ - - rompath = "../pokered-baserom.gbc" - -class CryGraph(RomGraph): - exclusions = [ - [0x000, 0x149], - ] - - rompath = "../baserom.gbc" - -if __name__ == "__main__": - crygraph = CryGraph() - crygraph.pretty_printer() - crygraph.to_gephi() -- cgit v1.2.3 From a5f1029d1cefb93ddbaad3261d27eefa3b17929f Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 3 Aug 2013 16:17:25 -0500 Subject: update extras submodule to latest master branch --- extras | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'extras/graph.py') diff --git a/extras b/extras index 13dfbba8d..a14c36ead 160000 --- a/extras +++ b/extras @@ -1 +1 @@ -Subproject commit 13dfbba8d21b843cc3bb871ed06088ca72cde8c3 +Subproject commit a14c36eadb75ea3d6fbc4cb3f382d7c9785d9fe9 -- cgit v1.2.3 From 2b7b3b6dc2bf8052de8747b353205963b6aa22f4 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 3 Aug 2013 16:22:08 -0500 Subject: update extras submodule on the "organizing" branch The eggified version of all of the python stuff will probably not work immediately. --- extras | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'extras/graph.py') diff --git a/extras b/extras index a14c36ead..a76acbadd 160000 --- a/extras +++ b/extras @@ -1 +1 @@ -Subproject commit a14c36eadb75ea3d6fbc4cb3f382d7c9785d9fe9 +Subproject commit a76acbadd2571c0d73b0797b2b68e205ab882b64 -- cgit v1.2.3 From 4619cf13def369c9612621c4689bad364b14bee3 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 3 Aug 2013 16:54:28 -0500 Subject: reset extras submodule to branch master The eggify branch was a success, so the submodule's upstream changes have been merged in. --- extras | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'extras/graph.py') diff --git a/extras b/extras index a76acbadd..0403a4a90 160000 --- a/extras +++ b/extras @@ -1 +1 @@ -Subproject commit a76acbadd2571c0d73b0797b2b68e205ab882b64 +Subproject commit 0403a4a90d473cc0a4bf5c53677c0a84406bc4ad -- cgit v1.2.3 From 268a2d28fdbacf48ea5e9d0cbac37ac4deee7082 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 3 Aug 2013 20:13:37 -0500 Subject: probably fix the pngs target for make Update the submodule to a version where gfx.py is able to handle the current paths. Make some other fixes to Makefile to call gfx.py correctly. --- extras | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'extras/graph.py') diff --git a/extras b/extras index 0403a4a90..3011f9243 160000 --- a/extras +++ b/extras @@ -1 +1 @@ -Subproject commit 0403a4a90d473cc0a4bf5c53677c0a84406bc4ad +Subproject commit 3011f9243cbe4b0de7ab2392941385c705697909 -- cgit v1.2.3 From 94f5f61265b9654925b66dca7c3256668435eeea Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Tue, 27 Aug 2013 11:15:19 -0500 Subject: bump extras submodule to v1.1.0 The extras submodule is provided by pokemon-reverse-engineering-tools v1.1.0 at commit 016f0206b5029fc83a6200be29b0f980c76dfd90. --- extras | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'extras/graph.py') diff --git a/extras b/extras index 3011f9243..016f0206b 160000 --- a/extras +++ b/extras @@ -1 +1 @@ -Subproject commit 3011f9243cbe4b0de7ab2392941385c705697909 +Subproject commit 016f0206b5029fc83a6200be29b0f980c76dfd90 -- cgit v1.2.3