I would make this cross-platform but yknow, no access to a linux machine, they manage processes very differently, etc etc.
[URL="http://codepad.org/KaZEgAA8"]Source[/URL][SUB](behold horrible code)[/SUB]
Quick struct links: [URL="http://msdn.microsoft.com/en-us/library/windows/desktop/ms684839%28v=vs.85%29.aspx"]PROCESSENTRY32[/URL] [URL="http://msdn.microsoft.com/en-us/library/windows/desktop/ms684877%28v=vs.85%29.aspx"]PROCESS_MEMORY_COUNTERS[/URL]
Usage:
[code]
process.GetAll()
Returns a table of processes. Lua replication of the PROCESSENTRY32 struct.
process.GetByPID(id)
Returns a new Process userdata or nil if failed.
[/code]
Process metatable:
[code]
:Kill(ExitCode)
Terminates the process, optionally with the exit code.
:GetPath()
Returns the full path to the process
:GetName()
Returns the name of the process(like calc.exe)
:GetModuleInfo()
Returns a list of modules(usually DLLs) that are loaded into the process.
:GetMemoryInfo()
Returns Lua replication of the PROCESS_MEMORY_COUNTERS struct.
:Close()
Closes the process handle, rendering the userdata useless.
[/code]
After I finish it, I will clean up that god awful source code. I just noticed it has remnants of an old project which I'll also clean up later.
Download: [URL="http://puu.sh/Funb"]http://puu.sh/FBSv[/URL]
[editline]3rd July 2012[/editline]
I'll add process.Launch(commandline) later and methods to get STDIN/STDOUT/STDERR and read/writing from memory once I iron out this version.
[editline]3rd July 2012[/editline]
Possibly I'll add access to PDH too(so you can get things like CPU usage and I/O usage)
Update log:
[code]
July 02: [URL]http://puu.sh/Funb[/URL]
Initial Release
July 03: [URL="http://puu.sh/Funb"]http://puu.sh/FBSv[/URL]
Fixed crash with GetPath/GetName.
[/code]
I recommend using SIGAR API. It's a library for obtaining various kinds of information from the OS like CPU usage. It's a bit complicated though. If you need help using it, I'm available. It has support for multiple OSes. It is licensed under Apache 2. [url]http://sourceforge.net/projects/sigar/files/[/url]
[QUOTE=Map in a box;36601730]
(*: Crashes game if ran twice, and sometimes corrupts Lua stack. If anyone can tell me why, please speak up)[/QUOTE]
I'm surprised it doesn't crash on the first run. LPSTR is a typedef of char*. You're declaring a pointer to char but not initializing it.
Use this instead
[cpp]char Buffer[MAX_PATH];
if(GetModuleBaseName(handle, 0, Buffer, MAX_PATH)){
Lua()->Push(Buffer);
return 1;
}[/cpp]
Same for GetPath.
I was at first I believe but I got some compile errors. I'll try using that.
[editline]3rd July 2012[/editline]
That fixed it! -snip- Updating OP
What sort of use would this module have?
[QUOTE=Remscar;36611392]What sort of use would this module have?[/QUOTE]
Maybe you can tell them their antivirus is outdated or something.
[QUOTE=Remscar;36611392]What sort of use would this module have?[/QUOTE]
Everything I said in the OP shows ways it can be used.
[QUOTE=Map in a box;36611766]Everything I said in the OP shows ways it can be used.[/QUOTE]
Ways a module can be used != uses for a module
IMO this module has absolutely zero usage. There is no reason to use it.
Uh, I think he means real world examples.
Which I can't think of any, besides maybe checking if a process is using to much memory and possibly kill it. But then again, this should be handled outside of a game.
[b]edit:[/b]
tits, Remscar got it.
You could force all clients to have it installed and use GetModuleInfo() to see if they've attached any nasty DLL's to GMod :wink:
Of course, at the sacrifice of your entire userbase.
It's just for private use. I don't expect this to be used on a server. I didn't think I'd be told "THIS MODULE HAS NO USAGE AT ALL" as I expected people just to use it like the steamworks module, for fun.
[QUOTE=Not Flapadar;36613635]You could force all clients to have it installed and use GetModuleInfo() to see if they've attached any nasty DLL's to GMod :wink:
Of course, at the sacrifice of your entire userbase.[/QUOTE]
A injected dll can circumvent this pretty easily.
[QUOTE=Nexus435;36616508]A injected dll can circumvent this pretty easily.[/QUOTE]
Of course, but you do only need to catch people out once to be able to ban them.
snip
Sorry, you need to Log In to post a reply to this thread.