This is the simplest example of how to use assembly language to create a DLL file functional.
It is written using flat assembler (FASM).
Example is simple and I created for testing with python.
You can call the function created with other programming languages??.
After I created the DLL file can execute the following python code to check if it works correctly.
Let’s go to the DLL file creation.
Theory says about this example, show in the end of this tutorial:
format directive allows to select the output format.
entry directive sets the entry point for Portable Executable, the value of entry point should follow.
include directive includes the specified source file at the position where it is used and should be followed by the quoted name of file that should be included.
section directive defines a new section, it should be followed by quoted string defining the name of section, then one or more section arguments can follow.
Available arguments are: code, data, readable, writeable, executable,shareable, discardable, notpageable.
section is marked to contain fixups, they are generated automatically and no more data needs to be defined in this section.
In the section code we define two procedures.
The first procedure allows a DLL to use its entry-point function for allocating memory in the virtual address space of the calling process or to open handles accessible to the process.
The second procedure will call a MessageBox function from operating system, see more here.
data directive begins the definition of special PE data.
It should be followed by one of the data identifiers (export, import, resource or fixups) or by the number of data entry in PE header.
format PE GUI 4.0 DLL
section '.code' code readable executable
proc EntryPoint hinstDLL,fdwReason,lpvReserved
proc afiseaza, msg
section '.idata' import data readable writeable
section '.edata' export data readable
section '.reloc' fixups data discardable
This example can be developed and completed with additional functions.