Class: Idevice::LockdownClient

Inherits:
C::ManagedOpaquePointer show all
Defined in:
lib/idevice/lockdown.rb

Overview

Used to manage device preferences, start services, pairing and activation on the device.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from C::ManagedOpaquePointer

#initialize

Constructor Details

This class inherits a constructor from Idevice::C::ManagedOpaquePointer

Class Method Details

.attach(opts = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/idevice/lockdown.rb', line 40

def self.attach(opts={})
  idevice = opts[:idevice] || Idevice.attach(opts)

  label = opts[:label] || "ruby-idevice"

  FFI::MemoryPointer.new(:pointer) do |p_lockdown_client|
    err =
      if opts[:nohandshake]
        C.lockdownd_client_new(idevice, p_lockdown_client, label)
      else
        C.lockdownd_client_new_with_handshake(idevice, p_lockdown_client, label)
      end

    raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS

    lockdown_client = p_lockdown_client.read_pointer
    if lockdown_client.null?
      raise LockdownError, "lockdownd_client creation returned a NULL object"
    else
      return new(lockdown_client)
    end
  end
end

.release(ptr) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/idevice/lockdown.rb', line 32

def self.release(ptr)
  C::Freelock.synchronize do
    unless ptr.null?
      C.lockdownd_client_free(ptr)
    end
  end
end

Instance Method Details

#activate(activation_record) ⇒ Object

Raises:



206
207
208
209
210
# File 'lib/idevice/lockdown.rb', line 206

def activate(activation_record)
  err = C.lockdownd_activate(self, Plist_t.from_ruby(activation_record))
  raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS
  return true
end

#deactivateObject

Raises:



212
213
214
215
216
# File 'lib/idevice/lockdown.rb', line 212

def deactivate
  err = C.lockdownd_deactivate(self)
  raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS
  return true
end

#device_nameObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/idevice/lockdown.rb', line 79

def device_name
  res = nil
  FFI::MemoryPointer.new(:pointer) do |p_name|
    err = C.lockdownd_get_device_name(self, p_name)
    raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS

    name = p_name.read_pointer
    unless name.null?
      res = name.read_string
      C.free(name)
    end
  end
  return res
end

#device_udidObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/idevice/lockdown.rb', line 64

def device_udid
  res = nil
  FFI::MemoryPointer.new(:pointer) do |p_udid|
    err = C.lockdownd_get_device_udid(self, p_udid)
    raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS

    udid = p_udid.read_pointer
    unless udid.null?
      res = udid.read_string
      C.free(udid)
    end
  end
  return res
end

#enter_recoveryObject

Raises:



218
219
220
221
222
# File 'lib/idevice/lockdown.rb', line 218

def enter_recovery
  err = C.lockdownd_enter_recovery(self)
  raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS
  return true
end

#get_value(domain, key) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/idevice/lockdown.rb', line 126

def get_value(domain, key)
  res = nil
  FFI::MemoryPointer.new(:pointer) do |p_val|
    err = C.lockdownd_get_value(self, domain, key, p_val)
    if err == :SUCCESS
        res = p_val.read_pointer.read_plist_t
    elsif err == :UNKNOWN_ERROR
        res = nil
    else
        raise LockdownError, "Lockdownd error: #{err}"
    end
  end
  return res
end

#goodbyeObject

Raises:



224
225
226
227
228
# File 'lib/idevice/lockdown.rb', line 224

def goodbye
  err = C.lockdownd_goodbye(self)
  raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS
  return true
end

#pair(pair_record) ⇒ Object

Raises:

  • (TypeError)


185
186
187
188
189
190
# File 'lib/idevice/lockdown.rb', line 185

def pair(pair_record)
  raise TypeError, "pair_record must be a LockdownPairRecord" unless pair_record.is_a?(LockdownPairRecord)
  err = C.lockdownd_pair(self, pair_record)
  raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS
  return true
end

#query_typeObject



113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/idevice/lockdown.rb', line 113

def query_type
  res = nil
  FFI::MemoryPointer.new(:pointer) do |p_type|
    err = C.lockdownd_query_type(self, p_type)
    raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS

    type = p_type.read_pointer
    res = type.read_string
    C.free(type)
  end
  return res
end

#receive_plistObject



174
175
176
177
178
179
180
181
182
183
# File 'lib/idevice/lockdown.rb', line 174

def receive_plist
  ret = nil
  FFI::MemoryPointer.new(:pointer) do |p_plist|
    err = C.lockdownd_receive(self, p_plist)
    raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS

    ret = p_plist.read_pointer.read_plist_t
  end
  return ret
end

#remove_value(domain, key) ⇒ Object

Raises:



147
148
149
150
151
# File 'lib/idevice/lockdown.rb', line 147

def remove_value(domain, key)
  err = C.lockdownd_remove_value(self, domain, key)
  raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS
  return true
end

#send_plist(obj) ⇒ Object

Raises:



167
168
169
170
171
172
# File 'lib/idevice/lockdown.rb', line 167

def send_plist(obj)
  err = C.lockdownd_send(self, Plist_t.from_ruby(obj))
  raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS

  return true
end

#set_label(label) ⇒ Object



230
231
232
233
# File 'lib/idevice/lockdown.rb', line 230

def set_label(label)
  C.lockdownd_client_set_label(self, label)
  return true
end

#set_value(domain, key, value) ⇒ Object

Raises:



141
142
143
144
145
# File 'lib/idevice/lockdown.rb', line 141

def set_value(domain, key, value)
  err = C.lockdownd_set_value(self, domain, key, Plist_t_Unmanaged.from_ruby(value))
  raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS
  return true
end

#start_service(identifier) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/idevice/lockdown.rb', line 153

def start_service(identifier)
  ret = nil
  FFI::MemoryPointer.new(:pointer) do |p_ldsvc|
    err = C.lockdownd_start_service(self, identifier, p_ldsvc)
    raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS

    ldsvc = p_ldsvc.read_pointer
    unless ldsvc.null?
      ret = LockdownServiceDescriptor.new(ldsvc)
    end
  end
  return ret
end

#sync_data_classesObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/idevice/lockdown.rb', line 94

def sync_data_classes
  res = nil
  FFI::MemoryPointer.new(:pointer) do |p_sync_classes|
    FFI::MemoryPointer.new(:int) do |p_count|
      err = C.lockdownd_get_sync_data_classes(self, p_sync_classes, p_count)
      raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS

      sync_classes = p_sync_classes.read_pointer
      count = p_count.read_int
      unless sync_classes.null?
        res = sync_classes.read_array_of_pointer(count).map{|p| p.read_string }
        err = C.lockdownd_data_classes_free(sync_classes)
        raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS
      end
    end
  end
  return res
end

#unpair(pair_record) ⇒ Object

Raises:

  • (TypeError)


199
200
201
202
203
204
# File 'lib/idevice/lockdown.rb', line 199

def unpair(pair_record)
  raise TypeError, "pair_record must be a LockdownPairRecord" unless pair_record.is_a?(LockdownPairRecord)
  err = C.lockdownd_unpair(self, pair_record)
  raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS
  return true
end

#validate_pair(pair_record) ⇒ Object

Raises:

  • (TypeError)


192
193
194
195
196
197
# File 'lib/idevice/lockdown.rb', line 192

def validate_pair(pair_record)
  raise TypeError, "pair_record must be a LockdownPairRecord" unless pair_record.is_a?(LockdownPairRecord)
  err = C.lockdownd_validate_pair(self, pair_record)
  raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS
  return true
end