NefMoto

Technical => Reverse Engineering => Topic started by: Tony@NefMoto on September 03, 2009, 11:25:20 AM



Title: Bosch ME7 IDA Plugin
Post by: Tony@NefMoto on September 03, 2009, 11:25:20 AM
Bosch ME7 IDA Plugin

This was written by Andy Whittaker to help with initial disassembly setup when dealing with the ME7.


Title: Re: Bosch ME7 IDA Plugin
Post by: robin on December 21, 2009, 05:47:37 PM
I get this error when IDA tries to load the plugin:


LoadLibrary(C:\Program Files\IDA Free\plugins\boschme7x.plw) => error code 127
C:\Program Files\IDA Free\plugins\boschme7x.plw: can't load file

Any clues?


Title: Re: Bosch ME7 IDA Plugin
Post by: Tony@NefMoto on December 26, 2009, 01:28:03 PM
Could be a version mismatch between the plugin and IDA.


Title: Re: Bosch ME7 IDA Plugin
Post by: 20VT on March 22, 2010, 03:15:46 PM
Is this plugin specific for ME7.1 control unit ?


Title: Re: Bosch ME7 IDA Plugin
Post by: ArgDub on March 24, 2010, 04:04:34 AM
Is this plugin specific for ME7.1 control unit ?

It's for M7.1 and M7.5, the guy who wrote the plugin also made a video tutorial with the basics to use it

http://www.andywhittaker.com/ECU/DisassemblingaBoschME755/tabid/96/language/en-GB/Default.aspx (http://www.andywhittaker.com/ECU/DisassemblingaBoschME755/tabid/96/language/en-GB/Default.aspx)


Title: Re: Bosch ME7 IDA Plugin
Post by: phila_dot on September 07, 2010, 12:14:25 AM
Can anyone explain how to get from video one to video two? How do you seperate the bin? Is this required prior to running the plugin?


Title: Re: Bosch ME7 IDA Plugin
Post by: lulu2003 on September 07, 2010, 08:29:32 AM
BTW: what happened to Andy? Long time he did not update his website! Is he already being hired by CMD etc. and had to sign a NDA? ;)


Title: Re: Bosch ME7 IDA Plugin
Post by: Tony@NefMoto on September 07, 2010, 11:27:22 AM
You use a hex editor to separate the file into two parts according to Andy.

I disagree with Andy on this, and I think he is completely wrong. In my opinion the entire flash memory image is mapped to address 0x800000, and you don't split it at all. I don't think he sets up the DPP registers correctly, and he never maps in the internal ROM on the processor.

If you ask me, you should load the entire flash memory image to address 0x800000 and set DPP0 to 0x204, DPP1 to 0x205, DPP2 to 0x0E0, and DPP3 to 0x003. Then RAM is located at 0x380000, with size 0x8000.

Andy has always been hard to get a hold of, and I am not sure if he still works on ME7 projects.


Title: Re: Bosch ME7 IDA Plugin
Post by: spen on September 21, 2010, 03:54:46 PM
Hello all - here goes my first post. As a quick intro I have been into reverse engineering uC firmwares for a few years, usually with a plan to add new functions rather than alter some data.  My daily drive is stage 3 S4, d box.

Returning to the topic at hand ;) I agree with the DPP settings noted above.

Andy's plugin is unfinished, and there are only a few functions labelled.  Some are correct, many are not.  In particular Andy started calling various routines LookupA, through LookupZ and beyond.  Then he tried to isolate what each Lookup did, here was a mistake.

ME7x uses the Lookup routines by data structure, not by motronic function.  Ie there is a Lookup which reads 8byte signed integers, with independent external axes.  It is not LookupIgnition for example as Andy hints.  

I have reversed his plugin  :)  It is a dead end, fortunately it only took a few minutes to figure out what it was doing and how it was doing it.


All in all, the excitement of the old plugin should fade quickly.  

Now, where you load the binary.  It is interesting as motronic is broken in to three areas by design. The ERCOS real time OS, a library area, and a user code area.  What people upload on to the internet is usually the library and user area, starting at 0x800000 code , 0x810000 data and 0x820000 code.  ERCOS resides much lower.

