Notices

ROM disassembly as raw text file

Thread Tools
 
Search this Thread
 
Old Mar 12, 2012 | 09:24 PM
  #166  
lodifreefly's Avatar
Evolving Member
iTrader: (1)
 
Joined: Jun 2009
Posts: 136
Likes: 0
From: Lodi, CA
Originally Posted by ofey

For the Mac crowd though, do not use the MacPort's version. They didn't configure with m32r, so you won't be able to do any disassembly.
Don't use macports! Use homebrew, you'll be a happier human being

To use brew to install objdump, you can use the formula I just finished. First enter:

brew edit binutils

then just paste in the following:

require 'formula'

class Binutils < Formula
url 'http://mirrors.ibiblio.org/pub/mirrors/gnu/ftp/gnu/binutils/binutils-2.22.tar.bz2'
mirror 'http://ftp.gnu.org/gnu/binutils/binutils-2.22.tar.bz2'
homepage 'http://www.gnu.org/software/binutils/binutils.html'
md5 'ee0f10756c84979622b992a4a61ea3f5'

def install
system "./configure", "--disable-debug",
"--disable-dependency-tracking",
"--program-prefix=g",
"--prefix=#{prefix}",
"--infodir=#{info}",
"--mandir=#{man}",
"--disable-werror",
"--enable-interwork",
"--enable-multilib",
"--enable-targets=x86_64-elf",
"--enable-targets=arm-none-eabi",
"--enable-targets=m32r"
system "make"
system "make install"
end
end

Save, and exit your editor. Then do:

brew install binutils

