Search code examples
c#processanti-cheat

How to access MainModule of a game with anti-cheat?


About a month ago, I wrote myself a python script to log running program and its other related information automatically and I used a C# program to get the information.

I downloaded a game today and when I ran it, I got a System.ComponentModel.Win32Exception error dialog.

I opened Visual Studio to debug where I get the errors. I get the error when I try to access Process.MainModule.

When I got an error while writing that program, I searched on the internet for answers and I made the C# program 64 bit to access 64 bit processes and request admin privileges to access processes running as admin. All the questions I could find about errors in MainModule are related to these 2 problems.

The game is using Easy Anti Cheat and I guess that might be preventing me from accessing the process.

I also used WMI to try to get at least the file path so I can get some info from FileVersionInfo.GetVersionInfo function but wmi didn't return file path or command line either.

I was using psutil in python to get the command line because I couldn't get that from C# without using WMI so I tried to get some information from there, but it errors on anything that I try to do, I can't even get the filename whereas I could get that from C#.

The related part of the C# code is

int pid; //I get this from command line arguments
Process p;
p = Process.GetProcessById(pid);
var filename = p.MainModule.FileName ?? "";

Is there a way I can get at least the exe path so I can use FileVersionInfo without triggering the anti-cheat program and potentially get myself banned? Even the Windows 10 task manager doesn't show the command line (But it opens the file folder when I right click the game and select open file path).


Solution

  • I found a working example in C++ and built an executable with it to get the path of the process and called FileVersionInfo.GetVersionInfo with the returned path to get the information I wanted.