When you load ERCOS into the CPU internal rom you can see all those calls suchas calls 0, 754e etc line up perfectly.  ERCOS *seems* byte compatible across the family.  You can also see how the interrupts are routed through a gateway, some are handled by ERCOS, some are passed to routines in higher memory.


I have been trying to automate some of the donkey work with the reverse engineering.  I have created some code which creates output like

(http://i272.photobucket.com/albums/jj172/spen0007/winscan-1.jpg)

With it if you give me an address of some ME7 data and a binary, I can more than likely locate it in another binary if it exists.

Spen    


Title: Re: Bosch ME7 IDA Plugin
Post by: Tony@NefMoto on September 21, 2010, 06:34:55 PM
Welcome to the forum, glad you found us. I will confirm for other people reading that everything you posted is correct.

Glad to see you are working on ME7 tools. How are you detecting the relocated tables between different ME7 versions? Are you using function signatures, or data signatures?


Title: Re: Bosch ME7 IDA Plugin
Post by: spen on September 22, 2010, 08:12:20 AM
The code seeks the entry point to any address I specify, as there are finite ways ME7 does that. Once I have that I can build a fingerprint for the function which I can locate in other ME7 roms.

Once my program finds the fingerprint it locates the register which is loaded with the target address and converts it to an absolute address.  The program counter, the DPR, the page offset and data absolute address are then thrown in to a data grid.  The code also notes if there are any bytes of axes in front of the data, as some structures contain internal axes.

To be honest how I handle the axes needs to change, it's not accurate enough.

Once I have that data grid I can export to csv, text, ida idc script and I am 90% through to xdf.  On the agenda are damos, maybe mappack.

In short I want to be able to regenerate a damos for any ME7 binary automatically.  I'm not looking at pure rom addresses, I really want to understand the structures in ram also.





Title: Re: Bosch ME7 IDA Plugin
Post by: Asassini on September 23, 2010, 04:24:26 PM
Great work Spen, ;)


Title: Re: Bosch ME7 IDA Plugin
Post by: robin on October 14, 2010, 02:37:55 PM
Wow, great work.


Title: Re: Bosch ME7 IDA Plugin
Post by: 360trev on January 08, 2011, 02:31:38 PM
Hi all,
My first post on here. I'm very interested in doing some more work on advanced automated IDA plugin work on the ME7 firmware. Basically walking through and automatically rename all signatures for common functions found and then comment all the trouble codes, etc.

Did Andy ever release his C++ IDA plugin source-code? If not is there any ongoing projects by anyone to re-do this work properly and in more depth?

Are there any well comment ida IDB files to help me with this? I'm willing to re-write the Andy Whittaker plug-in to make it work on any ME7 fw.

My interest is reverse engineering the 512kbyte ME7 firmware for a Ferrari 360 (all variants, 360, CS, Spider). I want to be able to add new functions to the firmware and fully understand what is going on in both the Bosch Montronic ME7.1 ecu's (2 ecu's, 1 per bank). I have full access to all the wiring schematics and can post the relevant ecu pin-outs.

I have managed to get the pair of working ECU's to dump and now need to create a bench flashing lead using a wiring harness and ob2 to first dump the firmware using the bootmode technique.

Q. Has anyone on here's has already dumped these models before?

Will the NefMoto flashing s/w likely work on this model? I'm guessing yes...

 


Title: Re: Bosch ME7 IDA Plugin
Post by: 360trev on January 08, 2011, 02:34:14 PM
The code seeks the entry point to any address I specify, as there are finite ways ME7 does that. Once I have that I can build a fingerprint for the function which I can locate in other ME7 roms.

Once my program finds the fingerprint it locates the register which is loaded with the target address and converts it to an absolute address.  The program counter, the DPR, the page offset and data absolute address are then thrown in to a data grid.  The code also notes if there are any bytes of axes in front of the data, as some structures contain internal axes.

To be honest how I handle the axes needs to change, it's not accurate enough.

