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
189
190
191
192
193
194
|
/* swig.i */
%module(package="libiphone") iPhone
%feature("autodoc", "1");
%{
/* Includes the header in the wrapper code */
#include <libiphone/libiphone.h>
#include <libiphone/lockdown.h>
#include <libiphone/mobilesync.h>
#include <plist/plist.h>
#include "../src/utils.h"
typedef struct {
iphone_device_t dev;
} iPhone;
typedef struct {
iPhone* dev;
lockdownd_client_t client;
} Lockdownd;
typedef struct {
iPhone* dev;
mobilesync_client_t client;
} MobileSync;
//now declare funtions to handle creation and deletion of objects
void my_delete_iPhone(iPhone* dev);
Lockdownd* my_new_Lockdownd(iPhone* phone);
void my_delete_Lockdownd(Lockdownd* lckd);
MobileSync* my_new_MobileSync(Lockdownd* lckd);
%}
/* Parse the header file to generate wrappers */
%include "stdint.i"
%include "cstring.i"
%include "plist/swig/plist.i"
#define DBGMASK_ALL 0xFFFF
#define DBGMASK_NONE 0x0000
#define DBGMASK_LOCKDOWND (1 << 1)
#define DBGMASK_MOBILESYNC (1 << 2)
typedef struct {
iphone_device_t dev;
} iPhone;
typedef struct {
iPhone* dev;
lockdownd_client_t client;
} Lockdownd;
typedef struct {
iPhone* dev;
mobilesync_client_t client;
} MobileSync;
%inline %{
//now define funtions to handle creation and deletion of objects
void my_delete_iPhone(iPhone* dev) {
if (dev) {
iphone_device_free(dev->dev);
free(dev);
}
}
Lockdownd* my_new_Lockdownd(iPhone* phone) {
if (!phone) return NULL;
Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd));
client->dev = phone;
client->client = NULL;
if (LOCKDOWN_E_SUCCESS == lockdownd_client_new(phone->dev , &(client->client))) {
return client;
}
else {
free(client);
return NULL;
}
}
void my_delete_Lockdownd(Lockdownd* lckd) {
if (lckd) {
lockdownd_client_free(lckd->client);
free(lckd);
}
}
MobileSync* my_new_MobileSync(Lockdownd* lckd) {
if (!lckd || !lckd->dev) return NULL;
MobileSync* client = NULL;
int port = 0;
if (LOCKDOWN_E_SUCCESS == lockdownd_start_service(lckd->client, "com.apple.mobilesync", &port)) {
client = (MobileSync*) malloc(sizeof(MobileSync));
client->dev = lckd->dev;
client->client = NULL;
mobilesync_client_new(lckd->dev->dev, port, &(client->client));
}
return client;
}
%}
%extend iPhone { // Attach these functions to struct iPhone
iPhone() {
iPhone* phone = (iPhone*) malloc(sizeof(iPhone));
phone->dev = NULL;
return phone;
}
~iPhone() {
my_delete_iPhone($self);
}
void set_debug_mask(uint16_t mask) {
iphone_set_debug_mask(mask);
}
void set_debug_level(int level) {
iphone_set_debug_level(level);
}
int init_device_by_uuid(char* uuid) {
if (IPHONE_E_SUCCESS == iphone_device_new(&($self->dev), uuid))
return 1;
return 0;
}
int init_device() {
if (IPHONE_E_SUCCESS == iphone_device_new(&($self->dev), NULL))
return 1;
return 0;
}
%newobject get_uuid;
char* get_uuid(){
char* uuid = NULL;
iphone_device_get_uuid($self->dev, &uuid);
return uuid;
}
Lockdownd* get_lockdown_client() {
return my_new_Lockdownd($self);
}
};
%extend Lockdownd { // Attach these functions to struct Lockdownd
Lockdownd(iPhone* phone) {
return my_new_Lockdownd(phone);
}
~Lockdownd() {
my_delete_Lockdownd($self);
}
void send(PListNode* node) {
lockdownd_send($self->client, node->node);
}
PListNode* receive() {
PListNode* node = (PListNode*)malloc(sizeof(PListNode));
node->node = NULL;
lockdownd_recv($self->client, &(node->node));
return node;
}
MobileSync* get_mobilesync_client() {
return my_new_MobileSync($self);
}
};
%extend MobileSync { // Attach these functions to struct MobileSync
MobileSync(Lockdownd* lckd) {
return my_new_MobileSync(lckd);
}
~MobileSync() {
mobilesync_client_free($self->client);
free($self);
}
void send(PListNode* node) {
mobilesync_send($self->client, node->node);
}
PListNode* receive() {
PListNode* node = (PListNode*)malloc(sizeof(PListNode));
node->node = NULL;
mobilesync_recv($self->client, &(node->node));
return node;
}
};
|