EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

8052 emulator in C

Started by joolzg May 24, 2011
Anybody got a simple 8052 emulator in C source, im trying to reverse engineer 
some code and would like to emulate/simulate the code to get a better 
understanding as it looks like  it was written in C and compiled by a very bad 
compiler

joolz



-- 
--------------------------------- --- -- -
Posted with NewsLeecher v5.0 Beta 6
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

In message <4ddb6833$0$1509$c3e8da3$efbdef2c@news.astraweb.com>, joolzg
<joolzg@btinternet.com> writes
>Anybody got a simple 8052 emulator in C source, im trying to reverse engineer >some code and would like to emulate/simulate the code to get a better >understanding as it looks like it was written in C and compiled by a very bad >compiler
What is the target MCU? The 51 family is huge (over 600 variants) and whilst the cores are similar there are some big differences. Why do you want the source of the simulator? How do you know the binary was written in C? How big is the binary? What is it supposed to do? -- \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
On 5/24/2011 2:11 AM, joolzg wrote:
> Anybody got a simple 8052 emulator in C source, im trying to reverse engineer > some code and would like to emulate/simulate the code to get a better > understanding as it looks like it was written in C and compiled by a very bad > compiler > > joolz > > >
You don't what a emulator, you want a de-compiler or reverse compiler. An emulator will just execute the binary code as the real hardware would. Using the binary to get the C back is impossible !!!! Except for very simple programs. Even if you have the compiler sources and understood the compile process, you still would not be able to get the binary -> C conversion to work. But, have fun and good luck. hamilton
Hi Hamilton,

On 5/24/2011 12:23 PM, hamilton wrote:
> On 5/24/2011 2:11 AM, joolzg wrote: >> Anybody got a simple 8052 emulator in C source, im trying to reverse >> engineer >> some code and would like to emulate/simulate the code to get a better >> understanding as it looks like it was written in C and compiled by a >> very bad compiler > > You don't what a emulator, you want a de-compiler or reverse compiler. > > An emulator will just execute the binary code as the real hardware would. > > Using the binary to get the C back is impossible !!!!
Actually, for some simple-minded compilers, you can often reverse engineer the code to get much of the "C" source (neglecting variable names, some expressions, etc.). This is especially true of old/early compilers that didn't do much optimization. I was able to recreate C source for a client's libraries from binaries using this approach. Though it required a fair bit of "organic computing" to recognize the "patterns" in the code (a decompiler wasn't available). Of course, familiarity with the product (application) goes a long way -- especially when it comes to annotating the sources! Note that the "organic" method can be painfully slow -- I was only able to decompile a few KB per week. :< But, the alternative is to recreate the sources from the *specification*... [if you've never done this, it can be a really fun problem! Sure beats crossword puzzles!]
> Except for very simple programs. > > Even if you have the compiler sources and understood the compile > process, you still would not be able to get the binary -> C conversion > to work.
On 5/24/2011 1:30 PM, D Yuniskis wrote:
> Hi Hamilton, > > On 5/24/2011 12:23 PM, hamilton wrote: >> On 5/24/2011 2:11 AM, joolzg wrote: >>> Anybody got a simple 8052 emulator in C source, im trying to reverse >>> engineer >>> some code and would like to emulate/simulate the code to get a better >>> understanding as it looks like it was written in C and compiled by a >>> very bad compiler >> >> You don't what a emulator, you want a de-compiler or reverse compiler. >> >> An emulator will just execute the binary code as the real hardware would. >> >> Using the binary to get the C back is impossible !!!! > > Actually, for some simple-minded compilers, you can often reverse > engineer the code to get much of the "C" source (neglecting > variable names, some expressions, etc.). This is especially > true of old/early compilers that didn't do much optimization.
For years I have heard that story. I have always asked to show me any links with the compiler in question, So I will ask if you have any links to this "simple compiler" ? I took a compiler class 30 years ago, and my professor at the time stated that it was not possible. With the better compiler available today it would be even more impossible.
> > I was able to recreate C source for a client's libraries from > binaries using this approach. Though it required a fair bit of > "organic computing" to recognize the "patterns" in the code > (a decompiler wasn't available). Of course, familiarity with > the product (application) goes a long way -- especially when > it comes to annotating the sources!
Being familiar with the code is the only way to get back the C code. But the OP seems to have no knowledge of the application. I have lost sources in disk crashes and have had to re-create the C sources by watching the operation of the application. reverse-engineering is always easier when you have a good idea of what is suppose to happen.
> > Note that the "organic" method can be painfully slow -- I was > only able to decompile a few KB per week. :< But, the alternative > is to recreate the sources from the *specification*...
Yes, building a spec for functions code is not bad, but as you say very slow. A few years ago I had a company needing to reverse engineer their legacy assembly 68hc11 product. I was able to recreate most of the application in C, but some of the algorithms were so convoluted that I could never understand the dis-assembly. So, we repackaged the assembly into a C in-line assembly function and everything still worked. Lucky !!!
> > [if you've never done this, it can be a really fun problem! Sure > beats crossword puzzles!] > >> Except for very simple programs. >> >> Even if you have the compiler sources and understood the compile >> process, you still would not be able to get the binary -> C conversion >> to work. >
hamilton <hamilton@nothere.com> wrote:
> I took a compiler class 30 years ago, and my professor at the time > stated that it was not possible. > With the better compiler available today it would be even more impossible.
Have you looked at eg. Hex-Rays? From what I've seen of it, it's pretty good at what it does. -a
joolzg <joolzg@btinternet.com> wrote:
> Anybody got a simple 8052 emulator in C source, im trying to reverse > engineer some code and would like to emulate/simulate the code to get a > better understanding as it looks like it was written in C and compiled > by a very bad compiler
There's the Daniel's s51 simulator[1] which is used in the SDCC[2] debugger. -a [1] <http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/ucsim/> [2] <http://sdcc.sourceforge.net/>
In reply to "Chris H" who wrote the following:

> In message <4ddb6833$0$1509$c3e8da3$efbdef2c@news.astraweb.com>, joolzg > <joolzg@btinternet.com> writes > > Anybody got a simple 8052 emulator in C source, im trying to reverse > > engineer > > some code and would like to emulate/simulate the code to get a better > > understanding as it looks like it was written in C and compiled by a very > > bad > > compiler > > What is the target MCU? The 51 family is huge (over 600 variants) and > whilst the cores are similar there are some big differences. >
Analog Devices ADuC84x
> Why do you want the source of the simulator? >
So i can add in a serial driver, also the output display, you know make the simulator behave like the real thing with inputs and outputs
> How do you know the binary was written in C? >
I can tell from the way the code is written!! cant you tell the differnece between human and machine created code
> How big is the binary? >
64k but not all used
> What is it supposed to do? >
cant say -- --------------------------------- --- -- - Posted with NewsLeecher v5.0 Beta 6 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- -
In reply to "hamilton" who wrote the following:

> On 5/24/2011 2:11 AM, joolzg wrote: > > Anybody got a simple 8052 emulator in C source, im trying to reverse > > engineer > > some code and would like to emulate/simulate the code to get a better > > understanding as it looks like it was written in C and compiled by a very > > bad > > compiler > > > > joolz > > > > > > > You don't what a emulator, you want a de-compiler or reverse compiler. > > An emulator will just execute the binary code as the real hardware would. > > Using the binary to get the C back is impossible !!!! > > Except for very simple programs. > > Even if you have the compiler sources and understood the compile > process, you still would not be able to get the binary -> C conversion > to work. > > But, have fun and good luck. > > hamilton
Ive got that already, i want to SIMULATE THE CODE and give the code real inputs so i can validate my findings I will be rewriting it for another cpu as well so want to find out as much joolz -- --------------------------------- --- -- - Posted with NewsLeecher v5.0 Beta 6 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- -
In reply to "Anders.Montonen@kapsi.spam.stop.fi.invalid" who wrote the 
following:

> hamilton <hamilton@nothere.com> wrote: > > I took a compiler class 30 years ago, and my professor at the time > > stated that it was not possible. > > With the better compiler available today it would be even more impossible. > > Have you looked at eg. Hex-Rays? From what I've seen of it, it's pretty > good at what it does. > > -a
i want to simulate the code, hence the question!!!!! i alread have the binary and disassembly joolz -- --------------------------------- --- -- - Posted with NewsLeecher v5.0 Beta 6 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- -

The 2024 Embedded Online Conference