Once I have that data grid I can export to csv, text, ida idc script and I am 90% through to xdf.  On the agenda are damos, maybe mappack.

In short I want to be able to regenerate a damos for any ME7 binary automatically.  I'm not looking at pure rom addresses, I really want to understand the structures in ram also.





Have you posted these apps up yet? or are they private?

i'm planning to release all my work on here.


Title: Re: Bosch ME7 IDA Plugin
Post by: 360trev on January 08, 2011, 04:59:21 PM
Q. Does this IDA Bosch ME7 plugin only support 'some' variants of Bosch ME ?

Andy did quite a bit of hardcoding in that code. Must have written it fast, fast, fast.

Noticed in the segments section of the C++ code it does the following (hardcoded)
-without any ability to change from a config file.
Same thing goes for the function signatures it finds. All of them hardcoded with no ability to extend or modify the signature names for both functions and data that it finds... :(

Here's the CreateSegmemts() function (C++ code)...

---cut---cut---cut---cut---cut---cut

  if (NewBoschME7111)
  {
    result = BoschHelper::CreateC16xSmallBoschSegments(0x00000, 0x08000, "MEM_EXT",  "CODE", 44, 45, 60, 3);
    result = BoschHelper::CreateC16xSmallBoschSegments(0x08000, 0x0E000, "MEM_EXT",  "CODE", 44, 45, 60, 3);
    result = BoschHelper::CreateC16xSmallBoschSegments(0x0E000, 0x0E800, "XRAM",     "DATA", 44, 45, 60, 3);
    result = BoschHelper::CreateC16xSmallBoschSegments(0x0E800, 0x0EF00, "RESERVED", "BSS",  44, 45, 60, 3);
    result = BoschHelper::CreateC16xSmallBoschSegments(0x0EF00, 0x0F000, "CAN1",     "DATA", 44, 45, 60, 3);
    result = BoschHelper::CreateC16xSmallBoschSegments(0x0F000, 0x0F200, "E_SFR",    "DATA", 44, 45, 60, 3);
    result = BoschHelper::CreateC16xSmallBoschSegments(0x0F200, 0x0F600, "RESERVED", "BSS",  44, 45, 60, 3);
    result = BoschHelper::CreateC16xSmallBoschSegments(0x0F600, 0x0FE00, "IRAM",     "CODE", 44, 45, 60, 3);
    result = BoschHelper::CreateC16xSmallBoschSegments(0x0FE00, 0x10000, "SFR",      "DATA", 44, 45, 60, 3);
   
   result = BoschHelper::CreateC16xBoschSegments(0x01000, 4, "CODE", 44, 45, 60, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x02000, 4, "CODE", 44, 45, 60, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x03000, 4, "CODE", 44, 45, 60, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x04000, 4, "CODE", 44, 45, 60, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x05000, 4, "CODE", 44, 45, 60, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x06000, 4, "CODE", 44, 45, 60, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x07000, 4, "CODE", 44, 45, 60, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x08000, 4, "CODE", 44, 45, 60, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x09000, 4, "CODE", 44, 45, 60, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x0A000, 4, "CODE", 44, 45, 60, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x0B000, 4, "DATA", 44, 45, 60, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x0C000, 4, "DATA", 44, 45, 60, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x0F000, 4, "RAM",  44, 45, 60, 3);
  }
  else
  {
    result = BoschHelper::CreateC16xSmallBoschSegments(0x00000, 0x08000, "MEM_EXT",  "CODE", 0, 1, 2, 3);
    result = BoschHelper::CreateC16xSmallBoschSegments(0x08000, 0x0E000, "MEM_EXT",  "CODE", 0, 1, 2, 3);
    result = BoschHelper::CreateC16xSmallBoschSegments(0x0E000, 0x0E800, "XRAM",     "DATA", 0, 1, 2, 3);
    result = BoschHelper::CreateC16xSmallBoschSegments(0x0E800, 0x0EF00, "RESERVED", "BSS",  0, 1, 2, 3);
    result = BoschHelper::CreateC16xSmallBoschSegments(0x0EF00, 0x0F000, "CAN1",     "DATA", 0, 1, 2, 3);
    result = BoschHelper::CreateC16xSmallBoschSegments(0x0F000, 0x0F200, "E_SFR",    "DATA", 0, 1, 2, 3);
    result = BoschHelper::CreateC16xSmallBoschSegments(0x0F200, 0x0F600, "RESERVED", "BSS",  0, 1, 2, 3);
    result = BoschHelper::CreateC16xSmallBoschSegments(0x0F600, 0x0FE00, "IRAM",     "CODE", 0, 1, 2, 3);
    result = BoschHelper::CreateC16xSmallBoschSegments(0x0FE00, 0x10000, "SFR",      "DATA", 0, 1, 2, 3);
   
    result = BoschHelper::CreateC16xBoschSegments(0x38000, 2, "DATA", 516, 517, 224, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x80000, 4, "CODE", 516, 517, 224, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x81000, 4, "CODE", 516, 517, 224, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x82000, 4, "CODE", 516, 517, 224, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x83000, 4, "CODE", 516, 517, 224, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x84000, 4, "CODE", 516, 517, 224, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x85000, 4, "CODE", 516, 517, 224, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x86000, 4, "CODE", 516, 517, 224, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x87000, 4, "CODE", 516, 517, 224, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x88000, 4, "CODE", 516, 517, 224, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x89000, 4, "CODE", 516, 517, 224, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x8A000, 4, "CODE", 516, 517, 224, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x8B000, 4, "CODE", 516, 517, 224, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x8C000, 4, "CODE", 516, 517, 224, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x8D000, 4, "CODE", 516, 517, 224, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x8E000, 4, "CODE", 516, 517, 224, 3);
    result = BoschHelper::CreateC16xBoschSegments(0x8F000, 4, "CODE", 516, 517, 224, 3);
  }

---cut---cut---cut---cut---cut---cut

and the 'MakeDiss()' function

---cut---cut---cut---cut---cut---cut

 
char MakeDissCode(int NewBoschME7111_Mode)
{
  char result;

  if ( BoschME7111_Mode )
  {
    result = Create_Dissassembly(0x00000, 0xA7FFF);
    result = Create_Dissassembly(0xC0000, 0xCDFFF);
  }
  else
  {
    result = Create_Dissassembly(0x000000, 0x0001FF);
    result = Create_Dissassembly(0x000700, 0x007FFF);
    result = Create_Dissassembly(0x800000, 0x810000);
    result = Create_Dissassembly(0x830000, 0x8FFF00);
  }
  return result;
}


---cut---cut---cut---cut---cut---cut

Perhaps I need to re-write the entire thing...


Title: Re: Bosch ME7 IDA Plugin
Post by: Tony@NefMoto on January 20, 2011, 01:19:24 PM
My suggestion would be to use Andy's plugin as an example and write your own.


Title: Re: Bosch ME7 IDA Plugin
Post by: 360trev on January 04, 2013, 04:55:10 PM
I know this is an old topic but here goes...

Anyone fancy contributing to re-writing Andy's old plug-in as an source project that we can all contribute too?
Andy has pretty much given up on the old one so here is some inspiration to get you guys started.. this will need porting to the IDA plug-in dev kit!

The attached bits are a "work-in-progress" reverse into C. I looked at Andy's old IDA plug-in to see how he did it and surprisingly its actually very simple stuff actually so I will re-write it from scratch. Watch this space. I will put all my work on git hub...

Here's a great starting place to learn how to write an IDA plug-in...

http://www.binarypool.com/idapluginwriting


Title: Re: Bosch ME7 IDA Plugin
Post by: 360trev on January 05, 2013, 05:48:22 AM
Right, latest update on this. (If anyone is interested)  ???

I have now downloaded a sample IDA plugin and installed VC++ 2010 express (free edition).

I too have now built a basic plugin this morning that can walk through the entire functions list in the buffer. I've just tested it and yes it works (yipee!). The first thing I did was search for known signatures by using the signature/mask function searched from our Open Source ME7 Checksum tool (thanks nyet!), so far it only knows how to find a couple of functions (!) but I will add more signatures [I'll make the signature use an external config file so you DON'T have to re-compile the plugin].

So in forthcoming days I will clean this lot up and upload the entire plugin and sources onto github, so you'll be free to add to contribute to it and make a really useful Bosch ME plugin! Yes you'll be able to add your own config with the ini file loader (again from our other project!).

Things are looking promising!


Title: Re: Bosch ME7 IDA Plugin
Post by: littco on January 05, 2013, 06:09:34 AM
Brilliant..

Sounds very promising, I will be very keen to see this as spent a lot if time recently on Ida


Title: Re: Bosch ME7 IDA Plugin
Post by: 360trev on January 05, 2013, 06:13:57 AM
Brilliant..

Sounds very promising, I will be very keen to see this as spent a lot if time recently on Ida

Wasn't sure if anyone cared anymore. Its quite old now.

Here's the latest trace using Andy's signature names db. We really need better names, anyone got a good IDB file that I could take them from or is this something we need to do too?

Code:
NefMotoBoschME7x plugin: 
Version: 0.1 Alpha
Last Built: Jan  5 2013 (14:01:05) by 360trev

Found 'LookupA_803826' at 00803826
Found 'LookupB_803866' at 00803866
Found 'LookupC_8038a6' at 008038A6
Found 'LookupD_8038ee' at 008038EE
Found 'LookupE_803936' at 00803936
Found 'LookupF_8039ba' at 008039BA
Found 'LookupG_803a50' at 00803A50
Found 'LookupH_803ad4' at 00803AD4
Found 'LookupI_803b6a' at 00803B6A
Found 'LookupJ_803bde' at 00803BDE
Found 'LookupK_803c58' at 00803C58
Found 'LookupL_803cd0' at 00803CD0
Found 'LookupM_803d4a' at 00803D4A
Found 'LookupN_803e36' at 00803E36
Found 'LookupO_803f52' at 00803F52
Found 'LookupP_803f98' at 00803F98
Found 'LookupQ_803fde' at 00803FDE
Found 'LookupR_80402c' at 0080402C
Found 'LookupS_80407a' at 0080407A
Found 'LookupT_8040a0' at 008040A0
Found 'LookupU_8040ae' at 008040AE
Found 'LookupU_8040be' at 008040BE
Found 'LookupV_8040ce' at 008040CE
Found 'WLookup1DIAT_8040dc' at 008040DC
Found 'LookupX_804102' at 00804102
Found 'LookupY_804134' at 00804134
Found 'LookupZ_804166' at 00804166
Found 'LookupAA_80424e' at 0080424E
Found 'WLookup2DBoost_8042ea' at 008042EA
Found 'LookupAC_804386' at 00804386
Found 'LookupAD_8043b6' at 008043B6
Found 'LookupAE_8043e6' at 008043E6
Found 'LookupAF_804456' at 00804456
Found 'Do803cChksumLoop_80602a' at 0080602A
Found 'ReadADC1_80790e' at 0080790E
Found 'SetupADC_80793e' at 0080793E
Found 'ReadADC2_807966' at 00807966
Found 'EnableADC_807a56' at 00807A56
Found 'CANWriteToMsgController_807b90' at 00807B90
Found 'CANStuff1_807bea' at 00807BEA
Found 'CopyROMtoRAM_80dc70' at 0080DC70
Found 'ReadADC3_80de6a' at 0080DE6A
Found 'WLookup1D_CTS_824000' at 00824000
Found 'BLookup2D_Fuel_8240a0' at 008240A0
Found 'WLookup2D_Spark_8241ce' at 008241CE
Found 'SetDTCME71_82ea26' at 0082EA26
Found 'CRC32ME75_86be6e' at 0086BE6E
Found 'CRC32ME71Sub_86bedc' at 0086BEDC

Getting there ;)


