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:



202
203
204
205
206
# File 'lib/idevice/lockdown.rb', line 202

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:



208
209
210
211
212
# File 'lib/idevice/lockdown.rb', line 208

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:



214
215
216
217
218
# File 'lib/idevice/lockdown.rb', line 214

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
# 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)
    raise LockdownError, "Lockdownd error: #{err}" if err != :SUCCESS

    res = p_val.read_pointer.read_plist_t
  end
  return res
end

#goodbyeObject

Raises:



220
221
222
223
224
# File 'lib/idevice/lockdown.rb', line 220

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

#pair(pair_record) ⇒ Object

Raises:

  • (TypeError)


181
182
183
184
185
186
# File 'lib/idevice/lockdown.rb', line 181

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



170
171
172
173
174
175
176
177
178
179
# File 'lib/idevice/lockdown.rb', line 170

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:



143
144
145
146
147
# File 'lib/idevice/lockdown.rb', line 143

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:



163
164
165
166
167
168
# File 'lib/idevice/lockdown.rb', line 163

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



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

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

#set_value(domain, key, value) ⇒ Object

Raises:



137
138
139
140
141
# File 'lib/idevice/lockdown.rb', line 137

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

#start_service(identifier) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/idevice/lockdown.rb', line 149

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)


195
196
197
198
199
200
# File 'lib/idevice/lockdown.rb', line 195

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)


188
189
190
191
192
193
# File 'lib/idevice/lockdown.rb', line 188

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