Skip to content

Instantly share code, notes, and snippets.

@DankRank
Created July 14, 2018 23:42
Show Gist options
  • Save DankRank/ca3926dce9c279f4b0273a49117e5e90 to your computer and use it in GitHub Desktop.
Save DankRank/ca3926dce9c279f4b0273a49117e5e90 to your computer and use it in GitHub Desktop.
dsound wrapper dll
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#define enum_dsound(_helper) \
_helper(DirectSoundCreate) \
_helper(DirectSoundEnumerateA) \
_helper(DirectSoundEnumerateW) \
_helper(DllCanUnloadNow) \
_helper(DllGetClassObject) \
_helper(DirectSoundCaptureCreate) \
_helper(DirectSoundCaptureEnumerateA) \
_helper(DirectSoundCaptureEnumerateW) \
_helper(GetDeviceID) \
_helper(DirectSoundFullDuplexCreate) \
_helper(DirectSoundCreate8) \
_helper(DirectSoundCaptureCreate8)
#define x(y) static FARPROC fp##y;
enum_dsound(x)
#undef x
#define x(y) __declspec(naked) void y(void){_asm{jmp fp##y}}
enum_dsound(x)
#undef x
static HMODULE dsound;
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
if (fdwReason == DLL_PROCESS_ATTACH) {
wchar_t origpath[MAX_PATH];
GetSystemDirectory(origpath, MAX_PATH);
wcscat_s(origpath, MAX_PATH, L"\\dsound.dll");
dsound = LoadLibrary(origpath);
if (!dsound) return FALSE;
#define x(y) fp##y = GetProcAddress(dsound,#y);
enum_dsound(x)
#undef x
/* Payload goes here */
}
else if (fdwReason == DLL_PROCESS_DETACH) {
FreeLibrary(dsound);
}
return TRUE;
}
LIBRARY "dsound"
EXPORTS
DirectSoundCreate @1
DirectSoundEnumerateA @2
DirectSoundEnumerateW @3
DllCanUnloadNow @4 PRIVATE
DllGetClassObject @5 PRIVATE
DirectSoundCaptureCreate @6
DirectSoundCaptureEnumerateA @7
DirectSoundCaptureEnumerateW @8
GetDeviceID @9
DirectSoundFullDuplexCreate @10
DirectSoundCreate8 @11
DirectSoundCaptureCreate8 @12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment