Page 43 of 68

Re: Ford MPC565 Tuning

Posted: Wed Jan 11, 2017 11:34 am
by rolls
headsex wrote:Implementing the Calibration only write (particularly for the BA's which 443kb mpc555 flash was slow!!) saved my sanity. Think back when SCT released their XCAL1. It was serial interface to the PC, 115200 baud.. So, you make a change to your file, upload the 1.4mb file to the XCAL1 (took about 5 minutes), and then flash the PCM (another 5 minutes).. thats like 10 minutes (or more) of wasted time, because usually you'd walk away from the PC at the first step!
So, yeah.. Sanity saved! Unfortunately for Workshops, they still have a ~4minute wait for the flash, as transferring the file to the xcal now is via USB, and relatively fast these days.
We really do have it easy these days! I can see why you implemented that now.
In terms of the file, yeah, full size is ok, but do you include the 0x0 -> 0x10000 in that file? of not, you already have a need for a -0x10000 offset. My view on the subject is bigger, Ie, not to limit your editing software to just this purpose, but makes it available for all micro controller types.. Also, ZF transmission, from memory, the Calibration data (the only data you need to write) will give you large files with null at the start, when the entire cal section is only about 100k in size.. Its just my suggestion, You will thank me later.. Once you have it in a non raw format, you could always write a exporter which exports it to HEX, to be able to open in IDA, so best of both worlds there.
I current read from 0x0 all the way to the end, so I do include the 0x10000 in the file. I however have my own file format that has all of the parameters, data, etc in a C# structure which I can also save to disk which does not have to include the raw binary (though I do include it as well), I can easily convert this back to binary for writing/saving.

So the process is read entire bin -> convert to my file format then use this within my program. I then save the calibration back over the raw binary, kind of like an overlay that only overwrites changes bytes and write this back to the PCM. I can leave the raw binary out, however I would need to do a full read before being able to write my file format back to the PCM.

There are a few bonuses of this approach, the raw file format doesn't matter like you suggested, it can be PHF, bin, read from PCM etc. It also makes copying tables between different calibrations possible (like HPT can do). I can also distribute these files without having to distribute the address information, this makes it possible for unlicensed users to view other peoples files without there being any opportunity to reverse engineer the addresses (as they are not included in the file).
I'm also surprised you mentioned PHF, as I believe ford moved away from that format to VBF, which, out of all things is a Volvo format (volvo binary file?).. Its a very cool format, I'll have to try and find references online that i found years ago for you to look at.
It appears they still use PHF for all the PPC stuff, at least all the strategies up to 2015 are available as PHF files. They do seem to use VBF on other cars though, eg the focus.
I haven't had a chance to look at your code on github, however, i read in this thread you've changed timeout values a number of time.. I spent alot of time optimising my code that interfaced with the j2543 dll / PCM to improve speed significantly.. Of what you've noticed, yeah, the BA can take OVER 1 minute to erase in some instances, HPTuners was bricking PCM's at one point cause they didnt cater for this excessive period, assumed 40 seconds was enough.. (bricking in the sence of blanking out the pcm, and not writing to it).
In terms of the transfer loops to send and receive data on the bus, with the j2534 read command, i would only requested 1 message, with a large timeout (ie, 5 seconds). If no data is read from the pcm, the app would loop the request. this reduced the talk between the app and passthru device, and the moment it had data, the app had it. When writing, I always made the timeout 0. Took me a while to determine this was fastest way of doing it, as it wouldnt hammer the passthru dll/device with huge amount of requests.
Yep this took a while to figure out. I did the same thing as HPT on one of the guys spare BA pcms that was testing my early flash software, erased fine but the timeouts needed to be massive upon restart to finish the flash so it temporarily bricked the pcm. The code on github is a very early version, I haven't published anything later than that. Mainly put it up so people can use it as a base to write their own software if they desire, however it seems not many people are coders.

I think I do it similar to you, basically I send a write command then loop with a ~5 second timeout attempting to read the next packet, so basically everything sits idle until the J2534 gets the next response. I have an overall timeout as well so it doesn't infinite loop.
headsex wrote:Oh, furthermore, given that you cant erase the bootloader code, you cant change the seed/key algorithm in order to "lock" these pcms, like you can in the GM world.
Its interesting to see how SCT have attempted to stop HPtuners Reading the tunes. They appear to be garbling the Strategy text in the VID block, this is given away by the fact that when you read the strategy (via the xcal hand held, or hptuners), its non english characters. As a result, it makes it difficult for hptuners to know what definition file to associated with the file you just read.
Hptuners however don't appear to garble the strategy in order to "lock" the tune.. It appears they have implemented some additional data in the file written to the pcm.. Presumably to lock the tune between HPtuner customers.
HPTuners only lock their .hpt file format from what I can tell (I'm not 100%), they don't bother doing anything more than that. SCT garble the OSID however HPT can now read those files now, its not that difficult to build a signature of the strategy to allow detection without the VID block either.

I'm not interesting in locking PCMs personally, though I am interested purely from an interest perspective how you could do it. I suspect you could add some init code that breaks the UDS handler routine by modifying the canbus registers or possibly just corrupting the RAM that it uses, this could then be disabled by writing to a specific ram address. Though this effort would be better spent on live tuning or improving the software. I'm of the opinion anything is achievable with enough time and money!

Out of curiosity how did you initially figure out the seed key routine. Did you get a BDM to rip the code from the flash chip directly, then look for the flash read/write commands in the UDS routine? I posted up the location earlier in the thread, but as I already knew what I was looking for it was easy. If I was doing it entirely from scratch I imagine it would have taken much much longer to find.

Or did you go down the route of reversing the IDS software instead? (much easier to reverse X86 than PPC asm IMO)

Re: Ford MPC565 Tuning

Posted: Wed Jan 11, 2017 11:59 am
by headsex
rolls wrote: HPTuners only lock their .hpt file format from what I can tell (I'm not 100%), they don't bother doing anything more than that. SCT garble the OSID however HPT can now read those files now, its not that difficult to build a signature of the strategy to allow detection without the VID block either.

I'm not interesting in locking PCMs personally, though I am interested purely from an interest perspective how you could do it. I suspect you could add some init code that breaks the UDS handler routine by modifying the canbus registers or possibly just corrupting the RAM that it uses, this could then be disabled by writing to a specific ram address. Though this effort would be better spent on live tuning or improving the software. I'm of the opinion anything is achievable with enough time and money!

Out of curiosity how did you initially figure out the seed key routine. Did you get a BDM to rip the code from the flash chip directly, then look for the flash read/write commands in the UDS routine? I posted up the location earlier in the thread, but as I already knew what I was looking for it was easy. If I was doing it entirely from scratch I imagine it would have taken much much longer to find.

Or did you go down the route of reversing the IDS software instead? (much easier to reverse X86 than PPC asm IMO)
HPtuners appears to write additional (signature?) info in the file in unused space.. I'm talking from a PCM read perspective, So, if another HPTuner workshop reads a tune, the software sees that signature, and says its "locked"... If yoru implementation reads the PCM, it would be none the wiser.

Given my Cardaq has a "Debug mode" build into the dll, i used FMP (ford module programming), and i enabled debug, and logged everything to a text file to understand how the flashing worked. This method is certainly better than sniffing the canbus, as it logged the entire iso15765 message, not just the can frame.

I certainly hit a brick wall without knowing the s/k algorithm. I did have a phf file, but initially that didn't help in that it did not include the bootloader code (>0x10000 only). I then found and reversed a x86 diagnostics application (as you are right, reversing x86 is certainly easier than ppc), and found the algorithm there. It later turned out that it actually was in the phf file i already had(to access diagnostic modes), however, the cooffs are different for diagnostic mode vs reflash mode, i just never found it as i was still learning ppc reversing at the time.

I haven't actually played with or reversed IDS due to not having the hardware, But i did read earlier it now supports j2534 passthru device with some dll swapping?

Re: Ford MPC565 Tuning

Posted: Wed Jan 11, 2017 12:04 pm
by rolls
Interesting that they sign the code. Smart move.

You can use ids with openport if you swap the DLLs, posted many pages back how though I forget what I did now.

I found the seed key via the adventures in IO document. The reversed ids and published a paper showing the algorithm, surprised ford haven't done anything about it.

Re: Ford MPC565 Tuning

Posted: Wed Jan 11, 2017 12:14 pm
by headsex
Not familiar with those documents. Got a link? Be interesting read

Re: Ford MPC565 Tuning

Posted: Wed Jan 11, 2017 12:24 pm
by rolls
headsex wrote:Not familiar with those documents. Got a link? Be interesting read
http://www.ioactive.com/pdfs/IOActive_A ... _Units.pdf

Re: Ford MPC565 Tuning

Posted: Wed Jan 11, 2017 1:11 pm
by headsex
Very cool information there! one thing i didnt notice is that the seed/key co-offs were actually ASCII NAMes!! LOL ... there is actually JESUS! Thats so damn funny!

However,, If you wanted "GOD" mode security, you cant have it... but you can have "Jesus" mode!

Re: Ford MPC565 Tuning

Posted: Wed Jan 11, 2017 1:34 pm
by rolls
headsex wrote:Very cool information there! one thing i didnt notice is that the seed/key co-offs were actually ASCII NAMes!! LOL ... there is actually JESUS! Thats so damn funny!

However,, If you wanted "GOD" mode security, you cant have it... but you can have "Jesus" mode!
If you want to know something else funny I opened ptdiag up in ida pro and found that theres a secret word game hidden somewhere in it. I found all the passwords to access the special engineering modes (like disabling PATS etc), but I couldn't figure out how to launch the game. Well I assumed it was a word game, no idea why they would have hundreds of 4 letter words stored in a table otherwise!

Passwords are "42CATS" and "playtaps". Super easy to find, just searched for calls to strncmp. Must be a super old application written in C

a few hundred of these...

Code: Select all

db '\',0 ; DATA XREF: sub_4ECC97+F4 o
.data:0066D856 align 4
.data:0066D858 aApex db 'APEX',0 ; DATA XREF: .rdata:off_561528 o
.data:0066D85D align 10h
.data:0066D860 aDuck db 'DUCK',0 ; DATA XREF: .rdata:0056152C o
.data:0066D865 align 4
.data:0066D868 aAunt db 'AUNT',0 ; DATA XREF: .rdata:00561530 o
.data:0066D86D align 10h
.data:0066D870 aEyes db 'EYES',0 ; DATA XREF: .rdata:00561534 o
.data:0066D875 align 4
.data:0066D878 aBite db 'BITE',0 ; DATA XREF: .rdata:00561538 o
.data:0066D87D align 10h
.data:0066D880 aFlag_0 db 'FLAG',0 ; DATA XREF: .rdata:0056153C o
.data:0066D885 align 4
.data:0066D888 aCube db 'CUBE',0 ; DATA XREF: .rdata:00561540 o
.data:0066D88D align 10h
.data:0066D890 aGold db 'GOLD',0 ; DATA XREF: .rdata:00561544 o
.data:0066D895 align 4
.data:0066D898 aHour db 'HOUR',0 ; DATA XREF: .rdata:00561548 o
.data:0066D89D align 10h
.data:0066D8A0 aJury db 'JURY',0 ; DATA XREF: .rdata:0056154C o
.data:0066D8A5 align 4
.data:0066D8A8 aDiet db 'DIET',0 ; DATA XREF: .rdata:00561550 o
.data:0066D8AD align 10h
.data:0066D8B0 aCrab db 'CRAB',0 ; DATA XREF: .rdata:00561554 o
.data:0066D8B5 align 4
.data:0066D8B8 aDust db 'DUST',0 ; DATA XREF: .rdata:00561558 o
.data:0066D8BD align 10h
.data:0066D8C0 aWild db 'WILD',0 ; DATA XREF: .rdata:0056155C o
.data:0066D8C5 align 4
.data:0066D8C8 aHens db 'HENS',0 ; DATA XREF: .rdata:00561560 o
.data:0066D8CD align 10h
.data:0066D8D0 aCozy db 'COZY',0 ; DATA XREF: .rdata:00561564 o
.data:0066D8D5 align 4
.data:0066D8D8 aDirt db 'DIRT',0 ; DATA XREF: .rdata:00561568 o
.data:0066D8DD align 10h
.data:0066D8E0 aKiwi db 'KIWI',0 ; DATA XREF: .rdata:0056156C o
.data:0066D8E5 align 4
.data:0066D8E8 aEnds db 'ENDS',0 ; DATA XREF: .rdata:00561570 o
.data:0066D8ED align 10h
aLamb db 'LAMB',0 ; DATA XREF: .rdata:00561574 o

Re: Ford MPC565 Tuning

Posted: Wed Jan 11, 2017 1:39 pm
by headsex
haha.. the developers must be real special!

and yeah.. from a earlier post, it appears the mcs1 (and there used to be a cardaq version), have the j2543 dll files statically compiled in the exe, so certainly must be some old school compiler!

Re: Ford MPC565 Tuning

Posted: Wed Jan 11, 2017 2:11 pm
by rolls
headsex wrote:haha.. the developers must be real special!

and yeah.. from a earlier post, it appears the mcs1 (and there used to be a cardaq version), have the j2543 dll files statically compiled in the exe, so certainly must be some old school compiler!
Yeah I tried to get it to work with an open port but looked like too much work. Oddly I couldn't find any internal references to the J2534 api within the exe despite the DLL functions being exported. Seemed very odd. I was going to try and replace them with external calls but it seems it must talk to the MSC1 directly using serial?

Someone on here has kindly lent me an msc1 (sent from the USA!!) so I'm going to have a play when it arrives.

Re: Ford MPC565 Tuning

Posted: Wed Jan 11, 2017 8:00 pm
by Tazzi
rolls wrote: If you want to know something else funny I opened ptdiag up in ida pro and found that theres a secret word game hidden somewhere in it. I found all the passwords to access the special engineering modes (like disabling PATS etc), but I couldn't figure out how to launch the game. Well I assumed it was a word game, no idea why they would have hundreds of 4 letter words stored in a table otherwise!

Passwords are "42CATS" and "playtaps". Super easy to find, just searched for calls to strncmp. Must be a super old application written in C
Even back then they were obsessed with cats :lol: