The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: RedGhost on April 24, 2005, 07:32:33 PM

Title: help with conversion!
Post by: RedGhost on April 24, 2005, 07:32:33 PM
okay, once again since i don't know masm well im forced to try and translate some of the c code i use  :red

but im lost, if one of you would be so kind!

c code:

void __stdcall someFUNC( );
unsigned int *somePTR
unsigned int someTHING;

unsigned int someBASE = 0xBASE;
somePTR = (unsigned int*)( someBASE + 0xSTUFF );
someTHING = *somePTR;
*somePTR = (unsigned int)&someFUNC;



this is my sad attempt at an asm conversion  :U



someFUNC PROTO
somePTR PDWORD ?
someTHING DWORD  ?
someBASE DWORD  ?

mov someBASE, BASEh
mov eax, [someBASE+STUFFh]
mov somePTR, eax
mov eax, dword ptr [somePTR]
mov someTHING, eax
mov DWORD PTR [somePTR], offset someFUNC


thanks in advance
   


edit*

i compiled the exact code i wanted in c, diasassembled it, and copied the disassembled asm in, filled in the blanks and it worked lol
so i saw where my flaws were (soft of :P)
Title: Re: help with conversion!
Post by: thomasantony on April 25, 2005, 05:05:18 AM
Can you post how you corrected it? It will be helpful to others

Thomas :U
Title: Re: help with conversion!
Post by: AeroASM on April 25, 2005, 06:44:48 AM
What flaws? The oly flaws I can see is that you have used invalid hex digits and PDWORD should be DWORD.
Title: Re: help with conversion!
Post by: RedGhost on April 25, 2005, 04:39:39 PM
the code that finally worked after disassembling my src was:


mov someBASE, BASEh
mov eax, [someBASE]
add eax, STUFFh
mov somePTR, eax
mov eax, somePTR
mov eax, [eax]
mov someTHING, eax
mov eax, somePTR
mov DWORD PTR [eax], offset someFUNC


now the thing that bothers me was that if i did
mov eax, [somePTR]
move someTHING, eax

it would crash or just not work but

mov eax, somePTR
mov eax, [eax]
mov someTHING, eax

worked great
Title: Re: help with conversion!
Post by: AeroASM on April 25, 2005, 06:37:37 PM
That is very strange. Could you post the whole code sample so we can test it?
Title: Re: help with conversion!
Post by: GregL on April 25, 2005, 07:03:51 PM
RedGhost,

BASEh is not a vailid hex number, neither is STUFFh, so you couldn't have assembled it successfully. Your C code wouldn't compile either for the same reason.


Title: Re: help with conversion!
Post by: Mark Jones on April 25, 2005, 07:08:06 PM
Also note a small caveat: hex immed's must always start with a "0":


mov eax,  FFAh  <--- will produce an error
mov eax, 0FFAh  <--- no error
Title: Re: help with conversion!
Post by: thomasantony on April 26, 2005, 05:43:54 AM
Quote from: Mark Jones on April 25, 2005, 07:08:06 PM
Also note a small caveat: hex immed's must always start with a "0":


mov eax,  FFAh  <--- will produce an error
mov eax, 0FFAh  <--- no error

A slight mistake there. Only hex values that does not start with a digit need a 0 in front of it.

Thomas. :U
Title: Re: help with conversion!
Post by: pbrennick on April 26, 2005, 11:10:45 AM
Hi All,

I think you guys are way off base.  BASEh and STUFFh are labels, not numbers and they are fine.

Paul
Title: Re: help with conversion!
Post by: roticv on April 26, 2005, 11:44:40 AM
RedGhost,

mov eax, [somePTR]

just move the values (your pointer) located at the label somePTR to eax.

mov eax, [eax]
moves the data pointed by your pointer into eax.

mov [something], eax
store your data

it is the same as
mov esi, [somePTR]
mov edi, [someTHING]
movsd
Title: Re: help with conversion!
Post by: AeroASM on April 26, 2005, 01:01:47 PM
I disagree. It is:


mov esi,somePTR
mov edi,offset someTHING
movsd
Title: Re: help with conversion!
Post by: Mark Jones on April 26, 2005, 05:38:01 PM
Quote from: pbrennick on April 26, 2005, 11:10:45 AM
I think you guys are way off base.  BASEh and STUFFh are labels, not numbers and they are fine.

Hi Paul, yes of course that is correct. I should have explained more clearly. I was simply adding that if one wanted to use an immediate value (in which the MSD is other than 0-9), a 0 must precede it. So:


mov eax,  DEADBEEFh <---- error unless DEADBEEFh is a defined variable
mov eax, 0DEADBEEFh <---- valid immediate value
Title: Re: help with conversion!
Post by: Vortex on April 26, 2005, 06:41:25 PM
Mark, I liked your new avatar  :U :U :U
Title: Re: help with conversion!
Post by: GregL on April 26, 2005, 07:51:35 PM
OK, I guess I was off base, sorry RedGhost.

They sure look like hex numbers, especially in the C code.

What is this some sort of obfuscated code?
Title: Re: help with conversion!
Post by: RedGhost on April 27, 2005, 02:28:31 PM
i should have been a little more clear :P

they are infact hex numbers, if you look at the c code 0xSTUFF thats just pseudo code for an address, could be eg: 0x12345678

and, they both have numbers as the first digit but i did not know without the 0 if its a non number that would be an error thanks mark and thomas  :8)

Quote
To understand recursion, you must first understand recursion.

haha i love that