Title: Re: Bosch ME7 IDA Plugin
Post by: littco on January 05, 2013, 06:29:20 AM
Think rajiv66 might the man for an idb. I gave up with Angus plugin as it seemed very hit or miss whether it worked or not.

I'm Definately interested but know nothing about coding so input will be limited but I like soduko so happy to descramble :-)


Title: Re: Bosch ME7 IDA Plugin
Post by: 360trev on January 05, 2013, 06:33:41 AM
Think rajiv66 might the man for an idb. I gave up with Angus plugin as it seemed very hit or miss whether it worked or not.

I'm Definately interested but know nothing about coding so input will be limited but I like soduko so happy to descramble :-)

No need to be a coder to help us, we will require testers too as well as people to find signatures, maps, etc..

Just think how many variants of dumps we have on here to test alone!


Title: Re: Bosch ME7 IDA Plugin
Post by: prj on January 05, 2013, 06:55:22 AM
I made a macro that loads a binary into ida properly and allows you to quickly convert everything needed to code.
As for identifying functions, well I don't know.

If you have seen the function once, then it won't be too hard to find in any other binary, since you pretty much know exactly what to look for.


Title: Re: Bosch ME7 IDA Plugin
Post by: lulu2003 on January 16, 2013, 06:01:42 AM
macro ...and allows you to quickly convert everything needed to code.

