Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C/C++ - base address
Forum - C/C++ - base address

Avatar
gianluca (Normal User)
Pro


Messaggi: 103
Iscritto: 23/06/2008

Segnala al moderatore
Postato alle 15:13
Lunedì, 20/10/2008
come si trova in C il base address di un processo?

PM Quote
Avatar
eddiewrc (Member)
Expert


Messaggi: 560
Iscritto: 30/04/2006

Segnala al moderatore
Postato alle 16:18
Lunedì, 20/10/2008
bella domanda!

PM Quote
Avatar
gianluca (Normal User)
Pro


Messaggi: 103
Iscritto: 23/06/2008

Segnala al moderatore
Postato alle 16:52
Lunedì, 20/10/2008
loooooool:rotfl: dai, spero ke qualcuno lo sappia!XD

PM Quote
Avatar
pierotofy (Admin)
Guru^2


Messaggi: 6230
Iscritto: 04/12/2003

Segnala al moderatore
Postato alle 23:59
Lunedì, 20/10/2008
Testo quotato

Postato originariamente da eddiewrc:

bella domanda!



Evitiamo questi post inutili per favore.

Supponendo che tu ti riferisca ad un sistema Windows, dall'MSDN:

Codice sorgente - presumibilmente C++

  1. #include <windows.h>
  2. #include <tlhelp32.h>
  3. #include <tchar.h>
  4. #include <stdio.h>
  5.  
  6. //  Forward declarations:
  7. BOOL GetProcessList( );
  8. BOOL ListProcessModules( DWORD dwPID );
  9. BOOL ListProcessThreads( DWORD dwOwnerPID );
  10. void printError( TCHAR* msg );
  11.  
  12. void main( )
  13. {
  14.   GetProcessList( );
  15. }
  16.  
  17. BOOL GetProcessList( )
  18. {
  19.   HANDLE hProcessSnap;
  20.   HANDLE hProcess;
  21.   PROCESSENTRY32 pe32;
  22.   DWORD dwPriorityClass;
  23.  
  24.   // Take a snapshot of all processes in the system.
  25.   hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
  26.   if( hProcessSnap == INVALID_HANDLE_VALUE )
  27.   {
  28.     printError( TEXT("CreateToolhelp32Snapshot (of processes)") );
  29.     return( FALSE );
  30.   }
  31.  
  32.   // Set the size of the structure before using it.
  33.   pe32.dwSize = sizeof( PROCESSENTRY32 );
  34.  
  35.   // Retrieve information about the first process,
  36.   // and exit if unsuccessful
  37.   if( !Process32First( hProcessSnap, &pe32 ) )
  38.   {
  39.     printError( TEXT("Process32First") ); // show cause of failure
  40.     CloseHandle( hProcessSnap );          // clean the snapshot object
  41.     return( FALSE );
  42.   }
  43.  
  44.   // Now walk the snapshot of processes, and
  45.   // display information about each process in turn
  46.   do
  47.   {
  48.     printf( "\n\n=====================================================" );
  49.     _tprintf( TEXT("\nPROCESS NAME:  %s"), pe32.szExeFile );
  50.     printf( "\n-----------------------------------------------------" );
  51.  
  52.     // Retrieve the priority class.
  53.     dwPriorityClass = 0;
  54.     hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID );
  55.     if( hProcess == NULL )
  56.       printError( TEXT("OpenProcess") );
  57.     else
  58.     {
  59.       dwPriorityClass = GetPriorityClass( hProcess );
  60.       if( !dwPriorityClass )
  61.         printError( TEXT("GetPriorityClass") );
  62.       CloseHandle( hProcess );
  63.     }
  64.  
  65.     printf( "\n  Process ID        = 0x%08X", pe32.th32ProcessID );
  66.     printf( "\n  Thread count      = %d",   pe32.cntThreads );
  67.     printf( "\n  Parent process ID = 0x%08X", pe32.th32ParentProcessID );
  68.     printf( "\n  Priority base     = %d", pe32.pcPriClassBase );
  69.     if( dwPriorityClass )
  70.       printf( "\n  Priority class    = %d", dwPriorityClass );
  71.  
  72.     // List the modules and threads associated with this process
  73.     ListProcessModules( pe32.th32ProcessID );
  74.     ListProcessThreads( pe32.th32ProcessID );
  75.  
  76.   } while( Process32Next( hProcessSnap, &pe32 ) );
  77.  
  78.   CloseHandle( hProcessSnap );
  79.   return( TRUE );
  80. }
  81.  
  82.  
  83. BOOL ListProcessModules( DWORD dwPID )
  84. {
  85.   HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
  86.   MODULEENTRY32 me32;
  87.  
  88.   // Take a snapshot of all modules in the specified process.
  89.   hModuleSnap = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, dwPID );
  90.   if( hModuleSnap == INVALID_HANDLE_VALUE )
  91.   {
  92.     printError( TEXT("CreateToolhelp32Snapshot (of modules)") );
  93.     return( FALSE );
  94.   }
  95.  
  96.   // Set the size of the structure before using it.
  97.   me32.dwSize = sizeof( MODULEENTRY32 );
  98.  
  99.   // Retrieve information about the first module,
  100.   // and exit if unsuccessful
  101.   if( !Module32First( hModuleSnap, &me32 ) )
  102.   {
  103.     printError( TEXT("Module32First") );  // show cause of failure
  104.     CloseHandle( hModuleSnap );           // clean the snapshot object
  105.     return( FALSE );
  106.   }
  107.  
  108.   // Now walk the module list of the process,
  109.   // and display information about each module
  110.   do
  111.   {
  112.     _tprintf( TEXT("\n\n     MODULE NAME:     %s"),   me32.szModule );
  113.     _tprintf( TEXT("\n     Executable     = %s"),     me32.szExePath );
  114.     printf( "\n     Process ID     = 0x%08X",         me32.th32ProcessID );
  115.     printf( "\n     Ref count (g)  = 0x%04X",     me32.GlblcntUsage );
  116.     printf( "\n     Ref count (p)  = 0x%04X",     me32.ProccntUsage );
  117.     printf( "\n     Base address   = 0x%08X", (DWORD) me32.modBaseAddr );
  118.     printf( "\n     Base size      = %d",             me32.modBaseSize );
  119.  
  120.   } while( Module32Next( hModuleSnap, &me32 ) );
  121.  
  122.   CloseHandle( hModuleSnap );
  123.   return( TRUE );
  124. }
  125.  
  126. BOOL ListProcessThreads( DWORD dwOwnerPID )
  127. {
  128.   HANDLE hThreadSnap = INVALID_HANDLE_VALUE;
  129.   THREADENTRY32 te32;
  130.  
  131.   // Take a snapshot of all running threads  
  132.   hThreadSnap = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );
  133.   if( hThreadSnap == INVALID_HANDLE_VALUE )
  134.     return( FALSE );
  135.  
  136.   // Fill in the size of the structure before using it.
  137.   te32.dwSize = sizeof(THREADENTRY32 );
  138.  
  139.   // Retrieve information about the first thread,
  140.   // and exit if unsuccessful
  141.   if( !Thread32First( hThreadSnap, &te32 ) )
  142.   {
  143.     printError( TEXT("Thread32First") ); // show cause of failure
  144.     CloseHandle( hThreadSnap );          // clean the snapshot object
  145.     return( FALSE );
  146.   }
  147.  
  148.   // Now walk the thread list of the system,
  149.   // and display information about each thread
  150.   // associated with the specified process
  151.   do
  152.   {
  153.     if( te32.th32OwnerProcessID == dwOwnerPID )
  154.     {
  155.       printf( "\n\n     THREAD ID      = 0x%08X", te32.th32ThreadID );
  156.       printf( "\n     Base priority  = %d", te32.tpBasePri );
  157.       printf( "\n     Delta priority = %d", te32.tpDeltaPri );
  158.     }
  159.   } while( Thread32Next(hThreadSnap, &te32 ) );
  160.  
  161.   CloseHandle( hThreadSnap );
  162.   return( TRUE );
  163. }
  164.  
  165. void printError( TCHAR* msg )
  166. {
  167.   DWORD eNum;
  168.   TCHAR sysMsg[256];
  169.   TCHAR* p;
  170.  
  171.   eNum = GetLastError( );
  172.   FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
  173.          NULL, eNum,
  174.          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  175.          sysMsg, 256, NULL );
  176.  
  177.   // Trim the end of the line and terminate it with a null
  178.   p = sysMsg;
  179.   while( ( *p > 31 ) || ( *p == 9 ) )
  180.     ++p;
  181.   do { *p-- = 0; } while( ( p >= sysMsg ) &&
  182.                           ( ( *p == '.' ) || ( *p < 33 ) ) );
  183.  
  184.   // Display the message
  185.   _tprintf( TEXT("\n  WARNING: %s failed with error %d (%s)"), msg, eNum, sysMsg );
  186. }



