Thanks to Joachim Bauch's tutorial about Loading a DLL from memory. Here comes the easiest way to run the codes written in other language. All you need to do are make a DLL, convert it to HEX format, and embed into your script. For now, only stdcall is supported (up to four parameters) (There is no limit now, see update note). BTW, this script is only tested on Windows XP SP3. If you can run it in other systems, please let me know, thanks. Demo how to use: (this 3k md5.dll is written by myself and anyone is welcome to use it. But the machine code version of MD5 should be better choice in AutoIt) ; -------------------------------------------------------------
;
; Step 1: Try to use the DLLs in the normal method (by DllCall)
;
; -------------------------------------------------------------
$String = "The quick brown fox jumps over the lazy dog"
$Digest = DllStructCreate("byte[16]")
DllCall("md5.dll", "str", "md5", "str", $String, "uint", StringLen($String), "ptr", DllStructGetPtr($Digest))
$Hash = DllStructGetData($Digest, 1)
$Digest = 0
MsgBox(0, 'MD5 Hash', $Hash)
; ----------------------------------------------------------------------------
;
; Step 2: Use MemoryDllGen.au3 to convert the DLL to script form and paste it.
;
; ----------------------------------------------------------------------------
Dim $DllBinary = ''; this line is too long to omit, check the attachment
; --------------------------------------------------------------------------------
;
; Step 3: Replace DllCall to MemoryDllCall, and use $DllBinary instead of dll name
;
; --------------------------------------------------------------------------------
#Include "MemoryDll.au3"
MemoryDllInit()
$String = "The quick brown fox jumps over the lazy dog"
$Digest = DllStructCreate("byte[16]")
MemoryDllCall($DllBinary, "str", "md5", "str", $String, "uint", StringLen($String), "ptr", DllStructGetPtr($Digest))
$Hash = DllStructGetData($Digest, 1)
$Digest = 0
MsgBox(0, 'MD5 Hash', $Hash)
MemoryDllExit()
; -------------------------------------------------------------------------
;
; Step 4: Finally, you have the functions in Pure AutoIt Scirpt. Have fun !
;
; -------------------------------------------------------------------------MemoryDll.zip (4.67K) Number of downloads: 253 08/08/03 Update Note: Rearrange the return array of MemoryDllCall, now it's return should just like DllCall.Add support to accept more than four parameters, but in this case, some return value will be destoryed.Add a little Tutorial.MemoryDll.zip (9.17K) Number of downloads: 251 08/08/18 Update Note: I finally found a perfect trick to call a function in memory. So this UDF now supports DLL functions in both stdcall and cdecl mode with any number of parameters. In theory, DllCall now can be fully replaced by MemoryDllCall.There is a new func called MemoryFuncCall in this version. It is a new way to call a memory address. Compared to CallWindowProc (old method), MemoryFuncCall is flexible (supports cdecl, etc. ), but a bit slower.There are also two new utility scripts in attachment. AESFile uses the dll downloaded from http://adeil.com. It encrypt/decrypt files by a key of 32, 48 or 64 bytes long. SHA2 is written by Brian Gladman and compiled to DLL by me. It generates SHA2 hash of 224, 256, 384, or 512 bits long. Thanks to -Ultima- and ProgAndy's suggestion.MemoryDll.zip (50.27K) Number of downloads: 441 08/12/06 Update Note: Improves compatibility. Now MemoryDllCall should work better under Vista.Example of AESFile and SHA512 are removed. Please see my other post about AES and Hashes.MemoryDll.zip (8.95K) Number of downloads: 1118 2010/10/18 Update Note: Avoiding DEP issue.Improves compatibility. Now BASS.DLL is supported.MemoryDll.zip 2011/04/03 Update Note: Rewritten all code in AutoIt. Now both x86 and x64 DLL are supported.MemoryDllInit(), MemoryDllExit(), and old examples are removed.Add new example, MemoryDll version of SQLite.au3.Ps. I think old version are still good or even better when only used under x86 mode.But this version support x64 and has better compatibility I guess.MemoryDll.zip 2015/01/08 Update Note: Update the machine code version. Both x86 and x64 DLL are supported.TLS callback are supported.Remove all MemoryFuncXXX() related functions. Use build-in DllCallAddress instead.Add MemoryDllLoadString(), MemoryDllLoadResource() Add _WinAPI_MemoryFindResource(), _WinAPI_MemoryFindResourceEx(), _WinAPI_MemorySizeOfResource(), _WinAPI_MemoryLoadResource(), _WinAPI_MemoryLoadString(), _WinAPI_MemoryLoadStringEx()Using BinaryCall.au3 to loading the machine code.MemoryDll.zip 2015/01/23 Update Node: Add ability to load a DLL that needs other DLLs. For example: libcurl.dll needs libeay32.dll and ssleay32.dll for https support. Now you can load all of them by MemoryDll UDF. Before this version, only libcurl.dll can loaded by MemoryDll, other files must store on the disk.Add ability to call functions by ordinal value.Add MemoryDllRun(). It run a EXE file from memory. Relocation table in EXE file is required. Most PE rebuilding tools remove the section to reduce the file size.Add a script to demonstrate all the new features.This version of MemoryDll can works together with BinaryCall UDF. Binary machine code can call functions in DLL loaded by MemoryDll. MemoryDll.zip