any quick tip to get that -> next unexplored -> create function loop done inside IDA?


Title: Re: Bosch ME7 IDA Plugin
Post by: prj on January 16, 2013, 06:23:28 AM
any quick tip to get that -> next unexplored -> create function loop done inside IDA?


No idea, I just wrote a macro, haven't explored IDA commands.


Title: Re: Bosch ME7 IDA Plugin
Post by: Joe_Jinkx on January 16, 2013, 01:22:45 PM
Thanks for the head start on this. I'll take a look at the plugin when I have time, and let you know what I find.

Joe


Title: Re: Bosch ME7 IDA Plugin
Post by: lulu2003 on January 17, 2013, 04:47:19 PM
No idea, I just wrote a macro, haven't explored IDA commands.

you mean that auto it makro?
works fine for me, thanks!


Title: Re: Bosch ME7 IDA Plugin
Post by: 360trev on January 20, 2013, 03:12:31 AM
Sorry guys, been very busy lately with work so haven't had any time to play with this. I did however get working a tool which is already very useful (to me anyway). I can now dump all of the individual binary functions out of a dump directly into separate files. I can then compare them with dumps from other me7's. The goal here is to be able to auto detect ALL equivalent rom functions and then easily look up the actual addresses of information using that approach (such as checksum boundary locations, etc.). Its close to being useful and as soon as I get some free time I will post the whole thing on github...

 


