forked from applidium/Cracking-Siri
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Siri.rb
executable file
·129 lines (102 loc) · 2.44 KB
/
Siri.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
#!/usr/bin/env ruby
require 'stringio'
require 'rubygems'
require 'eventmachine'
require 'zlib'
require 'cfpropertylist'
require 'uuidtools'
require 'pp'
class String
def to_hex
self.unpack('H*').first
end
def from_hex
[self].pack('H*')
end
end
module Siri
class Client
end
class Server
end
class AceObject
def self.has_header(header)
@@headers ||= {}
@@header = header.to_s[1..-1].to_i(16)
@@headers[@@header] = self
puts @@headers
end
def self.from_binary(stream)
header = stream.readbyte
puts "Instantiating item with header #{header}"
obj_class = @@headers[header]
obj_class.from_binary(stream)
end
def to_binary
@@header.to_s(16).rjust(2, '0').from_hex + self.binary_payload
end
end
class Notice < AceObject
has_header :h03
def initialize(index)
@index = index
end
def self.from_binary(stream)
self.new(stream.read(4).to_hex.to_i(16))
end
def binary_payload
@index.to_s(16).rjust(8, '0').from_hex
end
end
class Ping < Notice
has_header :h03
end
class Pong < AceObject
has_header :h04
end
class Payload < AceObject
has_header :h02
attr_accessor :object
def initialize(object)
self.object = object
end
def self.from_binary(stream)
plist_data_length = stream.read(4).to_hex.to_i(16)
puts "Chunk length = #{plist_data_length}"
plist = CFPropertyList::List.new(:data => stream.read(plist_data_length))
self.new(CFPropertyList.native_types(plist.value))
end
def binary_payload
plist = CFPropertyList::List.new
plist.value = CFPropertyList.guess(self.object)
plist_data = plist.to_str(CFPropertyList::List::FORMAT_BINARY)
plist_data.length.to_s(16).rjust(8, '0') + plist_data
end
end
class SerializerStream
def initialize
@zstream = Zlib::Deflate.new(Zlib::BEST_COMPRESSION)
end
def <<(object)
@zstream.deflate(object.to_binary, Zlib::NO_FLUSH)
object.to_binary
end
def data
# Returns the available data
end
end
class DeserializerStream
def initialize
@inflate = Zlib::Inflate.new
@stream = ""
end
def <<(data)
@stream << @zstream.inflate(data)
end
def objects
# Returns an array of parsed Siri objects
end
end
end
stream = StringIO.new(["020000FFFF"].pack('H*'))
puts Siri::AceObject.from_binary(stream)