1

Lets say I have a folder called "Games". And I have all my games saved in that particular folders.

I want to extract all the binaries from all those folders which launch my games. Here I cannot use any launchers: Eg. Steam / origin etc.

So far I have managed to get all the binaries existing within that folder. But those all are random binaries mixed up with the actual game binaries.

Any way to extract game only binaries?

    '''
Finding binaries for games 
Eliminating other types of binaries, eg: uninstall.exe etc
''' 
def getStandalone(filePath = 'D:\\Games\\'):
    pattern = "*.exe"
    pattern2 = "unin*"
    for  root, dir, files in os.walk(filePath):
        for file in files:
            if(
                fnmatch.fnmatch(file, pattern) and 
                fnmatch.fnmatch(file, pattern) != 
                fnmatch.fnmatch(file, pattern2)
            ):
                print(file)

# print(getStandalone())

I was able to remove "uninstall" binaries since most of them start with unin--

But that's a very dirty way of doing this, and I would rather like to extract game binaries than remove all the other stuff.

One thing popped up in my mind. Windows registry. But I have no idea how to go about "Finding Games" in the registry. I have a bunch of old games copied directly from CDs. And they are not even really installed. They just exist on my drive. So how do I go about finding those?

ScreX
  • 43
  • 1
  • 7
  • are the games in sub-folders inside the Games folder? – marxmacher Feb 02 '20 at 11:18
  • Can you elaborate *which* `.exe` files you want? There can be multiple `.exe` files in a single game directory, the program will have no way to know which one you want, unless you specify the name. However, keep in mind, many games don't use the game's own name for the executables. – Chase Feb 02 '20 at 11:26
  • @marxmacher Yes the games are in subfolders inside the Games Folder. – ScreX Feb 03 '20 at 13:13
  • @Chase I wan the `.exe` file which launches the game itself. Yes I am aware there can be multiple exe files. Thats the issue I am try to solve. Finding the **right** `.exe` file for the game. – ScreX Feb 03 '20 at 13:15
  • if the sub folders and the executable names are same then its rather easy. iterate over the list of folders and use the folder name variable with the .exe suffix to get the game executables. might be even easier in bash – marxmacher Feb 03 '20 at 16:55

3 Answers3

0

The dumbest approach is to predefine a list with known executable game names and use that to filter the results in files. It might take longer to build a respectful list but your results will be very precise.

A more clever approach would be to go through each element in files, list the DLLs loaded by that application (and perhaps list the DLLs of those DLLs) and discard the elements that don't use DLLs from DirectX or OpenGL. However, this approach might produce some false-negatives: applications that are actually games but do not load these libraries directly will be flagged as non-games.

I don't think installers leave a special/standard key behind in the registry. The PE format also doesn't seem to carry a special flag to help differentiate games from regular binaries of non-game applications.

In the end, I believe that a good solution for this problem will probably use multiple strategies to filter out game candidates. I simply offer something for you to start from.

karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • Thanks I will look into this. This seems like a daunting task atm. – ScreX Feb 03 '20 at 13:17
  • Welcome to Stackoverflow, there is no need for "thank you" messages here. We thank people by up-voting their answers when they are helpful. Also, feel free to click on the checkbox near an answer to select it as the official problem solver. By doing these things you will be helping future visitors. – karlphillip Feb 03 '20 at 14:42
  • 1
    I selected the answer, but can't upvote since I am new :p – ScreX Feb 11 '20 at 11:40
0

You should use a list of known game executable files. As stated, many games can embed several executable files. Then simply check if you have any file matching this list.

Registry keys are not fully reliable. Games might just be copied in a portable way, just like any other portable software.

VincentRG
  • 94
  • 4
  • Is there any list of known game executable files? Floating around on github? etc – ScreX Feb 03 '20 at 13:15
  • I don't know if there is something up-to-date and well-populated. Tried to search on Google, I just ended on Reddit for a post with someone trying to do that, but it seems outdated and even not containing most popular ones. – VincentRG Feb 03 '20 at 13:52
0

If you just want the .exe files you can do this, which should be fast enough and also clean.

Note : There's no guarantee there will only be one .exe file in the directory. This will find all of them. Since you mentioned you don't want the uninstall.exe explicitly, you can definitely add a conditional check to remove just that, but if you want to remove additional .exe files, you'll need additional parameters.

import os
'''
Finding binaries for games 
Eliminating other types of binaries, eg: uninstall.exe etc

''' 
def getStandalone(filePath = 'D:\\Games\\'):
    for dir in os.listdir(filePath):
        if os.path.isdir(os.path.join(filePath, dir)):
            bins = [file for file in os.listdir(os.path.join(filePath, dir)) if file.endswith('.exe') and not file.startswith('unin')]
            print(bins)

You can also simply that whole thing into a single list comprehension-

[file for dir in os.listdir(os.getcwd()) if os.path.isdir(os.path.join(os.getcwd(), dir)) for file in os.listdir(os.path.join(os.getcwd(), dir)) if file.endswith('.exe') and not file.startswith('unin')]
Chase
  • 5,315
  • 2
  • 15
  • 41