Author Topic: Can the source code be converted after reading the bin file?  (Read 533 times)

0 Members and 1 Guest are viewing this topic.

Offline daisizhou

  • Regular Contributor
  • *
  • Posts: 89
  • Country: cn
I read the bin file in the flash memory through the programmer.I want to know the source code, is there a way to achieve it?
The mcu model is MC9S12XDP512,Please tell me the tools and steps used, thank you
daisizhou#sina.com #=@
 

Offline coromonadalix

  • Super Contributor
  • ***
  • Posts: 3270
  • Country: ca
Re: Can the source code be converted after reading the bin file?
« Reply #1 on: May 17, 2021, 08:51:45 am »
Normally   once converted to an hex   it can not reverted  or easily decompiled,   tools like IDA  Ghidra cant decompile completely an HEX

It would be too easy to do reverse engineering  loll
 

Offline tv84

  • Super Contributor
  • ***
  • Posts: 2191
  • Country: pt
Re: Can the source code be converted after reading the bin file?
« Reply #2 on: May 17, 2021, 09:25:20 am »
I read the bin file in the flash memory through the programmer.I want to know the source code, is there a way to achieve it?
The mcu model is MC9S12XDP512,Please tell me the tools and steps used, thank you

That is a .bin dump, not an .hex file.
 

Offline tunk

  • Frequent Contributor
  • **
  • Posts: 407
  • Country: no
 

Offline tv84

  • Super Contributor
  • ***
  • Posts: 2191
  • Country: pt
Re: Can the source code be converted after reading the bin file?
« Reply #4 on: May 17, 2021, 10:22:52 am »
And the OP has been there...
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 1758
  • Country: ua
Re: Can the source code be converted after reading the bin file?
« Reply #5 on: May 17, 2021, 10:55:44 am »
I read the bin file in the flash memory through the programmer.I want to know the source code, is there a way to achieve it?
The mcu model is MC9S12XDP512,Please tell me the tools and steps used, thank you

No, compilation from source code to the binary is one way operation. All information needed for human readability will be lost.

Recreate source code from binary is reverse engineering. This is very complex work which needs to analyze what machine code doing and then write your own source code which doing the same things. In most cases it's more easy and cheaper to write your own source code from scratch than reverse engineering for existing binary.

Some tools like decompilers are exists, but they just help to translate machine code into more readable format for analysis. They are not intended to restore functional source code.
« Last Edit: May 17, 2021, 11:01:48 am by radiolistener »
 
The following users thanked this post: daisizhou

Offline daisizhou

  • Regular Contributor
  • *
  • Posts: 89
  • Country: cn
daisizhou#sina.com #=@
 

Offline Bicurico

  • Super Contributor
  • ***
  • Posts: 1201
  • Country: pt
    • VMA's Satellite Blog
Re: Can the source code be converted after reading the bin file?
« Reply #7 on: May 17, 2021, 11:29:07 am »
Some notes:

1) Reverse Engineering of software can be illegal, depending on the purpose: https://en.wikipedia.org/wiki/Reverse_engineering#Legality
2) Authors of software are not happy when people try to reverse engineer their work, which leads to the next important question:
3) What do you want to achieve? Why do you want to reverse engineer a binary file?

While it is not an easy task, it is not impossible, to do so.

As already mentioned in both threads that you started, you can use a DECOMPILER. In your case, you have two options: IDA Pro (expensive) or Ghidra (open source).

If correctly configured and used, they allow to convert a binary (in one of the supported CPU languages) into human readable source code (assembly language) and/or pseudo C code.

This code cannot be edited in a regular SDK and then compiled into a binary again, as it will miss information and be incomplete. To do so, would probably take more time than simply writing a similar program from scratch.

However, it does allow to understand some principles and is certainly used for another "illegal" activity: generation of patched and keygens. I do imagine that there are some legal applications, but only few come to my mind.

"Learning" how to program is certainly NOT an application for reverse engineering! If you want to learn how to program, you should take a course in exactly that subject.

Regards,
Vitor

Offline Bicurico

  • Super Contributor
  • ***
  • Posts: 1201
  • Country: pt
    • VMA's Satellite Blog
Re: Can the source code be converted after reading the bin file?
« Reply #8 on: May 17, 2021, 12:33:49 pm »
Of course you can decompile a HEX file. It is just a representation of the binary file in a text readable format, where each byte is represented as a hexadecimal number.

You only need to consider the memory layout represented in the HEX file, which might not be contiguous, but rather list different memory locations

Offline daisizhou

  • Regular Contributor
  • *
  • Posts: 89
  • Country: cn
Re: Can the source code be converted after reading the bin file?
« Reply #9 on: May 17, 2021, 12:43:33 pm »
I hope to add some functions that were originally restricted,At the same time some interest in decompilation
My assumption is that if the same environment can be configured, the code and machine language should be interchangeable--Of course this is the ideal state
daisizhou#sina.com #=@
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 10298
  • Country: my
  • reassessing directives...
Re: Can the source code be converted after reading the bin file?
« Reply #10 on: May 17, 2021, 01:28:57 pm »
And the OP has been there...
no he hasnt... nobody has.. afaik.. but with current age of AI this and AI that, instead of apps that make people's face like shit, efforts should be spent on this kind of thing, if some hackers come to their senses.
« Last Edit: May 17, 2021, 01:31:02 pm by Mechatrommer »
It's extremely difficult to start life.. one features of nature.. physical laws are mathematical theory of great beauty... You may wonder Why? our knowledge shows that nature is so constructed. We simply have to accept it. One could describe the situation by saying that... (Paul Dirac)
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 21139
  • Country: nl
    • NCT Developments
Re: Can the source code be converted after reading the bin file?
« Reply #11 on: May 17, 2021, 02:16:24 pm »
When one covert source code into an hex it can not reverted or decompiled, tools like IDA Ghidra are not able to decompile completely an HEX file,
It would too easy to do reverse engineering
Actually some decompilers can do a reasonable job for decompiling binary code. In the end compilers follow a certain strategy to convert code into assembly; based on that a readable source can be created which allows to study the flow of the program.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline tv84

  • Super Contributor
  • ***
  • Posts: 2191
  • Country: pt
Re: Can the source code be converted after reading the bin file?
« Reply #12 on: May 17, 2021, 03:06:53 pm »
And the OP has been there...
no he hasnt... nobody has.. afaik.. but with current age of AI this and AI that, instead of apps that make people's face like shit, efforts should be spent on this kind of thing, if some hackers come to their senses.

The OP has been in the thread advised by @tunk, that what I was referring to.

Actually some decompilers can do a reasonable job for decompiling binary code. In the end compilers follow a certain strategy to convert code into assembly; based on that a readable source can be created which allows to study the flow of the program.

They sure do. IDA and Ghidra do AWESOME jobs for the processors they can already pseudo-decompile.

BTW, one doesn't need a readable source to study the flow. A flow graphic (that they both provide) is already a great help in studying the flow.

In more general terms:

A big problem is that there are very few schools where reversing is even touched.

Erroneously, people then to relate reversing with hacking and keep away from it. BUT they loose all the benefits in debugging skills that reversing provides.

And this forum has lots of people that do it in the HW world but much less in the SW world.
 

Offline ucanel

  • Regular Contributor
  • *
  • Posts: 131
  • Country: tr
Re: Can the source code be converted after reading the bin file?
« Reply #13 on: May 17, 2021, 03:21:22 pm »
I recently ran into a video about the topic:
https://youtu.be/q4CxE5P6RUE

That would not be a route that i will take in same situation,
writing the code from scratch would be easier.

If you will change just some little things like messages on screen etc. it is doable with a little bit effort.
 

Offline tv84

  • Super Contributor
  • ***
  • Posts: 2191
  • Country: pt
Re: Can the source code be converted after reading the bin file?
« Reply #14 on: May 17, 2021, 03:55:23 pm »
I recently ran into a video about the topic:
https://youtu.be/q4CxE5P6RUE

A nice video to give OP a quick overview about what is at play.

Although this uses ARM proc language which Ghidra can decompile.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf