Author Topic: Can someone convert this ASM code to C?  (Read 20963 times)

Offline hockey97

  • Jr. Member
  • *
  • Posts: 8
Can someone convert this ASM code to C?
« on: June 15, 2014, 06:31:42 PM »
Hi, I  am learning ASM x86 and got this code for an example. I would like if someone could convert it from ASM to C or C++. Also explain what each line does.

I am new here and I know the basics of ASM. I am now trying to learn how to translate ASM code to C or a higher language.

Here's the code:

UnknownFunction:
    MOV EDI,EDI
    PUSH EBP
    MOV EBP,ESP
    MOV EAX,DWORD PTR SS:[EBP+8]
    XOR EDX,EDX
    LEA ECX,DWORD PTR DS:[EAX+4]
    MOV DWORD PTR DS:[EAX],EDX
    MOV DWORD PTR DS:[ECX+4],ECX
    MOV DWORD PTR DS:[ECX],ECX
    MOV DWORD PTR DS:[EAX+C],ECX
    MOV ECX,DWORD PTR SS:[EBP+C]
    MOV DWORD PTR DS:[EAX+18],ECX
    MOV ECX,DWORD PTR SS:[EBP+10]
    MOV DWORD PTR DS:[EAX+1C],ECX
    MOV ECX,DWORD PTR SS:[EBP+14]
    MOV DWORD PTR DS:[EAX+20],ECX
    MOV ECX,DWORD PTR SS:[EBP+18]
    MOV DWORD PTR DS:[EAX+14],EDX
    MOV DWORD PTR DS:[EAX+10],EDX
    MOV DWORD PTR DS:[EAX+24],ECX
    POP EBP
    RETN 14


All I know is that it's pushing stuff off and on a stack. It has pointers and uses exclusive or conditional statement.

I am guessing that RETN 14 is the same as returning 0 in C or C++.
This whole thing is a function.

Offline gammac

  • Jr. Member
  • *
  • Posts: 71
  • Country: 00
Re: Can someone convert this ASM code to C?
« Reply #1 on: June 16, 2014, 10:46:54 AM »
I am sure, you won't learn assembly programming by the use of reverse engeneering!
Please comment your code! It helps to help you.

Offline encryptor256

  • Full Member
  • **
  • Posts: 250
  • Country: lv
  • Win64 .
    • On Youtube: encryptor256
Re: Can someone convert this ASM code to C?
« Reply #2 on: June 17, 2014, 08:51:33 AM »
I am guessing that RETN 14 is the same as returning 0 in C or C++.

I think, Your "quessing" is a bit wrong. It pops 14 bytes off the stack and only then - returns. Returns value that is stored into eax.

Thanks, bye.
Encryptor256's Investigation \ Research Department.

Offline hockey97

  • Jr. Member
  • *
  • Posts: 8
Re: Can someone convert this ASM code to C?
« Reply #3 on: June 18, 2014, 02:58:42 AM »
I am guessing that RETN 14 is the same as returning 0 in C or C++.

I think, Your "quessing" is a bit wrong. It pops 14 bytes off the stack and only then - returns. Returns value that is stored into eax.

Thanks, bye.

So, then how would you write that in C or C++?

Offline franciscamitchell

  • Jr. Member
  • *
  • Posts: 2
Re: Can someone convert this ASM code to C?
« Reply #4 on: July 07, 2014, 09:32:13 AM »
I have seen a couple applications that can do that but the code you will get will not be anything similar to the original code. I just complete an assignment about conversion of ASM to C with the help of genuine essay writing service, but i can't follow the method described in it. I think that to call assembly from C, you simply use the normal C syntax for a function call. This assumes, of course, that the assembly function was written using the C calling conventions.

Offline jiminan

  • Jr. Member
  • *
  • Posts: 2
  • Country: am
    • What do sharks eat ?
Re: Can someone convert this ASM code to C?
« Reply #5 on: August 30, 2014, 09:23:01 AM »
I have seen a couple applications that can do that but the code you will get will not be anything similar to the original code. I just complete an assignment about conversion of ASM to C with the help of genuine essay writing service, but i can't follow the method described in it. I think that to call assembly from C, you simply use the normal C syntax for a function call. This assumes, of course, that the assembly function was written using the C calling conventions.

I'm absolutely agree with you .

Offline haliesean55

  • New Member
  • Posts: 1
Re: Can someone convert this ASM code to C?
« Reply #6 on: July 23, 2016, 11:23:15 AM »
Your assigned essay writer will handle every aspect of formatting to ensure that you receive buy narrative essay and submit a properly formatted essay.