Title: Re: Bosch ME7 IDA Plugin
Post by: 360trev on January 20, 2013, 03:21:58 AM
Here's the main 'business function' that finds all the functions and dumps them into separate files...
Ironically due to the flexible way IDA api's are built the dumping of binaries for individual functions works across any cpu architecture, not just c167...

Here's the main code snippet for interested parties... once cleaned up and doing all the useful stuff I will release it properly...

Code:
static void PlugIn_process(int iArg)
{
  char funcName[MAXSTR];
  char filename[MAXSTR];
  char mnem[MAXSTR];
  char tmp[1024*512];
  int offset=0;
  int inst_count,func_len;
  unsigned int x, num_funcs, num_segments;
  ea_t addr, start_addr;
  asize_t our_size;
  flags_t flags;
  func_t *f=0;
  segment_t *seg=0;

  // We are only interested in segments containing code.
  seg = getnseg(0);
  num_funcs = get_func_qty();

         // Loop through each function
  msg("Found <%d> functions\n",num_funcs);

for (x = 0; x < num_funcs; x++)
        {
        f = getn_func(x);      // get ptr to the function itself
if(f == 0) {
msg("func not found at address %p\n");
}
else
{
// start address of this function..
start_addr = f->startEA;
addr = start_addr;

get_func_name(addr, funcName, sizeof(funcName)-1); // find the function name
//      set_name(addr, new_funcName, SN_NOWARN);

flags = get_flags_novalue(addr);
msg("Found %-32.32s: at %p, func_flags(%lx)",funcName,addr,flags);
//  Add name if there's no meaningful name assigned.
if(has_name(flags) != 0)       { msg("(customized name   ) "); }
if(has_dummy_name(flags) != 0) { msg("(autogenerated name) "); }
if(has_auto_name(flags) != 0)  { msg("(has_auto_name     ) "); }

//
// calc number of instructions
//
inst_count = 0;
addr = start_addr; // start of function
func_len   = ((f->endEA)-(start_addr));

// count the number of instructions within the function
for (; addr < f->endEA;) {
  // Get the flags for this address
  flags = get_flags_novalue(addr);
  // Only look at the address if it's a head byte, i.e. the start of an instruction and is code.
  if (isHead(flags) && isCode(flags))  {   
  inst_count++; // increase number of instructions counter we have seenn within this function
  }
  our_size = get_item_size(addr); // get number of bytes within this function
  addr += our_size;                 // move addres pc to next instruction...
}
//
// at this point 'inst_count' is total number of asm instructions within the buffer
//
msg(" func len = %-8d bytes (%-8d instructions)\n",func_len, inst_count );

sprintf(filename,"c:\\bin\\%p_%s_%d.bin",start_addr,funcName,inst_count);

#if 1
addr = start_addr; // start of function
offset=0;
// lets now loop through the instructions in each function
for (; addr < f->endEA;)
{
  // Get the flags for this address
  flags = get_flags_novalue(addr);

    // get the size of this item (e.g. instruction length)
  our_size = get_item_size(addr);

  // Only look at the address if it's a head byte, i.e.
  // the start of an instruction and is code.
  if (isHead(flags) && isCode(flags))
  {   
char instruction[16];

// Fill the cmd structure with the disassembly of the current address and get the mnemonic text.
ua_mnem(addr, mnem, sizeof(mnem)-1);

ua_ana0(addr);
ua_mnem(addr, instruction, sizeof(instruction));
tag_remove(instruction, instruction, sizeof(instruction));

// lets view the mnemonic of *this* address
// msg("%p:[%-2.2d] ", addr, our_size);
#if 1
msg(".");
get_many_bytes(addr,&tmp[offset],our_size);
offset += our_size;
#else
for(int j=0;j < our_size; j++)
{
tmp[j] = get_byte(addr+j);
}
#endif
// show the hex dump of the instruction
// hex_dump((unsigned char *)&tmp[offset], our_size);
// show the mnemonic of the instruction
// msg(" %-8.8s\n",instruction);
  }
  // move addres pc to next instruction...
  addr += our_size;
}

// dump it..
msg("dumping %s\n",filename);
save_file(filename, (unsigned char *)tmp, (size_t)offset);

#endif
}//end if

  }//end for
}


Enjoy!


Title: Re: Bosch ME7 IDA Plugin
Post by: 360trev on January 20, 2013, 03:26:09 AM
Using this technique I discovered there are around 3800 functions in the typical rom dump of these ecu's and that at very large proportion of routines are shared across many of the variants... I.e. identical apart from location and reloc information...


Title: Re: Bosch ME7 IDA Plugin
Post by: Joe_Jinkx on January 25, 2013, 03:29:23 PM
You use a hex editor to separate the file into two parts according to Andy.

I disagree with Andy on this, and I think he is completely wrong. In my opinion the entire flash memory image is mapped to address 0x800000, and you don't split it at all. I don't think he sets up the DPP registers correctly, and he never maps in the internal ROM on the processor.

If you ask me, you should load the entire flash memory image to address 0x800000 and set DPP0 to 0x204, DPP1 to 0x205, DPP2 to 0x0E0, and DPP3 to 0x003. Then RAM is located at 0x380000, with size 0x8000.

Andy has always been hard to get a hold of, and I am not sure if he still works on ME7 projects.

I know this is a really old post to be be replying, but you are correct about the addressing. If you have the A2Ls you can verify this by looking for the Pst800000 and the Pst8E0000. The memory is contiguous so you don't really need to split it up.

I do have a question about DPP0-DPP3. How do you figure out what the ECU is setting them to? I'm looking at the ME7.8.2 and I can't figure what those registers have been set to.

