Aufrufparameter von Fremdprogrammen herausfinden
-
Hi,
Kennt sich jemand mit dem Environment unter 64bit Windows aus?
Hintergrund ist folgender:
Es geht um eine Funktion, die unter Angabe der Pid die Aufrufparameter beliebiger Prozesse ermittelt. Leider funktioniert die Funktion zwar unter 32bit Windows, nicht jedoch unter 64bit.void ExtProcInfo::GetProcessCmdLine(DWORD pid,char* sCmdLine,int sizeCmdLine)
{
LPBYTE lpPos=NULL;
DWORD dwBytesRead;
MEMORY_BASIC_INFORMATION mbi;
HANDLE hProcess=NULL;try {
if(sizeCmdLine<=0)
throw BASEException("size of command line buffer is 0");
InitBuffer();
EnableTokenPrivilege(SE_DEBUG_NAME);
if(pid==0) {
strncpy(sCmdLine,"System Idle Process",sizeCmdLine);
sCmdLine[sizeCmdLine-1]='\0';
return;
}
sCmdLine[0]='\0';
if((hProcess=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_QUERY_INFORMATION,FALSE,pid))==NULL) {
char sError[100];
sError[sizeof(sError)-1]='\0';
snprintf(sError,sizeof(sError),"failed to open process - pid: %lu",pid);
throw BASEException(sError);
}
if(VirtualQueryEx(hProcess,BLOCK_ADDRESS,&mbi,sizeof(mbi))==0)
throw BASEException("virtual query ex failed");
if(IsBadReadPtr(mbi.BaseAddress,1))
throw BASEException("bad read pointer 1");
if(!ReadProcessMemory(hProcess,mbi.BaseAddress,(LPVOID)m_lpBuffer,m_sysinfo.dwPageSize,&dwBytesRead))
throw BASEException("reading process memory failed");
lpPos=m_lpBuffer+((DWORD)BLOCK_ADDRESS-(DWORD)mbi.BaseAddress);
if(IsBadReadPtr(lpPos,1))
throw BASEException("bad read pointer 2");
lpPos=lpPos+(wcslen((LPWSTR)lpPos)+1)*sizeof(WCHAR);
lpPos=(LPBYTE)ALIGN_DWORD((DWORD)lpPos);
if(IsBadReadPtr(lpPos,1))
throw BASEException("bad read pointer 3");
lpPos=lpPos+(wcslen((LPWSTR)lpPos)+1)*sizeof(WCHAR);
if(*lpPos=='\0')
lpPos+=sizeof(WCHAR);
if(IsBadReadPtr(lpPos,1))
throw BASEException("bad read pointer 4");
sCmdLine[sizeCmdLine-1]='\0';
if(WideCharToMultiByte(CP_ACP,0,(LPWSTR)lpPos,-1,sCmdLine,sizeCmdLine-1,NULL,NULL)<=0)
sCmdLine[0]='\0';
if(sCmdLine[0]=='\0')
throw BASEException("command line is empty");
}
catch(BASEException &e) {
if(hProcess!=NULL)
CloseHandle(hProcess);
char sError[100];
snprintf(sError,sizeof(sError),"failed to get process command line: %s,error %lu",e.GetMsg(),GetLastError());
sError[sizeof(sError)-1]='\0';
BASEException ee(sError,"ExtProcInfo::GetProcessCmdLine");
if(strlen(e.GetFkt())>0)
ee.SetFkt(e.GetFkt());
throw ee;
}
CloseHandle(hProcess);
}
-
sollte das nicht nach WinAPI?
und ich denke, ohne CodeTags wird sich das niemand anschauen!
-
Hat sich mittlerweile eh erledigt, danke
-
Dieser Thread wurde von Moderator/in HumeSikkins aus dem Forum C++ in das Forum WinAPI verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
leachim schrieb:
Hat sich mittlerweile eh erledigt, danke
Es wäre sinnvoll, den Grund auch posten
. Nur so für die Allgemeinheit
.
-
Grund: Ich bin auf WMI - WIN32_PROCESS class umgestiegen
