-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenginedetect.py
519 lines (454 loc) · 16.3 KB
/
enginedetect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
# enginedetect.py - a dirty hacky script to detect game engines
# By Yellowberry
# https://github.com/YellowberryHN/enginedetect
import argparse
import gc
import json
import mmap
import os
import platform
import struct
import zipfile
args = {"engine": "", "dir": "", "game": "", "verbose": 0}
if __name__ == "__main__":
if platform.system() != "Windows":
print("WARNING: This script is designed for a Windows environment and Windows games! You may run into issues.")
input("Press ENTER to run anyway!")
parser = argparse.ArgumentParser()
parser.add_argument("-e", metavar="ENGINE", help="filter specific game engines")
parser.add_argument("-d", metavar="DIR", help="specifies directory to scan, defaults to working directory")
parser.add_argument("-g", metavar="GAME", help="scan directory GAME inside of DIR as a game")
parser.add_argument("-v", help="display verbose info", action="count")
arg = parser.parse_args()
args = {
"engine": arg.e if arg.e else "",
"dir": arg.d if arg.d else "",
"game": arg.g if arg.g else "",
"verbose": arg.v if arg.v else 0
}
engineDict = {} # Used for counting games
gameDir = []
filterEngine = args["engine"] # Engine to filter results
def inc_engine_counter(name):
if not name in engineDict.keys():
engineDict[name] = 0
engineDict[name] += 1
def in_list(string, sList=None): # return all string in list that match
if not sList: sList = gameDir
return [i for i in sList if i.lower() == string.lower()]
def in_list_starts(string, sList=None): # return all string in list that match
if not sList: sList = gameDir
return [i for i in sList if i.lower().startswith(string.lower())]
def in_list_ends(string, sList=None):
if not sList: sList = gameDir
return [i for i in sList if i.lower().endswith(string.lower())]
def in_list_loose(string, sList=None): # return all string in list that match
if not sList: sList = gameDir
return [i for i in sList if string.lower() in i.lower()]
def pj(*args): # path join
return "/".join(list(args))
def dotClean(gameDir):
if any(in_list_starts(".")):
for x in in_list_starts("."):
gameDir.remove(x)
return gameDir
def recurseDir(dirName, gameDir): # recurses through directories to find one that actually has stuff in it.
gameDir = dotClean(gameDir)
i = 0
while len(gameDir) < 2:
if i == 5 or len(gameDir) < 1:
return (dirName, gameDir)
if len(gameDir) == 1 and os.path.isdir(pj(dirName,gameDir[0])):
dirName = pj(dirName,gameDir[0])
gameDir = dotClean(os.listdir(dirName)) # If directory only has one folder, assume game data is in here.
i += 1
return (dirName, gameDir)
# Game detection
def detectGame(dirName, fastParse=False):
# fastParse: Parse extremely quickly, just based on files and folders (highly discouraged)
global gameDir
gameName = dirName
dirName = pj(args["dir"],dirName) if args["dir"] else dirName
gameDir = os.listdir(dirName)
engineType = "Unknown"
engineSet = False # Used for engines which might trigger multiple detections
subGames = [] # Used for GoldSrc
dirName, gameDir = recurseDir(dirName, gameDir)
if any(in_list("application_info.json")):
dirName = pj(dirName,"content")
gameDir = os.listdir(dirName) # Discord Games
if len(gameDir) < 1:
return
if any(in_list("game.pak")):
ver_num = [0, 0]
with open(pj(dirName,"game.pak"), "rb") as file:
file.read(8) # skip things we don't know
old_ind = 133 # hardcoded beginning
while True:
begin_ind = file.read(1)[0]
if begin_ind - 1 != old_ind:
old_ind = begin_ind
break
file.read(2)
old_ind = begin_ind
file.read(1) # go away 00
if old_ind == 8:
file.read(7) # we don't need the other shit
# Check pak version number
ver_num[0] = int(struct.unpack("<H",file.read(2))[0]/16)
file.read(2)
ver_num[1] = int(struct.unpack("<H",file.read(2))[0]/16)
file.read(2)
if ver_num[0] == ver_num[1]:
engineType = "Raycasting Game Maker"
if ver_num[0] == 25: engineType += " 4"
elif ver_num[0] == 31: engineType += " 5"
file.close()
elif any(in_list_starts("data.")):
if any(in_list("Data.wolf")):
engineType = "WOLF RPG Editor"
elif any(in_list("data.xp3")):
engineType = "Kirikiri Z"
else:
dataFiles = [in_list_starts("data.")]
for g in dataFiles:
with open(pj(dirName,g[0]),"rb") as fi:
if fi.read(4) == b'FORM':
engineType = "GameMaker Studio"
fi.close()
elif any(in_list("Common.dll")):
with open(pj(dirName,"Common.dll"), "r+b") as f:
mmw = mmap.mmap(f.fileno(), 0)
f.close()
if mmw.find('Visual RPG Studio'.encode('utf-16be')) > 0:
engineType = "Visual RPG Studio"
elif any(in_list("libpanda.dll")):
engineType = "Panda3D"
engineSet = True
elif any(in_list_loose("ChromeEngine")): # Chrome Engine DLLs
engineType = "Chrome Engine"
engineSet = True
elif any(in_list_ends(".RPG")):
dataFiles = [in_list_ends(".RPG")]
for g in dataFiles:
with open(pj(dirName,g[0]),"rb") as fi:
if fi.read(12) == b'RPG Maker 95':
engineType = "RPG Maker 95"
fi.close()
elif any(in_list_ends(".rpf")):
engineType = "RAGE"
elif any(in_list_ends(".pck")):
engineType = "Godot"
elif any(in_list_ends(".grp")):
engineType = "Build Engine"
elif any(in_list("nw.pak")):
if any(in_list("package.nw")) and zipfile.is_zipfile(pj(dirName,"package.nw")):
with zipfile.ZipFile("package.nw","r") as nwpak:
if any(in_list("data.json",nwpak.namelist())):
engineType = "Construct 3"
else:
engineType = "Construct 2"
try:
with open(pj(dirName,"package.json"), "r") as file:
jn = json.load(file)
if jn["name"] == "KADOKAWA/RPGMV":
engineType = "RPG Maker MV"
else:
engineType = "nw.js"
except OSError:
engineType = "nw.js"
elif any(in_list("resources.pak")):
if any(in_list("package.nw")):
engineType = "nw.js"
else:
try:
with open(pj(dirName,"package.json"), "r") as file:
jn = json.load(file)
if jn["name"] == "rmmz-game":
engineType = "RPG Maker MZ"
else:
engineType = "nw.js"
except OSError:
engineType = "Electron [Web App]"
elif any(in_list("renpy")):
engineType = "Ren'Py"
engineSet = True
elif any(in_list("ID1")):
# I should check for .pak files, but some only have the folder as compat
engineType = "id Tech 2 [Quake]"
elif any(in_list("baseq2")):
# I should check for .pk2 files, but some only have the folder as compat
engineType = "id Tech 2 [Quake 2]"
elif any(in_list("baseq3")):
# I should check for .pk3 files, but some only have the folder as compat
engineType = "id Tech 3 [Quake 3]"
elif any(in_list("base")):
eee = in_list("base")[0]
if os.path.isdir(pj(dirName,eee)):
dataDir = os.listdir(pj(dirName,eee))
if any(in_list_ends(".pk4",dataDir)):
engineType = "id Tech 4"
elif any(in_list("3DRad_res")):
engineType = "3D Rad"
elif any(in_list("Program")) and any(in_list("Songs")):
engineType = "StepMania"
elif any(in_list("Adobe AIR")):
if any(in_list_ends(".swf")): # that's a pretty fucking bold assumption, fix this later.
engineType = "Adobe AIR"
elif any(in_list("packages")) and os.path.isdir(pj(dirName,"packages")):
if any(in_list("textures",os.listdir(pj(dirName,"packages")))) and os.path.isdir(pj(dirName,"packages","textures")):
if any(in_list("notexture.png",os.listdir(pj(dirName,"packages","textures")))):
engineType = "Cube 2"
elif any(in_list("Engine")) and os.path.isdir(pj(dirName,"Engine")):
if any(in_list("Binaries", os.listdir(pj(dirName,"Engine")))) or any(in_list("Config", os.listdir(pj(dirName,"Engine")))):
engineType = "Unreal Engine 4"
elif any(in_list_starts("Xenko")):
engineType = "Xenko"
elif any(in_list_starts("Data")):
eee = in_list_starts("Data")[0]
if os.path.isdir(pj(dirName,eee)):
dataDir = os.listdir(pj(dirName,eee))
if any(in_list_ends(".rxdata",dataDir)):
engineType = "RPG Maker XP"
if any(in_list_ends(".esm",dataDir)):
engineType = "Creation Engine [GameBryo]"
elif any(in_list_loose("desktop")):
eee = in_list_loose("desktop")[0]
if any(in_list("gdx.dll",eee)) or any(in_list("gdx64.dll",eee)):
engineType = "libGDX"
exeList = in_list_ends(".exe")
dirList = [i for i in gameDir if os.path.isdir(pj(dirName,i))]
# Dirty hack to sort the exes by filesize, since games usually have higher byte count exes than their launchers
# not superhot tho... stupid dumb idiot balls.
if len(exeList) > 1:
exeSize = []
for exe in exeList:
size = os.path.getsize(pj(dirName,exe))
exeSize.append((size, exe))
exeSize.sort(key=lambda s: s[0])
exeSize.reverse()
exeList.clear()
for pair in exeSize:
exeList.append(pair[1])
detectExe = ""
for g in dirList: # this is bound to be incredibly slow
if any(in_list_ends(".vpk",os.listdir(pj(dirName,g)))):
engineType = "Source Engine"
elif any(in_list("halflife.wad",os.listdir(pj(dirName,g)))):
engineType = "GoldSrc"
if not (fastParse and engineType=="Unknown") and engineType=="Unknown": # If fast mode, only run deep scan when we haven't found another engine
for exe in exeList:
exeName = exe[:-4]
exeType = None
exeArch = None
if exeName == "dosbox":
engineType = "DOSbox"
detectExe = exe
continue
elif exeName.startswith("UnityCrashHandler") or "unins" in exeName.lower():
continue
elif any(in_list(exeName+".rgss2a")) or any(in_list(exeName+".rvproj")):
engineType = "RPG Maker VX"
detectExe = exe
continue
elif any(in_list(exeName+".rgss3a")) or any(in_list(exeName+".rvproj2")):
engineType = "RPG Maker VX Ace"
detectExe = exe
continue
elif exeName.startswith("th") and any(i for i in gameDir if (i.lower().endswith(".dat") and i.lower().startswith(exeName))):
engineType = "Touhou"
detectExe = exe
continue
elif any(in_list(exeName+"_Data")):
engineType = "Unity"
detectExe = exe
continue
elif exeName == "hl": # hardcoding is bad
engineType = "GoldSrc"
detectExe = exe
for g in dirList:
if any(in_list("dlls", os.listdir(pj(dirName,g)))):
subGames.append(g)
if not args["game"]: inc_engine_counter(engineType)
continue
# slow shit beyond this point
else:
try:
with open(pj(dirName,exe), "rb") as f:
mm = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
f.close() # not really needed, makes me feel better.
if findBin(mm, b'UnityMain'):
engineType = "Unity"
detectExe = exe
continue
elif findBin(mm, b'Microsoft.Xna.Framework'):
engineType = "XNA"
detectExe = exe
continue
elif findBin(mm, 'Pixel Game Maker MV'.encode('utf-16be')):
engineType = "Pixel Game Maker MV"
detectExe = exe
continue
elif findBin(mm, 'Clickteam Fusion'.encode('utf-16be')):
engineType = "Clickteam Fusion 2.5"
detectExe = exe
continue
elif findBin(mm, 'Multimedia Fusion'.encode('utf-16be')):
engineType = "Multimedia Fusion 2"
detectExe = exe
continue
elif findBin(mm, 'FPSC'.encode('utf-16be')):
engineType = "FPS Creator"
detectExe = exe
continue
elif findBin(mm, 'Game Guru'.encode('utf-16be')):
engineType = "GameGuru"
detectExe = exe
continue
elif findBin(mm, 'Godot'.encode('utf-16be')):
engineType = "Godot"
detectExe = exe
continue
elif findBin(mm, 'ZeroEngine'.encode('utf-16be')):
engineType = "ZeroEngine"
detectExe = exe
continue
elif findBin(mm, 'RPG Maker 95'.encode('utf-16be')):
engineType = "RPG Maker 95"
detectExe = exe
continue
elif findBin(mm, 'RPG Maker 2000'.encode('utf-16be')):
engineType = "RPG Maker 2000"
detectExe = exe
continue
elif findBin(mm, 'RPG Maker 2003'.encode('utf-16be')):
engineType = "RPG Maker 2003"
detectExe = exe
continue
elif findBin(mm, b'RPG Paper Maker'):
engineType = "RPG Paper Maker"
detectExe = exe
continue
elif findBin(mm, b':heGame'):
engineType = "Hacker Evolution"
detectExe = exe
continue
elif findBin(mm, b'hedGame:'):
engineType = "Hacker Evolution: Duality"
detectExe = exe
continue
elif findBin(mm, b'@Sexy@'):
engineType = "Sexy"
detectExe = exe
continue
elif findBin(mm, b'gamemaker') and engineType != "GameMaker Studio":
engineType = "GameMaker Legacy"
detectExe = exe
continue
elif findBin(mm, b'pygame'):
engineType = "PyGame"
detectExe = exe
continue
elif findBin(mm, b'\x00python') and not engineSet:
engineType = "Python-based (PyGame?)"
detectExe = exe
continue
elif findBin(mm, b'HaxeFlixel'):
engineType = "HaxeFlixel"
detectExe = exe
continue
elif findBin(mm, 'electron.app'.encode('utf-16be')):
engineType = "Electron [Web App]" # TODO: Detect CEF icudtl.dat
detectExe = exe
continue
elif findBin(mm, b'dieselx'):
engineType = "Diesel"
detectExe = exe
continue
elif findBin(mm, b'ChromeEngine'):
engineType = "Chrome Engine"
detectExe = exe
continue
elif (findBin(mm, b'Renderware') and not findBin(mm, b'Renderware TXD')) or findBin(mm, b'RenderWare') or findBin(mm, b'RwEngine'):
engineType = "RenderWare"
detectExe = exe
continue
elif findBin(mm, b'Gamebryo') or findBin(mm, b'gamebryo') or findBin(mm, b'GameBryo'):
engineType = "GameBryo"
detectExe = exe
continue
elif findBin(mm, b'reengine'):
engineType = "RE Engine"
detectExe = exe
continue
elif zipfile.is_zipfile(pj(dirName,exe)):
with zipfile.ZipFile(pj(dirName,exe), 'r') as exeZip:
if any(in_list("main.lua",exeZip.namelist())):
engineType = "LOVE"
elif any(in_list("gdx.dll",exeZip.namelist())) or any(in_list("gdx64.dll",exeZip.namelist())):
engineType = "libGDX"
elif any(in_list("META-INF",exeZip.namelist())):
exeType = "Java"
exeArch = "Universal"
exeZip.close() # again, not needed.
if engineType == "Unknown": # If we still come up with nothing matched, just output some info about the executable
if not exeType and not exeArch:
peHeader = mm.find(b'PE\x00\x00')
if peHeader < 0:
exeArch = "16-bit"
exeType = "DOS"
else:
mm.seek(peHeader+4)
fileArch = struct.unpack("<H", mm.read(2))[0]
if fileArch == 332:
exeArch = "32-bit"
mm.seek(226, 1)
exeType = "Win32" if struct.unpack("<I", mm.read(4))[0] == 0 else ".NET"
elif fileArch == 34404:
exeArch = "64-bit"
mm.seek(242, 1)
exeType = "Win32" if struct.unpack("<I", mm.read(4))[0] == 0 else ".NET"
if exeType and exeArch:
engineType += " [%s, %s]" % (exeType, exeArch)
# Try to detect packers (experimental)
if findBin(mm, b'.enigma1'):
engineType += ", [Enigma Virtual Box]"
detectExe = exe
del mm
gc.collect() # this might cause problems, but it might make it faster
except:
print("Error reading %s! Moving on." % (exe))
if engineType == "Unknown" and not fastParse:
if any(in_list("bin")) and os.path.isdir(pj(dirName,"bin")):
if args["verbose"] > 0: print("* %s - TODO: bin folder present, might contain something." % gameName)
return
else:
return # At this point, if we don't know what it is, it's probably not a game at all.
if not args["game"]: inc_engine_counter(engineType)
return [gameName, engineType, subGames, detectExe]
def findBin(binary, find):
return binary.find(find) > 0
def detectClean(game, list):
info = detectGame(game)
if not info: return
if filterEngine == "" or filterEngine.lower() in info[1].lower():
if list:
pfmt = "- %s (%s) [%s]" if args["verbose"] > 0 else "- %s (%s)"
else:
pfmt = "%s (%s) [%s]" if args["verbose"] > 0 else "%s (%s)"
print(pfmt % (info[0], info[1], info[3] if info[3] else "N/A") if args["verbose"] > 0 else pfmt % (info[0], info[1]) )
if len(info[2]) > 0: print(" - Sub-games: %s" % str(info[2])[1:-1])
if __name__ == "__main__":
# Gather all game directories
if not args["game"]:
gamedirs = sorted(next(os.walk(args["dir"] if args["dir"] else '.'))[1], key=str.casefold)
print("== Games ==")
for game in gamedirs:
detectClean(game, True)
else:
detectClean(args["game"], False)
if not args["game"]:
eCount = {k: v for k, v in sorted(engineDict.items(), reverse=True, key=lambda item: item[1])}
print("\n== Engine Count ==")
for x,y in eCount.items():
print("%s: %s" % (x, y))