gm_process - Process manipulation for Winders

I would make this cross-platform but yknow, no access to a linux machine, they manage processes very differently, etc etc.
Source[SUB](behold horrible code)[/SUB]
Quick struct links: PROCESSENTRY32 PROCESS_MEMORY_COUNTERS
Usage:



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.


Process metatable:



: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.


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: http://puu.sh/FBSv

[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:



July 02: http://puu.sh/Funb
  Initial Release
July 03: [http://puu.sh/FBSv](http://puu.sh/Funb)
  Fixed crash with GetPath/GetName.


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. http://sourceforge.net/projects/sigar/files/

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?

Maybe you can tell them their antivirus is outdated or something.

Everything I said in the OP shows ways it can be used.

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.

edit:
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.

A injected dll can circumvent this pretty easily.

Of course, but you do only need to catch people out once to be able to ban them.

snip