it will install everything with a "g" prefix (so that it won't override some of the MacOS builtin binaries). Once it's all done:

gobjdump -b binary --architecture=m32r --disassemble-all --disassemble-zeroes -EB myrom.hex > myrom_asm.txt

You should now have a disassembled ROM.

I'll also be submitting the formula to homebrew so hopefully soon the brew edit step won't be necessary in a bit.
Reply
Old Mar 13, 2012 | 12:51 AM
  #167  
ofey's Avatar
Newbie
iTrader: (1)
 
Joined: Nov 2008
Posts: 21
Likes: 0
From: Melbourne, Australia
Thanks for all that lodi but as I mentioned, I downloaded and compiled my own objdump, so that part of the challenge is over. Still got much more bigger fish to fry...
Reply
Old Mar 13, 2012 | 03:38 PM
  #168  
lodifreefly's Avatar
Evolving Member
iTrader: (1)
 
Joined: Jun 2009
Posts: 136
Likes: 0
From: Lodi, CA
Yeah, reread your post and saw that, sorry. What is your strategy at this point?

I've been using the ecuflash xml files to locate addresses of tables, then looking for references to them in the code and starting to grok and comment code from there. Trying to follow richard's style as much as possible.

As soon as I have a decent amount of progress, I'm going to post my files up on github and start accepting pull requests from anyone who wants to participate.
Reply
Old Mar 14, 2012 | 01:52 PM
  #169  
ofey's Avatar
Newbie
iTrader: (1)
 
Joined: Nov 2008
Posts: 21
Likes: 0
From: Melbourne, Australia
Originally Posted by lodifreefly
I've been using the ecuflash xml files to locate addresses of tables, then looking for references to them in the code and starting to grok and comment code from there. Trying to follow richard's style as much as possible.
Pretty much the same direction here. Been given the same advice by richard.
Unfortunately, his hands are abit tied in providing e.g.s

Originally Posted by lodifreefly
As soon as I have a decent amount of progress, I'm going to post my files up on github and start accepting pull requests from anyone who wants to participate.
We'll see how far I'm able to get ... .
Reply
Old Mar 14, 2012 | 04:29 PM
  #170  
richardjh's Avatar
Thread Starter
Evolved Member
 
Joined: Oct 2010
Posts: 2,447
Likes: 14
From: Australia
Nah, I'm totally 100% happy to provide examples of how to bounce through code to tables... backtrack from tables to code, suss out scales, etc. If that's what you want.

What I'm not able to do is provide annotated, dissected, commented code of other peoples' patches.

I've got my own patches too, of course. Those are totally fair game for anyone, and I'm happy to provide commented code for all of those.

A table discovery project is a great starting point for learning how all this stuff hangs together. My advice was (and is) to go for the tables first. Biggest gain for least pain... and a brilliant learning experience.

Rich
Reply
Old Mar 14, 2012 | 06:12 PM
  #171  
lodifreefly's Avatar
Evolving Member
iTrader: (1)
 
Joined: Jun 2009
Posts: 136
Likes: 0
From: Lodi, CA
I'd love to learn more about table discovery... I've seen some posts on it they seem to like to mention things like "triangulation" that I know nothing about.

As you may have noticed I'm all about building tools to automate things and sharing those with others. So if I learn how to do table discovery I will figure out a way to automate it and I will open source the tools for doing it.
Reply
Old Mar 18, 2012 | 01:16 AM
  #172  
lodifreefly's Avatar
Evolving Member
iTrader: (1)
 
Joined: Jun 2009
Posts: 136
Likes: 0
From: Lodi, CA
Alright. I have a tool now that will automagically comment all tables in the assembly as well as find and comment references to all tables. If you're interested in helping me check the references it found for accuracy, let me know and I will send over the fully commented disassembly for whatever ROM you want.
Reply
Old Mar 18, 2012 | 04:51 AM
  #173  
ofey's Avatar
Newbie
iTrader: (1)
 
Joined: Nov 2008
Posts: 21
Likes: 0
From: Melbourne, Australia
wow lodifreefly, that was RAPID!

I'm still slowly working my way through my first table.

I'll PM you my request.
Reply
Old Mar 18, 2012 | 06:18 AM
  #174  
richardjh's Avatar
Thread Starter
Evolved Member
 
Joined: Oct 2010
Posts: 2,447
Likes: 14
From: Australia
Here are the common scale and table "header" structures...



Scales - 16 bit format

2 bytes: Destination Variable Address (relative to fp)
2 bytes: Source Variable Address (relative to fp)
2 bytes: Number of elements that follow
...
...then the scale data.


Tables - 8 bit format, 2-Dimensional

1 byte: Style of table. 02 = 2-dimensional
1 byte: Value offset (a fixed value to add to every raw table element)
2 bytes: Source Scaling Variable Address (relative to fp)
...
...then the table data.


Tables - 8 bit format, 3-Dimensional

1 byte: Style of table. 03 = 3-dimensional.
1 byte: Value offset (a fixed value to add to every raw table element)
2 bytes: Source X Scaling Variable Address (relative to fp)
2 bytes: Source Y Scaling Variable Address (relative to fp)
1 byte: Number of rows (or columns... I forget)
...
...then the table data.


Tables - 16 bit format, 2-Dimensional

2 bytes: Style of table. 0002 = 2-dimensional
2 bytes: Value offset (a fixed value to add to every raw table element)
2 bytes: Source Scaling Variable Address (relative to fp)
...
...then the table data.


Tables - 16 bit format, 3-Dimensional

2 bytes: Style of table. 0003 = 3-dimensional.
2 bytes: Value offset (a fixed value to add to every raw table element)
2 bytes: Source X Scaling Variable Address (relative to fp)
2 bytes: Source Y Scaling Variable Address (relative to fp)
2 bytes: Number of rows (or columns... I forget)
...
...then the table data.




There are some weirdo extra formats that crop up in later year ROMs (eg. 2011), but the above will cover 99.9% of all data styles.

If any typos have snuck in, let me know and I'll edit to fix.

Rich
Reply
Old Mar 21, 2012 | 04:30 PM
  #175  
lodifreefly's Avatar
Evolving Member
iTrader: (1)
 
Joined: Jun 2009
Posts: 136
Likes: 0
From: Lodi, CA
I think it's pretty safe to say that we just blew the doors off this whole thing Thank you richard for giving me the info necessary to make this tool... I can't wait to see what it helps people find in these cars. For anyone who is serious about ROM disassembly, you can find my tool's source code at http://github.com/javiermuniz/ecutools

If you have any questions about it, or are having issues with it, feel free to drop me a PM.

If you find the tool useful to you I have one request: share what you find. I do not have a paypal account and will not be making one. I don't want donations. I just want access to the information that this tool helps you get
Reply
Old Mar 21, 2012 | 04:38 PM
  #176  
RazorLab's Avatar
EvoM Guru
20 Year Member
Liked
Loved
Community Favorite
iTrader: (8)
 
Joined: Aug 2003
Posts: 14,094
Likes: 1,092
From: Mid-Hudson, NY
Javier, wait, you wrote an app that will go through a ROM and find tables automatically?
Reply
Old Mar 21, 2012 | 05:13 PM
  #177  
Beeble's Avatar
Evolving Member
 
Joined: Feb 2009
Posts: 340
Likes: 2
From: Australia
God mode enabled
Reply
Old Mar 21, 2012 | 06:27 PM
  #178  
lodifreefly's Avatar
Evolving Member
iTrader: (1)
 
Joined: Jun 2009
Posts: 136
Likes: 0
From: Lodi, CA
Originally Posted by razorlab
Javier, wait, you wrote an app that will go through a ROM and find tables automatically?
I can find and annotate tables from XML, and their references all the way from RAM addresses.

Automatic table discovery is next. If all goes well I should have it working this weekend. The tricky part will be making it aware that two tables in different ROMs are the same, but based on what I've learned this week about the subroutines in these ROMs, I should be able to determine that with near certainty.
Reply
Old Mar 21, 2012 | 09:07 PM
  #179  
lodifreefly's Avatar
Evolving Member
iTrader: (1)
 
Joined: Jun 2009
Posts: 136
Likes: 0
From: Lodi, CA
Just got automated scale discovery working. That was the big missing step towards automated table discovery. Now that I have this working I can look for valid table headers since the source address of the header will match the source address of a known scale, and the rest of the header will be valid. Figuring out the size of the table (# of elements in X/Y axis) is the only missing step at this point, I'm not sure if I can nail that 100% because it requires automated backtracing which gets very complex when you encounter branch statements in the assembly, but we'll see what I can get out of it

The last run of the program found about 168 previously undocumented scales, the # of elements, as well as the input and output addresses.

Of course, the real trick will be figuring out what these tables *do* but the fact that the application outputs valid EcuFlash XML and auto-comments the assembly should make tracking this stuff down way, way easier.
Reply
Old Mar 21, 2012 | 11:34 PM
  #180  
lodifreefly's Avatar
Evolving Member
iTrader: (1)
 
Joined: Jun 2009
Posts: 136
Likes: 0
From: Lodi, CA
Automated table discovery is now a reality.

Can't vouch for it's accuracy just yet, but what richard calls the "rombot" just found and generated XML for 307 new tables in the 52690021 ROM. I am going through right now and checking the scaling values by hand, so far so good.
Reply



All times are GMT -7. The time now is 06:13 PM.