Author Topic: Help Required - How to convert bin file to source code  (Read 4499 times)

0 Members and 1 Guest are viewing this topic.

Online daisizhouTopic starter

  • Frequent Contributor
  • **
  • Posts: 533
  • Country: cn
Help Required - How to convert bin file to source code
« on: April 17, 2021, 11:48:59 pm »
I use a programmer to read the information in the flash memory of the motherboard,But there are incomprehensible garbled characters.
How to convert BIN files (ie garbled files) into codes?
« Last Edit: April 18, 2021, 11:34:38 am by daisizhou »
daisizhou#sina.com #=@
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 11790
  • Country: us
Re: Help Required - How to convert bin file to source code
« Reply #1 on: April 17, 2021, 11:53:51 pm »
I use a programmer to read the information in the flash memory of the motherboard,But there are incomprehensible garbled characters.
How to convert BIN files (ie garbled files) into codes?

You will have to use a disassembler. The resulting output will not have any comments or symbolic names to help you interpret it, but it will be better than nothing.

You can, if you are patient, read the datasheet of the microcontroller and manually interpret the codes in the raw hex as CPU instructions. But this is only for small amounts of code, and if you have no other option. Otherwise the disassembler is best.

In some cases it might be possible to "decompile" the machine language back into some semblance of a language like C, but it is not easy or straightforward to do. And the result will never be the same as the original source code.
 

Online daisizhouTopic starter

  • Frequent Contributor
  • **
  • Posts: 533
  • Country: cn
Re: Help Required - How to convert bin file to source code
« Reply #2 on: April 18, 2021, 12:00:22 am »
How do I choose a disassembler?Because I don’t know which language the source code is written in,I guess it may be C language
Can you recommend me a better decompiler software?My MCU is Freescale MC9S12XDP512MAG QFP144
daisizhou#sina.com #=@
 

Offline dc101

  • Regular Contributor
  • *
  • Posts: 220
  • Country: us
Re: Help Required - How to convert bin file to source code
« Reply #3 on: April 18, 2021, 01:00:31 am »
If you post the bin file, I can take a look at it. There are commercial tools like IDA Pro and Binary Ninja, as well as the opensource Ghidra that can disassemble and decompile binary files.

To do proper disassembly you need to know the architecture, the endianness and the base-address of the code. ARM 32 is probably the easiest to determine by looking at the binary file which usually consists of a pattern where every forth byte is eX. 1212141-0

For endianness, usually MIPS is big-endian but there are some cores that are little. ARM almost always little, x86 is little and PowerPC is big.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 11790
  • Country: us
Re: Help Required - How to convert bin file to source code
« Reply #4 on: April 18, 2021, 01:48:23 am »
How do I choose a disassembler?Because I don’t know which language the source code is written in,I guess it may be C language
Can you recommend me a better decompiler software?My MCU is Freescale MC9S12XDP512MAG QFP144

You are seeing garbled characters because you are trying to view the binary file as if it were a text file. To view a binary file you need to use a hex editor, which shows you each byte in the file as a hex code.

In case you don't realize it, an MCU does not execute a language like C, it executes machine code. Machine code consists of a sequence of binary values that represent machine instructions. To interpret those instructions you need to look at the datasheet for the MCU. Disassemblers translate the machine code instructions into text that is easier for humans to read, but you will still need the datasheet to properly understand it.

Once a C program has been compiled into binary code, the original C language has been lost. You cannot get it back again. Compilation is a one-way trip. The only thing you can do is guess what the original C code might have looked like, which is what decompilers try to do. However, decompiling will never be 100% successful.
 

Online daisizhouTopic starter

  • Frequent Contributor
  • **
  • Posts: 533
  • Country: cn
Re: Help Required - How to convert bin file to source code
« Reply #5 on: April 18, 2021, 11:36:09 am »
I uploaded the hex file, which software is the best decompiler for me
daisizhou#sina.com #=@
 

Online daisizhouTopic starter

  • Frequent Contributor
  • **
  • Posts: 533
  • Country: cn
Re: Help Required - How to convert bin file to source code
« Reply #6 on: April 19, 2021, 01:29:25 pm »
How do I choose a disassembler?Because I don’t know which language the source code is written in,I guess it may be C language
Can you recommend me a better decompiler software?My MCU is Freescale MC9S12XDP512MAG QFP144
I hope to learn the source code,Does anyone have a better suggestion?
daisizhou#sina.com #=@
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 11790
  • Country: us
Re: Help Required - How to convert bin file to source code
« Reply #7 on: April 19, 2021, 02:00:23 pm »
I hope to learn the source code,Does anyone have a better suggestion?

Once a C program has been compiled into binary code, the original C language has been lost. You cannot get it back again.

Is that clear enough for you?
 
The following users thanked this post: blueskull, AndersJ


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf