flat assembler
Message board for the users of flat assembler.

Index > Windows > Returning values in DLL Functions?

Author
Thread Post new topic Reply to topic
hansdieter



Joined: 22 Feb 2011
Posts: 5
hansdieter 22 Feb 2011, 00:10
Hello, i'm somewhat new to fasm and trying to make a dll.
the DLL is a plugin for a 64 and 32 bit program, now i made it to compile for 64 bit. But i somewhat don't understand how i can return values in my functions.

Code:
_test db 'This is a test string',0    


Code:
proc GetString id,flags
   mov rax,_test ; this will assemble just fine but it somehow doesn't return the string
      ret
endp
    


The Program requires an LPCTSTR, also: how can i return "UINT"'s in the proc?
Post 22 Feb 2011, 00:10
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20344
Location: In your JS exploiting you and your system
revolution 22 Feb 2011, 00:15
The type of LPCTSTR is dependant upon the unicode setting. Your code always returns LPCSTR.
Post 22 Feb 2011, 00:15
View user's profile Send private message Visit poster's website Reply with quote
hansdieter



Joined: 22 Feb 2011
Posts: 5
hansdieter 22 Feb 2011, 00:19
the program needs:
Code:
LPCTSTR GetString(UINT id, UINT flags)    


But with the Proc i posted above, it will not show my _test string, instead it shows some kind of japanese characters.
Post 22 Feb 2011, 00:19
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20344
Location: In your JS exploiting you and your system
revolution 22 Feb 2011, 00:21
Is your project unicode?
Post 22 Feb 2011, 00:21
View user's profile Send private message Visit poster's website Reply with quote
hansdieter



Joined: 22 Feb 2011
Posts: 5
hansdieter 22 Feb 2011, 00:25
Well i don't quite know if the target project is unicode, but here is an example plugin: http://code.google.com/p/rainmeter/source/browse/trunk/Plugins/PluginExample/ExamplePlugin.c

I just want to write a plugin for it, that uses GetString to give a string to the calling progam.

full source:
Code:
;format PE GUI 4.0 DLL ;FOR 32 BIT DLL
format PE64 GUI 4.0 DLL ;FOR 64 BIT DLL
entry DllEntryPoint

include '../INCLUDE/win64a.inc'
;include '../INCLUDE/win32a.inc'

section '.code' code readable writeable executable

_test db 'Test',0
_strTest db 'This is a test string',0
_author db 'test',0
_ver dq 1001d

proc DllEntryPoint hinstDLL,fdwReason,lpvReserved
 sub rsp,8*5
 mov     rax,TRUE
    ret
endp

; VOID Initialize(HWND instance,DWORD iniFile,DWORD section,DWORD ID);

proc Initialize hWnd,iniFile,section,id
    invoke  MessageBox,0,_test,NULL,MB_OK
       mov rax,0
   ret
endp

; DWORD Update(DWORD id);

proc Update id
  ;local buffer:DWORD
     ;lea eax,[buffer]
   ;invoke MessageBox,0,_test,NULL,MB_OK
       mov eax,0
   ret
endp

; DWORD GetString(UINT id, UINT flags);
proc GetString id,flags
       mov rax,_test
       ret
endp

; DWORD GetPluginVersion();
proc GetPluginVersion
     mov rax,_ver
        ret
endp

; DWORD GetPluginAuthor();
proc GetPluginAuthor
       lea eax, [_author]
  lea rax, [_author]
  ;mov eax,_author
    ret
endp

; VOID Finalize();
proc Finalize instance,id
  mov rax,TRUE
        ret
endp

section '.idata' import data readable writeable

  library user,'USER32.DLL'

  import user,\
    MessageBox,'MessageBoxA'

section '.edata' export data readable

  export 'TEST.DLL',\
   Initialize,'Initialize',\
        Finalize,'Finalize',\
    Update,'Update',\
        GetString,'GetString',\
  GetPluginAuthor,'GetPluginAuthor',\
      GetPluginVersion,'GetPluginVersion'

section '.reloc' fixups data discardable    
Post 22 Feb 2011, 00:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20344
Location: In your JS exploiting you and your system
revolution 22 Feb 2011, 00:28
hansdieter wrote:
Well i don't quite know if the target project is unicode ...
If you are returning strings then you will have to find out if your project is unicode. You can't return ASCII strings in a unicode project. And you can't return unicode strings in an ASCII project. LPCTSTR changes its type based upon the project setting.
Post 22 Feb 2011, 00:28
View user's profile Send private message Visit poster's website Reply with quote
hansdieter



Joined: 22 Feb 2011
Posts: 5
hansdieter 22 Feb 2011, 00:30
Ok, yes it seems to be unicode.
Post 22 Feb 2011, 00:30
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20344
Location: In your JS exploiting you and your system
revolution 22 Feb 2011, 00:31
http://msdn.microsoft.com/en-us/library/aa383751%28v=vs.85%29.aspx:
Code:
#ifdef UNICODE
 typedef LPCWSTR LPCTSTR; 
#else
 typedef LPCSTR LPCTSTR;
#endif    
Post 22 Feb 2011, 00:31
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20344
Location: In your JS exploiting you and your system
revolution 22 Feb 2011, 00:32
hansdieter wrote:
Ok, yes it seems to be unicode.
Then do this:
Code:
_test du 'This is a test string',0    
Post 22 Feb 2011, 00:32
View user's profile Send private message Visit poster's website Reply with quote
hansdieter



Joined: 22 Feb 2011
Posts: 5
hansdieter 22 Feb 2011, 00:34
It works! Thank you very much. Your help is much appreciated!
Post 22 Feb 2011, 00:34
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.