Joe


Title: Re: Bosch ME7 IDA Plugin
Post by: fluke9 on April 08, 2013, 06:50:27 AM
Anyone still working on this ?

I just digged out an old harddisk which has an IDA plugin on it i wrote like 3 years ago as a quick hack.
It parses a DAMOS and labels everything in the bin with comments...

If anyone is interested in this i could probably fix it up in few days so its usable. (hardcoded filenames and stuff, didnt bother...)  ;)




Title: Re: Bosch ME7 IDA Plugin
Post by: Axis on April 08, 2013, 10:55:55 AM
That sounds really useful. Please fix it.
Does it also add comments to bits in format like this FD00.1 ?
From what I know the only way to name these is to add a comment to the line (extracted from damos). And since some of them appear MANY times it is a very time consuming manual task.


Title: Re: Bosch ME7 IDA Plugin
Post by: fluke9 on April 08, 2013, 12:31:08 PM
That sounds really useful. Please fix it.
I will start a new thread when its done ;)

Does it also add comments to bits in format like this FD00.1 ?
Thats actually a bug i need to fix, currently it names the bitfield after the first bit it finds in the damos...
I will change it to generate comments with all bits listed, if anyone knows a better way to do this please tell me.


Title: Re: Bosch ME7 IDA Plugin
Post by: Axis on April 08, 2013, 12:38:30 PM
I will start a new thread when its done ;)
Thats actually a bug i need to fix, currently it names the bitfield after the first bit it finds in the damos...
I will change it to generate comments with all bits listed, if anyone knows a better way to do this please tell me.
a comment with only the particular bit  would be nice since they are easily identified as 1,2,3,4,10,20,30,40,100.... in the damos.
Rather large comments if it should list all 16 everytime


Title: Re: Bosch ME7 IDA Plugin
Post by: Jerry Tunin on February 25, 2015, 10:50:33 AM
Anything new with these plugins?  Didn't really want to dig up an old thread but it mentions a lot of good starting points.


Title: Re: Bosch ME7 IDA Plugin
Post by: lulu2003 on May 24, 2015, 05:16:34 AM
User 360trev supplied some source of obvious nice IDA Plugs, but any compiled ready to use code?


Title: Re: Bosch ME7 IDA Plugin
Post by: lulu2003 on June 08, 2015, 05:46:08 AM
It parses a DAMOS and labels everything in the bin with comments...

If anyone is interested in this i could probably fix it up in few days so its usable. (hardcoded filenames and stuff, didnt bother...)  ;)

yes, please.
bitwise naming would be challanging :)


Title: Re: Bosch ME7 IDA Plugin
Post by: dragon187 on September 15, 2016, 09:48:05 AM
Very interesting in that too


Title: Re: Bosch ME7 IDA Plugin
Post by: nubcake on September 15, 2016, 01:38:25 PM
Very interesting in that too

Actually it's fairly easy to implement basic (RAM vars & ROM values) renaming by "semi-manually" parsing the A2L for "name+offset", then feeding it into the modified "parse .ecu" of the autoit script (http://nefariousmotorsports.com/forum/index.php?topic=2431.0). Or at least that's how I do it to create "reference" binaries. There are better ways ofc, i.e. using python.


Title: Re: Bosch ME7 IDA Plugin
Post by: unicornux on December 19, 2019, 03:00:16 AM
Bosch ME7 IDA Plugin

This was written by Andy Whittaker to help with initial disassembly setup when dealing with the ME7.

i downloded this file and copy in my ida plugin path but nothing shown in ida and plugin menu. ??? ??? ??? ???
what is problem.
help me please.
thanks.


Title: Re: Bosch ME7 IDA Plugin
Post by: fluke9 on December 23, 2019, 03:17:05 AM
i downloded this file and copy in my ida plugin path but nothing shown in ida and plugin menu. ??? ??? ??? ???
what is problem.
help me please.
thanks.
Does your IDA Version match ? Andys plugin is for older versions of IDA Pro, i think 6.x