Modify Binary

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Modify Binary

411 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by GPh on Mon Aug 10 02:36:06 MST 2015
Hi,

Probably my need seem's curious but in our process it's usefull.

I need to modify a const value in the binary program before flash it in the LPC1768.
This value is a customer code and crypto key, and in production we have to put it in the FLASH for security reason.

I want : In production they take the axf, change the code and key, and program the flash (we have made an internal tools for automate this tasks).
But i don't understand the axf format and i don't find in it my constant !

Does anyone have a suggestion ?
Or an advise for help me ?

Thanks a lots, Philippe.
0 Kudos
6 Replies

390 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ramana on Tue Aug 11 21:03:46 MST 2015
Hi,
I think it better to modify the hex file using HEX2BIN/BIN2HEX utilities with required key and then download the converted file into flash, So that no need to recompile the code every time.
0 Kudos

390 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wmues on Mon Aug 10 13:58:01 MST 2015
Remember that a "const" value might be optimized away by the compiler.
0 Kudos

390 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Mon Aug 10 07:02:58 MST 2015
I gave you a couple of options, both of which will work. The simplest/most reliable is to convert to binary. The use of magic numbers will also work.

I guess you are doing something wrong if you can't make it work. If you want any more help, suggest you tell us what you tried (sharing your code) and then somebody will be able to tell you what you did wrong.
0 Kudos

390 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by GPh on Mon Aug 10 06:58:40 MST 2015
Thanks.

I know it's not simple.
I try the magic way without succes.

But i can't let production recompile each time and i can't put it in external EEProm ...
if i have a good idea, i share it  :)


0 Kudos

390 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Mon Aug 10 05:33:45 MST 2015
Another thought.

You could surround your value with some magic numbers. Then write a utility to search the AXF file for those magic numbers and then modify your data.

You will have to be very careful with your choice of magic numbers so there is not an accidental match with other data in your application AXF file. If you do this use a magic number of at least 16 bytes before and after your data.
0 Kudos

390 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Mon Aug 10 02:43:25 MST 2015
.axf files are in ELF format. Reading and modifying ELF files is not easy... If you really want to go down this route, you can probably start from the GNU 'readelf' utility (GPL licensed).

But, you will find it easier to ensure this value is always in a fixed, known location and then convert it to binary and modify that - which what NXP do with the checksum utility.
0 Kudos