NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: frankly on August 31, 2018, 11:32:22 AM

Title: Need help converting a couple MASM instructions into NASM instructions
Post by: frankly on August 31, 2018, 11:32:22 AM
Hello again everyone, and thank you in advance for any replies I get.

I am having a little problem finding information on the following MASM code -

Code: [Select]
DllEntry proc hInst:DWORD, reason:DWORD, reserved1:DWORD
push hInst

My goal is to tranlsate it as close as possible to NASM
Title: Re: Need help converting a couple MASM instructions into NASM instructions
Post by: frankly on September 01, 2018, 01:42:40 AM
I think I found half the answer to my own question here -

http://win32assembly.programminghorizon.com/tut17.html

Quote
DllEntry proc hInstDLL:HINSTANCE, reason:DWORD, reserved1:DWORD

This function takes three parameters, only the first two of which are important.
hInstDLL is the module handle of the DLL. It's not the same as the instance handle of the process. You should keep this value if you need to use it later. You can't obtain it again easily.
reason can be one of the four values:

    DLL_PROCESS_ATTACH The DLL receives this value when it is first injected into the process address space. You can use this opportunity to do initialization.
    DLL_PROCESS_DETACH The DLL receives this value when it is being unloaded from the process address space. You can use this opportunity to do some cleanup such as deallocate memory and so on.
    DLL_THREAD_ATTACH The DLL receives this value when the process creates a new thread.
    DLL_THREAD_DETACH The DLL receives this value when a thread in the process is destroyed.

You return TRUE in eax if you want the DLL to go on running. If you return FALSE, the DLL will not be loaded.

Maybe if I get some time off from work I'll be able to answer the rest of my original question myself.  But I will always take any advice from those that have experience in converting these instructions from MASM to NASM.
Title: Re: Need help converting a couple MASM instructions into NASM instructions
Post by: Frank Kotler on September 01, 2018, 02:00:02 AM
Hi frankly,
I think you may need a Windows user to help you with this. I used to know a little of it, but that memory is "paged out" at the moment.

I don't recall that "proc" actually generates much code. In 16-bit code "proc far" is an option, and that changes "ret" to "retf" and the like. I think "endp" may generate a "ret" if you haven't got one. Otherwise, I think just:
Code: [Select]
DllEntry:
will do it. The parameters and sizes are (I think) information for "invoke" if you use it.

You encounter an important difference between Masm and Nasm syntax:
Code: [Select]
push hInst
in Masm syntax means the contents of "hInst", in Nasm it means address (offset part if the address). We need:
Code: [Select]
push dword [hInst]
Nasm won't remember that we called hInst "dd" or "dword" elsewhere, so we have to provide the size.

Micro$oft says this:
https://docs.microsoft.com/en-us/cpp/assembler/masm/proc?view=vs-2017
They speak of providing "rewind information" for "structured exception handling. I don't know how to do that.

Sorry I can't help you more!

Best,
Frank

Well, I see you've found out more. Carry on! :)

Title: Re: Need help converting a couple MASM instructions into NASM instructions
Post by: frankly on September 01, 2018, 11:11:24 AM

Thanks again Frank for your knowledge and willingness to share it.

I will continue to play around with the NASM code using the information you provided and see if I can get my conversion from MASM to NASM to work.

Basically I am converting a larger program that creates a .dll that was written in MASM to NASM.
The .dll program was written by Iczelion and takes a .bmp graphic and displays it on the screen without a window and without a border.

His MASM source code and working program can be found here -
http://win32assembly.programminghorizon.com/tut26.html
http://win32assembly.programminghorizon.com/files/tut26.zip

Again, thanks to anyone else in advance for any other information you are willing to share on my original post.

Title: Re: Need help converting a couple MASM instructions into NASM instructions
Post by: frankly on September 06, 2018, 09:59:20 AM
In that same source code from Iczelion there are 2 other instructions that I would like to convert from MASM to NASM -

Code: [Select]
LOCAL wc:WNDCLASSEX
mov wc.cbSize,SIZEOF WNDCLASSEX

I am still working on trying to find the conversion from MASM to NASM on the code from my original post of this thread -

Code: [Select]
DllEntry proc hInst:DWORD, reason:DWORD, reserved1:DWORD
push hInst

I will continue to work on converting Iczelion's .dll source code from MASM to NASM myself and if/when I get properly working code in NASM, I will reply and upload it on this thread.

Thank you again to anyone that replies to this thread.