Получение названия экспортированных функций из DLL

Данный пример вытаскивает все (даже недокументированные) экспортируемые названия функций из файла библиотеки DLL. Для примера взят файл User32.DLL
Платформы: Windows
Автор: Станислав Будинов, создано в 2011 году.

получение функций dll

#INCLUDE "windows.bi"
#DEFINE NTSIGNATURE(a) (Cast(Byte Ptr,a) + (Cast(PIMAGE_DOS_HEADER,a)->e_lfanew))
#DEFINE MakePtr(Type_, Base, Offset) (Cast(Type_,(Cast(Uinteger,Base) + Cast(Uinteger,Offset))))

Dim As HMODULE hUser32
Dim As PIMAGE_DOS_HEADER pDOSHead
Dim As PIMAGE_NT_HEADERS pPEHeader
Dim As IMAGE_FILE_HEADER FileHeader
Dim As PIMAGE_EXPORT_DIRECTORY pImportDesc
Dim As IMAGE_OPTIONAL_HEADER Ptr OptionHeader
Dim As Integer TMem

Sub Error_Dll(Byval Er As String)
    MessageBox(0,Er,"Error",0)
    End
End Sub
Function PeekS(Byval Memory As Integer) As String Export
    Dim sss As String
    Dim buf As Byte
    Dim a As Integer
    Do
        buf=Peek(Memory+a)
        sss=sss+Chr(buf)
        a=a+1
    Loop Until buf=0
    Return sss
End Function
hUser32=GetModuleHandle("user32")
If hUser32=0 Then Error_Dll("Error Load User32")
pDOSHead = Cast(PIMAGE_DOS_HEADER,hUser32)
If pDOSHead->e_magic <> IMAGE_DOS_SIGNATURE Then Error_Dll("Error Dos Header signature MZ")
pPEHeader=Cast(PIMAGE_NT_HEADERS,NTSIGNATURE(pDOSHead))
If pPEHeader->Signature <> IMAGE_NT_SIGNATURE Then Error_Dll("Error PE Header signature PE")
FileHeader=Cast(IMAGE_FILE_HEADER,pPEHeader->FileHeader)
If FileHeader.Machine<>IMAGE_FILE_MACHINE_I386 Then Error_Dll("Error Not 386 Proccesor")
OptionHeader=cast(IMAGE_OPTIONAL_HEADER Ptr,@pPEHeader->OptionalHeader)
pImportDesc=MakePtr(PIMAGE_EXPORT_DIRECTORY,hUser32,OptionHeader->DataDirectory(0).VirtualAddress)

For a As Integer=0 To pImportDesc->NumberOfNames-1
    Tmem=Cast(Integer,pImportDesc->AddressOfNames+a)
    Dim As String Ptr Ptr ST=(MakePtr(String Ptr Ptr,hUser32,Tmem))
    ST=MakePtr(String Ptr Ptr,hUser32,*ST)
    ? a+1 & "   "& PeekS(Cast(Integer,st))  
Next
Sleep