I know that executables can delete themself, now i want that a into a process loaded dll does a self deletion. i'm coding the dll in unicode.
here is a short code snippet that works for a standalone executable
and the bool to trigger the function:
TCHAR szFile[MAX_PATH], szCmd[MAX_PATH];
if ((GetModuleFileName(0, szFile, MAX_PATH) != 0) &&
(GetShortPathName(szFile, szFile, MAX_PATH) != 0))
lstrcpy(szCmd, "/c del ");
lstrcat(szCmd, " >> NUL");
if ((GetEnvironmentVariable("ComSpec", szFile, MAX_PATH) != 0) &&
((INT)ShellExecute(0, 0, szFile, szCmd, 0, SW_HIDE) > 32))
this code above works also for a executable, because after the selfdelete call, i do a exitprocess call to the target process.
if (!bWhatImCheckingHere(myparam1, myparam2, myparam3, myparam4, myparam5))
//shutdownpc();//shutdowns pc if wrong serial
here is the code i use to get the path and name of the dll
BOOL APIENTRY DllMain(HMODULE hDll, DWORD Reason, PVOID lpReserved)
if (Reason == DLL_PROCESS_ATTACH)
GetModuleFileNameA((HMODULE)hDll, bfr, sizeof(bfr));
i have used another code in my loaded dll, but all the dll did, was to delete the binary file of the target process on the hard disk.
FILE *pDLLFile;//pointer to DLL
pDLLFile = fopen(bfr, "rb");//open .DLL for read in binary mode
i want that the loaded dll, deletes itself and exits the process. it does all that, except the self deletion.
any help, tips, hints and push into the right direction is more than welcome