17. maj 2006 - 23:31
Der er
3 kommentarer
open process virker ikke
Er det ikke muligt at bruge openprocess på denne måde ? Jeg vil bare læse i med process api'en i windows. long i =1234; // resolve dette process id DWORD* m_pids= NULL;; DWORD m_count; DWORD m_current; m_current = (DWORD)-1; m_count = 0; DWORD nalloc = 1024; do { delete [] m_pids; m_pids = new DWORD [nalloc]; if ( EnumProcesses(m_pids, nalloc*sizeof(DWORD), &m_count) ) { m_count /= sizeof(DWORD); m_current = 1; // important: skip IDLE process with pid=0. } } while (nalloc <= m_count); DWORD pid= m_pids && m_current < m_count ? m_pids[m_current++] : 0; HANDLE hProc = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pid ); cout << "hProc = " << hProc << endl; long a_addr=1; SIZE_T bytesread =0; ReadProcessMemory( hProc, 0, &i, 4, &bytesread ); cout << bytesread << endl;
Annonceindlæg fra Novataris
Vejen til devops med Bavarian Nordic
Bavarian Nordics vækst blev starten på et DevOps-samarbejde med Novataris for hurtigt at kunne tilpasse IT-organisation til forretningen.
7. december 2023
Dette giver success for flere af mine processer: #include <iostream> #include <windows.h> #include <psapi.h> using namespace std; int main() { // resolve dette process id DWORD* m_pids= NULL;; DWORD m_count; DWORD m_current; m_count = 0; DWORD nalloc = 1024; do { delete [] m_pids; m_pids = new DWORD [nalloc]; if( EnumProcesses(m_pids, nalloc*sizeof(DWORD), &m_count)) { m_count /= sizeof(DWORD); } } while (nalloc <= m_count); DWORD pid; for(m_current = 0; m_current < m_count; m_current++) { pid = m_pids[m_current]; HANDLE hProc = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pid ); if(hProc) { long a_addr= 0x40000; long i = 0; SIZE_T bytesread = 0; if(ReadProcessMemory( hProc, &a_addr, &i, 4, &bytesread)) { cout << "Success: " << bytesread << ", " << pid << ", " << i << endl; } } } }
Fandt kom op med denne løsning long i =1234; long a_addr=1; SIZE_T bytesread=0; long buffer; ReadProcessMemory( GetCurrentProcess(), &i, &buffer , 4, &bytesread ); cout << "buffer : " << buffer << endl;