Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libplist
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pwn
libplist
Commits
0b2cfd2c
Commit
0b2cfd2c
authored
Oct 25, 2008
by
Jonathan Beck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle debugging through utilitary functions
parent
bbd813da
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
240 additions
and
248 deletions
+240
-248
libiphone.h
include/libiphone/libiphone.h
+1
-0
AFC.c
src/AFC.c
+39
-77
Makefile.am
src/Makefile.am
+2
-2
initconf.c
src/initconf.c
+2
-1
iphone.c
src/iphone.c
+19
-37
lockdown.c
src/lockdown.c
+52
-99
usbmux.c
src/usbmux.c
+12
-27
userpref.c
src/userpref.c
+3
-5
utils.c
src/utils.c
+80
-0
utils.h
src/utils.h
+30
-0
No files found.
include/libiphone/libiphone.h
View file @
0b2cfd2c
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
#include <stdint.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
...
...
src/AFC.c
View file @
0b2cfd2c
...
@@ -27,16 +27,13 @@
...
@@ -27,16 +27,13 @@
// This is the maximum size an AFC data packet can be
// This is the maximum size an AFC data packet can be
const
int
MAXIMUM_PACKET_SIZE
=
(
2
<<
15
)
-
32
;
const
int
MAXIMUM_PACKET_SIZE
=
(
2
<<
15
)
-
32
;
extern
int
debug
;
/** Locks an AFC client, done for thread safety stuff
/** Locks an AFC client, done for thread safety stuff
*
*
* @param client The AFC client connection to lock
* @param client The AFC client connection to lock
*/
*/
static
void
afc_lock
(
iphone_afc_client_t
client
)
static
void
afc_lock
(
iphone_afc_client_t
client
)
{
{
if
(
debug
)
log_debug_msg
(
"Locked
\n
"
);
fprintf
(
stderr
,
"Locked
\n
"
);
while
(
client
->
lock
)
{
while
(
client
->
lock
)
{
usleep
(
500
);
// they say it's obsolete, but whatever
usleep
(
500
);
// they say it's obsolete, but whatever
}
}
...
@@ -49,8 +46,7 @@ static void afc_lock(iphone_afc_client_t client)
...
@@ -49,8 +46,7 @@ static void afc_lock(iphone_afc_client_t client)
*/
*/
static
void
afc_unlock
(
iphone_afc_client_t
client
)
static
void
afc_unlock
(
iphone_afc_client_t
client
)
{
// just to be pretty
{
// just to be pretty
if
(
debug
)
log_debug_msg
(
"Unlocked
\n
"
);
fprintf
(
stderr
,
"Unlocked
\n
"
);
client
->
lock
=
0
;
client
->
lock
=
0
;
}
}
...
@@ -156,16 +152,12 @@ static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, int
...
@@ -156,16 +152,12 @@ static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, int
memcpy
(
buffer
,
(
char
*
)
client
->
afc_packet
,
sizeof
(
AFCPacket
));
memcpy
(
buffer
,
(
char
*
)
client
->
afc_packet
,
sizeof
(
AFCPacket
));
offset
=
client
->
afc_packet
->
this_length
-
sizeof
(
AFCPacket
);
offset
=
client
->
afc_packet
->
this_length
-
sizeof
(
AFCPacket
);
if
(
debug
)
log_debug_msg
(
"dispatch_AFC_packet: Offset: %i
\n
"
,
offset
);
fprintf
(
stderr
,
"dispatch_AFC_packet: Offset: %i
\n
"
,
offset
);
if
((
length
)
<
(
client
->
afc_packet
->
entire_length
-
client
->
afc_packet
->
this_length
))
{
if
((
length
)
<
(
client
->
afc_packet
->
entire_length
-
client
->
afc_packet
->
this_length
))
{
if
(
debug
)
{
log_debug_msg
(
"dispatch_AFC_packet: Length did not resemble what it was supposed"
);
fprintf
(
stderr
,
"dispatch_AFC_packet: Length did not resemble what it was supposed"
);
log_debug_msg
(
"to based on the packet.
\n
"
);
fprintf
(
stderr
,
"to based on the packet.
\n
"
);
log_debug_msg
(
"length minus offset: %i
\n
"
,
length
-
offset
);
fprintf
(
stderr
,
"length minus offset: %i
\n
"
,
length
-
offset
);
log_debug_msg
(
"rest of packet: %i
\n
"
,
client
->
afc_packet
->
entire_length
-
client
->
afc_packet
->
this_length
);
fprintf
(
stderr
,
"rest of packet: %i
\n
"
,
client
->
afc_packet
->
entire_length
-
client
->
afc_packet
->
this_length
);
}
free
(
buffer
);
free
(
buffer
);
return
-
1
;
return
-
1
;
}
}
...
@@ -176,32 +168,25 @@ static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, int
...
@@ -176,32 +168,25 @@ static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, int
return
bytes
;
return
bytes
;
}
}
if
(
debug
)
{
log_debug_msg
(
"dispatch_AFC_packet: sent the first now go with the second
\n
"
);
fprintf
(
stderr
,
"dispatch_AFC_packet: sent the first now go with the second
\n
"
);
log_debug_msg
(
"Length: %i
\n
"
,
length
-
offset
);
fprintf
(
stderr
,
"Length: %i
\n
"
,
length
-
offset
);
log_debug_msg
(
"Buffer:
\n
"
);
fprintf
(
stderr
,
"Buffer:
\n
"
);
log_debug_msg
(
data
+
offset
);
fwrite
(
data
+
offset
,
1
,
length
-
offset
,
stdout
);
}
iphone_mux_send
(
client
->
connection
,
data
+
offset
,
length
-
offset
,
&
bytes
);
iphone_mux_send
(
client
->
connection
,
data
+
offset
,
length
-
offset
,
&
bytes
);
return
bytes
;
return
bytes
;
}
else
{
}
else
{
if
(
debug
)
log_debug_msg
(
"dispatch_AFC_packet doin things the old way
\n
"
);
fprintf
(
stderr
,
"dispatch_AFC_packet doin things the old way
\n
"
);
char
*
buffer
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
client
->
afc_packet
->
this_length
);
char
*
buffer
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
client
->
afc_packet
->
this_length
);
if
(
debug
)
log_debug_msg
(
"dispatch_AFC_packet packet length = %i
\n
"
,
client
->
afc_packet
->
this_length
);
fprintf
(
stderr
,
"dispatch_AFC_packet packet length = %i
\n
"
,
client
->
afc_packet
->
this_length
);
memcpy
(
buffer
,
(
char
*
)
client
->
afc_packet
,
sizeof
(
AFCPacket
));
memcpy
(
buffer
,
(
char
*
)
client
->
afc_packet
,
sizeof
(
AFCPacket
));
if
(
debug
)
log_debug_msg
(
"dispatch_AFC_packet packet data follows
\n
"
);
fprintf
(
stderr
,
"dispatch_AFC_packet packet data follows
\n
"
);
if
(
length
>
0
)
{
if
(
length
>
0
)
{
memcpy
(
buffer
+
sizeof
(
AFCPacket
),
data
,
length
);
memcpy
(
buffer
+
sizeof
(
AFCPacket
),
data
,
length
);
buffer
[
sizeof
(
AFCPacket
)
+
length
]
=
'\0'
;
buffer
[
sizeof
(
AFCPacket
)
+
length
]
=
'\0'
;
}
}
if
(
debug
)
log_debug_buffer
(
buffer
,
client
->
afc_packet
->
this_length
);
fwrite
(
buffer
,
1
,
client
->
afc_packet
->
this_length
,
stdout
);
log_debug_msg
(
"
\n
"
);
if
(
debug
)
fprintf
(
stderr
,
"
\n
"
);
iphone_mux_send
(
client
->
connection
,
buffer
,
client
->
afc_packet
->
this_length
,
&
bytes
);
iphone_mux_send
(
client
->
connection
,
buffer
,
client
->
afc_packet
->
this_length
,
&
bytes
);
if
(
buffer
)
{
if
(
buffer
)
{
...
@@ -257,29 +242,22 @@ static int receive_AFC_data(iphone_afc_client_t client, char **dump_here)
...
@@ -257,29 +242,22 @@ static int receive_AFC_data(iphone_afc_client_t client, char **dump_here)
free
(
buffer
);
free
(
buffer
);
if
(
r_packet
->
operation
==
AFC_ERROR
&&
!
(
client
->
afc_packet
->
operation
==
AFC_DELETE
&&
param1
==
7
))
{
if
(
r_packet
->
operation
==
AFC_ERROR
&&
!
(
client
->
afc_packet
->
operation
==
AFC_DELETE
&&
param1
==
7
))
{
if
(
debug
)
log_debug_msg
(
"Oops? Bad operation code received: 0x%X, operation=0x%X, param1=%d
\n
"
,
fprintf
(
stderr
,
"Oops? Bad operation code received: 0x%X, operation=0x%X, param1=%d
\n
"
,
r_packet
->
operation
,
client
->
afc_packet
->
operation
,
param1
);
r_packet
->
operation
,
client
->
afc_packet
->
operation
,
param1
);
recv_len
=
r_packet
->
entire_length
-
r_packet
->
this_length
;
recv_len
=
r_packet
->
entire_length
-
r_packet
->
this_length
;
free
(
r_packet
);
free
(
r_packet
);
if
(
debug
)
log_debug_msg
(
"recv_len=%d
\n
"
,
recv_len
);
fprintf
(
stderr
,
"recv_len=%d
\n
"
,
recv_len
);
if
(
param1
==
0
)
{
if
(
param1
==
0
)
{
if
(
debug
)
log_debug_msg
(
"... false alarm, but still
\n
"
);
fprintf
(
stderr
,
"... false alarm, but still
\n
"
);
*
dump_here
=
NULL
;
*
dump_here
=
NULL
;
return
0
;
return
0
;
}
else
{
}
else
{
if
(
debug
)
log_debug_msg
(
"Errno %i
\n
"
,
param1
);
fprintf
(
stderr
,
"Errno %i
\n
"
,
param1
);
}
}
*
dump_here
=
NULL
;
*
dump_here
=
NULL
;
return
-
1
;
return
-
1
;
}
else
{
}
else
{
if
(
debug
)
log_debug_msg
(
"Operation code %x
\n
Full length %i and this length %i
\n
"
,
fprintf
(
stderr
,
"Operation code %x
\n
Full length %i and this length %i
\n
"
,
r_packet
->
operation
,
r_packet
->
entire_length
,
r_packet
->
this_length
);
r_packet
->
operation
,
r_packet
->
entire_length
,
r_packet
->
this_length
);
}
}
...
@@ -294,25 +272,19 @@ static int receive_AFC_data(iphone_afc_client_t client, char **dump_here)
...
@@ -294,25 +272,19 @@ static int receive_AFC_data(iphone_afc_client_t client, char **dump_here)
final_buffer
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
recv_len
);
final_buffer
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
recv_len
);
while
(
current_count
<
recv_len
)
{
while
(
current_count
<
recv_len
)
{
iphone_mux_recv
(
client
->
connection
,
buffer
,
recv_len
-
current_count
,
&
bytes
);
iphone_mux_recv
(
client
->
connection
,
buffer
,
recv_len
-
current_count
,
&
bytes
);
if
(
debug
)
log_debug_msg
(
"receive_AFC_data: still collecting packets
\n
"
);
fprintf
(
stderr
,
"receive_AFC_data: still collecting packets
\n
"
);
if
(
bytes
<
0
)
{
if
(
bytes
<
0
)
{
if
(
debug
)
log_debug_msg
(
"receive_AFC_data: mux_recv failed: %d
\n
"
,
bytes
);
fprintf
(
stderr
,
"receive_AFC_data: mux_recv failed: %d
\n
"
,
bytes
);
break
;
break
;
}
}
if
(
bytes
>
recv_len
-
current_count
)
{
if
(
bytes
>
recv_len
-
current_count
)
{
if
(
debug
)
log_debug_msg
(
"receive_AFC_data: mux_recv delivered too much data
\n
"
);
fprintf
(
stderr
,
"receive_AFC_data: mux_recv delivered too much data
\n
"
);
break
;
break
;
}
}
if
(
bytes
>
7
&&
strstr
(
buffer
,
"CFA6LPAA"
))
{
if
(
bytes
>
7
&&
strstr
(
buffer
,
"CFA6LPAA"
))
{
if
(
debug
)
log_debug_msg
(
"receive_AFC_data: WARNING: there is AFC data in this packet at %ti
\n
"
,
fprintf
(
stderr
,
"receive_AFC_data: WARNING: there is AFC data in this packet at %ti
\n
"
,
strstr
(
buffer
,
"CFA6LPAA"
)
-
buffer
);
strstr
(
buffer
,
"CFA6LPAA"
)
-
buffer
);
if
(
debug
)
log_debug_msg
(
"receive_AFC_data: the total packet length is %i
\n
"
,
bytes
);
fprintf
(
stderr
,
"receive_AFC_data: the total packet length is %i
\n
"
,
bytes
);
}
}
memcpy
(
final_buffer
+
current_count
,
buffer
,
bytes
);
memcpy
(
final_buffer
+
current_count
,
buffer
,
bytes
);
...
@@ -701,8 +673,7 @@ iphone_afc_open_file(iphone_afc_client_t client, const char *filename,
...
@@ -701,8 +673,7 @@ iphone_afc_open_file(iphone_afc_client_t client, const char *filename,
free
(
data
);
free
(
data
);
if
(
bytes
<=
0
)
{
if
(
bytes
<=
0
)
{
if
(
debug
)
log_debug_msg
(
"afc_open_file: Didn't receive a response to the command
\n
"
);
fprintf
(
stderr
,
"afc_open_file: Didn't receive a response to the command
\n
"
);
afc_unlock
(
client
);
afc_unlock
(
client
);
return
IPHONE_E_NOT_ENOUGH_DATA
;
return
IPHONE_E_NOT_ENOUGH_DATA
;
}
}
...
@@ -718,8 +689,7 @@ iphone_afc_open_file(iphone_afc_client_t client, const char *filename,
...
@@ -718,8 +689,7 @@ iphone_afc_open_file(iphone_afc_client_t client, const char *filename,
*
file
=
file_loc
;
*
file
=
file_loc
;
return
IPHONE_E_SUCCESS
;
return
IPHONE_E_SUCCESS
;
}
else
{
}
else
{
if
(
debug
)
log_debug_msg
(
"afc_open_file: Didn't get any further data
\n
"
);
fprintf
(
stderr
,
"afc_open_file: Didn't get any further data
\n
"
);
afc_unlock
(
client
);
afc_unlock
(
client
);
return
IPHONE_E_NOT_ENOUGH_DATA
;
return
IPHONE_E_NOT_ENOUGH_DATA
;
}
}
...
@@ -747,16 +717,14 @@ iphone_afc_read_file(iphone_afc_client_t client, iphone_afc_file_t file, char *d
...
@@ -747,16 +717,14 @@ iphone_afc_read_file(iphone_afc_client_t client, iphone_afc_file_t file, char *d
if
(
!
client
||
!
client
->
afc_packet
||
!
client
->
connection
||
!
file
)
if
(
!
client
||
!
client
->
afc_packet
||
!
client
->
connection
||
!
file
)
return
IPHONE_E_INVALID_ARG
;
return
IPHONE_E_INVALID_ARG
;
if
(
debug
)
log_debug_msg
(
"afc_read_file called for length %i
\n
"
,
length
);
fprintf
(
stderr
,
"afc_read_file called for length %i
\n
"
,
length
);
afc_lock
(
client
);
afc_lock
(
client
);
// Looping here to get around the maximum amount of data that
// Looping here to get around the maximum amount of data that
// recieve_AFC_data can handle
// recieve_AFC_data can handle
while
(
current_count
<
length
)
{
while
(
current_count
<
length
)
{
if
(
debug
)
log_debug_msg
(
"afc_read_file: current count is %i but length is %i
\n
"
,
current_count
,
length
);
fprintf
(
stderr
,
"afc_read_file: current count is %i but length is %i
\n
"
,
current_count
,
length
);
// Send the read command
// Send the read command
AFCFilePacket
*
packet
=
(
AFCFilePacket
*
)
malloc
(
sizeof
(
AFCFilePacket
));
AFCFilePacket
*
packet
=
(
AFCFilePacket
*
)
malloc
(
sizeof
(
AFCFilePacket
));
...
@@ -774,8 +742,7 @@ iphone_afc_read_file(iphone_afc_client_t client, iphone_afc_file_t file, char *d
...
@@ -774,8 +742,7 @@ iphone_afc_read_file(iphone_afc_client_t client, iphone_afc_file_t file, char *d
}
}
// Receive the data
// Receive the data
bytes_loc
=
receive_AFC_data
(
client
,
&
input
);
bytes_loc
=
receive_AFC_data
(
client
,
&
input
);
if
(
debug
)
log_debug_msg
(
"afc_read_file: bytes returned: %i
\n
"
,
bytes_loc
);
fprintf
(
stderr
,
"afc_read_file: bytes returned: %i
\n
"
,
bytes_loc
);
if
(
bytes_loc
<
0
)
{
if
(
bytes_loc
<
0
)
{
if
(
input
)
if
(
input
)
free
(
input
);
free
(
input
);
...
@@ -790,8 +757,7 @@ iphone_afc_read_file(iphone_afc_client_t client, iphone_afc_file_t file, char *d
...
@@ -790,8 +757,7 @@ iphone_afc_read_file(iphone_afc_client_t client, iphone_afc_file_t file, char *d
// success
// success
}
else
{
}
else
{
if
(
input
)
{
if
(
input
)
{
if
(
debug
)
log_debug_msg
(
"afc_read_file: %d
\n
"
,
bytes_loc
);
fprintf
(
stderr
,
"afc_read_file: %d
\n
"
,
bytes_loc
);
memcpy
(
data
+
current_count
,
input
,
(
bytes_loc
>
length
)
?
length
:
bytes_loc
);
memcpy
(
data
+
current_count
,
input
,
(
bytes_loc
>
length
)
?
length
:
bytes_loc
);
free
(
input
);
free
(
input
);
input
=
NULL
;
input
=
NULL
;
...
@@ -799,8 +765,7 @@ iphone_afc_read_file(iphone_afc_client_t client, iphone_afc_file_t file, char *d
...
@@ -799,8 +765,7 @@ iphone_afc_read_file(iphone_afc_client_t client, iphone_afc_file_t file, char *d
}
}
}
}
}
}
if
(
debug
)
log_debug_msg
(
"afc_read_file: returning current_count as %i
\n
"
,
current_count
);
fprintf
(
stderr
,
"afc_read_file: returning current_count as %i
\n
"
,
current_count
);
afc_unlock
(
client
);
afc_unlock
(
client
);
*
bytes
=
current_count
;
*
bytes
=
current_count
;
...
@@ -831,8 +796,7 @@ iphone_afc_write_file(iphone_afc_client_t client, iphone_afc_file_t file,
...
@@ -831,8 +796,7 @@ iphone_afc_write_file(iphone_afc_client_t client, iphone_afc_file_t file,
afc_lock
(
client
);
afc_lock
(
client
);
if
(
debug
)
log_debug_msg
(
"afc_write_file: Write length: %i
\n
"
,
length
);
fprintf
(
stderr
,
"afc_write_file: Write length: %i
\n
"
,
length
);
// Divide the file into segments.
// Divide the file into segments.
for
(
i
=
0
;
i
<
segments
;
i
++
)
{
for
(
i
=
0
;
i
<
segments
;
i
++
)
{
...
@@ -893,8 +857,7 @@ iphone_afc_write_file(iphone_afc_client_t client, iphone_afc_file_t file,
...
@@ -893,8 +857,7 @@ iphone_afc_write_file(iphone_afc_client_t client, iphone_afc_file_t file,
bytes_loc
=
receive_AFC_data
(
client
,
&
acknowledgement
);
bytes_loc
=
receive_AFC_data
(
client
,
&
acknowledgement
);
afc_unlock
(
client
);
afc_unlock
(
client
);
if
(
bytes_loc
<
0
)
{
if
(
bytes_loc
<
0
)
{
if
(
debug
)
log_debug_msg
(
"afc_write_file: uh oh?
\n
"
);
fprintf
(
stderr
,
"afc_write_file: uh oh?
\n
"
);
}
}
*
bytes
=
current_count
;
*
bytes
=
current_count
;
return
IPHONE_E_SUCCESS
;
return
IPHONE_E_SUCCESS
;
...
@@ -916,8 +879,7 @@ iphone_error_t iphone_afc_close_file(iphone_afc_client_t client, iphone_afc_file
...
@@ -916,8 +879,7 @@ iphone_error_t iphone_afc_close_file(iphone_afc_client_t client, iphone_afc_file
afc_lock
(
client
);
afc_lock
(
client
);
if
(
debug
)
log_debug_msg
(
"afc_close_file: File handle %i
\n
"
,
file
->
filehandle
);
fprintf
(
stderr
,
"afc_close_file: File handle %i
\n
"
,
file
->
filehandle
);
// Send command
// Send command
memcpy
(
buffer
,
&
file
->
filehandle
,
sizeof
(
uint32
));
memcpy
(
buffer
,
&
file
->
filehandle
,
sizeof
(
uint32
));
...
...
src/Makefile.am
View file @
0b2cfd2c
...
@@ -7,7 +7,7 @@ bin_PROGRAMS = iphoneclient libiphone-initconf lckd-client
...
@@ -7,7 +7,7 @@ bin_PROGRAMS = iphoneclient libiphone-initconf lckd-client
iphoneclient_SOURCES
=
main.c
iphoneclient_SOURCES
=
main.c
iphoneclient_LDADD
=
libiphone.la
iphoneclient_LDADD
=
libiphone.la
libiphone_initconf_SOURCES
=
initconf.c userpref.c lockdown.c plist.c usbmux.c iphone.c
libiphone_initconf_SOURCES
=
initconf.c userpref.c lockdown.c plist.c usbmux.c iphone.c
utils.c
libiphone_initconf_CFLAGS
=
$(libgthread2_CFLAGS)
$(AM_CFLAGS)
libiphone_initconf_CFLAGS
=
$(libgthread2_CFLAGS)
$(AM_CFLAGS)
libiphone_initconf_LDFLAGS
=
$(libgthread2_LIBS)
$(AM_LDFLAGS)
libiphone_initconf_LDFLAGS
=
$(libgthread2_LIBS)
$(AM_LDFLAGS)
...
@@ -17,4 +17,4 @@ lckd_client_LDFLAGS = -lreadline $(AM_LDFLAGS)
...
@@ -17,4 +17,4 @@ lckd_client_LDFLAGS = -lreadline $(AM_LDFLAGS)
lckd_client_LDADD
=
libiphone.la
lckd_client_LDADD
=
libiphone.la
lib_LTLIBRARIES
=
libiphone.la
lib_LTLIBRARIES
=
libiphone.la
libiphone_la_SOURCES
=
usbmux.c iphone.c plist.c lockdown.c AFC.c userpref.c
libiphone_la_SOURCES
=
usbmux.c iphone.c plist.c lockdown.c AFC.c userpref.c
utils.c
src/initconf.c
View file @
0b2cfd2c
...
@@ -26,9 +26,10 @@
...
@@ -26,9 +26,10 @@
#include <gnutls/x509.h>
#include <gnutls/x509.h>
#include <glib.h>
#include <glib.h>
#include "libiphone/libiphone.h"
#include "userpref.h"
#include "userpref.h"
#include "lockdown.h"
#include "lockdown.h"
#include "utils.h"
/** Generates a 2048 byte key, split into a function so that it can be run in a
/** Generates a 2048 byte key, split into a function so that it can be run in a
* thread.
* thread.
...
...
src/iphone.c
View file @
0b2cfd2c
...
@@ -21,24 +21,13 @@
...
@@ -21,24 +21,13 @@
#include "usbmux.h"
#include "usbmux.h"
#include "iphone.h"
#include "iphone.h"
#include "utils.h"
#include <arpa/inet.h>
#include <arpa/inet.h>
#include <usb.h>
#include <usb.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
int
iphone_debug
=
0
;
/**
* Sets the level of debugging. Currently the only acceptable values are 0 and
* 1.
*
* @param level Set to 0 for no debugging or 1 for debugging.
*/
void
iphone_set_debug
(
int
level
)
{
iphone_debug
=
level
;
}
/**
/**
* Given a USB bus and device number, returns a device handle to the iPhone on
* Given a USB bus and device number, returns a device handle to the iPhone on
...
@@ -90,18 +79,18 @@ iphone_error_t iphone_get_specific_device(int bus_n, int dev_n, iphone_device_t
...
@@ -90,18 +79,18 @@ iphone_error_t iphone_get_specific_device(int bus_n, int dev_n, iphone_device_t
}
}
iphone_free_device
(
phone
);
iphone_free_device
(
phone
);
if
(
iphone_debug
)
fprintf
(
stderr
,
"iphone_get_specific_device: iPhone not found
\n
"
);
log_debug_msg
(
"iphone_get_specific_device: iPhone not found
\n
"
);
return
IPHONE_E_NO_DEVICE
;
return
IPHONE_E_NO_DEVICE
;
found:
found:
// Send the version command to the phone
// Send the version command to the phone
version
=
version_header
();
version
=
version_header
();
bytes
=
usb_bulk_write
(
phone
->
device
,
BULKOUT
,
(
char
*
)
version
,
sizeof
(
*
version
),
800
);
bytes
=
usb_bulk_write
(
phone
->
device
,
BULKOUT
,
(
char
*
)
version
,
sizeof
(
*
version
),
800
);
if
(
bytes
<
20
&&
iphone_debug
)
{
if
(
bytes
<
20
)
{
fprintf
(
stderr
,
"get_iPhone(): libusb did NOT send enough!
\n
"
);
log_debug_msg
(
"get_iPhone(): libusb did NOT send enough!
\n
"
);
if
(
bytes
<
0
)
{
if
(
bytes
<
0
)
{
fprintf
(
stderr
,
"get_iPhone(): libusb gave me the error %d: %s (%s)
\n
"
,
log_debug_msg
(
"get_iPhone(): libusb gave me the error %d: %s (%s)
\n
"
,
bytes
,
usb_strerror
(),
strerror
(
-
bytes
));
bytes
,
usb_strerror
(),
strerror
(
-
bytes
));
}
}
}
}
...
@@ -112,11 +101,9 @@ iphone_error_t iphone_get_specific_device(int bus_n, int dev_n, iphone_device_t
...
@@ -112,11 +101,9 @@ iphone_error_t iphone_get_specific_device(int bus_n, int dev_n, iphone_device_t
if
(
bytes
<
20
)
{
if
(
bytes
<
20
)
{
free
(
version
);
free
(
version
);
iphone_free_device
(
phone
);
iphone_free_device
(
phone
);
if
(
iphone_debug
)
log_debug_msg
(
"get_iPhone(): Invalid version message -- header too short.
\n
"
);
fprintf
(
stderr
,
"get_iPhone(): Invalid version message -- header too short.
\n
"
);
if
(
bytes
<
0
)
if
(
iphone_debug
&&
bytes
<
0
)
log_debug_msg
(
"get_iPhone(): libusb error message %d: %s (%s)
\n
"
,
bytes
,
usb_strerror
(),
strerror
(
-
bytes
));
fprintf
(
stderr
,
"get_iPhone(): libusb error message %d: %s (%s)
\n
"
,
bytes
,
usb_strerror
(),
strerror
(
-
bytes
));
return
IPHONE_E_NOT_ENOUGH_DATA
;
return
IPHONE_E_NOT_ENOUGH_DATA
;
}
}
// Check for correct version
// Check for correct version
...
@@ -130,14 +117,12 @@ iphone_error_t iphone_get_specific_device(int bus_n, int dev_n, iphone_device_t
...
@@ -130,14 +117,12 @@ iphone_error_t iphone_get_specific_device(int bus_n, int dev_n, iphone_device_t
// Bad header
// Bad header
iphone_free_device
(
phone
);
iphone_free_device
(
phone
);
free
(
version
);
free
(
version
);
if
(
iphone_debug
)
log_debug_msg
(
"get_iPhone(): Received a bad header/invalid version number."
);
fprintf
(
stderr
,
"get_iPhone(): Received a bad header/invalid version number."
);
return
IPHONE_E_BAD_HEADER
;
return
IPHONE_E_BAD_HEADER
;
}
}
// If it got to this point it's gotta be bad
// If it got to this point it's gotta be bad
if
(
iphone_debug
)
log_debug_msg
(
"get_iPhone(): Unknown error.
\n
"
);
fprintf
(
stderr
,
"get_iPhone(): Unknown error.
\n
"
);
iphone_free_device
(
phone
);
iphone_free_device
(
phone
);
free
(
version
);
free
(
version
);
return
IPHONE_E_UNKNOWN_ERROR
;
// if it got to this point it's gotta be bad
return
IPHONE_E_UNKNOWN_ERROR
;
// if it got to this point it's gotta be bad
...
@@ -218,13 +203,12 @@ int send_to_phone(iphone_device_t phone, char *data, int datalen)
...
@@ -218,13 +203,12 @@ int send_to_phone(iphone_device_t phone, char *data, int datalen)
if
(
!
phone
)
if
(
!
phone
)
return
-
1
;
return
-
1
;
if
(
iphone_debug
)
log_debug_msg
(
"send_to_phone: Attempting to send datalen = %i data = %p
\n
"
,
datalen
,
data
);
fprintf
(
stderr
,
"send_to_phone: Attempting to send datalen = %i data = %p
\n
"
,
datalen
,
data
);
bytes
=
usb_bulk_write
(
phone
->
device
,
BULKOUT
,
data
,
datalen
,
800
);
bytes
=
usb_bulk_write
(
phone
->
device
,
BULKOUT
,
data
,
datalen
,
800
);
if
(
bytes
<
datalen
)
{
if
(
bytes
<
datalen
)
{
if
(
iphone_debug
&&
bytes
<
0
)
if
(
bytes
<
0
)
fprintf
(
stderr
,
"send_to_iphone(): libusb gave me the error %d: %s - %s
\n
"
,
bytes
,
usb_strerror
(),
log_debug_msg
(
"send_to_iphone(): libusb gave me the error %d: %s - %s
\n
"
,
bytes
,
usb_strerror
(),
strerror
(
-
bytes
));
strerror
(
-
bytes
));
return
-
1
;
return
-
1
;
}
else
{
}
else
{
...
@@ -250,13 +234,11 @@ int recv_from_phone(iphone_device_t phone, char *data, int datalen)
...
@@ -250,13 +234,11 @@ int recv_from_phone(iphone_device_t phone, char *data, int datalen)
if
(
!
phone
)
if
(
!
phone
)
return
-
1
;
return
-
1
;
if
(
iphone_debug
)
log_debug_msg
(
"recv_from_phone(): attempting to receive %i bytes
\n
"
,
datalen
);
fprintf
(
stderr
,
"recv_from_phone(): attempting to receive %i bytes
\n
"
,
datalen
);
bytes
=
usb_bulk_read
(
phone
->
device
,
BULKIN
,
data
,
datalen
,
3500
);
bytes
=
usb_bulk_read
(
phone
->
device
,
BULKIN
,
data
,
datalen
,
3500
);
if
(
bytes
<
0
)
{
if
(
bytes
<
0
)
{
if
(
iphone_debug
)
log_debug_msg
(
"recv_from_phone(): libusb gave me the error %d: %s (%s)
\n
"
,
bytes
,
usb_strerror
(),
fprintf
(
stderr
,
"recv_from_phone(): libusb gave me the error %d: %s (%s)
\n
"
,
bytes
,
usb_strerror
(),
strerror
(
-
bytes
));
strerror
(
-
bytes
));
return
-
1
;
return
-
1
;
}
}
...
...
src/lockdown.c
View file @
0b2cfd2c
This diff is collapsed.
Click to expand it.
src/usbmux.c
View file @
0b2cfd2c
...
@@ -27,8 +27,6 @@
...
@@ -27,8 +27,6 @@
#include "usbmux.h"
#include "usbmux.h"
extern
int
debug
;
static
iphone_umux_client_t
*
connlist
=
NULL
;
static
iphone_umux_client_t
*
connlist
=
NULL
;
static
int
clients
=
0
;
static
int
clients
=
0
;
...
@@ -151,8 +149,7 @@ iphone_error_t iphone_mux_new_client(iphone_device_t device, uint16_t src_port,
...
@@ -151,8 +149,7 @@ iphone_error_t iphone_mux_new_client(iphone_device_t device, uint16_t src_port,
}
else
{
}
else
{
free
(
response
);
free
(
response
);
if
(
debug
)
log_debug_msg
(
"mux_connect: connection success
\n
"
);
printf
(
"mux_connect: connection success
\n
"
);
new_connection
->
header
->
tcp_flags
=
0x10
;
new_connection
->
header
->
tcp_flags
=
0x10
;
new_connection
->
header
->
scnt
=
1
;
new_connection
->
header
->
scnt
=
1
;
new_connection
->
header
->
ocnt
=
1
;
new_connection
->
header
->
ocnt
=
1
;
...
@@ -189,12 +186,12 @@ iphone_error_t iphone_mux_free_client(iphone_umux_client_t client)
...
@@ -189,12 +186,12 @@ iphone_error_t iphone_mux_free_client(iphone_umux_client_t client)
int
bytes
=
0
;
int
bytes
=
0
;
bytes
=
usb_bulk_write
(
client
->
phone
->
device
,
BULKOUT
,
(
char
*
)
client
->
header
,
sizeof
(
usbmux_tcp_header
),
800
);
bytes
=
usb_bulk_write
(
client
->
phone
->
device
,
BULKOUT
,
(
char
*
)
client
->
header
,
sizeof
(
usbmux_tcp_header
),
800
);
if
(
debug
&&
bytes
<
0
)
if
(
bytes
<
0
)
printf
(
"iphone_muxèfree_client(): when writing, libusb gave me the error: %s
\n
"
,
usb_strerror
());
log_debug_msg
(
"iphone_muxèfree_client(): when writing, libusb gave me the error: %s
\n
"
,
usb_strerror
());
bytes
=
usb_bulk_read
(
client
->
phone
->
device
,
BULKIN
,
(
char
*
)
client
->
header
,
sizeof
(
usbmux_tcp_header
),
800
);
bytes
=
usb_bulk_read
(
client
->
phone
->
device
,
BULKIN
,
(
char
*
)
client
->
header
,
sizeof
(
usbmux_tcp_header
),
800
);
if
(
debug
&&
bytes
<
0
)
if
(
bytes
<
0
)
printf
(
"get_iPhone(): when reading, libusb gave me the error: %s
\n
"
,
usb_strerror
());
log_debug_msg
(
"get_iPhone(): when reading, libusb gave me the error: %s
\n
"
,
usb_strerror
());
delete_connection
(
client
);
delete_connection
(
client
);
...
@@ -220,8 +217,7 @@ iphone_error_t iphone_mux_send(iphone_umux_client_t client, const char *data, ui
...
@@ -220,8 +217,7 @@ iphone_error_t iphone_mux_send(iphone_umux_client_t client, const char *data, ui
// client->scnt and client->ocnt should already be in host notation...
// client->scnt and client->ocnt should already be in host notation...
// we don't need to change them juuuust yet.
// we don't need to change them juuuust yet.
*
sent_bytes
=
0
;
*
sent_bytes
=
0
;
if
(
debug
)
log_debug_msg
(
"mux_send(): client wants to send %i bytes
\n
"
,
datalen
);
printf
(
"mux_send(): client wants to send %i bytes
\n
"
,
datalen
);
char
*
buffer
=
(
char
*
)
malloc
(
sizeof
(
usbmux_tcp_header
)
+
datalen
+
2
);
// allow 2 bytes of safety padding
char
*
buffer
=
(
char
*
)
malloc
(
sizeof
(
usbmux_tcp_header
)
+
datalen
+
2
);
// allow 2 bytes of safety padding
// Set the length and pre-emptively htonl/htons it
// Set the length and pre-emptively htonl/htons it
client
->
header
->
length
=
htonl
(
sizeof
(
usbmux_tcp_header
)
+
datalen
);
client
->
header
->
length
=
htonl
(
sizeof
(
usbmux_tcp_header
)
+
datalen
);
...
@@ -235,21 +231,13 @@ iphone_error_t iphone_mux_send(iphone_umux_client_t client, const char *data, ui
...
@@ -235,21 +231,13 @@ iphone_error_t iphone_mux_send(iphone_umux_client_t client, const char *data, ui
memcpy
(
buffer
+
sizeof
(
usbmux_tcp_header
),
data
,
datalen
);
memcpy
(
buffer
+
sizeof
(
usbmux_tcp_header
),
data
,
datalen
);
// We have a buffer full of data, we should now send it to the phone.
// We have a buffer full of data, we should now send it to the phone.
if
(
debug
)
log_debug_msg
(
"actually sending %zi bytes of data at %p
\n
"
,
sizeof
(
usbmux_tcp_header
)
+
datalen
,
buffer
);
printf
(
"actually sending %zi bytes of data at %p
\n
"
,
sizeof
(
usbmux_tcp_header
)
+
datalen
,
buffer
);
*
sent_bytes
=
send_to_phone
(
client
->
phone
,
buffer
,
sizeof
(
usbmux_tcp_header
)
+
datalen
);
*
sent_bytes
=
send_to_phone
(
client
->
phone
,
buffer
,
sizeof
(
usbmux_tcp_header
)
+
datalen
);
if
(
debug
)
log_debug_msg
(
"mux_send: sent %i bytes!
\n
"
,
*
sent_bytes
);
printf
(
"mux_send: sent %i bytes!
\n
"
,
*
sent_bytes
);
// Now that we've sent it off, we can clean up after our sloppy selves.
// Now that we've sent it off, we can clean up after our sloppy selves.
if
(
debug
)
{
dump_debug_buffer
(
"packet"
,
buffer
,
*
sent_bytes
);
FILE
*
packet
=
fopen
(
"packet"
,
"a+"
);
fwrite
(
buffer
,
1
,
*
sent_bytes
,
packet
);
fclose
(
packet
);
printf
(
"
\n
"
);
}
if
(
buffer
)
if
(
buffer
)
free
(
buffer
);
free
(
buffer
);
// Re-calculate scnt and ocnt
// Re-calculate scnt and ocnt
...
@@ -294,8 +282,7 @@ iphone_error_t iphone_mux_recv(iphone_umux_client_t client, char *data, uint32_t
...
@@ -294,8 +282,7 @@ iphone_error_t iphone_mux_recv(iphone_umux_client_t client, char *data, uint32_t
* a.) Check incoming packet's ports. If proper, follow proper buffering and receiving operation.
* a.) Check incoming packet's ports. If proper, follow proper buffering and receiving operation.
* b.) If not, find the client the ports belong to and fill that client's buffer, then return mux_recv with the same args to try again.
* b.) If not, find the client the ports belong to and fill that client's buffer, then return mux_recv with the same args to try again.
*/
*/
if
(
debug
)
log_debug_msg
(
"mux_recv: datalen == %i
\n
"
,
datalen
);
printf
(
"mux_recv: datalen == %i
\n
"
,
datalen
);
int
bytes
=
0
,
i
=
0
,
complex
=
0
,
offset
=
0
;
int
bytes
=
0
,
i
=
0
,
complex
=
0
,
offset
=
0
;
*
recv_bytes
=
0
;
*
recv_bytes
=
0
;
char
*
buffer
=
NULL
;
char
*
buffer
=
NULL
;
...
@@ -333,8 +320,7 @@ iphone_error_t iphone_mux_recv(iphone_umux_client_t client, char *data, uint32_t
...
@@ -333,8 +320,7 @@ iphone_error_t iphone_mux_recv(iphone_umux_client_t client, char *data, uint32_t
bytes
=
recv_from_phone
(
client
->
phone
,
buffer
,
131072
);
bytes
=
recv_from_phone
(
client
->
phone
,
buffer
,
131072
);
if
(
bytes
<
28
)
{
if
(
bytes
<
28
)
{
free
(
buffer
);
free
(
buffer
);
if
(
debug
)
log_debug_msg
(
"mux_recv: Did not even get the header.
\n
"
);
printf
(
"mux_recv: Did not even get the header.
\n
"
);
return
IPHONE_E_NOT_ENOUGH_DATA
;
return
IPHONE_E_NOT_ENOUGH_DATA
;
}
}
...
@@ -390,7 +376,6 @@ iphone_error_t iphone_mux_recv(iphone_umux_client_t client, char *data, uint32_t
...
@@ -390,7 +376,6 @@ iphone_error_t iphone_mux_recv(iphone_umux_client_t client, char *data, uint32_t
}
}
// If we get to this point, 'tis probably bad.
// If we get to this point, 'tis probably bad.
if
(
debug
)
log_debug_msg
(
"mux_recv: Heisenbug: bytes and datalen not matching up
\n
"
);
printf
(
"mux_recv: Heisenbug: bytes and datalen not matching up
\n
"
);
return
IPHONE_E_UNKNOWN_ERROR
;
return
IPHONE_E_UNKNOWN_ERROR
;
}
}
src/userpref.c
View file @
0b2cfd2c
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include "userpref.h"
#include "userpref.h"
#include "utils.h"
#include <string.h>
#include <string.h>
#include <stdlib.h>
#include <stdlib.h>
...
@@ -35,7 +36,6 @@
...
@@ -35,7 +36,6 @@
#define LIBIPHONE_ROOT_CERTIF "RootCertificate.pem"
#define LIBIPHONE_ROOT_CERTIF "RootCertificate.pem"
#define LIBIPHONE_HOST_CERTIF "HostCertificate.pem"
#define LIBIPHONE_HOST_CERTIF "HostCertificate.pem"
extern
int
debug
;
/** Creates a freedesktop compatible configuration directory for libiphone.
/** Creates a freedesktop compatible configuration directory for libiphone.
*/
*/
...
@@ -77,8 +77,7 @@ char *get_host_id()
...
@@ -77,8 +77,7 @@ char *get_host_id()
g_key_file_free
(
key_file
);
g_key_file_free
(
key_file
);
g_free
(
config_file
);
g_free
(
config_file
);
if
(
debug
)
log_debug_msg
(
"get_host_id(): Using %s as HostID
\n
"
,
host_id
);
printf
(
"get_host_id(): Using %s as HostID
\n
"
,
host_id
);
return
host_id
;
return
host_id
;
}
}
...
@@ -246,8 +245,7 @@ int init_config_file(char *host_id, gnutls_datum_t * root_key, gnutls_datum_t *
...
@@ -246,8 +245,7 @@ int init_config_file(char *host_id, gnutls_datum_t * root_key, gnutls_datum_t *
key_file
=
g_key_file_new
();
key_file
=
g_key_file_new
();
/* Store in config file */
/* Store in config file */
if
(
debug
)
log_debug_msg
(
"init_config_file(): setting hostID to %s
\n
"
,
host_id
);
printf
(
"init_config_file(): setting hostID to %s
\n
"
,
host_id
);
g_key_file_set_value
(
key_file
,
"Global"
,
"HostID"
,
host_id
);
g_key_file_set_value
(
key_file
,
"Global"
,
"HostID"
,
host_id
);
/* Write config file on disk */
/* Write config file on disk */
...
...
src/utils.c
0 → 100644
View file @
0b2cfd2c
/*
* utils.c
* contains utilitary methos for logging and debugging
*
* Copyright (c) 2008 Jonathan Beck All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdarg.h>
#include <stdio.h>
#include "utils.h"
int
toto_debug
=
0
;
/**
* Sets the level of debugging. Currently the only acceptable values are 0 and
* 1.
*
* @param level Set to 0 for no debugging or 1 for debugging.
*/
void
iphone_set_debug
(
int
level
)
{
toto_debug
=
level
;
}
void
log_debug_msg
(
const
char
*
format
,
...)
{
#ifndef STRIP_DEBUG
va_list
args
;
/* run the real fprintf */
va_start
(
args
,
format
);
if
(
toto_debug
)
fprintf
(
stderr
,
format
,
args
);
va_end
(
args
);
#endif
}
inline
void
log_debug_buffer
(
const
char
*
data
,
const
int
length
)
{
#ifndef STRIP_DEBUG
/* run the real fprintf */
if
(
toto_debug
)
fwrite
(
data
,
1
,
length
,
stderr
);
#endif
}
inline
void
dump_debug_buffer
(
const
char
*
file
,
const
char
*
data
,
const
int
length
)
{
#ifndef STRIP_DEBUG
/* run the real fprintf */
if
(
toto_debug
)
{
FILE
*
my_ssl_packet
=
fopen
(
file
,
"w+"
);
fwrite
(
data
,
1
,
length
,
my_ssl_packet
);
fflush
(
my_ssl_packet
);
fprintf
(
stderr
,
"Wrote SSL packet to drive, too.
\n
"
);
fclose
(
my_ssl_packet
);
}
#endif
}
src/utils.h
0 → 100644
View file @
0b2cfd2c
/*
* utils.h
* contains utilitary methos for logging and debugging
*
* Copyright (c) 2008 Jonathan Beck All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef UTILS_H
#define UTILS_H
#include "libiphone/libiphone.h"
inline
void
log_debug_msg
(
const
char
*
format
,
...);
inline
void
log_debug_buffer
(
const
char
*
data
,
const
int
length
);
inline
void
dump_debug_buffer
(
const
char
*
file
,
const
char
*
data
,
const
int
length
);
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment