flat assembler
Message board for the users of flat assembler.

Index > Main > Help Convert DLL Export Function Syntax

Author
Thread Post new topic Reply to topic
Ultraplayer



Joined: 12 Aug 2021
Posts: 3
Ultraplayer 12 Aug 2021, 11:02
I am trying to convert the pascal code for a .DLL library.

Pascal version:
Code:
function luaopen_random(L: lua_State): Integer; cdecl;
begin
  // ... skipped...
  Result := 1;
end;
    


Disassembler C++ version:
Code:
signed int __cdecl luaopen_random(int a1)
{
  signed int v1; // eax
  return 1;
}
    


I found this topic about ccall directive, but FASM say - Extra character on line.
My INCORRECT ver:
Code:
proc ccall luaopen_random L: DWORD
  mov eax, 1
endp ; <<-- [Error] Extra character on line
    


How to make it properly?
Post 12 Aug 2021, 11:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20450
Location: In your JS exploiting you and your system
revolution 12 Aug 2021, 11:18
Something like this maybe?
Code:
include 'win32ax.inc'
proc luaopen_random ccall, L
  mov ecx, [L]
  mov eax, 1
  ret
endp    
Post 12 Aug 2021, 11:18
View user's profile Send private message Visit poster's website Reply with quote
Ultraplayer



Joined: 12 Aug 2021
Posts: 3
Ultraplayer 12 Aug 2021, 16:50
revolution wrote:
Something like this maybe?
Code:
include 'win32ax.inc'
proc luaopen_random ccall, L
  mov ecx, [L]
  mov eax, 1
  ret
endp    

Thanks, it finally compiled! But, after "ccall" directive I can't make any calls!
Code:
proc luaopen_luadlgs ccall, L
  invoke  MessageBoxA,NULL,_e1,NULL,MB_ICONINFORMATION+MB_OK ; -- Illegal instruction
  cinvoke  MessageBoxA,NULL,_e1,NULL,MB_ICONINFORMATION+MB_OK ; -- Illegal instruction
  call  MessageBoxA ; -- Illegal instruction
  stdcall MessageBoxA ; -- Illegal instruction
end;
    
Post 12 Aug 2021, 16:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20450
Location: In your JS exploiting you and your system
revolution 12 Aug 2021, 20:27
There is a mistake. Change ccall to c
Code:
include 'win32ax.inc'
proc luaopen_random c, L
  mov ecx, [L]
  mov eax, 1
  ret
endp
ccall luaopen_random    
Post 12 Aug 2021, 20:27
View user's profile Send private message Visit poster's website Reply with quote
Ultraplayer



Joined: 12 Aug 2021
Posts: 3
Ultraplayer 12 Aug 2021, 20:37
revolution wrote:
There is a mistake. Change ccall to c

It works! Thank you!
Post 12 Aug 2021, 20:37
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 15 Aug 2021, 14:43
revolution wrote:
proc luaopen_random c, L
mov ecx, [L]
mov eax, 1
ret
endp
ccall luaopen_random

And how in this case proc get params c and L ?
Post 15 Aug 2021, 14:43
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20450
Location: In your JS exploiting you and your system
revolution 15 Aug 2021, 15:25
c isn't a parameter, it is a modifier to make it a ccall function.

To read L: mov ecx, [L]

Call it with: ccall luaopen_random, my_L_value
Post 15 Aug 2021, 15:25
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 16 Aug 2021, 03:33
Ccall luaopen_random, param.
This is work only for 32 bit?
Post 16 Aug 2021, 03:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20450
Location: In your JS exploiting you and your system
revolution 16 Aug 2021, 04:01
For DLLs in Windows 64-bit you need to use fastcall to make it standard.

If you want to use ccall in Windows then you can, but you need to make your own macros and things to support it.
Post 16 Aug 2021, 04:01
View user's profile Send private message Visit poster's website 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.