-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrace.rb
executable file
·189 lines (159 loc) · 3.65 KB
/
race.rb
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
#!/usr/local/bin/pry
require 'pwn'
def deg2rad(deg)
return deg * Math::PI / 180
end
def findLL(latitude)
a = 6378.1370
b = 6356.7523142
e = Math::sqrt((a*a - b*b) / (a*a))
lat = deg2rad(latitude)
numerator = (Math::PI * a * Math::cos(lat))
denominator = 180 * Math::sqrt(1 - e*e*(Math::sin(lat)**2))
long = numerator/denominator
end
def vector(from, to)
dX = (to[0] - from[0])
dY = (to[1] - from[1])
dX = dX % 360 if (dX%360).abs < dX.abs
dY = dY % 360 if (dY%360).abs < dY.abs
return [dX,dY]
end
def distance(from, to)
# we assume a degree of latitude is 111.7km
latLength = 111.7 # km
longLength = findLL(from[0])
delta = vector(from, to)
dXkm = delta[0]*latLength
dYkm = delta[1]*longLength
return Math::sqrt(dXkm**2 + dYkm**2)
end
def oneStep(from, to, speed=$carSpeed)
delta = vector(from, to)
dH = distance(from, to)
return to if dH < speed
scale = speed / dH
step = [from[0]+delta[0]*scale, from[1]+delta[1]*scale]
step[0] += 360 if step[0] <= -180
step[0] += 360 if step[0] <= -180
step[1] -= 360 if step[1] >= 180
step[1] -= 360 if step[1] >= 180
return step
end
def printStep(pos)
return "%9.6f %9.6f" % [pos[0],pos[1]]
end
def findPath(origin, destination, speed)
path = []
current = origin
loop do
step = oneStep(current, destination, speed)
path << step
current = step
break if current==destination
end
return path
end
def findPathTo(destination, speed=$carSpeed)
return findPath($location, destination, speed)
end
def walkStep(step)
$serial.sendline "%9.6f %9.6f" % step
$history << $location
$location = step
input = $serial.recvpred(timeout:2) { |data|
result = false
result = true if data =~ /\n> /
result = true if data =~ /==END==/
result
}
return processInput input
end
def walkPath(path)
path.each do |step|
return false unless walkStep(step)
end
return true
end
$planeSpeed = 655.0
def fly(destination)
walkPath findPathTo(destination, $planeSpeed)
end
$carSpeed = 99.0
def drive(destination)
walkPath findPathTo(destination, $carSpeed)
end
$boatSpeed = 30.0
def sail(destination)
walkPath findPathTo(destination, $boatSpeed)
end
$buffer=nil
$history=[]
def processInput(input)
puts input
$buffer = input
lines = input.split("\n")
lines.each do |line|
case line
when /Latitude/
parts = line.split("\t")
lat = parts.first.split.last.to_f
long = parts.last .split.last.to_f
old = $location
$location = [lat,long]
puts "New location: #{$location}"
puts "old was: #{old}"
when /Location: /
parts = line.split
$destination = parts[1..2].map{|x| x.to_f}
puts "New destination: #{$destination}"
return nil
when /Enter your name to start/
$history = []
$serial.sendline "Go Go Go Bot"
when /==END==/
puts "busted, fail."
return nil
end
end
puts "Time: #{$history.length}h"
return $location
end
def status()
processInput $serial.read(5000, timeout:1)
return $location
end
# Local Utility:
Office = [51.9979258, 4.3834606] # Riscure Head Office, aka Delft
RNA = [37.7932696,-122.4065417] # Riscure North America
CDG = [49.0096906, 2.5457305]
SFO = [37.6213129, -122.3811494]
PVG = [31.1443439, 121.806079]
Shanghai = [31.2231281,120.9149854]
def leg1()
drive(Office)
end
def leg2()
drive(CDG) && fly(PVG) && drive(Shanghai) && sail($destination)
end
def leg3()
sail(Shanghai) && drive(PVG) && fly(SFO) && drive(RNA)
end
def leg4()
drive(SFO) && fly(CDG) && drive(Office)
end
# Harness
begin
if ARGV.length < 1 then
puts "Usage: #{$0} <port>"
exit(1)
end
port = ARGV[0]
$location = nil
$serial = Pwnlib::Tubes::SerialTube.new port
#$conn = Pwnlib::Tubes::Sock.new 'localhost', 10233
status()
puts "we are in"
binding.pry
puts "we are out"
end