Process List AND Modules List 64 bit (HELP!)
Posted: Tue Jun 01, 2010 9:07 pm
I am porting my 32 bit apps up to 64 bit. One of the things I am having problems with is getting ahold of the Processes and then the Modules of that process. Note the code below:
this is similar to my own code and works. However, I need to be able to list the Modules for each Process and their Base Address in memory. This needs to work with 64 bit purebasic in 64 bit OS.
the following info would be helpful.
[program name] [PID][Handle]
then modules of that program below it like this:
[program][base address of program]
[module 1][base address of module 1]
[etc.][etc.]
traversing through each module within that program (modules such as ntdll.dll, etc.)
my old module code looked like this but it doesn't work... hWnd is handle to the process in question.
At any rate, a tight, small code or procedure that outlines the running processes (and their PID and Handle) and then another tight procedure outlining the modules and thier base address within memory of a particular process would be appreciated. it needs to run on 64 bit OS windows and work ON 64 bit running processes.
thx-
best,
Mike
Code: Select all
#NbProcessesMax=10000
Global Dim ProcessesArray.l(#NbProcessesMax)
Procedure GetProcessList()
If OpenLibrary(0, "psapi.dll")
EnumProcesses = GetFunction(0, "EnumProcesses")
EnumProcessModules = GetFunction(0, "EnumProcessModules")
GetModuleBaseName = GetFunction(0, "GetModuleBaseNameA")
CallFunctionFast(EnumProcesses, ProcessesArray(), #NbProcessesMax, @nProcesses)
For k = 0 To nProcesses >> 2
hProcess = OpenProcess_(#PROCESS_QUERY_INFORMATION | #PROCESS_VM_READ, #False, ProcessesArray(k))
If hProcess
CallFunctionFast(EnumProcessModules, hProcess, @BaseModule, 4, @cbNeeded)
Prozess$ = Space(cbNeeded)
CallFunctionFast(GetModuleBaseName, hProcess, BaseModule, @Prozess$, cbNeeded)
If Len(Prozess$) <> 0 ;z.B. System
;AddGadgetItem(Gadget, -1, Prozess$ + Chr(10) + Str(ProcessesArray(k)))
Debug Prozess$+" "+Str(ProcessesArray(k))
EndIf
CloseHandle_(hProcess)
EndIf
Next
CloseLibrary(0)
EndIf
EndProcedure
GetProcessList()the following info would be helpful.
[program name] [PID][Handle]
then modules of that program below it like this:
[program][base address of program]
[module 1][base address of module 1]
[etc.][etc.]
traversing through each module within that program (modules such as ntdll.dll, etc.)
my old module code looked like this but it doesn't work... hWnd is handle to the process in question.
Code: Select all
; ----------------------------------------
;Get Base Address of .exe or .dll
; ----------------------------------------
GetBaseAddress:
;{
baseaddress = 0 ; reset baseaddress
app2 = OpenProcess_(#PROCESS_ALL_ACCESS,Null,hWnd)
hProcess = app2
ws_psapi_lib = 1
ws_psapi_h.l = OpenLibrary(ws_psapi_lib,"PSAPI.DLL")
*ws_EnumProcessModules = GetFunction(ws_psapi_lib,"EnumProcessModules")
*ws_GetModuleBaseNameA = GetFunction(ws_psapi_lib,"GetModuleBaseNameA")
#PROCESS_QUERY_INFORMATION = $400
#PROCESS_VM_READ = $10
Dim aProcesses.l(1024)
Dim hMods.l(1024)
If OpenLibrary(1, "Psapi.dll") = #Null
MessageRequester("Problem!", "Could not load the 'Paspi.dll' library.",#PB_MessageRequester_Ok)
End
EndIf
buffer$=Space(4024)
hProcess = OpenProcess_(#PROCESS_QUERY_INFORMATION | #PROCESS_VM_READ, #False, hWnd)
If CallFunction(1, "EnumProcessModules", hProcess, hMods(), 4096, @cbNeeded)
Debug cbNeeded/4-1
For i = 0 To cbNeeded/4-1
If CallFunction(1, "GetModuleFileNameExA" ,hProcess, hMods(i), @buffer$, 4024)
sModName$=Space(#MAX_PATH)
CallFunction (1,"GetModuleBaseNameA" ,hProcess, hMods(i), @sModName$, Len(sModName$))
;Debug baseaddress
Debug sModName$
Delay(1000)
If UCase(sModName$) = UCase(File$)
baseaddress=hmods(i) ; store base address of File$ to variable baseaddress
Debug baseaddress
Debug sModName$
EndIf
If UCase(sModName$) = UCase(ProgramName$)
CopyPath$=buffer$
Dir$= GetTemporaryDirectory()
Result = CopyFile(CopyPath$, Dir$+"Copy.dll")
EndIf
EndIf
Next
EndIf
CloseLibrary(ws_psapi_lib) thx-
best,
Mike