J
jt
For some stupid reason, I can't get this to work in Release mode, but works
well in Debug mode.
Below is the function:
Here is the line:
pos=strpos(pszCmdLine,cmdLineStr); // in release mode this doesn't find
the match, but in debug mode it does
See strpos prototype below this
---------------------------------------------------------------------------------
int OnSelchangeProcesses(DWORD dwProcessID, STRING cmdLineStr)
{
DWORD dwSize;
PROCESS_BASIC_INFORMATION pbi;
NTQIP *lpfnNtQueryInformationProcess;
__PEB PEB;
__INFOBLOCK Block;
TCHAR *pszCmdLine = NULL;
int pos;
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ, FALSE, dwProcessID);
if (NULL != hProcess)
{
pbi.PebBaseAddress = (_PEB *) 0x7ffdf000;
// we'll default to the above address, but newer OSs might have
a different
// base address for the PEB
HMODULE hLibrary = GetModuleHandle(_T("ntdll.dll"));
if (NULL != hLibrary)
{
lpfnNtQueryInformationProcess = (NTQIP *)
GetProcAddress(hLibrary, "ZwQueryInformationProcess");
if (NULL != lpfnNtQueryInformationProcess)
(*lpfnNtQueryInformationProcess)(hProcess,
ProcessBasicInformation, &pbi, sizeof(pbi), &dwSize);
}
BOOL bSuccess = ReadProcessMemory(hProcess, pbi.PebBaseAddress,
&PEB, sizeof(PEB), &dwSize);
if (bSuccess != FALSE)
{
bSuccess = ReadProcessMemory(hProcess, (LPVOID)
PEB.dwInfoBlockAddress, &Block, sizeof(Block), &dwSize);
pszCmdLine = new TCHAR[Block.wMaxLength];
}
if (bSuccess != FALSE)
{
bSuccess = ReadProcessMemory(hProcess, (LPVOID)
Block.dwCmdLineAddress, pszCmdLine, Block.wMaxLength, &dwSize);
pos=strpos(pszCmdLine,cmdLineStr); // in release mode this doesn't find
the match, but in debug mode it does
printf("%d\n",pos);
if (pos >= 0 )
_tprintf(TEXT("%s\n"),pszCmdLine);
}
if (NULL != pszCmdLine)
delete [] pszCmdLine;
CloseHandle(hProcess);
}
return pos;
}
I found this on the internet.
-----------------------------------------------------------------------------------------
#ifndef UNICODE
# define TCHAR char
# define STRING char *
#else
# ifndef TCHAR
# define TCHAR wchar_t
# endif /* TCHAR */
# define STRING wchar_t *
#endif /* UNICODE */
int strpos( STRING haystack, STRING needle )
{
STRING pDest;
int position;
#ifdef DEBUG_VERBOSE
TCHAR lpBuf[1024];
#endif /* def DEBUG_VERBOSE */
#ifndef UNICODE
pDest = (STRING) strstr( haystack, needle );
#else
pDest = (STRING) wcsstr( haystack, needle );
#endif /* UNICODE */
if( pDest )
position = pDest - haystack;
else
{
#ifdef DEBUG_VERBOSE
# ifdef UNICODE
printf( L"strpos(): Could not find '%s' in '%s'.\tFAIL.", needle,
haystack );
# else
printf( "strpos(): Could not find '%s' in '%s'.\tFAIL.", needle,
haystack );
# endif /* def UNICODE */
#endif /* def DEBUG_VERBOSE */
return -1;
}
#ifdef DEBUG_VERBOSE
# ifdef UNICODE
printf( L"strpos(): Found '%s' at position: %d.\t\tOK.", needle,
position );
# else
printf( "strpos(): Found '%s' at position: %d.\t\tOK.", needle,
position );
# endif /* def UNICODE */
#endif /* def DEBUG_VERBOSE */
return position;
}
well in Debug mode.
Below is the function:
Here is the line:
pos=strpos(pszCmdLine,cmdLineStr); // in release mode this doesn't find
the match, but in debug mode it does
See strpos prototype below this
---------------------------------------------------------------------------------
int OnSelchangeProcesses(DWORD dwProcessID, STRING cmdLineStr)
{
DWORD dwSize;
PROCESS_BASIC_INFORMATION pbi;
NTQIP *lpfnNtQueryInformationProcess;
__PEB PEB;
__INFOBLOCK Block;
TCHAR *pszCmdLine = NULL;
int pos;
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ, FALSE, dwProcessID);
if (NULL != hProcess)
{
pbi.PebBaseAddress = (_PEB *) 0x7ffdf000;
// we'll default to the above address, but newer OSs might have
a different
// base address for the PEB
HMODULE hLibrary = GetModuleHandle(_T("ntdll.dll"));
if (NULL != hLibrary)
{
lpfnNtQueryInformationProcess = (NTQIP *)
GetProcAddress(hLibrary, "ZwQueryInformationProcess");
if (NULL != lpfnNtQueryInformationProcess)
(*lpfnNtQueryInformationProcess)(hProcess,
ProcessBasicInformation, &pbi, sizeof(pbi), &dwSize);
}
BOOL bSuccess = ReadProcessMemory(hProcess, pbi.PebBaseAddress,
&PEB, sizeof(PEB), &dwSize);
if (bSuccess != FALSE)
{
bSuccess = ReadProcessMemory(hProcess, (LPVOID)
PEB.dwInfoBlockAddress, &Block, sizeof(Block), &dwSize);
pszCmdLine = new TCHAR[Block.wMaxLength];
}
if (bSuccess != FALSE)
{
bSuccess = ReadProcessMemory(hProcess, (LPVOID)
Block.dwCmdLineAddress, pszCmdLine, Block.wMaxLength, &dwSize);
pos=strpos(pszCmdLine,cmdLineStr); // in release mode this doesn't find
the match, but in debug mode it does
printf("%d\n",pos);
if (pos >= 0 )
_tprintf(TEXT("%s\n"),pszCmdLine);
}
if (NULL != pszCmdLine)
delete [] pszCmdLine;
CloseHandle(hProcess);
}
return pos;
}
I found this on the internet.
-----------------------------------------------------------------------------------------
#ifndef UNICODE
# define TCHAR char
# define STRING char *
#else
# ifndef TCHAR
# define TCHAR wchar_t
# endif /* TCHAR */
# define STRING wchar_t *
#endif /* UNICODE */
int strpos( STRING haystack, STRING needle )
{
STRING pDest;
int position;
#ifdef DEBUG_VERBOSE
TCHAR lpBuf[1024];
#endif /* def DEBUG_VERBOSE */
#ifndef UNICODE
pDest = (STRING) strstr( haystack, needle );
#else
pDest = (STRING) wcsstr( haystack, needle );
#endif /* UNICODE */
if( pDest )
position = pDest - haystack;
else
{
#ifdef DEBUG_VERBOSE
# ifdef UNICODE
printf( L"strpos(): Could not find '%s' in '%s'.\tFAIL.", needle,
haystack );
# else
printf( "strpos(): Could not find '%s' in '%s'.\tFAIL.", needle,
haystack );
# endif /* def UNICODE */
#endif /* def DEBUG_VERBOSE */
return -1;
}
#ifdef DEBUG_VERBOSE
# ifdef UNICODE
printf( L"strpos(): Found '%s' at position: %d.\t\tOK.", needle,
position );
# else
printf( "strpos(): Found '%s' at position: %d.\t\tOK.", needle,
position );
# endif /* def UNICODE */
#endif /* def DEBUG_VERBOSE */
return position;
}