openrareplay 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # OpenRA Replay Sanitizer: Program/library to parse and generate
4
+ # OpenRA replay files
5
+ #
6
+ # Copyright (C) 2018 Luke Spangler
7
+ #
8
+ # This program is free software: you can redistribute it and/or modify
9
+ # it under the terms of the GNU Affero General Public License as
10
+ # published by the Free Software Foundation, either version 3 of the
11
+ # License, or (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU Affero General Public License for more details.
17
+
18
+ # You should have received a copy of the GNU Affero General Public License
19
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
20
+
21
+ require_relative '../miniyaml'
22
+
23
+ module OpenRAReplay
24
+ module Sanitize
25
+ class PacketSanitizer
26
+ attr_reader :ping, :message, :chat, :ip, :time, :password,
27
+ :player_name, :server_name, :player_map
28
+
29
+ def initialize(options = {})
30
+ @ping = options[:ping]
31
+ @message = options[:message]
32
+ @chat = options[:chat]
33
+ @ip = options[:ip]
34
+ @time = options[:time]
35
+ @password = options[:password]
36
+ @player_name = options[:player_name]
37
+ @server_name = options[:server_name]
38
+ @player_map = {}
39
+ end
40
+
41
+ def sanitize_packet(packet)
42
+ return sanitize_packet_metadata(packet) if packet.metadata?
43
+ return sanitize_packet_normal(packet) unless packet.unknown?
44
+ packet
45
+ end
46
+
47
+ private
48
+
49
+ def sanitize_packet_metadata(packet)
50
+ object = OpenRAReplay::MiniYaml.load(packet.data)
51
+ time_placeholder = sanitize_time_packet object if time
52
+ object.each_key do |key|
53
+ player = key.match(/^Player@(\d+)$/)
54
+ next unless player
55
+ sanitize_time_player object, key, time_placeholder if time
56
+ sanitize_name object, key if player_name
57
+ end
58
+ packet.class.new(data: OpenRAReplay::MiniYaml.dump(object))
59
+ end
60
+
61
+ def sanitize_packet_normal(packet)
62
+ packet.class.new(
63
+ client_id: packet.client_id,
64
+ frame: packet.frame,
65
+ orders: packet.orders.reject do |o|
66
+ (ping && (o.command.match('Ping') || o.command == 'Pong')) ||
67
+ (message && o.command == 'Message') || (chat &&
68
+ (o.command == 'Chat') || o.command == 'TeamChat')
69
+ end.map { |o| sanitize_order o }
70
+ )
71
+ end
72
+
73
+ def sanitize_order(order)
74
+ return order unless order.command.match('Sync') ||
75
+ order.command.match('Handshake')
76
+ object = OpenRAReplay::MiniYaml.load order.data
77
+ sanitize_password object if password
78
+ sanitize_server_name object if server_name
79
+ object.each_key do |key|
80
+ next unless key == 'Client' || key =~ /^Client@\d+$/
81
+ sanitize_name object, key if player_name
82
+ sanitize_ip object, key if ip
83
+ end
84
+ order.class.new(
85
+ command: order.command,
86
+ data: OpenRAReplay::MiniYaml.dump(object)
87
+ )
88
+ end
89
+
90
+ def sanitize_time_packet(object)
91
+ start_time = OpenRAReplay::MiniYaml.load_time(object['Root']['StartTimeUtc'])
92
+ epoch = Time.at(0).utc
93
+ start_time = start_time.to_i
94
+ stop_time = OpenRAReplay::MiniYaml.load_time(object['Root']['EndTimeUtc']) - start_time
95
+ object['Root']['StartTimeUtc'] = OpenRAReplay::MiniYaml.dump_time(epoch)
96
+ object['Root']['EndTimeUtc'] = OpenRAReplay::MiniYaml.dump_time(stop_time)
97
+ start_time
98
+ end
99
+
100
+ def sanitize_time_player(object, key, start_time)
101
+ object[key]['OutcomeTimestampUtc'] = OpenRAReplay::MiniYaml.dump_time(OpenRAReplay::MiniYaml.load_time(object[key]['OutcomeTimestampUtc']) - start_time)
102
+ end
103
+
104
+ def sanitize_password(object)
105
+ object['Handshake']['Password'] = nil if object['Handshake'] && object['Handshake']['Password']
106
+ end
107
+
108
+ def sanitize_server_name(object)
109
+ object['GlobalSettings']['ServerName'] = nil if object['GlobalSettings'] && object['GlobalSettings']['ServerName']
110
+ end
111
+
112
+ def sanitize_ip(object, key)
113
+ object[key]['IpAddress'] = nil if object[key]['IpAddress']
114
+ end
115
+
116
+ def sanitize_name(object, key)
117
+ return unless !object[key]['IsBot'] && object[key]['Name']
118
+ unless player_map[object[key]['Name']]
119
+ @player_map[object[key]['Name']] = "Player #{player_map.length + 1}"
120
+ end
121
+ object[key]['Name'] = player_map[object[key]['Name']]
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # OpenRA Replay Sanitizer: Program/library to parse and generate
4
+ # OpenRA replay files
5
+ #
6
+ # Copyright (C) 2018 Luke Spangler
7
+ #
8
+ # This program is free software: you can redistribute it and/or modify
9
+ # it under the terms of the GNU Affero General Public License as
10
+ # published by the Free Software Foundation, either version 3 of the
11
+ # License, or (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU Affero General Public License for more details.
17
+
18
+ # You should have received a copy of the GNU Affero General Public License
19
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
20
+
21
+ require_relative 'packet_sanitizer'
22
+ require_relative '../packet/packet_parser'
23
+
24
+ module OpenRAReplay
25
+ module Sanitize
26
+ class ReplaySanitizer
27
+ attr_reader :in_file, :out_file, :packet_sanitizer
28
+
29
+ def initialize(in_name, out_name, opts = {})
30
+ @in_file = in_name
31
+ @out_file = out_name
32
+ @packet_sanitizer = OpenRAReplay::Sanitize::PacketSanitizer.new opts
33
+ end
34
+
35
+ def sanitize
36
+ File.open(out_file, 'wb') do |output_file|
37
+ File.open(in_file, 'rb') do |input_file|
38
+ packet_parser = OpenRAReplay::PacketParser.new(input_file)
39
+ until packet_parser.eof?
40
+ packet_parser.read_packet do |packet|
41
+ next if packet.unknown?
42
+ np = packet_sanitizer.sanitize_packet packet
43
+ output_file.write np.byte_array
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # OpenRA Replay Sanitizer: Program/library to parse and generate
4
+ # OpenRA replay files
5
+ #
6
+ # Copyright (C) 2018 Luke Spangler
7
+ #
8
+ # This program is free software: you can redistribute it and/or modify
9
+ # it under the terms of the GNU Affero General Public License as
10
+ # published by the Free Software Foundation, either version 3 of the
11
+ # License, or (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU Affero General Public License for more details.
17
+
18
+ # You should have received a copy of the GNU Affero General Public License
19
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
20
+
21
+ module OpenRAReplay
22
+ VERSION = '0.1.1'.freeze
23
+ end
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # OpenRA Replay Sanitizer: Program/library to parse and generate
4
+ # OpenRA replay files
5
+ #
6
+ # Copyright (C) 2018 Luke Spangler
7
+ #
8
+ # This program is free software: you can redistribute it and/or modify
9
+ # it under the terms of the GNU Affero General Public License as
10
+ # published by the Free Software Foundation, either version 3 of the
11
+ # License, or (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU Affero General Public License for more details.
17
+
18
+ # You should have received a copy of the GNU Affero General Public License
19
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
20
+
21
+ lib = File.expand_path('lib', __dir__)
22
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
23
+ require 'openrareplay/version'
24
+
25
+ Gem::Specification.new do |spec|
26
+ spec.name = 'openrareplay'
27
+ spec.version = OpenRAReplay::VERSION
28
+ spec.authors = ['Luke Spangler']
29
+ spec.email = ['luke.a.spangler@gmail.com']
30
+
31
+ spec.summary = 'Program/library to parse and generate OpenRA
32
+ replays without identifying information'
33
+ spec.homepage = 'https://github.com/spanglel/OpenRAReplay-Sanitizer'
34
+ spec.license = 'AGPL-3.0'
35
+
36
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
37
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
38
+ end
39
+ spec.bindir = 'exe'
40
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
41
+ spec.require_paths = ['lib']
42
+
43
+ spec.add_development_dependency 'bundler', '~> 1.16'
44
+ spec.add_development_dependency 'minitest', '~> 5.0'
45
+ spec.add_development_dependency 'rake', '~> 10.0'
46
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openrareplay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Luke Spangler
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - luke.a.spangler@gmail.com
58
+ executables:
59
+ - openra-sanitize
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.md
67
+ - README.md
68
+ - Rakefile
69
+ - exe/openra-sanitize
70
+ - lib/openrareplay.rb
71
+ - lib/openrareplay/binary.rb
72
+ - lib/openrareplay/miniyaml.rb
73
+ - lib/openrareplay/order.rb
74
+ - lib/openrareplay/order/client.rb
75
+ - lib/openrareplay/order/notanorder.rb
76
+ - lib/openrareplay/order/order.rb
77
+ - lib/openrareplay/order/server.rb
78
+ - lib/openrareplay/packet.rb
79
+ - lib/openrareplay/packet/metadata_packet.rb
80
+ - lib/openrareplay/packet/packet.rb
81
+ - lib/openrareplay/packet/packet_parser.rb
82
+ - lib/openrareplay/sanitize.rb
83
+ - lib/openrareplay/sanitize/cli.rb
84
+ - lib/openrareplay/sanitize/packet_sanitizer.rb
85
+ - lib/openrareplay/sanitize/replay_sanitizer.rb
86
+ - lib/openrareplay/version.rb
87
+ - openrareplay.gemspec
88
+ homepage: https://github.com/spanglel/OpenRAReplay-Sanitizer
89
+ licenses:
90
+ - AGPL-3.0
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.7.7
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Program/library to parse and generate OpenRA replays without identifying
112
+ information
113
+ test_files: []