working, windows
This commit is contained in:
commit
8c002299dd
37 files changed
+4627
No files matched your search
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"cstdio": "cpp",
|
||||
"chrono": "cpp"
|
||||
}
|
||||
}
|
||||
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"tasks": [
|
||||
{
|
||||
"type": "cppbuild",
|
||||
"label": "C/C++: cl.exe build active file",
|
||||
"command": "cl.exe",
|
||||
"args": [
|
||||
"/Zi",
|
||||
"/EHsc",
|
||||
"/nologo",
|
||||
"/Fe${fileDirname}\\${fileBasenameNoExtension}.exe",
|
||||
"${file}"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${fileDirname}"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$msCompile"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"detail": "Task generated by Debugger."
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,131 @@
|
||||
#include "bink.h"
|
||||
#include <windows.h>
|
||||
|
||||
// Macro to define function pointer and global variable
|
||||
#define DECL_FN(ret, name, args, ptr) typedef ret (__cdecl *name##_t) args; name##_t p##name = NULL;
|
||||
|
||||
DECL_FN(RADEXPFUNC void *, BinkLogoAddress, (void), )
|
||||
DECL_FN(RADEXPFUNC void, BinkSetError, (char const * err), *)
|
||||
DECL_FN(RADEXPFUNC char *, BinkGetError, (void), )
|
||||
DECL_FN(RADEXPFUNC HBINK, BinkOpen, (char const * name, U32 flags), *)
|
||||
DECL_FN(RADEXPFUNC HBINK, BinkOpenWithOptions, (char const * name, BINK_OPEN_OPTIONS const * boo, U32 flags), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkGetFrameBuffersInfo, (HBINK bink, BINKFRAMEBUFFERS * fbset), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkRegisterFrameBuffers, (HBINK bink, BINKFRAMEBUFFERS * fbset), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkDoFrame, (HBINK bnk), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkDoFramePlane, (HBINK bnk, U32 which_planes), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkNextFrame, (HBINK bnk), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkWait, (HBINK bnk), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkClose, (HBINK bnk), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkPause, (HBINK bnk, S32 pause), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkCopyToBuffer, (HBINK bnk, void* dest, S32 destpitch, U32 destheight, U32 destx, U32 desty, U32 flags), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkCopyToBufferRect, (HBINK bnk, void* dest, S32 destpitch, U32 destheight, U32 destx, U32 desty, U32 srcx, U32 srcy, U32 srcw, U32 srch, U32 flags), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkGetRects, (HBINK bnk, U32 flags), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkGoto, (HBINK bnk, U32 frame, S32 flags), *)
|
||||
DECL_FN(RADEXPFUNC U32, BinkGetKeyFrame, (HBINK bnk, U32 frame, S32 flags), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkFreeGlobals, (void), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkGetPlatformInfo, (S32 bink_platform_enum, void * output), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkRegisterGPUDataBuffers, (HBINK bink, BINKGPUDATABUFFERS * gpu), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkGetGPUDataBuffersInfo, (HBINK bink, BINKGPUDATABUFFERS * gpu), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkSetVideoOnOff, (HBINK bnk, S32 onoff), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkSetSoundOnOff, (HBINK bnk, S32 onoff), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkSetVolume, (HBINK bnk, U32 trackid, S32 volume), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkSetPan, (HBINK bnk, U32 trackid, S32 pan), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkSetSpeakerVolumes, (HBINK bnk, U32 trackid, U32 * speaker_indexes, S32 * volumes, U32 total), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkService, (HBINK bink), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkShouldSkip, (HBINK bink), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkControlBackgroundIO, (HBINK bink, U32 control), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkSetWillLoop, (HBINK bink, S32 onoff), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkStartAsyncThread, (S32 thread_num, void const * param), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkDoFrameAsync, (HBINK bink, U32 thread_one, U32 thread_two), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkDoFrameAsyncMulti, (HBINK bink, U32* threads, S32 thread_count), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkDoFrameAsyncWait, (HBINK bink, S32 us), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkRequestStopAsyncThread, (S32 thread_num), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkWaitStopAsyncThread, (S32 thread_num), *)
|
||||
DECL_FN(RADEXPFUNC HBINKTRACK, BinkOpenTrack, (HBINK bnk, U32 trackindex), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkCloseTrack, (HBINKTRACK bnkt), *)
|
||||
DECL_FN(RADEXPFUNC U32, BinkGetTrackData, (HBINKTRACK bnkt, void * dest), *)
|
||||
DECL_FN(RADEXPFUNC U32, BinkGetTrackType, (HBINK bnk, U32 trackindex), *)
|
||||
DECL_FN(RADEXPFUNC U32, BinkGetTrackMaxSize, (HBINK bnk, U32 trackindex), *)
|
||||
DECL_FN(RADEXPFUNC U32, BinkGetTrackID, (HBINK bnk, U32 trackindex), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkGetSummary, (HBINK bnk, BINKSUMMARY * sum), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkGetRealtime, (HBINK bink, BINKREALTIME * run, U32 frames), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkSetFileOffset, (U64 offset), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkSetSoundTrack, (U32 total_tracks, U32 * tracks), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkSetIO, (BINKIOOPEN io), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkSetFrameRate, (U32 forcerate, U32 forceratediv), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkSetSimulate, (U32 sim), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkSetIOSize, (U32 iosize), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkSetSoundSystem, (BINKSNDSYSOPEN open, UINTa param), *)
|
||||
DECL_FN(RADEXPFUNC S32, BinkSetSoundSystem2, (BINKSNDSYSOPEN2 open, UINTa param1, UINTa param2), *)
|
||||
DECL_FN(RADEXPFUNC BINKSNDOPEN, BinkOpenDirectSound, (UINTa param), *)
|
||||
DECL_FN(RADEXPFUNC BINKSNDOPEN, BinkOpenWaveOut, (UINTa param), *)
|
||||
DECL_FN(RADEXPFUNC BINKSNDOPEN, BinkOpenXAudio2, (UINTa param), *)
|
||||
DECL_FN(RADEXPFUNC void, BinkSetMemory, (BINKMEMALLOC a, BINKMEMFREE f), *)
|
||||
|
||||
HMODULE dll = NULL;
|
||||
|
||||
int LoadBinkDLL(void) {
|
||||
if (dll) return 1;
|
||||
dll = LoadLibraryA("bink2w64.dll");
|
||||
if (!dll) return 0;
|
||||
|
||||
pBinkLogoAddress = (BinkLogoAddress_t)GetProcAddress(dll, "BinkLogoAddress");
|
||||
pBinkSetError = (BinkSetError_t)GetProcAddress(dll, "BinkSetError");
|
||||
pBinkGetError = (BinkGetError_t)GetProcAddress(dll, "BinkGetError");
|
||||
pBinkOpen = (BinkOpen_t)GetProcAddress(dll, "BinkOpen");
|
||||
pBinkOpenWithOptions = (BinkOpenWithOptions_t)GetProcAddress(dll, "BinkOpenWithOptions");
|
||||
pBinkGetFrameBuffersInfo = (BinkGetFrameBuffersInfo_t)GetProcAddress(dll, "BinkGetFrameBuffersInfo");
|
||||
pBinkRegisterFrameBuffers = (BinkRegisterFrameBuffers_t)GetProcAddress(dll, "BinkRegisterFrameBuffers");
|
||||
pBinkDoFrame = (BinkDoFrame_t)GetProcAddress(dll, "BinkDoFrame");
|
||||
pBinkDoFramePlane = (BinkDoFramePlane_t)GetProcAddress(dll, "BinkDoFramePlane");
|
||||
pBinkNextFrame = (BinkNextFrame_t)GetProcAddress(dll, "BinkNextFrame");
|
||||
pBinkWait = (BinkWait_t)GetProcAddress(dll, "BinkWait");
|
||||
pBinkClose = (BinkClose_t)GetProcAddress(dll, "BinkClose");
|
||||
pBinkPause = (BinkPause_t)GetProcAddress(dll, "BinkPause");
|
||||
pBinkCopyToBuffer = (BinkCopyToBuffer_t)GetProcAddress(dll, "BinkCopyToBuffer");
|
||||
pBinkCopyToBufferRect = (BinkCopyToBufferRect_t)GetProcAddress(dll, "BinkCopyToBufferRect");
|
||||
pBinkGetRects = (BinkGetRects_t)GetProcAddress(dll, "BinkGetRects");
|
||||
pBinkGoto = (BinkGoto_t)GetProcAddress(dll, "BinkGoto");
|
||||
pBinkGetKeyFrame = (BinkGetKeyFrame_t)GetProcAddress(dll, "BinkGetKeyFrame");
|
||||
pBinkFreeGlobals = (BinkFreeGlobals_t)GetProcAddress(dll, "BinkFreeGlobals");
|
||||
pBinkGetPlatformInfo = (BinkGetPlatformInfo_t)GetProcAddress(dll, "BinkGetPlatformInfo");
|
||||
pBinkRegisterGPUDataBuffers = (BinkRegisterGPUDataBuffers_t)GetProcAddress(dll, "BinkRegisterGPUDataBuffers");
|
||||
pBinkGetGPUDataBuffersInfo = (BinkGetGPUDataBuffersInfo_t)GetProcAddress(dll, "BinkGetGPUDataBuffersInfo");
|
||||
pBinkSetVideoOnOff = (BinkSetVideoOnOff_t)GetProcAddress(dll, "BinkSetVideoOnOff");
|
||||
pBinkSetSoundOnOff = (BinkSetSoundOnOff_t)GetProcAddress(dll, "BinkSetSoundOnOff");
|
||||
pBinkSetVolume = (BinkSetVolume_t)GetProcAddress(dll, "BinkSetVolume");
|
||||
pBinkSetPan = (BinkSetPan_t)GetProcAddress(dll, "BinkSetPan");
|
||||
pBinkSetSpeakerVolumes = (BinkSetSpeakerVolumes_t)GetProcAddress(dll, "BinkSetSpeakerVolumes");
|
||||
pBinkService = (BinkService_t)GetProcAddress(dll, "BinkService");
|
||||
pBinkShouldSkip = (BinkShouldSkip_t)GetProcAddress(dll, "BinkShouldSkip");
|
||||
pBinkControlBackgroundIO = (BinkControlBackgroundIO_t)GetProcAddress(dll, "BinkControlBackgroundIO");
|
||||
pBinkSetWillLoop = (BinkSetWillLoop_t)GetProcAddress(dll, "BinkSetWillLoop");
|
||||
pBinkStartAsyncThread = (BinkStartAsyncThread_t)GetProcAddress(dll, "BinkStartAsyncThread");
|
||||
pBinkDoFrameAsync = (BinkDoFrameAsync_t)GetProcAddress(dll, "BinkDoFrameAsync");
|
||||
pBinkDoFrameAsyncMulti = (BinkDoFrameAsyncMulti_t)GetProcAddress(dll, "BinkDoFrameAsyncMulti");
|
||||
pBinkDoFrameAsyncWait = (BinkDoFrameAsyncWait_t)GetProcAddress(dll, "BinkDoFrameAsyncWait");
|
||||
pBinkRequestStopAsyncThread = (BinkRequestStopAsyncThread_t)GetProcAddress(dll, "BinkRequestStopAsyncThread");
|
||||
pBinkWaitStopAsyncThread = (BinkWaitStopAsyncThread_t)GetProcAddress(dll, "BinkWaitStopAsyncThread");
|
||||
pBinkOpenTrack = (BinkOpenTrack_t)GetProcAddress(dll, "BinkOpenTrack");
|
||||
pBinkCloseTrack = (BinkCloseTrack_t)GetProcAddress(dll, "BinkCloseTrack");
|
||||
pBinkGetTrackData = (BinkGetTrackData_t)GetProcAddress(dll, "BinkGetTrackData");
|
||||
pBinkGetTrackType = (BinkGetTrackType_t)GetProcAddress(dll, "BinkGetTrackType");
|
||||
pBinkGetTrackMaxSize = (BinkGetTrackMaxSize_t)GetProcAddress(dll, "BinkGetTrackMaxSize");
|
||||
pBinkGetTrackID = (BinkGetTrackID_t)GetProcAddress(dll, "BinkGetTrackID");
|
||||
pBinkGetSummary = (BinkGetSummary_t)GetProcAddress(dll, "BinkGetSummary");
|
||||
pBinkGetRealtime = (BinkGetRealtime_t)GetProcAddress(dll, "BinkGetRealtime");
|
||||
pBinkSetFileOffset = (BinkSetFileOffset_t)GetProcAddress(dll, "BinkSetFileOffset");
|
||||
pBinkSetSoundTrack = (BinkSetSoundTrack_t)GetProcAddress(dll, "BinkSetSoundTrack");
|
||||
pBinkSetIO = (BinkSetIO_t)GetProcAddress(dll, "BinkSetIO");
|
||||
pBinkSetFrameRate = (BinkSetFrameRate_t)GetProcAddress(dll, "BinkSetFrameRate");
|
||||
pBinkSetSimulate = (BinkSetSimulate_t)GetProcAddress(dll, "BinkSetSimulate");
|
||||
pBinkSetIOSize = (BinkSetIOSize_t)GetProcAddress(dll, "BinkSetIOSize");
|
||||
pBinkSetSoundSystem = (BinkSetSoundSystem_t)GetProcAddress(dll, "BinkSetSoundSystem");
|
||||
pBinkSetSoundSystem2 = (BinkSetSoundSystem2_t)GetProcAddress(dll, "BinkSetSoundSystem2");
|
||||
pBinkOpenDirectSound = (BinkOpenDirectSound_t)GetProcAddress(dll, "BinkOpenDirectSound");
|
||||
pBinkOpenWaveOut = (BinkOpenWaveOut_t)GetProcAddress(dll, "BinkOpenWaveOut");
|
||||
pBinkOpenXAudio2 = (BinkOpenXAudio2_t)GetProcAddress(dll, "BinkOpenXAudio2");
|
||||
pBinkSetMemory = (BinkSetMemory_t)GetProcAddress(dll, "BinkSetMemory");
|
||||
|
||||
return 1;
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.5 MiB |
@@ -0,0 +1,80 @@
|
||||
BinkAllocateFrameBuffers
|
||||
BinkClose
|
||||
BinkCloseTrack
|
||||
BinkControlBackgroundIO
|
||||
BinkCopyToBuffer
|
||||
BinkCopyToBufferRect
|
||||
BinkCurrentSubtitle
|
||||
BinkDoFrame
|
||||
BinkDoFrameAsync
|
||||
BinkDoFrameAsyncMulti
|
||||
BinkDoFrameAsyncWait
|
||||
BinkDoFramePlane
|
||||
BinkFindXAudio2WinDevice
|
||||
BinkFreeGlobals
|
||||
BinkGetError
|
||||
BinkGetFrameBuffersInfo
|
||||
BinkGetGPUDataBuffersInfo
|
||||
BinkGetKeyFrame
|
||||
BinkGetPlatformInfo
|
||||
BinkGetRealtime
|
||||
BinkGetRects
|
||||
BinkGetSubtitleByIndex
|
||||
BinkGetSummary
|
||||
BinkGetTrackData
|
||||
BinkGetTrackID
|
||||
BinkGetTrackMaxSize
|
||||
BinkGetTrackType
|
||||
BinkGoto
|
||||
BinkLoadSubtitles
|
||||
BinkLogoAddress
|
||||
BinkNextFrame
|
||||
BinkOpen
|
||||
BinkOpenDirectSound
|
||||
BinkOpenTrack
|
||||
BinkOpenWaveOut
|
||||
BinkOpenWithOptions
|
||||
BinkOpenXAudio2
|
||||
BinkOpenXAudio27
|
||||
BinkOpenXAudio28
|
||||
BinkOpenXAudio29
|
||||
BinkPause
|
||||
BinkRegisterFrameBuffers
|
||||
BinkRegisterGPUDataBuffers
|
||||
BinkRequestStopAsyncThread
|
||||
BinkRequestStopAsyncThreadsMulti
|
||||
BinkService
|
||||
BinkSetError
|
||||
BinkSetFileOffset
|
||||
BinkSetFrameRate
|
||||
BinkSetIO
|
||||
BinkSetIOSize
|
||||
BinkSetMemory
|
||||
BinkSetOSFileCallbacks
|
||||
BinkSetPan
|
||||
BinkSetSimulate
|
||||
BinkSetSoundOnOff
|
||||
BinkSetSoundSystem
|
||||
BinkSetSoundSystem2
|
||||
BinkSetSoundSystem4
|
||||
BinkSetSoundTrack
|
||||
BinkSetSpeakerVolumes
|
||||
BinkSetVideoOnOff
|
||||
BinkSetVolume
|
||||
BinkSetWillLoop
|
||||
BinkShouldSkip
|
||||
BinkStartAsyncThread
|
||||
BinkUtilCPUs
|
||||
BinkUtilFree
|
||||
BinkUtilMalloc
|
||||
BinkUtilMutexCreate
|
||||
BinkUtilMutexDestroy
|
||||
BinkUtilMutexLock
|
||||
BinkUtilMutexLockTimeOut
|
||||
BinkUtilMutexUnlock
|
||||
BinkUtilSoundGlobalLock
|
||||
BinkUtilSoundGlobalUnlock
|
||||
BinkWait
|
||||
BinkWaitStopAsyncThread
|
||||
BinkWaitStopAsyncThreadsMulti
|
||||
RADTimerRead
|
||||
@@ -0,0 +1,57 @@
|
||||
import re
|
||||
|
||||
header_file = "bink.h"
|
||||
func_list_file = "functions.txt"
|
||||
out_file = "bink_loader_gen.c"
|
||||
|
||||
# Read function list
|
||||
with open(func_list_file) as f:
|
||||
func_names = set(line.strip() for line in f if line.strip())
|
||||
|
||||
# Read header
|
||||
with open(header_file) as f:
|
||||
header = f.read()
|
||||
|
||||
# Remove RADEXPLINK entirely
|
||||
header = re.sub(r'\bRADEXPLINK\b', '', header)
|
||||
|
||||
functions = []
|
||||
|
||||
# Regex to match return type + function name + args
|
||||
prototype_re = re.compile(
|
||||
r'^[ \t]*(\w[\w\s\*\d]+)[ \t]+(' + '|'.join(func_names) + r')[ \t]*\(([^)]*)\)\s*;',
|
||||
re.MULTILINE
|
||||
)
|
||||
|
||||
for match in prototype_re.finditer(header):
|
||||
ret_type = match.group(1).strip()
|
||||
name = match.group(2).strip()
|
||||
args = match.group(3).strip()
|
||||
args = re.sub(r'\s*,\s*', ', ', args)
|
||||
|
||||
# Only add * if return type is NOT already a pointer
|
||||
ptr_mark = '' if ret_type.endswith('*') else '*'
|
||||
|
||||
functions.append((ret_type, name, args, ptr_mark))
|
||||
|
||||
# Generate C file
|
||||
with open(out_file, "w") as f:
|
||||
f.write('#include "bink.h"\n#include <windows.h>\n\n')
|
||||
f.write('// Macro to define function pointer and global variable\n')
|
||||
f.write('#define DECL_FN(ret, name, args, ptr) typedef ret (__cdecl *name##_t) args; name##_t p##name = NULL;\n\n')
|
||||
|
||||
# Typedefs + globals
|
||||
for ret, name, args, ptr_mark in functions:
|
||||
f.write(f'DECL_FN({ret}, {name}, ({args}), {ptr_mark})\n')
|
||||
|
||||
f.write('\nHMODULE dll = NULL;\n\n')
|
||||
f.write('int LoadBinkDLL(void) {\n')
|
||||
f.write(' if (dll) return 1;\n')
|
||||
f.write(' dll = LoadLibraryA("bink2w64.dll");\n')
|
||||
f.write(' if (!dll) return 0;\n\n')
|
||||
|
||||
# Assign function pointers
|
||||
for _, name, _, _ in functions:
|
||||
f.write(f' p{name} = ({name}_t)GetProcAddress(dll, "{name}");\n')
|
||||
|
||||
f.write('\n return 1;\n}\n')
|
||||
+252
@@ -0,0 +1,252 @@
|
||||
typedef void* HWND;
|
||||
typedef void* LPUNKNOWN;
|
||||
typedef void* REFIID;
|
||||
typedef void* REFCLSID;
|
||||
typedef long HRESULT;
|
||||
typedef unsigned long DWORD;
|
||||
typedef unsigned int UINT;
|
||||
typedef int BOOL;
|
||||
typedef void* HANDLE;
|
||||
typedef void* LPVOID;
|
||||
typedef long LONG;
|
||||
typedef long LONG_PTR;
|
||||
typedef const char* LPCSTR;
|
||||
typedef size_t SIZE_T;
|
||||
typedef void* HMODULE;
|
||||
typedef HMODULE HINSTANCE;
|
||||
typedef void* FARPROC;
|
||||
typedef DWORD (*LPTHREAD_START_ROUTINE)(LPVOID lpThreadParameter);
|
||||
typedef union _LARGE_INTEGER {
|
||||
struct {
|
||||
unsigned long LowPart;
|
||||
long HighPart;
|
||||
};
|
||||
long long QuadPart;
|
||||
} LARGE_INTEGER;
|
||||
#define S_OK ((HRESULT)0L)
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#include <cstdlib>
|
||||
#include <cstdint>
|
||||
|
||||
extern "C" {
|
||||
|
||||
typedef HANDLE (*HeapCreate_t)(DWORD, SIZE_T, SIZE_T);
|
||||
typedef BOOL (*HeapDestroy_t)(HANDLE);
|
||||
typedef LPVOID (*HeapAlloc_t)(HANDLE, DWORD, SIZE_T);
|
||||
typedef BOOL (*HeapFree_t)(HANDLE, DWORD, LPVOID);
|
||||
typedef LPVOID (*HeapReAlloc_t)(HANDLE a, DWORD b, LPVOID c, SIZE_T d);
|
||||
|
||||
HeapCreate_t pHeapCreate = nullptr;
|
||||
HeapDestroy_t pHeapDestroy = nullptr;
|
||||
HeapAlloc_t pHeapAlloc = nullptr;
|
||||
HeapFree_t pHeapFree = nullptr;
|
||||
HeapReAlloc_t pHeapReAlloc = nullptr;
|
||||
|
||||
// Memory
|
||||
__declspec(dllexport) HANDLE HeapCreate(DWORD a, SIZE_T b, SIZE_T c) { return pHeapCreate(a, b, c); }
|
||||
__declspec(dllexport) BOOL HeapDestroy(HANDLE a) { return pHeapDestroy(a); }
|
||||
__declspec(dllexport) LPVOID HeapAlloc(HANDLE a, DWORD b, SIZE_T c) { return pHeapAlloc(a, b, c); }
|
||||
__declspec(dllexport) BOOL HeapFree(HANDLE a, DWORD b, LPVOID c) { return pHeapFree(a, b, c); }
|
||||
__declspec(dllexport) LPVOID HeapReAlloc(HANDLE a, DWORD b, LPVOID c, SIZE_T d) { return pHeapReAlloc(a, b, c, d); }
|
||||
|
||||
// Threads (fake)
|
||||
__declspec(dllexport) DWORD GetCurrentThreadId() { return 1; }
|
||||
__declspec(dllexport) HANDLE GetCurrentThread() { return (HANDLE)1; }
|
||||
__declspec(dllexport) HANDLE CreateThread(void*, SIZE_T, LPTHREAD_START_ROUTINE, void*, DWORD, DWORD*) { return (HANDLE)1; }
|
||||
__declspec(dllexport) DWORD WaitForSingleObject(HANDLE, DWORD) { return 0; }
|
||||
__declspec(dllexport) BOOL CloseHandle(HANDLE) { return 1; }
|
||||
|
||||
typedef DWORD (*GetTickCount_t)();
|
||||
typedef BOOL (*QueryPerformanceCounter_t)(LARGE_INTEGER* li);
|
||||
typedef BOOL (*QueryPerformanceFrequency_t)(LARGE_INTEGER* li);
|
||||
|
||||
GetTickCount_t pGetTickCount = nullptr;
|
||||
QueryPerformanceCounter_t pQueryPerformanceCounter = nullptr;
|
||||
QueryPerformanceFrequency_t pQueryPerformanceFrequency = nullptr;
|
||||
|
||||
// Timing
|
||||
__declspec(dllexport) DWORD GetTickCount() {
|
||||
return pGetTickCount();
|
||||
}
|
||||
|
||||
__declspec(dllexport) BOOL QueryPerformanceCounter(LARGE_INTEGER* li) {
|
||||
return pQueryPerformanceCounter(li);
|
||||
}
|
||||
|
||||
__declspec(dllexport) BOOL QueryPerformanceFrequency(LARGE_INTEGER* li) {
|
||||
return pQueryPerformanceFrequency(li);
|
||||
}
|
||||
|
||||
// Module / file
|
||||
__declspec(dllexport) HMODULE GetModuleHandleA(LPCSTR) { return (HMODULE)1; }
|
||||
__declspec(dllexport) FARPROC GetProcAddress(HMODULE, LPCSTR) { return nullptr; }
|
||||
__declspec(dllexport) HMODULE LoadLibraryA(LPCSTR) { return (HMODULE)1; }
|
||||
|
||||
// Process
|
||||
__declspec(dllexport) DWORD GetCurrentProcessId() { return 1; }
|
||||
__declspec(dllexport) HANDLE GetCurrentProcess() { return (HANDLE)1; }
|
||||
__declspec(dllexport) void ExitProcess(UINT) { while(1); }
|
||||
|
||||
typedef void (*OutputDebugStringA_t)(LPCSTR lpOutputString);
|
||||
|
||||
OutputDebugStringA_t pOutputDebugStringA = nullptr;
|
||||
|
||||
__declspec(dllexport) void OutputDebugStringA(LPCSTR lpOutputString) {
|
||||
pOutputDebugStringA(lpOutputString);
|
||||
}
|
||||
|
||||
HMODULE LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags);
|
||||
|
||||
#define IMAGE_DOS_SIGNATURE 0x5A4D // MZ
|
||||
#define IMAGE_NT_SIGNATURE 0x00004550 // PE00
|
||||
#define IMAGE_DIRECTORY_ENTRY_EXPORT 0
|
||||
|
||||
struct IMAGE_DOS_HEADER {
|
||||
uint16_t e_magic;
|
||||
uint16_t e_cblp;
|
||||
uint16_t e_cp;
|
||||
uint16_t e_crlc;
|
||||
uint16_t e_cparhdr;
|
||||
uint16_t e_minalloc;
|
||||
uint16_t e_maxalloc;
|
||||
uint16_t e_ss;
|
||||
uint16_t e_sp;
|
||||
uint16_t e_csum;
|
||||
uint16_t e_ip;
|
||||
uint16_t e_cs;
|
||||
uint16_t e_lfarlc;
|
||||
uint16_t e_ovno;
|
||||
uint16_t e_res[4];
|
||||
uint16_t e_oemid;
|
||||
uint16_t e_oeminfo;
|
||||
uint16_t e_res2[10];
|
||||
uint32_t e_lfanew;
|
||||
};
|
||||
|
||||
struct IMAGE_FILE_HEADER {
|
||||
uint16_t Machine;
|
||||
uint16_t NumberOfSections;
|
||||
uint32_t TimeDateStamp;
|
||||
uint32_t PointerToSymbolTable;
|
||||
uint32_t NumberOfSymbols;
|
||||
uint16_t SizeOfOptionalHeader;
|
||||
uint16_t Characteristics;
|
||||
};
|
||||
|
||||
struct IMAGE_DATA_DIRECTORY {
|
||||
uint32_t VirtualAddress;
|
||||
uint32_t Size;
|
||||
};
|
||||
|
||||
struct IMAGE_OPTIONAL_HEADER64 {
|
||||
uint16_t Magic;
|
||||
uint8_t MajorLinkerVersion;
|
||||
uint8_t MinorLinkerVersion;
|
||||
uint32_t SizeOfCode;
|
||||
uint32_t SizeOfInitializedData;
|
||||
uint32_t SizeOfUninitializedData;
|
||||
uint32_t AddressOfEntryPoint;
|
||||
uint32_t BaseOfCode;
|
||||
uint64_t ImageBase;
|
||||
uint32_t SectionAlignment;
|
||||
uint32_t FileAlignment;
|
||||
uint16_t MajorOperatingSystemVersion;
|
||||
uint16_t MinorOperatingSystemVersion;
|
||||
uint16_t MajorImageVersion;
|
||||
uint16_t MinorImageVersion;
|
||||
uint16_t MajorSubsystemVersion;
|
||||
uint16_t MinorSubsystemVersion;
|
||||
uint32_t Win32VersionValue;
|
||||
uint32_t SizeOfImage;
|
||||
uint32_t SizeOfHeaders;
|
||||
uint32_t CheckSum;
|
||||
uint16_t Subsystem;
|
||||
uint16_t DllCharacteristics;
|
||||
uint64_t SizeOfStackReserve;
|
||||
uint64_t SizeOfStackCommit;
|
||||
uint64_t SizeOfHeapReserve;
|
||||
uint64_t SizeOfHeapCommit;
|
||||
uint32_t LoaderFlags;
|
||||
uint32_t NumberOfRvaAndSizes;
|
||||
IMAGE_DATA_DIRECTORY DataDirectory[16];
|
||||
};
|
||||
|
||||
struct IMAGE_NT_HEADERS64 {
|
||||
uint32_t Signature;
|
||||
IMAGE_FILE_HEADER FileHeader;
|
||||
IMAGE_OPTIONAL_HEADER64 OptionalHeader;
|
||||
};
|
||||
|
||||
struct IMAGE_EXPORT_DIRECTORY {
|
||||
uint32_t Characteristics;
|
||||
uint32_t TimeDateStamp;
|
||||
uint16_t MajorVersion;
|
||||
uint16_t MinorVersion;
|
||||
uint32_t Name;
|
||||
uint32_t Base;
|
||||
uint32_t NumberOfFunctions;
|
||||
uint32_t NumberOfNames;
|
||||
uint32_t AddressOfFunctions; // RVA from base of image
|
||||
uint32_t AddressOfNames; // RVA from base of image
|
||||
uint32_t AddressOfNameOrdinals; // RVA from base of image
|
||||
};
|
||||
|
||||
int strcmp(const char* a, const char* b) {
|
||||
while (*a && (*a == *b)) {
|
||||
++a;
|
||||
++b;
|
||||
}
|
||||
return static_cast<unsigned char>(*a) - static_cast<unsigned char>(*b);
|
||||
}
|
||||
|
||||
FARPROC GetRealGetProcAddress(HMODULE hModule) {
|
||||
auto base = reinterpret_cast<uint8_t*>(hModule);
|
||||
auto dos = reinterpret_cast<IMAGE_DOS_HEADER*>(base);
|
||||
if (dos->e_magic != IMAGE_DOS_SIGNATURE) return nullptr;
|
||||
|
||||
auto nt = reinterpret_cast<IMAGE_NT_HEADERS64*>(base + dos->e_lfanew);
|
||||
if (nt->Signature != IMAGE_NT_SIGNATURE) return nullptr;
|
||||
|
||||
auto exportDirRVA = nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
|
||||
auto exportDir = reinterpret_cast<IMAGE_EXPORT_DIRECTORY*>(base + exportDirRVA);
|
||||
|
||||
auto names = reinterpret_cast<uint32_t*>(base + exportDir->AddressOfNames);
|
||||
auto ordinals = reinterpret_cast<uint16_t*>(base + exportDir->AddressOfNameOrdinals);
|
||||
auto functions = reinterpret_cast<uint32_t*>(base + exportDir->AddressOfFunctions);
|
||||
|
||||
for (uint32_t i = 0; i < exportDir->NumberOfNames; i++) {
|
||||
const char* name = reinterpret_cast<const char*>(base + names[i]);
|
||||
if (strcmp(name, "GetProcAddress") == 0) {
|
||||
uint16_t ord = ordinals[i];
|
||||
uint32_t funcRVA = functions[ord];
|
||||
return reinterpret_cast<FARPROC>(base + funcRVA);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
typedef FARPROC (*GetProcAddress_t)(HMODULE, LPCSTR);
|
||||
GetProcAddress_t pGetProcAddress = nullptr;
|
||||
|
||||
BOOL DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
|
||||
if (fdwReason == 1) { // DLL_PROCESS_ATTACH
|
||||
HMODULE kernel32 = LoadLibraryExA("kernel32.dll", NULL, 0x00000800);
|
||||
pGetProcAddress = (GetProcAddress_t)GetRealGetProcAddress(kernel32);
|
||||
|
||||
pHeapCreate = (HeapCreate_t)pGetProcAddress(kernel32, "HeapCreate");
|
||||
pHeapDestroy = (HeapDestroy_t)pGetProcAddress(kernel32, "HeapDestroy");
|
||||
pHeapAlloc = (HeapAlloc_t)pGetProcAddress(kernel32, "HeapAlloc");
|
||||
pHeapFree = (HeapFree_t)pGetProcAddress(kernel32, "HeapFree");
|
||||
pHeapReAlloc = (HeapReAlloc_t)pGetProcAddress(kernel32, "HeapReAlloc");
|
||||
|
||||
pGetTickCount = (GetTickCount_t)pGetProcAddress(kernel32, "GetTickCount");
|
||||
pQueryPerformanceCounter = (QueryPerformanceCounter_t)pGetProcAddress(kernel32, "QueryPerformanceCounter");
|
||||
pQueryPerformanceFrequency = (QueryPerformanceFrequency_t)pGetProcAddress(kernel32, "QueryPerformanceFrequency");
|
||||
|
||||
pOutputDebugStringA = (OutputDebugStringA_t)pGetProcAddress(kernel32, "OutputDebugStringA");
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,250 @@
|
||||
#include "bink.h"
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// Macro to define function pointer and global variable
|
||||
#define DECL_FN(ret, name, args, ptr) typedef ret (__cdecl *name##_t) args; name##_t p##name = NULL;
|
||||
|
||||
DECL_FN(void *, BinkLogoAddress, (void), )
|
||||
DECL_FN(void, BinkSetError, (char const * err), *)
|
||||
DECL_FN(char *, BinkGetError, (void), )
|
||||
DECL_FN(HBINK, BinkOpen, (char const * name, U32 flags), *)
|
||||
DECL_FN(HBINK, BinkOpenWithOptions, (char const * name, BINK_OPEN_OPTIONS const * boo, U32 flags), *)
|
||||
DECL_FN(void, BinkGetFrameBuffersInfo, (HBINK bink, BINKFRAMEBUFFERS * fbset), *)
|
||||
DECL_FN(void, BinkRegisterFrameBuffers, (HBINK bink, BINKFRAMEBUFFERS * fbset), *)
|
||||
DECL_FN(S32, BinkDoFrame, (HBINK bnk), *)
|
||||
DECL_FN(S32, BinkDoFramePlane, (HBINK bnk, U32 which_planes), *)
|
||||
DECL_FN(void, BinkNextFrame, (HBINK bnk), *)
|
||||
DECL_FN(S32, BinkWait, (HBINK bnk), *)
|
||||
DECL_FN(void, BinkClose, (HBINK bnk), *)
|
||||
DECL_FN(S32, BinkPause, (HBINK bnk, S32 pause), *)
|
||||
DECL_FN(S32, BinkCopyToBuffer, (HBINK bnk, void* dest, S32 destpitch, U32 destheight, U32 destx, U32 desty, U32 flags), *)
|
||||
DECL_FN(S32, BinkCopyToBufferRect, (HBINK bnk, void* dest, S32 destpitch, U32 destheight, U32 destx, U32 desty, U32 srcx, U32 srcy, U32 srcw, U32 srch, U32 flags), *)
|
||||
DECL_FN(S32, BinkGetRects, (HBINK bnk, U32 flags), *)
|
||||
DECL_FN(void, BinkGoto, (HBINK bnk, U32 frame, S32 flags), *)
|
||||
DECL_FN(U32, BinkGetKeyFrame, (HBINK bnk, U32 frame, S32 flags), *)
|
||||
DECL_FN(void, BinkFreeGlobals, (void), *)
|
||||
DECL_FN(S32, BinkGetPlatformInfo, (S32 bink_platform_enum, void * output), *)
|
||||
DECL_FN(void, BinkRegisterGPUDataBuffers, (HBINK bink, BINKGPUDATABUFFERS * gpu), *)
|
||||
DECL_FN(S32, BinkGetGPUDataBuffersInfo, (HBINK bink, BINKGPUDATABUFFERS * gpu), *)
|
||||
DECL_FN(S32, BinkSetVideoOnOff, (HBINK bnk, S32 onoff), *)
|
||||
DECL_FN(S32, BinkSetSoundOnOff, (HBINK bnk, S32 onoff), *)
|
||||
DECL_FN(void, BinkSetVolume, (HBINK bnk, U32 trackid, S32 volume), *)
|
||||
DECL_FN(void, BinkSetPan, (HBINK bnk, U32 trackid, S32 pan), *)
|
||||
DECL_FN(void, BinkSetSpeakerVolumes, (HBINK bnk, U32 trackid, U32 * speaker_indexes, S32 * volumes, U32 total), *)
|
||||
DECL_FN(void, BinkService, (HBINK bink), *)
|
||||
DECL_FN(S32, BinkShouldSkip, (HBINK bink), *)
|
||||
DECL_FN(S32, BinkControlBackgroundIO, (HBINK bink, U32 control), *)
|
||||
DECL_FN(void, BinkSetWillLoop, (HBINK bink, S32 onoff), *)
|
||||
DECL_FN(S32, BinkStartAsyncThread, (S32 thread_num, void const * param), *)
|
||||
DECL_FN(S32, BinkDoFrameAsync, (HBINK bink, U32 thread_one, U32 thread_two), *)
|
||||
DECL_FN(S32, BinkDoFrameAsyncMulti, (HBINK bink, U32* threads, S32 thread_count), *)
|
||||
DECL_FN(S32, BinkDoFrameAsyncWait, (HBINK bink, S32 us), *)
|
||||
DECL_FN(S32, BinkRequestStopAsyncThread, (S32 thread_num), *)
|
||||
DECL_FN(S32, BinkWaitStopAsyncThread, (S32 thread_num), *)
|
||||
DECL_FN(HBINKTRACK, BinkOpenTrack, (HBINK bnk, U32 trackindex), *)
|
||||
DECL_FN(void, BinkCloseTrack, (HBINKTRACK bnkt), *)
|
||||
DECL_FN(U32, BinkGetTrackData, (HBINKTRACK bnkt, void * dest), *)
|
||||
DECL_FN(U32, BinkGetTrackType, (HBINK bnk, U32 trackindex), *)
|
||||
DECL_FN(U32, BinkGetTrackMaxSize, (HBINK bnk, U32 trackindex), *)
|
||||
DECL_FN(U32, BinkGetTrackID, (HBINK bnk, U32 trackindex), *)
|
||||
DECL_FN(void, BinkGetSummary, (HBINK bnk, BINKSUMMARY * sum), *)
|
||||
DECL_FN(void, BinkGetRealtime, (HBINK bink, BINKREALTIME * run, U32 frames), *)
|
||||
DECL_FN(void, BinkSetFileOffset, (U64 offset), *)
|
||||
DECL_FN(void, BinkSetSoundTrack, (U32 total_tracks, U32 * tracks), *)
|
||||
DECL_FN(void, BinkSetIO, (BINKIOOPEN io), *)
|
||||
DECL_FN(void, BinkSetFrameRate, (U32 forcerate, U32 forceratediv), *)
|
||||
DECL_FN(void, BinkSetSimulate, (U32 sim), *)
|
||||
DECL_FN(void, BinkSetIOSize, (U32 iosize), *)
|
||||
DECL_FN(S32, BinkSetSoundSystem, (BINKSNDSYSOPEN open, UINTa param), *)
|
||||
DECL_FN(S32, BinkSetSoundSystem2, (BINKSNDSYSOPEN2 open, UINTa param1, UINTa param2), *)
|
||||
DECL_FN(BINKSNDOPEN, BinkOpenDirectSound, (UINTa param), *)
|
||||
DECL_FN(BINKSNDOPEN, BinkOpenWaveOut, (UINTa param), *)
|
||||
DECL_FN(BINKSNDOPEN, BinkOpenXAudio2, (UINTa param), *)
|
||||
DECL_FN(void, BinkSetMemory, (BINKMEMALLOC a, BINKMEMFREE f), *)
|
||||
|
||||
HMODULE dll = NULL;
|
||||
|
||||
int LoadBinkDLL(void) {
|
||||
if (dll) return 1;
|
||||
dll = LoadLibraryExA("bink2w64.dll", 0, 0);
|
||||
if (!dll) return 0;
|
||||
|
||||
pBinkLogoAddress = (BinkLogoAddress_t)GetProcAddress(dll, "BinkLogoAddress");
|
||||
pBinkSetError = (BinkSetError_t)GetProcAddress(dll, "BinkSetError");
|
||||
pBinkGetError = (BinkGetError_t)GetProcAddress(dll, "BinkGetError");
|
||||
pBinkOpen = (BinkOpen_t)GetProcAddress(dll, "BinkOpen");
|
||||
pBinkOpenWithOptions = (BinkOpenWithOptions_t)GetProcAddress(dll, "BinkOpenWithOptions");
|
||||
pBinkGetFrameBuffersInfo = (BinkGetFrameBuffersInfo_t)GetProcAddress(dll, "BinkGetFrameBuffersInfo");
|
||||
pBinkRegisterFrameBuffers = (BinkRegisterFrameBuffers_t)GetProcAddress(dll, "BinkRegisterFrameBuffers");
|
||||
pBinkDoFrame = (BinkDoFrame_t)GetProcAddress(dll, "BinkDoFrame");
|
||||
pBinkDoFramePlane = (BinkDoFramePlane_t)GetProcAddress(dll, "BinkDoFramePlane");
|
||||
pBinkNextFrame = (BinkNextFrame_t)GetProcAddress(dll, "BinkNextFrame");
|
||||
pBinkWait = (BinkWait_t)GetProcAddress(dll, "BinkWait");
|
||||
pBinkClose = (BinkClose_t)GetProcAddress(dll, "BinkClose");
|
||||
pBinkPause = (BinkPause_t)GetProcAddress(dll, "BinkPause");
|
||||
pBinkCopyToBuffer = (BinkCopyToBuffer_t)GetProcAddress(dll, "BinkCopyToBuffer");
|
||||
pBinkCopyToBufferRect = (BinkCopyToBufferRect_t)GetProcAddress(dll, "BinkCopyToBufferRect");
|
||||
pBinkGetRects = (BinkGetRects_t)GetProcAddress(dll, "BinkGetRects");
|
||||
pBinkGoto = (BinkGoto_t)GetProcAddress(dll, "BinkGoto");
|
||||
pBinkGetKeyFrame = (BinkGetKeyFrame_t)GetProcAddress(dll, "BinkGetKeyFrame");
|
||||
pBinkFreeGlobals = (BinkFreeGlobals_t)GetProcAddress(dll, "BinkFreeGlobals");
|
||||
pBinkGetPlatformInfo = (BinkGetPlatformInfo_t)GetProcAddress(dll, "BinkGetPlatformInfo");
|
||||
pBinkRegisterGPUDataBuffers = (BinkRegisterGPUDataBuffers_t)GetProcAddress(dll, "BinkRegisterGPUDataBuffers");
|
||||
pBinkGetGPUDataBuffersInfo = (BinkGetGPUDataBuffersInfo_t)GetProcAddress(dll, "BinkGetGPUDataBuffersInfo");
|
||||
pBinkSetVideoOnOff = (BinkSetVideoOnOff_t)GetProcAddress(dll, "BinkSetVideoOnOff");
|
||||
pBinkSetSoundOnOff = (BinkSetSoundOnOff_t)GetProcAddress(dll, "BinkSetSoundOnOff");
|
||||
pBinkSetVolume = (BinkSetVolume_t)GetProcAddress(dll, "BinkSetVolume");
|
||||
pBinkSetPan = (BinkSetPan_t)GetProcAddress(dll, "BinkSetPan");
|
||||
pBinkSetSpeakerVolumes = (BinkSetSpeakerVolumes_t)GetProcAddress(dll, "BinkSetSpeakerVolumes");
|
||||
pBinkService = (BinkService_t)GetProcAddress(dll, "BinkService");
|
||||
pBinkShouldSkip = (BinkShouldSkip_t)GetProcAddress(dll, "BinkShouldSkip");
|
||||
pBinkControlBackgroundIO = (BinkControlBackgroundIO_t)GetProcAddress(dll, "BinkControlBackgroundIO");
|
||||
pBinkSetWillLoop = (BinkSetWillLoop_t)GetProcAddress(dll, "BinkSetWillLoop");
|
||||
pBinkStartAsyncThread = (BinkStartAsyncThread_t)GetProcAddress(dll, "BinkStartAsyncThread");
|
||||
pBinkDoFrameAsync = (BinkDoFrameAsync_t)GetProcAddress(dll, "BinkDoFrameAsync");
|
||||
pBinkDoFrameAsyncMulti = (BinkDoFrameAsyncMulti_t)GetProcAddress(dll, "BinkDoFrameAsyncMulti");
|
||||
pBinkDoFrameAsyncWait = (BinkDoFrameAsyncWait_t)GetProcAddress(dll, "BinkDoFrameAsyncWait");
|
||||
pBinkRequestStopAsyncThread = (BinkRequestStopAsyncThread_t)GetProcAddress(dll, "BinkRequestStopAsyncThread");
|
||||
pBinkWaitStopAsyncThread = (BinkWaitStopAsyncThread_t)GetProcAddress(dll, "BinkWaitStopAsyncThread");
|
||||
pBinkOpenTrack = (BinkOpenTrack_t)GetProcAddress(dll, "BinkOpenTrack");
|
||||
pBinkCloseTrack = (BinkCloseTrack_t)GetProcAddress(dll, "BinkCloseTrack");
|
||||
pBinkGetTrackData = (BinkGetTrackData_t)GetProcAddress(dll, "BinkGetTrackData");
|
||||
pBinkGetTrackType = (BinkGetTrackType_t)GetProcAddress(dll, "BinkGetTrackType");
|
||||
pBinkGetTrackMaxSize = (BinkGetTrackMaxSize_t)GetProcAddress(dll, "BinkGetTrackMaxSize");
|
||||
pBinkGetTrackID = (BinkGetTrackID_t)GetProcAddress(dll, "BinkGetTrackID");
|
||||
pBinkGetSummary = (BinkGetSummary_t)GetProcAddress(dll, "BinkGetSummary");
|
||||
pBinkGetRealtime = (BinkGetRealtime_t)GetProcAddress(dll, "BinkGetRealtime");
|
||||
pBinkSetFileOffset = (BinkSetFileOffset_t)GetProcAddress(dll, "BinkSetFileOffset");
|
||||
pBinkSetSoundTrack = (BinkSetSoundTrack_t)GetProcAddress(dll, "BinkSetSoundTrack");
|
||||
pBinkSetIO = (BinkSetIO_t)GetProcAddress(dll, "BinkSetIO");
|
||||
pBinkSetFrameRate = (BinkSetFrameRate_t)GetProcAddress(dll, "BinkSetFrameRate");
|
||||
pBinkSetSimulate = (BinkSetSimulate_t)GetProcAddress(dll, "BinkSetSimulate");
|
||||
pBinkSetIOSize = (BinkSetIOSize_t)GetProcAddress(dll, "BinkSetIOSize");
|
||||
pBinkSetSoundSystem = (BinkSetSoundSystem_t)GetProcAddress(dll, "BinkSetSoundSystem");
|
||||
pBinkSetSoundSystem2 = (BinkSetSoundSystem2_t)GetProcAddress(dll, "BinkSetSoundSystem2");
|
||||
pBinkOpenDirectSound = (BinkOpenDirectSound_t)GetProcAddress(dll, "BinkOpenDirectSound");
|
||||
pBinkOpenWaveOut = (BinkOpenWaveOut_t)GetProcAddress(dll, "BinkOpenWaveOut");
|
||||
pBinkOpenXAudio2 = (BinkOpenXAudio2_t)GetProcAddress(dll, "BinkOpenXAudio2");
|
||||
pBinkSetMemory = (BinkSetMemory_t)GetProcAddress(dll, "BinkSetMemory");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
char* read_binary_file_to_memory(const char* filename, size_t* file_size) {
|
||||
FILE* file = fopen(filename, "rb"); // Use "rb" for binary mode
|
||||
if (file == NULL) {
|
||||
perror("Failed to open file");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Get file size
|
||||
fseek(file, 0, SEEK_END);
|
||||
long size = ftell(file);
|
||||
rewind(file);
|
||||
|
||||
if (size < 0) {
|
||||
perror("Failed to determine file size");
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Allocate memory. Note: no need for a null terminator since it's not a string.
|
||||
char* buffer = (char*)malloc(size);
|
||||
if (buffer == NULL) {
|
||||
perror("Memory allocation failed");
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Read file into buffer
|
||||
size_t bytes_read = fread(buffer, 1, size, file);
|
||||
if (bytes_read != (size_t)size) {
|
||||
perror("Failed to read file");
|
||||
free(buffer);
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
if (file_size) {
|
||||
*file_size = (size_t)size;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
int main() {
|
||||
if (!LoadBinkDLL()) {
|
||||
printf("we fucked up\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
pBinkSetSoundSystem((BINKSNDSYSOPEN)pBinkOpenDirectSound, 0);
|
||||
pBinkSetMemory((BINKMEMALLOC)malloc, (BINKMEMFREE)free);
|
||||
pBinkSetIO(NULL); // no io
|
||||
//pBinkSetTimerRead() // r.i.p.
|
||||
|
||||
size_t size = 0;
|
||||
char* buffer = read_binary_file_to_memory("you_are_nothing.bk2", &size);
|
||||
|
||||
HBINK bink = NULL;
|
||||
bink = pBinkOpen(buffer, BINKFROMMEMORY);
|
||||
|
||||
int width = bink->Width, height = bink->Height;
|
||||
|
||||
// Allocate framebuffer
|
||||
uint32_t* framebuffer = (uint32_t*)malloc(width * height * sizeof(uint32_t));
|
||||
if (!framebuffer) return 1;
|
||||
|
||||
// Decode one frame
|
||||
pBinkDoFrame(bink);
|
||||
|
||||
// Copy frame to our buffer
|
||||
pBinkCopyToBuffer(
|
||||
bink,
|
||||
framebuffer, // dest
|
||||
width * 4, // destpitch in bytes
|
||||
height, // destheight
|
||||
0, // destx
|
||||
0, // desty
|
||||
BINKSURFACE32 | BINKCOPYALL // flags
|
||||
);
|
||||
|
||||
// Create BMP headers
|
||||
BITMAPFILEHEADER bfh = {0};
|
||||
BITMAPINFOHEADER bih = {0};
|
||||
|
||||
bfh.bfType = 0x4D42; // 'BM'
|
||||
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
|
||||
bfh.bfSize = bfh.bfOffBits + width * height * 4;
|
||||
|
||||
bih.biSize = sizeof(BITMAPINFOHEADER);
|
||||
bih.biWidth = width;
|
||||
bih.biHeight = -height; // negative = top-down
|
||||
bih.biPlanes = 1;
|
||||
bih.biBitCount = 32;
|
||||
bih.biCompression = 0; // BI_RGB
|
||||
bih.biSizeImage = width * height * 4;
|
||||
|
||||
// Write BMP
|
||||
FILE* f = fopen("framebuffer.bmp", "wb");
|
||||
if (!f) return 1;
|
||||
|
||||
fwrite(&bfh, sizeof(bfh), 1, f);
|
||||
fwrite(&bih, sizeof(bih), 1, f);
|
||||
fwrite(framebuffer, 4, width * height, f);
|
||||
|
||||
fclose(f);
|
||||
free(framebuffer);
|
||||
|
||||
printf("Saved framebuffer.bmp\n");
|
||||
|
||||
pBinkClose(bink);
|
||||
|
||||
free(buffer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
typedef void* HWND;
|
||||
typedef void* LPUNKNOWN;
|
||||
typedef void* REFIID;
|
||||
typedef void* REFCLSID;
|
||||
typedef long HRESULT;
|
||||
typedef unsigned long DWORD;
|
||||
typedef unsigned int UINT;
|
||||
typedef int BOOL;
|
||||
typedef void* HANDLE;
|
||||
typedef void* LPVOID;
|
||||
typedef long LONG;
|
||||
typedef long LONG_PTR;
|
||||
typedef const char* LPCSTR;
|
||||
typedef size_t SIZE_T;
|
||||
typedef void* HMODULE;
|
||||
typedef HMODULE HINSTANCE;
|
||||
typedef void* FARPROC;
|
||||
typedef DWORD (*LPTHREAD_START_ROUTINE)(LPVOID lpThreadParameter);
|
||||
typedef union _LARGE_INTEGER {
|
||||
struct {
|
||||
unsigned long LowPart;
|
||||
long HighPart;
|
||||
};
|
||||
long long QuadPart;
|
||||
} LARGE_INTEGER;
|
||||
#define S_OK ((HRESULT)0L)
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
extern "C" {
|
||||
|
||||
// COM stubs
|
||||
__declspec(dllexport) HRESULT CoCreateInstance(REFCLSID, LPUNKNOWN, DWORD, REFIID, LPVOID* ppv) {
|
||||
if (ppv) *ppv = nullptr;
|
||||
return S_OK;
|
||||
}
|
||||
__declspec(dllexport) HRESULT CoInitializeEx(LPVOID, DWORD) { return S_OK; }
|
||||
__declspec(dllexport) void CoUninitialize() {}
|
||||
__declspec(dllexport) void CoTaskMemFree(LPVOID) {}
|
||||
__declspec(dllexport) HRESULT PropVariantClear(LPVOID) { return S_OK; }
|
||||
|
||||
BOOL DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { return TRUE; }
|
||||
|
||||
}
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
typedef void* HWND;
|
||||
typedef void* LPUNKNOWN;
|
||||
typedef void* REFIID;
|
||||
typedef void* REFCLSID;
|
||||
typedef long HRESULT;
|
||||
typedef unsigned long DWORD;
|
||||
typedef unsigned int UINT;
|
||||
typedef int BOOL;
|
||||
typedef void* HANDLE;
|
||||
typedef void* LPVOID;
|
||||
typedef long LONG;
|
||||
typedef long LONG_PTR;
|
||||
typedef const char* LPCSTR;
|
||||
typedef size_t SIZE_T;
|
||||
typedef void* HMODULE;
|
||||
typedef HMODULE HINSTANCE;
|
||||
typedef void* FARPROC;
|
||||
typedef DWORD (*LPTHREAD_START_ROUTINE)(LPVOID lpThreadParameter);
|
||||
typedef union _LARGE_INTEGER {
|
||||
struct {
|
||||
unsigned long LowPart;
|
||||
long HighPart;
|
||||
};
|
||||
long long QuadPart;
|
||||
} LARGE_INTEGER;
|
||||
#define S_OK ((HRESULT)0L)
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#include <cstdint>
|
||||
|
||||
extern "C" {
|
||||
|
||||
// Window stubs
|
||||
__declspec(dllexport) HWND GetDesktopWindow() { return (HWND)1; }
|
||||
__declspec(dllexport) HWND GetActiveWindow() { return (HWND)1; }
|
||||
__declspec(dllexport) HWND GetTopWindow(HWND) { return (HWND)1; }
|
||||
__declspec(dllexport) HWND GetWindow(HWND, UINT) { return (HWND)1; }
|
||||
__declspec(dllexport) LONG GetWindowLongA(HWND, int) { return 0; }
|
||||
__declspec(dllexport) LONG_PTR GetWindowLongPtrA(HWND, int) { return 0; }
|
||||
__declspec(dllexport) void GetWindowThreadProcessId(HWND, DWORD*) {}
|
||||
|
||||
typedef void (*OutputDebugStringA_t)(LPCSTR lpOutputString);
|
||||
|
||||
OutputDebugStringA_t pOutputDebugStringA = nullptr;
|
||||
|
||||
// MessageBox
|
||||
__declspec(dllexport) int MessageBoxA(HWND, LPCSTR text, LPCSTR caption, UINT) {
|
||||
pOutputDebugStringA("[MessageBox] ");
|
||||
pOutputDebugStringA(caption);
|
||||
pOutputDebugStringA(": ");
|
||||
pOutputDebugStringA(text);
|
||||
pOutputDebugStringA("\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
HMODULE LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags);
|
||||
|
||||
#define IMAGE_DOS_SIGNATURE 0x5A4D // MZ
|
||||
#define IMAGE_NT_SIGNATURE 0x00004550 // PE00
|
||||
#define IMAGE_DIRECTORY_ENTRY_EXPORT 0
|
||||
|
||||
struct IMAGE_DOS_HEADER {
|
||||
uint16_t e_magic;
|
||||
uint16_t e_cblp;
|
||||
uint16_t e_cp;
|
||||
uint16_t e_crlc;
|
||||
uint16_t e_cparhdr;
|
||||
uint16_t e_minalloc;
|
||||
uint16_t e_maxalloc;
|
||||
uint16_t e_ss;
|
||||
uint16_t e_sp;
|
||||
uint16_t e_csum;
|
||||
uint16_t e_ip;
|
||||
uint16_t e_cs;
|
||||
uint16_t e_lfarlc;
|
||||
uint16_t e_ovno;
|
||||
uint16_t e_res[4];
|
||||
uint16_t e_oemid;
|
||||
uint16_t e_oeminfo;
|
||||
uint16_t e_res2[10];
|
||||
uint32_t e_lfanew;
|
||||
};
|
||||
|
||||
struct IMAGE_FILE_HEADER {
|
||||
uint16_t Machine;
|
||||
uint16_t NumberOfSections;
|
||||
uint32_t TimeDateStamp;
|
||||
uint32_t PointerToSymbolTable;
|
||||
uint32_t NumberOfSymbols;
|
||||
uint16_t SizeOfOptionalHeader;
|
||||
uint16_t Characteristics;
|
||||
};
|
||||
|
||||
struct IMAGE_DATA_DIRECTORY {
|
||||
uint32_t VirtualAddress;
|
||||
uint32_t Size;
|
||||
};
|
||||
|
||||
struct IMAGE_OPTIONAL_HEADER64 {
|
||||
uint16_t Magic;
|
||||
uint8_t MajorLinkerVersion;
|
||||
uint8_t MinorLinkerVersion;
|
||||
uint32_t SizeOfCode;
|
||||
uint32_t SizeOfInitializedData;
|
||||
uint32_t SizeOfUninitializedData;
|
||||
uint32_t AddressOfEntryPoint;
|
||||
uint32_t BaseOfCode;
|
||||
uint64_t ImageBase;
|
||||
uint32_t SectionAlignment;
|
||||
uint32_t FileAlignment;
|
||||
uint16_t MajorOperatingSystemVersion;
|
||||
uint16_t MinorOperatingSystemVersion;
|
||||
uint16_t MajorImageVersion;
|
||||
uint16_t MinorImageVersion;
|
||||
uint16_t MajorSubsystemVersion;
|
||||
uint16_t MinorSubsystemVersion;
|
||||
uint32_t Win32VersionValue;
|
||||
uint32_t SizeOfImage;
|
||||
uint32_t SizeOfHeaders;
|
||||
uint32_t CheckSum;
|
||||
uint16_t Subsystem;
|
||||
uint16_t DllCharacteristics;
|
||||
uint64_t SizeOfStackReserve;
|
||||
uint64_t SizeOfStackCommit;
|
||||
uint64_t SizeOfHeapReserve;
|
||||
uint64_t SizeOfHeapCommit;
|
||||
uint32_t LoaderFlags;
|
||||
uint32_t NumberOfRvaAndSizes;
|
||||
IMAGE_DATA_DIRECTORY DataDirectory[16];
|
||||
};
|
||||
|
||||
struct IMAGE_NT_HEADERS64 {
|
||||
uint32_t Signature;
|
||||
IMAGE_FILE_HEADER FileHeader;
|
||||
IMAGE_OPTIONAL_HEADER64 OptionalHeader;
|
||||
};
|
||||
|
||||
struct IMAGE_EXPORT_DIRECTORY {
|
||||
uint32_t Characteristics;
|
||||
uint32_t TimeDateStamp;
|
||||
uint16_t MajorVersion;
|
||||
uint16_t MinorVersion;
|
||||
uint32_t Name;
|
||||
uint32_t Base;
|
||||
uint32_t NumberOfFunctions;
|
||||
uint32_t NumberOfNames;
|
||||
uint32_t AddressOfFunctions; // RVA from base of image
|
||||
uint32_t AddressOfNames; // RVA from base of image
|
||||
uint32_t AddressOfNameOrdinals; // RVA from base of image
|
||||
};
|
||||
|
||||
int strcmp(const char* a, const char* b) {
|
||||
while (*a && (*a == *b)) {
|
||||
++a;
|
||||
++b;
|
||||
}
|
||||
return static_cast<unsigned char>(*a) - static_cast<unsigned char>(*b);
|
||||
}
|
||||
|
||||
FARPROC GetRealGetProcAddress(HMODULE hModule) {
|
||||
auto base = reinterpret_cast<uint8_t*>(hModule);
|
||||
auto dos = reinterpret_cast<IMAGE_DOS_HEADER*>(base);
|
||||
if (dos->e_magic != IMAGE_DOS_SIGNATURE) return nullptr;
|
||||
|
||||
auto nt = reinterpret_cast<IMAGE_NT_HEADERS64*>(base + dos->e_lfanew);
|
||||
if (nt->Signature != IMAGE_NT_SIGNATURE) return nullptr;
|
||||
|
||||
auto exportDirRVA = nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
|
||||
auto exportDir = reinterpret_cast<IMAGE_EXPORT_DIRECTORY*>(base + exportDirRVA);
|
||||
|
||||
auto names = reinterpret_cast<uint32_t*>(base + exportDir->AddressOfNames);
|
||||
auto ordinals = reinterpret_cast<uint16_t*>(base + exportDir->AddressOfNameOrdinals);
|
||||
auto functions = reinterpret_cast<uint32_t*>(base + exportDir->AddressOfFunctions);
|
||||
|
||||
for (uint32_t i = 0; i < exportDir->NumberOfNames; i++) {
|
||||
const char* name = reinterpret_cast<const char*>(base + names[i]);
|
||||
if (strcmp(name, "GetProcAddress") == 0) {
|
||||
uint16_t ord = ordinals[i];
|
||||
uint32_t funcRVA = functions[ord];
|
||||
return reinterpret_cast<FARPROC>(base + funcRVA);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
typedef FARPROC (*GetProcAddress_t)(HMODULE, LPCSTR);
|
||||
GetProcAddress_t pGetProcAddress = nullptr;
|
||||
|
||||
BOOL DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
|
||||
if (fdwReason == 1) { // DLL_PROCESS_ATTACH
|
||||
HMODULE kernel32 = LoadLibraryExA("kernel32.dll", 0, 0x00000800);
|
||||
pGetProcAddress = (GetProcAddress_t)GetRealGetProcAddress(kernel32);
|
||||
|
||||
pOutputDebugStringA = (OutputDebugStringA_t)pGetProcAddress(kernel32, "OutputDebugStringA");
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,183 @@
|
||||
typedef void* HWND;
|
||||
typedef void* LPUNKNOWN;
|
||||
typedef void* REFIID;
|
||||
typedef void* REFCLSID;
|
||||
typedef long HRESULT;
|
||||
typedef unsigned long DWORD;
|
||||
typedef unsigned int UINT;
|
||||
typedef int BOOL;
|
||||
typedef void* HANDLE;
|
||||
typedef void* LPVOID;
|
||||
typedef long LONG;
|
||||
typedef long LONG_PTR;
|
||||
typedef const char* LPCSTR;
|
||||
typedef size_t SIZE_T;
|
||||
typedef void* HMODULE;
|
||||
typedef HMODULE HINSTANCE;
|
||||
typedef void* FARPROC;
|
||||
typedef DWORD (*LPTHREAD_START_ROUTINE)(LPVOID lpThreadParameter);
|
||||
typedef union _LARGE_INTEGER {
|
||||
struct {
|
||||
unsigned long LowPart;
|
||||
long HighPart;
|
||||
};
|
||||
long long QuadPart;
|
||||
} LARGE_INTEGER;
|
||||
#define S_OK ((HRESULT)0L)
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#include <cstdint>
|
||||
|
||||
extern "C" {
|
||||
|
||||
typedef DWORD (*timeGetTime_t)();
|
||||
timeGetTime_t ptimeGetTime = nullptr;
|
||||
|
||||
__declspec(dllexport) DWORD timeGetTime() {
|
||||
return ptimeGetTime();
|
||||
}
|
||||
|
||||
HMODULE LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags);
|
||||
|
||||
#define IMAGE_DOS_SIGNATURE 0x5A4D // MZ
|
||||
#define IMAGE_NT_SIGNATURE 0x00004550 // PE00
|
||||
#define IMAGE_DIRECTORY_ENTRY_EXPORT 0
|
||||
|
||||
struct IMAGE_DOS_HEADER {
|
||||
uint16_t e_magic;
|
||||
uint16_t e_cblp;
|
||||
uint16_t e_cp;
|
||||
uint16_t e_crlc;
|
||||
uint16_t e_cparhdr;
|
||||
uint16_t e_minalloc;
|
||||
uint16_t e_maxalloc;
|
||||
uint16_t e_ss;
|
||||
uint16_t e_sp;
|
||||
uint16_t e_csum;
|
||||
uint16_t e_ip;
|
||||
uint16_t e_cs;
|
||||
uint16_t e_lfarlc;
|
||||
uint16_t e_ovno;
|
||||
uint16_t e_res[4];
|
||||
uint16_t e_oemid;
|
||||
uint16_t e_oeminfo;
|
||||
uint16_t e_res2[10];
|
||||
uint32_t e_lfanew;
|
||||
};
|
||||
|
||||
struct IMAGE_FILE_HEADER {
|
||||
uint16_t Machine;
|
||||
uint16_t NumberOfSections;
|
||||
uint32_t TimeDateStamp;
|
||||
uint32_t PointerToSymbolTable;
|
||||
uint32_t NumberOfSymbols;
|
||||
uint16_t SizeOfOptionalHeader;
|
||||
uint16_t Characteristics;
|
||||
};
|
||||
|
||||
struct IMAGE_DATA_DIRECTORY {
|
||||
uint32_t VirtualAddress;
|
||||
uint32_t Size;
|
||||
};
|
||||
|
||||
struct IMAGE_OPTIONAL_HEADER64 {
|
||||
uint16_t Magic;
|
||||
uint8_t MajorLinkerVersion;
|
||||
uint8_t MinorLinkerVersion;
|
||||
uint32_t SizeOfCode;
|
||||
uint32_t SizeOfInitializedData;
|
||||
uint32_t SizeOfUninitializedData;
|
||||
uint32_t AddressOfEntryPoint;
|
||||
uint32_t BaseOfCode;
|
||||
uint64_t ImageBase;
|
||||
uint32_t SectionAlignment;
|
||||
uint32_t FileAlignment;
|
||||
uint16_t MajorOperatingSystemVersion;
|
||||
uint16_t MinorOperatingSystemVersion;
|
||||
uint16_t MajorImageVersion;
|
||||
uint16_t MinorImageVersion;
|
||||
uint16_t MajorSubsystemVersion;
|
||||
uint16_t MinorSubsystemVersion;
|
||||
uint32_t Win32VersionValue;
|
||||
uint32_t SizeOfImage;
|
||||
uint32_t SizeOfHeaders;
|
||||
uint32_t CheckSum;
|
||||
uint16_t Subsystem;
|
||||
uint16_t DllCharacteristics;
|
||||
uint64_t SizeOfStackReserve;
|
||||
uint64_t SizeOfStackCommit;
|
||||
uint64_t SizeOfHeapReserve;
|
||||
uint64_t SizeOfHeapCommit;
|
||||
uint32_t LoaderFlags;
|
||||
uint32_t NumberOfRvaAndSizes;
|
||||
IMAGE_DATA_DIRECTORY DataDirectory[16];
|
||||
};
|
||||
|
||||
struct IMAGE_NT_HEADERS64 {
|
||||
uint32_t Signature;
|
||||
IMAGE_FILE_HEADER FileHeader;
|
||||
IMAGE_OPTIONAL_HEADER64 OptionalHeader;
|
||||
};
|
||||
|
||||
struct IMAGE_EXPORT_DIRECTORY {
|
||||
uint32_t Characteristics;
|
||||
uint32_t TimeDateStamp;
|
||||
uint16_t MajorVersion;
|
||||
uint16_t MinorVersion;
|
||||
uint32_t Name;
|
||||
uint32_t Base;
|
||||
uint32_t NumberOfFunctions;
|
||||
uint32_t NumberOfNames;
|
||||
uint32_t AddressOfFunctions; // RVA from base of image
|
||||
uint32_t AddressOfNames; // RVA from base of image
|
||||
uint32_t AddressOfNameOrdinals; // RVA from base of image
|
||||
};
|
||||
|
||||
int strcmp(const char* a, const char* b) {
|
||||
while (*a && (*a == *b)) {
|
||||
++a;
|
||||
++b;
|
||||
}
|
||||
return static_cast<unsigned char>(*a) - static_cast<unsigned char>(*b);
|
||||
}
|
||||
|
||||
FARPROC GetRealGetProcAddress(HMODULE hModule) {
|
||||
auto base = reinterpret_cast<uint8_t*>(hModule);
|
||||
auto dos = reinterpret_cast<IMAGE_DOS_HEADER*>(base);
|
||||
if (dos->e_magic != IMAGE_DOS_SIGNATURE) return nullptr;
|
||||
|
||||
auto nt = reinterpret_cast<IMAGE_NT_HEADERS64*>(base + dos->e_lfanew);
|
||||
if (nt->Signature != IMAGE_NT_SIGNATURE) return nullptr;
|
||||
|
||||
auto exportDirRVA = nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
|
||||
auto exportDir = reinterpret_cast<IMAGE_EXPORT_DIRECTORY*>(base + exportDirRVA);
|
||||
|
||||
auto names = reinterpret_cast<uint32_t*>(base + exportDir->AddressOfNames);
|
||||
auto ordinals = reinterpret_cast<uint16_t*>(base + exportDir->AddressOfNameOrdinals);
|
||||
auto functions = reinterpret_cast<uint32_t*>(base + exportDir->AddressOfFunctions);
|
||||
|
||||
for (uint32_t i = 0; i < exportDir->NumberOfNames; i++) {
|
||||
const char* name = reinterpret_cast<const char*>(base + names[i]);
|
||||
if (strcmp(name, "GetProcAddress") == 0) {
|
||||
uint16_t ord = ordinals[i];
|
||||
uint32_t funcRVA = functions[ord];
|
||||
return reinterpret_cast<FARPROC>(base + funcRVA);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
typedef FARPROC (*GetProcAddress_t)(HMODULE, LPCSTR);
|
||||
GetProcAddress_t pGetProcAddress = nullptr;
|
||||
|
||||
BOOL DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
|
||||
if (fdwReason == 1) { // DLL_PROCESS_ATTACH
|
||||
HMODULE kernel32 = LoadLibraryExA("kernel32.dll", 0, 0x00000800);
|
||||
pGetProcAddress = (GetProcAddress_t)GetRealGetProcAddress(kernel32);
|
||||
|
||||
ptimeGetTime = (timeGetTime_t)pGetProcAddress(kernel32, "timeGetTime");
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
Reference in new issue
Block a user