http://msdn.microsoft.com/en-us/library/ms686701(VS.85).aspx

Attenzione che questo codice non è conforme allo standard ANSI.


Il mio blog: https://piero.dev
PM Quote
Avatar
gianluca (Normal User)
Pro


Messaggi: 103
Iscritto: 23/06/2008

Segnala al moderatore
Postato alle 0:40
Martedì, 21/10/2008
perfetto, sembra ke funzioni, ma nn so dove mettere il processo da scannerizzare! looooooool

Ultima modifica effettuata da gianluca il 21/10/2008 alle 0:55
PM Quote
Avatar
gioser (Normal User)
Pro


Messaggi: 111
Iscritto: 03/10/2008

Segnala al moderatore
Postato alle 9:05
Martedì, 21/10/2008
Il codice di MSDN elenca i base address di tutti i moduli di un processo.

Questi indirizzi sono riferiti allo spazio di indirizzamento del processo.

Lo spazio di indirizzamento di un processo è indipendente da processo a processo e dipende dalla gestione della memoria virtuale del sistema operativo.

Tu cosa intendevi per Base Address di un Processo? :)


PM Quote
Avatar
gianluca (Normal User)
Pro


Messaggi: 103
Iscritto: 23/06/2008

Segnala al moderatore
Postato alle 13:30
Martedì, 21/10/2008
intendevo la stessa cs, ma a me serviva sapere il base address di un solo processo XD nn di tt! cmq poko importante, provo ad adattarlo a quello ke mi serve, se avro dei problemi(cosa sicura) vi kiedero! grazie 1000

PM Quote