DLLをパックファイルしたまま、実行できるようなるサンプル(実験途中)
DLLをパックファイルしたまま、実行できるようなるサンプル(実験途中)
#runtime "hsp3ld" #include "user32.as" #include "kernel32.as" #module load_dll #deffunc load_dll_init sdim name, 261 GetModuleFileNameA 0, varptr(name), 260 LoadLibraryA getpath(name, 8) hEXE = stat GetProcAddress hEXE, "InitializeDLLLoad" pInitializeDLLLoad = stat if pInitializeDLLLoad == 0{ dialog "hsp3ldランタイムが使用されていません。終了します。" : end } prm = 0 ret = callfunc(prm, pInitializeDLLLoad, 0) return ret #deffunc LoadDLL str fname name = getpath(fname, 8) + "_DLLIMAGE" exist fname if strsize == -1 : return -1 size = strsize sdim buf, size bload fname, buf // DLLイメージを書き込む // PAGE_READWRITE CreateFileMapping -1, 0, 0x04, 0, size, varptr(name) hMapObj = stat // FILE_MAP_WRITE MapViewOfFile hMapObj, 0x02, 0, 0, size sharedMemPtr = stat if sharedMemPtr == 0 { CloseHandle hMapObj return -2 } dupptr sharedMemVal, sharedMemPtr, size, 2 // DLLイメージをコピーする memcpy sharedMemVal, buf, size, 0, 0 UnmapViewOfFile sharedMemPtr // 一度閉じておく // FILE_MAP_READ MapViewOfFile hMapObj, 0x04, 0, 0, 0 pBaseAddr = stat if pBaseAddr == 0{ CloseHandle hMapObj return -3 } // 実行 name = getpath(fname, 8) GetProcAddress hEXE, "LoadDLLFromImage" pLoadDLLFromImage = stat prm.0 = pBaseAddr, varptr(name), 0 ret = callfunc(prm, pLoadDLLFromImage, 3) UnmapViewOfFile pBaseAddr CloseHandle hMapObj return ret #defcfunc GetDLLProcAddress int handle, str fn _fn = fn GetProcAddress hEXE, "GetDLLProcAddress" pGetDLLProcAddress = stat prm = handle, varptr(_fn) ret = callfunc(prm, pGetDLLProcAddress, 2) return ret #global #pack "hspdsc.dll" load_dll_init LoadDLL "hspdsc.dll" hDLL = stat func = GetDLLProcAddress(hDLL, "dsc_Version") prm = 0 mes callfunc(prm, func, 0)