This is the simplest example of how to use assembly language to create a DLL file functional.
It is written using flat assembler (FASM).
An 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.
The theory says about this example, show at the end of this tutorial:
format directive allows selecting the output format.
entry directive sets the entry point for Portable Executable, the value of the 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 a file that should be included.
section directive defines a new section, it should be followed by quoted string defining the name of the section, then one or more section arguments can follow.
Available arguments are code, data, readable, writeable, executable, shareable, discardable, notpageable.
A 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 access to the process.
The second procedure will call a MessageBox function from the 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | format PE GUI 4.0 DLL entry EntryPoint include 'win32a.inc' section '.code' code readable executable proc EntryPoint hinstDLL,fdwReason,lpvReserved mov eax,TRUE ret endp proc afiseaza, msg invoke MessageBox,0,[msg],[msg],0 ret endp section '.idata' import data readable writeable library user,'USER32.DLL' import user,MessageBox,'MessageBoxA' section '.edata' export data readable export 'msg.DLL',afiseaza,'_afiseaza' section '.reloc' fixups data discardable |
This example can be developed and completed with additional functions.