Enumerating All Modules For A Process
Posted: Sun Jul 14, 2013 9:32 pm
I am trying to replicate this, and have it safe to call with the number of modules changing.
Here is the code I am using, I am unsure if I am replicating this properly. It returns just the process file name, which is due to a improper module handle. I am just trying to list all of the modules (.dll's) that are loaded with the injected process at any time. I am not very good at converting over C++ code.
Code: Select all
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682621(v=vs.85).aspx

Code: Select all
Procedure PrintModules(Parameter)
Dim hMods(1024)
hProcess = GetCurrentProcess_()
cbNeeded.l
If OpenLibrary(0, "Psapi.dll")
EnumProcessModules = GetFunction(0, "EnumProcessModules")
GetModuleFileName = GetFunction(0, "GetModuleFileNameExA")
If EnumProcessModules And GetModuleFileName
CallFunctionFast(EnumProcessModules, hProcess, @hMods, SizeOf(hMods), @cbNeeded)
For i = 0 To cbNeeded / SizeOf(hMods)
Name.s = Space(255)
CallFunctionFast(GetModuleFileName, hProcess, hMods(i), @Name, Len(Name))
PrintN(Name)
Next
Repeat
Delay(10)
ForEver
EndIf
EndIf
EndProcedure
ProcedureDLL AttachProcess(Instance)
OpenConsole()
CreateThread(@PrintModules(), 0)
EndProcedure
ProcedureDLL DetachProcess(Instance)
EndProcedure
ProcedureDLL AttachThread(Instance)
EndProcedure
ProcedureDLL DetachThread(Instance)
EndProcedure