How to edit a bin/img file's magic number?

sam1275tom

Reputable
Oct 13, 2014
462
0
4,860
Hello.
I'm trying to flash a router to openwrt, but the factory firmware don't accept the firmware "...invalid configuration...bad magic number..."
I can extract both factory.img and openwrt.bin using 7z, but the router just refuse any third-party firmware.
So how can I read out the factory magic number and write them to the custom image file?
Thanks.
 
Solution
The "magic number" is usually a CRC or hash. It's not something you can simply edit. It's generated by a calculation based on the length and content (the exact pattern of bits) in the file. It's used to protect against flashing with a binary which has become corrupted, although a lot of manufacturers have started using it to make it harder/impossible to upload third party firmwares.

Routers with this sort of safeguard usually have to be hacked to accept a third party firmware (the TTL cable). Once you get the third party firmware on there, it's easy to upload a different third party firmware.

What sometimes works is to downgrade your router's firmware to an older factory firmware created before the magic number check was...

sam1275tom

Reputable
Oct 13, 2014
462
0
4,860


Alfa R36.
The Openwrt forum have a discuss on this model, and they use TTL cable to hack it from boot, but I don't have the cable and I want try this way.
 
The "magic number" is usually a CRC or hash. It's not something you can simply edit. It's generated by a calculation based on the length and content (the exact pattern of bits) in the file. It's used to protect against flashing with a binary which has become corrupted, although a lot of manufacturers have started using it to make it harder/impossible to upload third party firmwares.

Routers with this sort of safeguard usually have to be hacked to accept a third party firmware (the TTL cable). Once you get the third party firmware on there, it's easy to upload a different third party firmware.

What sometimes works is to downgrade your router's firmware to an older factory firmware created before the magic number check was implemented, then upload the third party firmware. You'll have to search the DD-WRT forums for your particular router model to see if there are other methods of getting a third party firmware onto it. Also check the OpenWRT site - sometimes they have more straightforward answers (DD-WRT tends to be a big discussion forum with little in the way of consolidated answers).
 
Solution