-
Notifications
You must be signed in to change notification settings - Fork 31
/
gdb.py
120 lines (86 loc) · 2.83 KB
/
gdb.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
"""
1. Backup your profiles.bin in $HOME/.local/share/Tomorrow\ Corporation/7\ Billion\ Humans/
2. Start 7BillionHumans and goto the elevator.
3. Run gdb -p `pgrep -f "./7BillionHumans.bin.x86_64"`
4. Type "source /path/to/gdb.py" in the gdb command prompt
5. After each level click on "continue to elevator'
"""
import traceback
import gdb
#from antlr.SevenBillionHumansParser import SevenBillionHumansParser
from pathlib import Path
import subprocess
import re
import math
import json
from typing import Tuple as MyTuple
from typing import List as MyList
state = 0
lvl = 0
source = ""
def evlevator_actions():
global lvl
if lvl < 60:
game.enabled = True
gdb.execute("call (void)ConExecCommandLine(\"level {}\")".format(lvl))
lvl += 1
gdb.execute("continue")
def game_actions():
global source
reset.enabled = True
reset.cnt = 24
gdb.execute("set $clip = (void *) ElevatorGetClipboard2()")
gdb.execute("set $list = (char *) malloc (0x100000)")
gdb.execute("call (void)GenerateTextFromClipboard($clip, $list, 0x100000)")
source = gdb.execute("printf \"%s\", $list", to_string=True)
#source = source.strip('\r')
source = source.split('\n')
gdb.execute("call (void)free($list)")
gdb.execute("call (void)TriggerEndOfLevelScreen(1)")
gdb.execute("continue")
def end_of_level():
global source
try:
#avg_speed = gdb.execute("print (float)GetAvgRunSpeed()", to_string=True)
avg_speed = gdb.execute("printf \"%f\", (float)GetAvgRunSpeed()", to_string=True)
fail_cnt = gdb.execute("printf \"%d\", (int)CountRunsFailed()", to_string=True)
#partial = (fail_cnt, 25)
ele.enabled = True
print(">> source = {}".format(source))
print(">> avg_speed = {}".format(avg_speed))
print(">> fail_cnt = {}".format(fail_cnt))
gdb.execute("continue")
except Exception as e:
error = traceback.format_exc()
print(error)
class ResetBP(gdb.Breakpoint):
def __init__(self):
gdb.Breakpoint.__init__(self, "ResetLevel")
self.cnt = 24
def stop(self):
if self.cnt > 0:
self.cnt -= 1
return False
self.enabled = False
gdb.post_event(end_of_level)
return True
class GameBP(gdb.Breakpoint):
def __init__(self):
gdb.Breakpoint.__init__(self, "TestTick")
def stop(self):
self.enabled = False
gdb.post_event(game_actions)
return True
class ElevatorBP(gdb.Breakpoint):
def __init__(self):
gdb.Breakpoint.__init__(self, "ElevatorTick")
def stop(self):
self.enabled = False
gdb.post_event(evlevator_actions)
return True
reset = ResetBP()
reset.enabled = False
game = GameBP()
game.enabled = False
ele = ElevatorBP()
gdb.execute("continue")