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
Code:
BOOL SelfDelete()
{
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, szFile);
lstrcat(szCmd, " >> NUL");
if ((GetEnvironmentVariable("ComSpec", szFile, MAX_PATH) != 0) &&
((INT)ShellExecute(0, 0, szFile, szCmd, 0, SW_HIDE) > 32))
return TRUE;
}
return FALSE;
}
and the bool to trigger the function:
Code:
if (!bWhatImCheckingHere(myparam1, myparam2, myparam3, myparam4, myparam5))
{
SelfDelete();
ExitProcess(0);
//shutdownpc();//shutdowns pc if wrong serial
}
this code above works also for a executable, because after the selfdelete call, i do a exitprocess call to the target process.
here is the code i use to get the path and name of the dll
Code:
BOOL APIENTRY DllMain(HMODULE hDll, DWORD Reason, PVOID lpReserved)
{
if (Reason == DLL_PROCESS_ATTACH)
{
GetModuleFileNameA((HMODULE)hDll, bfr, sizeof(bfr));
DisableThreadLibraryCalls(hDll); ....u.s.w.
Code:
FILE *pDLLFile;//pointer to DLL
...
pDLLFile = fopen(bfr, "rb");//open .DLL for read in binary mode
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.
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