Skip to content

Commit

Permalink
Initialize from Setup() for SafeDisc v1
Browse files Browse the repository at this point in the history
  • Loading branch information
RibShark committed Feb 3, 2024
1 parent 18700cf commit bdb0c78
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,25 @@ void RunFromEntryPoint(bool(*funcToCall)()) {
&shellcodeTrampoline, sizeof(shellcodeTrampoline));
}

bool IsSafeDiscV1() {
// heuristic to detect SafeDisc v1 from the presence of a .ICD file
wchar_t exeName[MAX_PATH];
GetModuleFileNameW(nullptr, exeName, MAX_PATH);
wchar_t* extension = wcsrchr(exeName, L'.');
if ( !extension || _wcsicmp(extension, L".exe") != 0 ) {
return false;
}
wcscpy_s(extension, 5, L".icd");
if ( GetFileAttributesW(exeName) == INVALID_FILE_ATTRIBUTES )
return false;
return true;
}

BOOL WINAPI DllMain(HINSTANCE /*hinstDLL*/, DWORD fdwReason, LPVOID /*lpvReserved*/) {
switch( fdwReason ) {
case DLL_PROCESS_ATTACH:
RunFromEntryPoint(Initialize);
if (!IsSafeDiscV1())
RunFromEntryPoint(Initialize);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
Expand All @@ -212,6 +227,9 @@ BOOL WINAPI DllMain(HINSTANCE /*hinstDLL*/, DWORD fdwReason, LPVOID /*lpvReserve

// Exported functions from the original drvmgt.dll. 100 = success
extern "C" __declspec(dllexport) int Setup(LPCSTR /*lpSubKey*/, char* /*FullPath*/) {
/* will only be called from SafeDisc v1 since the other versions import
* drvmgt.dll from %temp% */
Initialize();
return 100;
}

Expand Down

0 comments on commit bdb0c78

Please sign in to comment.