Author Topic: DLL IMPORT AND EXPORT In NASM Under -Fwin32  (Read 17579 times)

Offline Dibya

  • Jr. Member
  • *
  • Posts: 19
DLL IMPORT AND EXPORT In NASM Under -Fwin32
« on: September 10, 2017, 06:21:38 AM »
Hi guys and gals ,
How to declare dll import and export under NASM while using -fwin32 as -fobj is outdated .
I need some help . My code is perfect but i need some help regarding dll import and export .
FOr example i want to import RtlInterlockedCompareExchange64 from ntdll.dll and export MYFUNCTION1 in my own dll.
I am new here hope i will get some help .
Thanks in Advance .
As a linker I want to use either link.exe or Golink
I have used PE macro but compiled binaries are not proper enough for serious purpose ...

Offline dreamCoder

  • Full Member
  • **
  • Posts: 107
Re: DLL IMPORT AND EXPORT In NASM Under -Fwin32
« Reply #1 on: September 11, 2017, 06:00:07 PM »
I don't know what and how Rtl.... works but here's something that features both things. This will translate to a .DLL file and "myfunction1" is visible.

Code: [Select]
;nasm -f win32 prog.asm
;golink /dll prog.obj ntdll.dll
;(ignore the warning)

global myfunction1
export myfunction1

extern RtlInterlockedCompareExchange64

section .text

myfunction1:
        push    eax  ;just guessing the arguments.
        push    ebx
        push    ecx
        call    RtlInterlockedCompareExchange64
        ret

Offline Dibya

  • Jr. Member
  • *
  • Posts: 19
Re: DLL IMPORT AND EXPORT In NASM Under -Fwin32
« Reply #2 on: September 12, 2017, 03:43:10 PM »
Thanks My friend You became my life savvier.
 If i have to include Kernel32 and shell32 then what should i do
golink /dll prog.obj ntdll.dll,shell32.dll,kernel32.dll is it alright to do so ?

Offline dreamCoder

  • Full Member
  • **
  • Posts: 107
Re: DLL IMPORT AND EXPORT In NASM Under -Fwin32
« Reply #3 on: September 13, 2017, 05:06:18 AM »
yes, but no commas.

Offline Dibya

  • Jr. Member
  • *
  • Posts: 19
Re: DLL IMPORT AND EXPORT In NASM Under -Fwin32
« Reply #4 on: September 13, 2017, 02:54:52 PM »
Thanks a lot

Offline Dibya

  • Jr. Member
  • *
  • Posts: 19
Re: DLL IMPORT AND EXPORT In NASM Under -Fwin32
« Reply #5 on: September 16, 2017, 02:11:49 PM »
  fdivp st qword (1),st
  push    dword [esi+34h]
  push    dword [eax+18h]
nasm is not accepting this opcodes what should i do?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: DLL IMPORT AND EXPORT In NASM Under -Fwin32
« Reply #6 on: September 16, 2017, 06:00:56 PM »
Use valid syntax?
Code: [Select]
fdivp st1, st0
Is that what you want? The rest of it looks okay to me...

Best,
Frank



Offline Dibya

  • Jr. Member
  • *
  • Posts: 19
Re: DLL IMPORT AND EXPORT In NASM Under -Fwin32
« Reply #7 on: September 17, 2017, 05:27:17 AM »
Thanks You are awesome

Offline Dibya

  • Jr. Member
  • *
  • Posts: 19
Re: DLL IMPORT AND EXPORT In NASM Under -Fwin32
« Reply #8 on: September 17, 2017, 02:08:55 PM »
I am getting Some weird result with GoLink Please help

Offline dreamCoder

  • Full Member
  • **
  • Posts: 107
Re: DLL IMPORT AND EXPORT In NASM Under -Fwin32
« Reply #9 on: September 17, 2017, 02:41:39 PM »
try adding "/mix" at the end of the GoLink script.

Offline Dibya

  • Jr. Member
  • *
  • Posts: 19
Re: DLL IMPORT AND EXPORT In NASM Under -Fwin32
« Reply #10 on: September 18, 2017, 07:26:56 AM »
Same issue please help . OBJ is ready but i am unable to get dll. :'(

which version of nasm do you use ?
« Last Edit: September 18, 2017, 07:29:15 AM by Dibya »

Offline dreamCoder

  • Full Member
  • **
  • Posts: 107
Re: DLL IMPORT AND EXPORT In NASM Under -Fwin32
« Reply #11 on: September 18, 2017, 07:37:27 AM »
@Dibya

I can't offer u much help because you're not showing any code. I am working in 'guessing mode' only. If you don't want to share the entire code, just show / test the minimum layout of your code where import / export is involved. Start small and proceed slowly to reduce mistakes.
 

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: DLL IMPORT AND EXPORT In NASM Under -Fwin32
« Reply #12 on: September 18, 2017, 08:48:18 AM »
At the risk of stating the obvious, "myfunction" is lowercase in the code shown above and uppercase in the error message... Sorry, but I'd feel like a fool if I didn't mention it...

Best,
Frank


Offline Dibya

  • Jr. Member
  • *
  • Posts: 19
Re: DLL IMPORT AND EXPORT In NASM Under -Fwin32
« Reply #13 on: September 18, 2017, 03:57:16 PM »
Nothing is Com pilling even simple one like this
EXPORT MYFUNCTION
GLOBAL MYFUNCTION
MYFUNCTION:
 xor eax,eax
 retn

Even i have tried code from other people who able to link properly
. Nasm Compiles with out issue but Golink fails
Even your code does not compile .
I am doing nothing just learning how to compile in NASM properly . I have been moving from MASM which became obsolete as it is not updated long .

Offline Dibya

  • Jr. Member
  • *
  • Posts: 19
Re: DLL IMPORT AND EXPORT In NASM Under -Fwin32
« Reply #14 on: September 18, 2017, 04:03:24 PM »
Sorry Guys Its utter foolishness of mine
i have not mentioned section
section .text

; Any way is it possible to specify dll for import in ex tern . lets take if i wish to specify to another program.dll
« Last Edit: September 18, 2017, 04:32:22 PM by Dibya »