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
aed2c025
Commit
aed2c025
authored
Nov 25, 2008
by
Jonathan Beck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix some warnings and indent
parent
0bca81e7
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
294 additions
and
274 deletions
+294
-274
lckdclient.c
dev/lckdclient.c
+1
-0
main.c
dev/main.c
+1
-1
plutil.c
dev/plutil.c
+113
-106
plist.c
src/plist.c
+172
-163
plist.h
src/plist.h
+7
-4
No files found.
dev/lckdclient.c
View file @
aed2c025
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
*/
*/
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <glib.h>
#include <glib.h>
#include <readline/readline.h>
#include <readline/readline.h>
...
...
dev/main.c
View file @
aed2c025
...
@@ -87,7 +87,7 @@ int main(int argc, char *argv[])
...
@@ -87,7 +87,7 @@ int main(int argc, char *argv[])
iphone_afc_get_file_attr
(
afc
,
"/iTunesOnTheGoPlaylist.plist"
,
&
stbuf
);
iphone_afc_get_file_attr
(
afc
,
"/iTunesOnTheGoPlaylist.plist"
,
&
stbuf
);
if
(
IPHONE_E_SUCCESS
==
if
(
IPHONE_E_SUCCESS
==
iphone_afc_open_file
(
afc
,
"/iTunesOnTheGoPlaylist.plist"
,
IPHONE_AFC_FILE_READ
,
&
my_file
)
&&
my_file
)
{
iphone_afc_open_file
(
afc
,
"/iTunesOnTheGoPlaylist.plist"
,
IPHONE_AFC_FILE_READ
,
&
my_file
)
&&
my_file
)
{
printf
(
"A file size: %i
\n
"
,
stbuf
.
st_size
);
printf
(
"A file size: %i
\n
"
,
(
int
)
stbuf
.
st_size
);
char
*
file_data
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
stbuf
.
st_size
);
char
*
file_data
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
stbuf
.
st_size
);
iphone_afc_read_file
(
afc
,
my_file
,
file_data
,
stbuf
.
st_size
,
&
bytes
);
iphone_afc_read_file
(
afc
,
my_file
,
file_data
,
stbuf
.
st_size
,
&
bytes
);
if
(
bytes
>=
0
)
{
if
(
bytes
>=
0
)
{
...
...
dev/plutil.c
View file @
aed2c025
...
@@ -5,23 +5,27 @@
...
@@ -5,23 +5,27 @@
#include "../src/plist.h"
#include "../src/plist.h"
#include "plutil.h"
#include "plutil.h"
#include <glib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int
debug
=
0
;
void
print_nodes
(
bplist_node
*
root_node
)
{
void
print_nodes
(
bplist_node
*
root_node
)
{
// Yay, great. Let's print the list of nodes recursively...
// Yay, great. Let's print the list of nodes recursively...
int
i
=
0
;
int
i
=
0
;
if
(
!
root_node
)
return
;
// or not, because the programmer's stupid.
if
(
!
root_node
)
return
;
// or not, because the programmer's stupid.
switch
(
root_node
->
type
)
{
switch
(
root_node
->
type
)
{
case
BPLIST_DICT
:
case
BPLIST_DICT
:
printf
(
"Dictionary node.
\n
Length %i
\n
"
,
root_node
->
length
);
printf
(
"Dictionary node.
\n
Length %lu
\n
"
,
(
long
unsigned
int
)
root_node
->
length
);
for
(
i
=
0
;
i
<
(
root_node
->
length
*
2
);
i
+=
2
)
{
for
(
i
=
0
;
i
<
(
root_node
->
length
*
2
);
i
+=
2
)
{
// HI!
// HI!
printf
(
"Key: "
);
printf
(
"Key: "
);
print_nodes
(
root_node
->
subnodes
[
i
]);
print_nodes
(
root_node
->
subnodes
[
i
]);
printf
(
"Value: "
);
printf
(
"Value: "
);
print_nodes
(
root_node
->
subnodes
[
i
+
1
]);
print_nodes
(
root_node
->
subnodes
[
i
+
1
]);
}
}
printf
(
"End dictionary node.
\n\n
"
);
printf
(
"End dictionary node.
\n\n
"
);
break
;
break
;
...
@@ -53,7 +57,7 @@ void print_nodes(bplist_node *root_node) {
...
@@ -53,7 +57,7 @@ void print_nodes(bplist_node *root_node) {
case
BPLIST_DATA
:
case
BPLIST_DATA
:
printf
(
"Data: "
);
printf
(
"Data: "
);
char
*
data
=
g_base64_encode
(
root_node
->
strval
,
root_node
->
length
);
char
*
data
=
g_base64_encode
(
root_node
->
strval
,
root_node
->
length
);
fwrite
(
format_string
(
data
,
60
,
0
),
sizeof
(
char
),
strlen
(
data
),
stdout
);
fwrite
(
format_string
(
data
,
60
,
0
),
sizeof
(
char
),
strlen
(
data
),
stdout
);
fflush
(
stdout
);
fflush
(
stdout
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
...
@@ -80,13 +84,14 @@ void print_nodes(bplist_node *root_node) {
...
@@ -80,13 +84,14 @@ void print_nodes(bplist_node *root_node) {
break
;
break
;
default:
default:
printf
(
"oops
\n
Type set to %x and length is %i
\n
"
,
root_node
->
type
,
root_node
->
length
);
printf
(
"oops
\n
Type set to %x and length is %lu
\n
"
,
root_node
->
type
,
(
long
unsigned
int
)
root_node
->
length
);
break
;
break
;
}
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
struct
stat
*
filestats
=
(
struct
stat
*
)
malloc
(
sizeof
(
struct
stat
));
{
struct
stat
*
filestats
=
(
struct
stat
*
)
malloc
(
sizeof
(
struct
stat
));
uint32_t
position
=
0
;
uint32_t
position
=
0
;
Options
*
options
=
parse_arguments
(
argc
,
argv
);
Options
*
options
=
parse_arguments
(
argc
,
argv
);
int
argh
=
0
;
int
argh
=
0
;
...
@@ -98,14 +103,14 @@ int main(int argc, char *argv[]) {
...
@@ -98,14 +103,14 @@ int main(int argc, char *argv[]) {
return
0
;
return
0
;
}
}
debug
=
options
->
debug
;
iphone_set_debug
(
options
->
debug
)
;
FILE
*
bplist
=
fopen
(
options
->
in_file
,
"r"
);
FILE
*
bplist
=
fopen
(
options
->
in_file
,
"r"
);
stat
(
options
->
in_file
,
filestats
);
stat
(
options
->
in_file
,
filestats
);
printf
(
"here?
\n
"
);
printf
(
"here?
\n
"
);
char
*
bplist_entire
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
(
filestats
->
st_size
+
1
));
char
*
bplist_entire
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
(
filestats
->
st_size
+
1
));
//argh = fgets(bplist_entire, filestats->st_size, bplist);
//argh = fgets(bplist_entire, filestats->st_size, bplist);
argh
=
fread
(
bplist_entire
,
sizeof
(
char
),
filestats
->
st_size
,
bplist
);
argh
=
fread
(
bplist_entire
,
sizeof
(
char
),
filestats
->
st_size
,
bplist
);
printf
(
"read %i bytes
\n
"
,
argh
);
printf
(
"read %i bytes
\n
"
,
argh
);
...
@@ -115,38 +120,39 @@ int main(int argc, char *argv[]) {
...
@@ -115,38 +120,39 @@ int main(int argc, char *argv[]) {
bplist_node
*
root_node
;
bplist_node
*
root_node
;
root_node
=
parse_nodes
(
bplist_entire
,
filestats
->
st_size
,
&
position
);
root_node
=
parse_nodes
(
bplist_entire
,
filestats
->
st_size
,
&
position
);
printf
(
"plutil debug mode
\n\n
"
);
printf
(
"plutil debug mode
\n\n
"
);
printf
(
"file size %i
\n\n
"
,
filestats
->
st_size
);
printf
(
"file size %i
\n\n
"
,
(
int
)
filestats
->
st_size
);
if
(
!
root_node
)
{
if
(
!
root_node
)
{
printf
(
"Invalid binary plist (or some other error occurred.)
\n
"
);
printf
(
"Invalid binary plist (or some other error occurred.)
\n
"
);
return
0
;
return
0
;
}
}
print_nodes
(
root_node
);
print_nodes
(
root_node
);
return
0
;
return
0
;
}
}
Options
*
parse_arguments
(
int
argc
,
char
*
argv
[])
{
Options
*
parse_arguments
(
int
argc
,
char
*
argv
[])
{
int
i
=
0
;
int
i
=
0
;
Options
*
options
=
(
Options
*
)
malloc
(
sizeof
(
Options
));
Options
*
options
=
(
Options
*
)
malloc
(
sizeof
(
Options
));
memset
(
options
,
0
,
sizeof
(
Options
));
memset
(
options
,
0
,
sizeof
(
Options
));
for
(
i
=
1
;
i
<
argc
;
i
++
)
{
for
(
i
=
1
;
i
<
argc
;
i
++
)
{
if
(
!
strcmp
(
argv
[
i
],
"--infile"
)
||
!
strcmp
(
argv
[
i
],
"-i"
))
{
if
(
!
strcmp
(
argv
[
i
],
"--infile"
)
||
!
strcmp
(
argv
[
i
],
"-i"
))
{
if
((
i
+
1
)
==
argc
)
{
if
((
i
+
1
)
==
argc
)
{
free
(
options
);
free
(
options
);
return
NULL
;
return
NULL
;
}
}
options
->
in_file
=
argv
[
i
+
1
];
options
->
in_file
=
argv
[
i
+
1
];
i
++
;
i
++
;
continue
;
continue
;
}
}
if
(
!
strcmp
(
argv
[
i
],
"--outfile"
)
||
!
strcmp
(
argv
[
i
],
"-o"
))
{
if
(
!
strcmp
(
argv
[
i
],
"--outfile"
)
||
!
strcmp
(
argv
[
i
],
"-o"
))
{
if
((
i
+
1
)
==
argc
)
{
if
((
i
+
1
)
==
argc
)
{
free
(
options
);
free
(
options
);
return
NULL
;
return
NULL
;
}
}
options
->
out_file
=
argv
[
i
+
1
];
options
->
out_file
=
argv
[
i
+
1
];
i
++
;
i
++
;
continue
;
continue
;
}
}
...
@@ -161,7 +167,7 @@ Options *parse_arguments(int argc, char *argv[]) {
...
@@ -161,7 +167,7 @@ Options *parse_arguments(int argc, char *argv[]) {
}
}
}
}
if
(
!
options
->
in_file
/*|| !options->out_file
*/
)
{
if
(
!
options
->
in_file
/*|| !options->out_file
*/
)
{
free
(
options
);
free
(
options
);
return
NULL
;
return
NULL
;
}
}
...
@@ -169,7 +175,8 @@ Options *parse_arguments(int argc, char *argv[]) {
...
@@ -169,7 +175,8 @@ Options *parse_arguments(int argc, char *argv[]) {
return
options
;
return
options
;
}
}
void
print_usage
()
{
void
print_usage
()
{
printf
(
"Usage: plistutil -i|--infile in_file.plist -o|--outfile out_file.plist [--debug]
\n
"
);
printf
(
"Usage: plistutil -i|--infile in_file.plist -o|--outfile out_file.plist [--debug]
\n
"
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
printf
(
"
\t
-i or --infile: The file to read in.
\n
"
);
printf
(
"
\t
-i or --infile: The file to read in.
\n
"
);
...
...
src/plist.c
View file @
aed2c025
...
@@ -261,8 +261,10 @@ void free_dictionary(char **dictionary)
...
@@ -261,8 +261,10 @@ void free_dictionary(char **dictionary)
* - parse_nodes() will return the first node it encounters, which is usually the "root" node.
* - parse_nodes() will return the first node it encounters, which is usually the "root" node.
*/
*/
uint32_t
uipow
(
uint32_t
value
,
uint32_t
power
)
{
uint32_t
uipow
(
uint32_t
value
,
uint32_t
power
)
if
(
!
power
)
return
1
;
{
if
(
!
power
)
return
1
;
int
i
=
0
,
oVal
=
value
;
int
i
=
0
,
oVal
=
value
;
for
(
i
=
1
;
i
<
power
;
i
++
)
{
for
(
i
=
1
;
i
<
power
;
i
++
)
{
value
*=
oVal
;
value
*=
oVal
;
...
@@ -270,28 +272,34 @@ uint32_t uipow(uint32_t value, uint32_t power) {
...
@@ -270,28 +272,34 @@ uint32_t uipow(uint32_t value, uint32_t power) {
return
value
;
return
value
;
}
}
void
byte_convert
(
char
*
address
,
size_t
size
)
{
void
byte_convert
(
char
*
address
,
size_t
size
)
{
int
i
=
0
,
j
=
0
;
int
i
=
0
,
j
=
0
;
char
tmp
=
'\0'
;
char
tmp
=
'\0'
;
for
(
i
=
0
;
i
<
(
size
/
2
);
i
++
)
{
for
(
i
=
0
;
i
<
(
size
/
2
);
i
++
)
{
tmp
=
address
[
i
];
tmp
=
address
[
i
];
j
=
((
size
-
1
)
+
0
)
-
i
;
j
=
((
size
-
1
)
+
0
)
-
i
;
address
[
i
]
=
address
[
j
];
address
[
i
]
=
address
[
j
];
address
[
j
]
=
tmp
;
address
[
j
]
=
tmp
;
}
}
}
}
bplist_node
*
parse_raw_node
(
const
char
*
bpbuffer
,
uint32_t
bplength
,
uint32_t
*
position
,
uint8_t
ref_size
)
{
bplist_node
*
parse_raw_node
(
const
char
*
bpbuffer
,
uint32_t
bplength
,
uint32_t
*
position
,
uint8_t
ref_size
)
if
(
!
position
||
!
bpbuffer
||
!
bplength
)
return
NULL
;
{
if
(
!
position
||
!
bpbuffer
||
!
bplength
)
return
NULL
;
uint8_t
modifier
=
0
;
uint8_t
modifier
=
0
;
bplist_node
*
new_node
=
(
bplist_node
*
)
malloc
(
sizeof
(
bplist_node
));
bplist_node
*
new_node
=
(
bplist_node
*
)
malloc
(
sizeof
(
bplist_node
));
bplist_node
*
length_stupidity
=
NULL
;
bplist_node
*
length_stupidity
=
NULL
;
memset
(
new_node
,
0
,
sizeof
(
bplist_node
));
// initialize the new struct
memset
(
new_node
,
0
,
sizeof
(
bplist_node
));
// initialize the new struct
int
myPos
=
*
position
;
int
myPos
=
*
position
;
if
(
myPos
==
bplength
||
(
myPos
+
1
)
==
bplength
)
{
free
(
new_node
);
return
NULL
;
}
// end of string
if
(
myPos
==
bplength
||
(
myPos
+
1
)
==
bplength
)
{
free
(
new_node
);
return
NULL
;
}
// end of string
uint32_t
length
=
0
;
uint32_t
length
=
0
;
if
(
!
myPos
)
{
if
(
!
myPos
)
{
...
@@ -300,15 +308,14 @@ bplist_node *parse_raw_node(const char *bpbuffer, uint32_t bplength, uint32_t *p
...
@@ -300,15 +308,14 @@ bplist_node *parse_raw_node(const char *bpbuffer, uint32_t bplength, uint32_t *p
}
}
myPos
+=
strlen
(
"bplist00"
);
myPos
+=
strlen
(
"bplist00"
);
}
}
// Get the node's type.
// Get the node's type.
if
(
bpbuffer
[
myPos
]
==
BPLIST_DATE
)
{
// handle date separately, but do it as a real
if
(
bpbuffer
[
myPos
]
==
BPLIST_DATE
)
{
// handle date separately, but do it as a real
// better handling of date; basically interpret as real or double
// better handling of date; basically interpret as real or double
new_node
->
type
=
BPLIST_DATE
;
new_node
->
type
=
BPLIST_DATE
;
new_node
->
length
=
8
;
// always 8 for "date" (Apple intended it, not me)
new_node
->
length
=
8
;
// always 8 for "date" (Apple intended it, not me)
myPos
++
;
myPos
++
;
memcpy
(
&
new_node
->
realval
,
bpbuffer
+
myPos
,
sizeof
(
new_node
->
realval
));
memcpy
(
&
new_node
->
realval
,
bpbuffer
+
myPos
,
sizeof
(
new_node
->
realval
));
byte_convert
(
&
new_node
->
realval
,
sizeof
(
new_node
->
realval
));
byte_convert
(
(
char
*
)
&
new_node
->
realval
,
sizeof
(
new_node
->
realval
));
myPos
+=
new_node
->
length
;
myPos
+=
new_node
->
length
;
*
position
=
myPos
;
*
position
=
myPos
;
return
new_node
;
return
new_node
;
...
@@ -357,13 +364,11 @@ bplist_node *parse_raw_node(const char *bpbuffer, uint32_t bplength, uint32_t *p
...
@@ -357,13 +364,11 @@ bplist_node *parse_raw_node(const char *bpbuffer, uint32_t bplength, uint32_t *p
*
position
=
myPos
;
*
position
=
myPos
;
free
(
length_stupidity
);
// cleanup
free
(
length_stupidity
);
// cleanup
}
}
// Now we're in the data.
// Now we're in the data.
// Error-checking sorta
// Error-checking sorta
if
((
myPos
+
new_node
->
length
)
>=
bplength
)
{
if
((
myPos
+
new_node
->
length
)
>=
bplength
)
{
new_node
->
length
=
bplength
-
myPos
;
// truncate the object
new_node
->
length
=
bplength
-
myPos
;
// truncate the object
}
}
// And now for the greatest show on earth: the giant fucking switch statement.
// And now for the greatest show on earth: the giant fucking switch statement.
switch
(
new_node
->
type
)
{
switch
(
new_node
->
type
)
{
case
BPLIST_INT
:
case
BPLIST_INT
:
...
@@ -373,20 +378,20 @@ bplist_node *parse_raw_node(const char *bpbuffer, uint32_t bplength, uint32_t *p
...
@@ -373,20 +378,20 @@ bplist_node *parse_raw_node(const char *bpbuffer, uint32_t bplength, uint32_t *p
new_node
->
intval8
=
bpbuffer
[
myPos
];
new_node
->
intval8
=
bpbuffer
[
myPos
];
break
;
break
;
case
sizeof
(
uint16_t
):
case
sizeof
(
uint16_t
):
memcpy
(
&
new_node
->
intval16
,
bpbuffer
+
myPos
,
sizeof
(
uint16_t
));
memcpy
(
&
new_node
->
intval16
,
bpbuffer
+
myPos
,
sizeof
(
uint16_t
));
new_node
->
intval16
=
ntohs
(
new_node
->
intval16
);
new_node
->
intval16
=
ntohs
(
new_node
->
intval16
);
break
;
break
;
case
sizeof
(
uint32_t
):
case
sizeof
(
uint32_t
):
memcpy
(
&
new_node
->
intval32
,
bpbuffer
+
myPos
,
sizeof
(
uint32_t
));
memcpy
(
&
new_node
->
intval32
,
bpbuffer
+
myPos
,
sizeof
(
uint32_t
));
new_node
->
intval32
=
ntohl
(
new_node
->
intval32
);
new_node
->
intval32
=
ntohl
(
new_node
->
intval32
);
break
;
break
;
case
sizeof
(
uint64_t
):
case
sizeof
(
uint64_t
):
memcpy
(
&
new_node
->
intval64
,
bpbuffer
+
myPos
,
sizeof
(
uint64_t
));
memcpy
(
&
new_node
->
intval64
,
bpbuffer
+
myPos
,
sizeof
(
uint64_t
));
byte_convert
(
&
new_node
->
intval64
,
sizeof
(
uint64_t
));
byte_convert
((
char
*
)
&
new_node
->
intval64
,
sizeof
(
uint64_t
));
break
;
break
;
default:
default:
free
(
new_node
);
free
(
new_node
);
printf
(
"parse_raw_node: lol: invalid int: size given %i
\n
"
,
new_node
->
length
);
printf
(
"parse_raw_node: lol: invalid int: size given %lu
\n
"
,
(
long
unsigned
int
)
new_node
->
length
);
printf
(
"parse_raw_node: lol: by the way sizeof(uint64) = %i
\n
"
,
sizeof
(
uint64_t
));
printf
(
"parse_raw_node: lol: by the way sizeof(uint64) = %i
\n
"
,
sizeof
(
uint64_t
));
return
NULL
;
return
NULL
;
}
}
...
@@ -394,9 +399,9 @@ bplist_node *parse_raw_node(const char *bpbuffer, uint32_t bplength, uint32_t *p
...
@@ -394,9 +399,9 @@ bplist_node *parse_raw_node(const char *bpbuffer, uint32_t bplength, uint32_t *p
case
BPLIST_REAL
:
case
BPLIST_REAL
:
new_node
->
length
=
uipow
(
2
,
new_node
->
length
);
new_node
->
length
=
uipow
(
2
,
new_node
->
length
);
memcpy
(
&
new_node
->
realval
,
bpbuffer
+
myPos
,
new_node
->
length
);
// XXX: probable buffer overflow here
memcpy
(
&
new_node
->
realval
,
bpbuffer
+
myPos
,
new_node
->
length
);
// XXX: probable buffer overflow here
//new_node->realval = bpbuffer[myPos]; // why not
//new_node->realval = bpbuffer[myPos]; // why not
byte_convert
(
&
new_node
->
realval
,
sizeof
(
double
));
byte_convert
((
char
*
)
&
new_node
->
realval
,
sizeof
(
double
));
break
;
break
;
case
BPLIST_DICT
:
/* returning a raw dict, it forward-references, so. */
case
BPLIST_DICT
:
/* returning a raw dict, it forward-references, so. */
...
@@ -407,13 +412,13 @@ bplist_node *parse_raw_node(const char *bpbuffer, uint32_t bplength, uint32_t *p
...
@@ -407,13 +412,13 @@ bplist_node *parse_raw_node(const char *bpbuffer, uint32_t bplength, uint32_t *p
case
BPLIST_DATA
:
case
BPLIST_DATA
:
default:
/* made to hold raw data. */
default:
/* made to hold raw data. */
modifier
=
(
new_node
->
intval8
>
0
)
?
new_node
->
intval8
:
1
;
modifier
=
(
new_node
->
intval8
>
0
)
?
new_node
->
intval8
:
1
;
new_node
->
strval
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
(
new_node
->
length
*
modifier
));
new_node
->
strval
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
(
new_node
->
length
*
modifier
));
memcpy
(
new_node
->
strval
,
bpbuffer
+
myPos
,
(
new_node
->
length
*
modifier
));
memcpy
(
new_node
->
strval
,
bpbuffer
+
myPos
,
(
new_node
->
length
*
modifier
));
break
;
break
;
case
BPLIST_UNICODE
:
case
BPLIST_UNICODE
:
new_node
->
unicodeval
=
(
wchar_t
*
)
malloc
(
sizeof
(
wchar_t
)
*
new_node
->
length
);
new_node
->
unicodeval
=
(
wchar_t
*
)
malloc
(
sizeof
(
wchar_t
)
*
new_node
->
length
);
memcpy
(
new_node
->
unicodeval
,
bpbuffer
+
myPos
,
new_node
->
length
);
memcpy
(
new_node
->
unicodeval
,
bpbuffer
+
myPos
,
new_node
->
length
);
break
;
break
;
}
}
...
@@ -422,51 +427,55 @@ bplist_node *parse_raw_node(const char *bpbuffer, uint32_t bplength, uint32_t *p
...
@@ -422,51 +427,55 @@ bplist_node *parse_raw_node(const char *bpbuffer, uint32_t bplength, uint32_t *p
return
new_node
;
return
new_node
;
}
}
void
print_bytes
(
char
*
val
,
size_t
size
)
{
void
print_bytes
(
char
*
val
,
size_t
size
)
{
int
i
=
0
;
int
i
=
0
;
for
(
i
=
0
;
i
<
size
;
i
++
)
{
for
(
i
=
0
;
i
<
size
;
i
++
)
{
printf
(
"Byte %i: 0x%x
\n
"
,
i
,
val
[
i
]);
printf
(
"Byte %i: 0x%x
\n
"
,
i
,
val
[
i
]);
}
}
}
}
bplist_node
*
parse_nodes
(
const
char
*
bpbuffer
,
uint32_t
bplength
,
uint32_t
*
position
)
{
bplist_node
*
parse_nodes
(
const
char
*
bpbuffer
,
uint32_t
bplength
,
uint32_t
*
position
)
{
bplist_node
**
nodeslist
=
NULL
,
**
newaddr
=
NULL
;
bplist_node
**
nodeslist
=
NULL
,
**
newaddr
=
NULL
;
bplist_node
*
new_node
=
NULL
,
*
root_node
=
NULL
;
bplist_node
*
new_node
=
NULL
,
*
root_node
=
NULL
;
uint32_t
nodeslength
=
0
;
uint32_t
nodeslength
=
0
;
uint8_t
offset_size
=
0
,
dict_param_size
=
0
;
uint8_t
offset_size
=
0
,
dict_param_size
=
0
;
offset_size
=
bpbuffer
[
bplength
-
26
];
offset_size
=
bpbuffer
[
bplength
-
26
];
dict_param_size
=
bpbuffer
[
bplength
-
25
];
dict_param_size
=
bpbuffer
[
bplength
-
25
];
uint64_t
current_offset
=
0
;
uint64_t
current_offset
=
0
;
//uint64_t num_objects = *(bpbuffer+(bplength-24)), root_object = *(bpbuffer+(bplength-16)), offset_table_index = *(bpbuffer+(bplength-8));
//uint64_t num_objects = *(bpbuffer+(bplength-24)), root_object = *(bpbuffer+(bplength-16)), offset_table_index = *(bpbuffer+(bplength-8));
uint64_t
num_objects
=
0
,
root_object
=
0
,
offset_table_index
=
0
;
uint64_t
num_objects
=
0
,
root_object
=
0
,
offset_table_index
=
0
;
memcpy
(
&
num_objects
,
bpbuffer
+
bplength
-
24
,
sizeof
(
uint64_t
));
memcpy
(
&
num_objects
,
bpbuffer
+
bplength
-
24
,
sizeof
(
uint64_t
));
memcpy
(
&
root_object
,
bpbuffer
+
bplength
-
16
,
sizeof
(
uint64_t
));
memcpy
(
&
root_object
,
bpbuffer
+
bplength
-
16
,
sizeof
(
uint64_t
));
memcpy
(
&
offset_table_index
,
bpbuffer
+
bplength
-
8
,
sizeof
(
uint64_t
));
memcpy
(
&
offset_table_index
,
bpbuffer
+
bplength
-
8
,
sizeof
(
uint64_t
));
byte_convert
(
&
num_objects
,
sizeof
(
uint64_t
));
byte_convert
(
(
char
*
)
&
num_objects
,
sizeof
(
uint64_t
));
byte_convert
(
&
root_object
,
sizeof
(
uint64_t
));
byte_convert
(
(
char
*
)
&
root_object
,
sizeof
(
uint64_t
));
byte_convert
(
&
offset_table_index
,
sizeof
(
uint64_t
));
byte_convert
(
(
char
*
)
&
offset_table_index
,
sizeof
(
uint64_t
));
log_debug_msg
(
"Offset size: %i
\n
Given: %i
\n
"
,
offset_size
,
bpbuffer
[
bplength
-
26
]);
log_debug_msg
(
"Offset size: %i
\n
Given: %i
\n
"
,
offset_size
,
bpbuffer
[
bplength
-
26
]);
log_debug_msg
(
"Ref size: %i
\n
Given: %i
\n
"
,
dict_param_size
,
bpbuffer
[
bplength
-
25
]);
log_debug_msg
(
"Ref size: %i
\n
Given: %i
\n
"
,
dict_param_size
,
bpbuffer
[
bplength
-
25
]);
log_debug_msg
(
"Number of objects: %lli
\n
Given: %llu
\n
"
,
num_objects
,
*
(
bpbuffer
+
bplength
-
24
));
log_debug_msg
(
"Number of objects: %lli
\n
Given: %llu
\n
"
,
num_objects
,
*
(
bpbuffer
+
bplength
-
24
));
log_debug_msg
(
"Root object index: %lli
\n
Given: %llu
\n
"
,
root_object
,
*
(
bpbuffer
+
bplength
-
16
));
log_debug_msg
(
"Root object index: %lli
\n
Given: %llu
\n
"
,
root_object
,
*
(
bpbuffer
+
bplength
-
16
));
log_debug_msg
(
"Offset table index: %lli
\n
Given: %llu
\n
"
,
offset_table_index
,
*
(
bpbuffer
+
bplength
-
8
));
log_debug_msg
(
"Offset table index: %lli
\n
Given: %llu
\n
"
,
offset_table_index
,
*
(
bpbuffer
+
bplength
-
8
));
log_debug_msg
(
"Size of uint64: %i
\n
"
,
sizeof
(
uint64_t
));
log_debug_msg
(
"Size of uint64: %i
\n
"
,
sizeof
(
uint64_t
));
int
i
=
0
,
j
=
0
,
k
=
0
,
str_i
=
0
,
str_j
=
0
;
int
i
=
0
,
j
=
0
,
k
=
0
,
str_i
=
0
,
str_j
=
0
;
uint32_t
index1
=
0
,
index2
=
0
;
uint32_t
index1
=
0
,
index2
=
0
;
nodeslist
=
(
bplist_node
**
)
malloc
(
sizeof
(
bplist_node
*
)
*
num_objects
);
nodeslist
=
(
bplist_node
**
)
malloc
(
sizeof
(
bplist_node
*
)
*
num_objects
);
if
(
!
nodeslist
)
return
NULL
;
if
(
!
nodeslist
)
return
NULL
;
for
(
i
=
0
;
i
<
num_objects
;
i
++
)
{
for
(
i
=
0
;
i
<
num_objects
;
i
++
)
{
memcpy
(
&
current_offset
,
bpbuffer
+
(
offset_table_index
+
(
i
*
offset_size
)),
offset_size
);
memcpy
(
&
current_offset
,
bpbuffer
+
(
offset_table_index
+
(
i
*
offset_size
)),
offset_size
);
//current_offset = (offset_size == 2) ? ntohs(current_offset) : (offset_size == 4) ? ntohl(current_offset) : current_offset;
//current_offset = (offset_size == 2) ? ntohs(current_offset) : (offset_size == 4) ? ntohl(current_offset) : current_offset;
//if (offset_size == 8) byte_convert(¤t_offset, 8);
//if (offset_size == 8) byte_convert(¤t_offset, 8);
byte_convert
(
&
current_offset
,
(
offset_size
<=
sizeof
(
current_offset
))
?
offset_size
:
sizeof
(
current_offset
));
byte_convert
((
char
*
)
&
current_offset
,
(
offset_size
<=
sizeof
(
current_offset
))
?
offset_size
:
sizeof
(
current_offset
));
log_debug_msg
(
"parse_nodes: current_offset = %x
\n
"
,
current_offset
);
log_debug_msg
(
"parse_nodes: current_offset = %x
\n
"
,
current_offset
);
nodeslist
[
i
]
=
parse_raw_node
(
bpbuffer
,
bplength
,
&
current_offset
,
dict_param_size
);
nodeslist
[
i
]
=
parse_raw_node
(
bpbuffer
,
bplength
,
(
uint32_t
*
)
&
current_offset
,
dict_param_size
);
log_debug_msg
(
"parse_nodes: parse_raw_node done
\n
"
);
log_debug_msg
(
"parse_nodes: parse_raw_node done
\n
"
);
}
}
...
@@ -477,17 +486,17 @@ bplist_node *parse_nodes(const char *bpbuffer, uint32_t bplength, uint32_t *posi
...
@@ -477,17 +486,17 @@ bplist_node *parse_nodes(const char *bpbuffer, uint32_t bplength, uint32_t *posi
switch
(
nodeslist
[
i
]
->
type
)
{
switch
(
nodeslist
[
i
]
->
type
)
{
case
BPLIST_DICT
:
case
BPLIST_DICT
:
log_debug_msg
(
"parse_nodes: dictionary found
\n
"
);
log_debug_msg
(
"parse_nodes: dictionary found
\n
"
);
nodeslist
[
i
]
->
subnodes
=
(
bplist_node
*
)
malloc
(
sizeof
(
bplist_node
)
*
nodeslist
[
i
]
->
length
);
nodeslist
[
i
]
->
subnodes
=
(
bplist_node
**
)
malloc
(
sizeof
(
bplist_node
)
*
nodeslist
[
i
]
->
length
);
for
(
j
=
0
;
j
<
(
nodeslist
[
i
]
->
length
/
2
);
j
++
)
{
for
(
j
=
0
;
j
<
(
nodeslist
[
i
]
->
length
/
2
);
j
++
)
{
str_i
=
j
*
nodeslist
[
i
]
->
intval8
;
str_i
=
j
*
nodeslist
[
i
]
->
intval8
;
str_j
=
(
j
+
(
nodeslist
[
i
]
->
length
/
2
))
*
nodeslist
[
i
]
->
intval8
;
str_j
=
(
j
+
(
nodeslist
[
i
]
->
length
/
2
))
*
nodeslist
[
i
]
->
intval8
;
memcpy
(
&
index1
,
nodeslist
[
i
]
->
strval
+
str_i
,
nodeslist
[
i
]
->
intval8
);
memcpy
(
&
index1
,
nodeslist
[
i
]
->
strval
+
str_i
,
nodeslist
[
i
]
->
intval8
);
memcpy
(
&
index2
,
nodeslist
[
i
]
->
strval
+
str_j
,
nodeslist
[
i
]
->
intval8
);
memcpy
(
&
index2
,
nodeslist
[
i
]
->
strval
+
str_j
,
nodeslist
[
i
]
->
intval8
);
//index1 = (dict_param_size == 1) ? index1 : (dict_param_size == 2) ? ntohs(index1) : (dict_param_size == 4) ? ntohl(index1) : index1;
//index1 = (dict_param_size == 1) ? index1 : (dict_param_size == 2) ? ntohs(index1) : (dict_param_size == 4) ? ntohl(index1) : index1;
//index2 = (dict_param_size == 1) ? index2 : (dict_param_size == 2) ? ntohs(index2) : (dict_param_size == 4) ? ntohl(index2) : index2;
//index2 = (dict_param_size == 1) ? index2 : (dict_param_size == 2) ? ntohs(index2) : (dict_param_size == 4) ? ntohl(index2) : index2;
byte_convert
(
&
index1
,
(
dict_param_size
<=
sizeof
(
index1
))
?
dict_param_size
:
sizeof
(
index2
));
byte_convert
((
char
*
)
&
index1
,
(
dict_param_size
<=
sizeof
(
index1
))
?
dict_param_size
:
sizeof
(
index2
));
byte_convert
(
&
index2
,
(
dict_param_size
<=
sizeof
(
index2
))
?
dict_param_size
:
sizeof
(
index2
));
byte_convert
((
char
*
)
&
index2
,
(
dict_param_size
<=
sizeof
(
index2
))
?
dict_param_size
:
sizeof
(
index2
));
//printf("parse_nodes: key index %i value %i\n", index1, index2);
//printf("parse_nodes: key index %i value %i\n", index1, index2);
//printf("parse_nodes: key type %x and length %i\n", nodeslist[index1]->type, nodeslist[index1]->length);
//printf("parse_nodes: key type %x and length %i\n", nodeslist[index1]->type, nodeslist[index1]->length);
//printf("parse_nodes: value type %x and length %i\n", nodeslist[index2]->type, nodeslist[index2]->length);
//printf("parse_nodes: value type %x and length %i\n", nodeslist[index2]->type, nodeslist[index2]->length);
...
@@ -502,16 +511,16 @@ bplist_node *parse_nodes(const char *bpbuffer, uint32_t bplength, uint32_t *posi
...
@@ -502,16 +511,16 @@ bplist_node *parse_nodes(const char *bpbuffer, uint32_t bplength, uint32_t *posi
case
BPLIST_ARRAY
:
case
BPLIST_ARRAY
:
log_debug_msg
(
"parse_nodes: array found
\n
"
);
log_debug_msg
(
"parse_nodes: array found
\n
"
);
nodeslist
[
i
]
->
subnodes
=
(
bplist_node
*
)
malloc
(
sizeof
(
bplist_node
)
*
nodeslist
[
i
]
->
length
);
// memory allocation helps a lot when storing data
nodeslist
[
i
]
->
subnodes
=
(
bplist_node
**
)
malloc
(
sizeof
(
bplist_node
)
*
nodeslist
[
i
]
->
length
);
// memory allocation helps a lot when storing data
for
(
j
=
0
;
j
<
nodeslist
[
i
]
->
length
;
j
++
)
{
for
(
j
=
0
;
j
<
nodeslist
[
i
]
->
length
;
j
++
)
{
log_debug_msg
(
"parse_nodes: array index %i
\n
"
,
j
);
log_debug_msg
(
"parse_nodes: array index %i
\n
"
,
j
);
str_j
=
j
*
nodeslist
[
i
]
->
intval8
;
str_j
=
j
*
nodeslist
[
i
]
->
intval8
;
//index1 = nodeslist[i]->strval[j];
//index1 = nodeslist[i]->strval[j];
memcpy
(
&
index1
,
nodeslist
[
i
]
->
strval
+
str_j
,
nodeslist
[
i
]
->
intval8
);
memcpy
(
&
index1
,
nodeslist
[
i
]
->
strval
+
str_j
,
nodeslist
[
i
]
->
intval8
);
log_debug_msg
(
"parse_nodes: post-memcpy
\n
"
);
log_debug_msg
(
"parse_nodes: post-memcpy
\n
"
);
//index1 = (dict_param_size == 1) ? index1 : (dict_param_size == 2) ? ntohs(index1) : (dict_param_size == 4) ? ntohl(index1) : index1;
//index1 = (dict_param_size == 1) ? index1 : (dict_param_size == 2) ? ntohs(index1) : (dict_param_size == 4) ? ntohl(index1) : index1;
byte_convert
(
&
index1
,
(
dict_param_size
<=
sizeof
(
index1
))
?
dict_param_size
:
sizeof
(
index1
));
byte_convert
((
char
*
)
&
index1
,
(
dict_param_size
<=
sizeof
(
index1
))
?
dict_param_size
:
sizeof
(
index1
));
log_debug_msg
(
"parse_nodes: post-ntohl
\n
index1 = %i
\n
"
,
index1
);
log_debug_msg
(
"parse_nodes: post-ntohl
\n
index1 = %i
\n
"
,
index1
);
nodeslist
[
i
]
->
subnodes
[
j
]
=
nodeslist
[
index1
];
nodeslist
[
i
]
->
subnodes
[
j
]
=
nodeslist
[
index1
];
log_debug_msg
(
"parse_nodes: post-assignment
\n
"
);
log_debug_msg
(
"parse_nodes: post-assignment
\n
"
);
...
...
src/plist.h
View file @
aed2c025
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
#include <sys/stat.h>
#include <sys/stat.h>
#include <unistd.h>
#include <unistd.h>
char
*
format_string
(
const
char
*
buf
,
int
cols
,
int
depth
);
xmlNode
*
add_key_dict_node
(
xmlDocPtr
plist
,
xmlNode
*
dict
,
const
char
*
key
,
const
char
*
value
,
int
depth
);
xmlNode
*
add_key_dict_node
(
xmlDocPtr
plist
,
xmlNode
*
dict
,
const
char
*
key
,
const
char
*
value
,
int
depth
);
xmlNode
*
add_key_str_dict_element
(
xmlDocPtr
plist
,
xmlNode
*
dict
,
const
char
*
key
,
const
char
*
value
,
int
depth
);
xmlNode
*
add_key_str_dict_element
(
xmlDocPtr
plist
,
xmlNode
*
dict
,
const
char
*
key
,
const
char
*
value
,
int
depth
);
xmlNode
*
add_key_data_dict_element
(
xmlDocPtr
plist
,
xmlNode
*
dict
,
const
char
*
key
,
const
char
*
value
,
int
depth
);
xmlNode
*
add_key_data_dict_element
(
xmlDocPtr
plist
,
xmlNode
*
dict
,
const
char
*
key
,
const
char
*
value
,
int
depth
);
...
@@ -73,4 +74,6 @@ typedef struct _bplist_node {
...
@@ -73,4 +74,6 @@ typedef struct _bplist_node {
wchar_t
*
unicodeval
;
wchar_t
*
unicodeval
;
}
bplist_node
;
}
bplist_node
;
bplist_node
*
parse_nodes
(
const
char
*
bpbuffer
,
uint32_t
bplength
,
uint32_t
*
position
);
#endif
#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