flat assembler
Message board for the users of flat assembler.

Index > Main > Equating a data entry to an import macro entry

Author
Thread Post new topic Reply to topic
ssjcoder



Joined: 20 Nov 2018
Posts: 6
ssjcoder 15 May 2019, 21:29
<data section>
_b dd CS_Print

<import section>
library _Lib, 'msvcrt.dll'
import _Lib, CS_Print, 'printf'

for some reason _b does not equate to CS_Print when the program starts, I guess I'm not sure exactly how to correctly get its value?

Any help appreciated
Post 15 May 2019, 21:29
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 15 May 2019, 21:47
CS_Print is not an address of imported function, it is an address of a 32-bit data field that contains an address of a function once the imports have been resolved. You call the function indirectly through this variable:
Code:
call [CS_Print]    
This field is filled with a correct address only at run-time, after PE loader has processed the imports.

Therefore if you need [_b] to have the address of imported function, you have to copy the value like:
Code:
mov eax,[CS_Print]
mov [_b],eax    
Post 15 May 2019, 21:47
View user's profile Send private message Visit poster's website Reply with quote
ssjcoder



Joined: 20 Nov 2018
Posts: 6
ssjcoder 15 May 2019, 21:59
thank you for your answer it's much appreciated.

It turns out _b stored the address of CS_Print rather than matching it (obviously)

So I needed to alter my code to this:
Code:
mov eax, dword [_b]
call dword [eax]    


In order to actually call the correct address, and as you have mentioned I need to copy it at the start of the program to get the correct value (without needing to go through extra instructions).

Thanks
Post 15 May 2019, 21:59
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.