Page 1 of 1

Library to load a DLL from memory

Posted: Tue Jan 10, 2017 9:59 pm
by oryaaaaa
Hello
I tested PureBasic 5.51 x64 unicode.

Memory module 0.0.4 supported UNICODE and x64 DLL.
This procedure use latest version. " MemoryModule.c MemoryModule.h [2016/09/20 14:38] "

GitHub - fancycode/MemoryModule: Library to load a DLL from memory.
https://github.com/fancycode/MemoryModule
*click GreenBox[Clone or download] [Download ZIP]

Download the Visual C++ Build Tools (standalone C++ compiler, libraries and tools)
http://landinghub.visualstudio.com/visu ... uild-tools
* Download Windows SDK and MFC
Visual C++ 2015 x64 Native Build Tools Command Prompt
%comspec% /k ""C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat"" amd64
changed MemoryModule.c

Code: Select all

extern HMEMORYMODULE MemoryLoadLibrary(const void *data, size_t size)
extern FARPROC MemoryGetProcAddress(HMEMORYMODULE module, LPCSTR name)
extern void MemoryFreeLibrary(HMEMORYMODULE mod)
>CL /LD /GS- /D "_UNICODE" /D "UNICODE" MemoryModule.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24210 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

MemoryModule.c
Microsoft (R) Incremental Linker Version 14.00.24210.0
Copyright (C) Microsoft Corporation. All rights reserved.

/out:MemoryModule.dll
/dll
/implib:MemoryModule.lib
MemoryModule.obj

>lib /OUT:MemoryModule.lib MemoryModule.obj
Microsoft (R) Library Manager Version 14.00.24210.0
Copyright (C) Microsoft Corporation. All rights reserved.
2017/01/10 12:19 AM 41,206 MemoryModule.c
2017/01/10 10:23 AM 102,912 MemoryModule.dll
2017/01/09 11:48 PM 5,428 MemoryModule.h
2017/01/10 10:23 AM 20,368 MemoryModule.lib
2017/01/10 10:23 AM 19,138 MemoryModule.obj

Code: Select all

Import "MemoryModule.lib"
  MemoryLoadLibrary.i(MemoryPointer.i, size.i)
  MemoryGetProcAddress.i(Hmodule.i,*Function)
  MemoryFreeLibrary(HModule.i)
EndImport

DataSection
  ABC:
  IncludeBinary "bassflac.dll"  
  ADD:
EndDataSection

*bassflac =MemoryLoadLibrary(?ABC, ?ADD-?ABC)
Debug *bassflac
function.s = Space(256)
PokeS(@function, "BASS_FLAC_StreamCreateFile", StringByteLength("BASS_FLAC_StreamCreateFile", #PB_Ascii), #PB_Ascii)
*BASS_FLAC_StreamCreateFile = MemoryGetProcAddress(*bassflac, @function)
Debug *BASS_FLAC_StreamCreateFile
MemoryFreeLibrary(*bassflac)
CallDebugger

Re: Library to load a DLL from memory

Posted: Wed Jan 11, 2017 11:23 am
by Mijikai
Great stuff (got it to work) :)
Thanks