News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

help with conversion!

Started by RedGhost, April 24, 2005, 07:32:33 PM

Previous topic - Next topic

RedGhost

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)

thomasantony

Can you post how you corrected it? It will be helpful to others

Thomas :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

AeroASM

What flaws? The oly flaws I can see is that you have used invalid hex digits and PDWORD should be DWORD.

RedGhost

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

AeroASM

That is very strange. Could you post the whole code sample so we can test it?

GregL

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.



Mark Jones

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
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

thomasantony

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
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

pbrennick

Hi All,

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

Paul

roticv

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

AeroASM

I disagree. It is:


mov esi,somePTR
mov edi,offset someTHING
movsd

Mark Jones

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
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Vortex

Mark, I liked your new avatar  :U :U :U

GregL

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?

RedGhost

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