flat assembler
Message board for the users of flat assembler.

Index > Windows > working on array in Dll :roll:

Author
Thread Post new topic Reply to topic
newtron333



Joined: 20 Dec 2009
Posts: 6
newtron333
i wrote simle function that includs array, the function is in dll, i dont know how to work with the array (for example if i want to write third element of array in eax).

please help me :SSS
Post 22 Dec 2009, 19:33
View user's profile Send private message Reply with quote
newtron333



Joined: 20 Dec 2009
Posts: 6
newtron333
DLL

;================================================
format PE GUI 4.0 DLL
entry DllMain

;================================================
include 'c:\fasmw\include\win32a.inc'


section '.data' code readable executable
x dd 0


;================================================
section '.text' code readable executable

DllMain:
mov eax,TRUE
ret 12

vec_dis:
mov eax,[esp+12] ;array third element :S
ret 8



;================================================
section '.edata' export readable writeable

export 'mydll',\
vec_dis,'vec_dis'
Post 22 Dec 2009, 19:37
View user's profile Send private message Reply with quote
newtron333



Joined: 20 Dec 2009
Posts: 6
newtron333
;this is simple program that uses that DLL
format PE CONSOLE 4.0

entry Start ;declare entrypoint

;include fasm inc directory
include 'C:\fasmw\include\win32w.inc'

section '.data' data readable writable

text1 db "%d",0
size dd 6
result dd 1,2,3,4,5,6
vec_array dd 7,4,23,87,13,74
vec dd 10
szPause db "pause",0


;code section
section '.code' code readable executable


Start:


invoke vec_dis,vec_array;,size,result
invoke printf,text1,[eax]

push szPause
call [system]

push 0
call [ExitProcess]

;================================================
section '.idata' import data readable executable

library kernel,'KERNEL32.DLL',\
user,'MSVCRT.DLL',\
mydll,'mydll.DLL'


import kernel,\
ExitProcess,'ExitProcess'


import user,\
printf,'printf',\
system,'system',\
scanf,'scanf'


import mydll,\
vec_dis,'vec_dis'
Post 22 Dec 2009, 19:38
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
newtron333,

First parameter is at [esp+4]. It is a pointer. Dereference it.
Post 22 Dec 2009, 19:50
View user's profile Send private message Reply with quote
newtron333



Joined: 20 Dec 2009
Posts: 6
newtron333
i dont understand


Last edited by newtron333 on 22 Dec 2009, 20:12; edited 1 time in total
Post 22 Dec 2009, 20:08
View user's profile Send private message Reply with quote
newtron333



Joined: 20 Dec 2009
Posts: 6
newtron333
what must i write here, to write third element in eax?

mov eax,[esp+12] ;

how to Dereference it?
Post 22 Dec 2009, 20:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17272
Location: In your JS exploiting you and your system
revolution
Code:
mov ecx,[esp+4] ;get first argument from caller
mov eax,[ecx+8] ;get third element from array
ret 4 ;restore stack and return    
Also use this:
Code:
cinvoke printf,text1,[eax]    
Notice that printf uses cinvoke because it is a var_arg function.
Post 22 Dec 2009, 21:26
View user's profile Send private message Visit poster's website Reply with quote
newtron333



Joined: 20 Dec 2009
Posts: 6
newtron333
tnks Smile)
Post 23 Dec 2009, 06:07
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-2020, Tomasz Grysztar.

Powered by rwasa.