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
d9752564
Commit
d9752564
authored
May 24, 2020
by
Jaywalker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plistutil: Added ability for files to be read from stdin
parent
15f2eea6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
25 deletions
+71
-25
plistutil.c
tools/plistutil.c
+71
-25
No files found.
tools/plistutil.c
View file @
d9752564
...
@@ -28,6 +28,9 @@
...
@@ -28,6 +28,9 @@
#include <string.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <errno.h>
#include <errno.h>
#include <unistd.h>
#define BUF_SIZE 2048 // Seems to be a decent start to cover most stdin files
#ifdef _MSC_VER
#ifdef _MSC_VER
#pragma warning(disable:4996)
#pragma warning(disable:4996)
...
@@ -45,8 +48,8 @@ static void print_usage(int argc, char *argv[])
...
@@ -45,8 +48,8 @@ static void print_usage(int argc, char *argv[])
name
=
strrchr
(
argv
[
0
],
'/'
);
name
=
strrchr
(
argv
[
0
],
'/'
);
printf
(
"Usage: %s -i|--infile FILE [-o|--outfile FILE] [-d|--debug]
\n
"
,
(
name
?
name
+
1
:
argv
[
0
]));
printf
(
"Usage: %s -i|--infile FILE [-o|--outfile FILE] [-d|--debug]
\n
"
,
(
name
?
name
+
1
:
argv
[
0
]));
printf
(
"Convert a plist FILE from binary to XML format or vice-versa.
\n\n
"
);
printf
(
"Convert a plist FILE from binary to XML format or vice-versa.
\n\n
"
);
printf
(
" -i, --infile FILE
\t
The FILE to convert from
\n
"
);
printf
(
" -i, --infile FILE
\t
Optional FILE to convert from or stdin if - or not used
\n
"
);
printf
(
" -o, --outfile FILE
\t
Optional FILE to convert to or stdout if not used
\n
"
);
printf
(
" -o, --outfile FILE
\t
Optional FILE to convert to or stdout if
- or
not used
\n
"
);
printf
(
" -d, --debug
\t\t
Enable extended debug output
\n
"
);
printf
(
" -d, --debug
\t\t
Enable extended debug output
\n
"
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
...
@@ -96,12 +99,6 @@ static options_t *parse_arguments(int argc, char *argv[])
...
@@ -96,12 +99,6 @@ static options_t *parse_arguments(int argc, char *argv[])
}
}
}
}
if
(
!
options
->
in_file
)
{
free
(
options
);
return
NULL
;
}
return
options
;
return
options
;
}
}
...
@@ -122,28 +119,77 @@ int main(int argc, char *argv[])
...
@@ -122,28 +119,77 @@ int main(int argc, char *argv[])
return
0
;
return
0
;
}
}
// read input file
if
(
!
options
->
in_file
||
!
strcmp
(
options
->
in_file
,
"-"
))
iplist
=
fopen
(
options
->
in_file
,
"rb"
);
{
if
(
!
iplist
)
{
read_size
=
0
;
printf
(
"ERROR: Could not open input file '%s': %s
\n
"
,
options
->
in_file
,
strerror
(
errno
));
plist_entire
=
malloc
(
sizeof
(
char
)
*
BUF_SIZE
);
free
(
options
);
if
(
plist_entire
==
NULL
)
return
1
;
{
printf
(
"ERROR: Failed to allocate buffer to read from stdin"
);
free
(
options
);
return
1
;
}
plist_entire
[
read_size
]
=
'\0'
;
char
ch
;
while
(
read
(
STDIN_FILENO
,
&
ch
,
1
)
>
0
)
{
if
(
read_size
>=
BUF_SIZE
)
{
char
*
old
=
plist_entire
;
plist_entire
=
realloc
(
plist_entire
,
sizeof
(
char
)
*
(
read_size
+
1
));
if
(
plist_entire
==
NULL
)
{
printf
(
"ERROR: Failed to reallocate stdin buffer
\n
"
);
free
(
old
);
free
(
options
);
return
1
;
}
}
plist_entire
[
read_size
]
=
ch
;
read_size
++
;
}
plist_entire
[
read_size
]
=
'\0'
;
// Not positive we need this, but it doesnt seem to hurt lol
if
(
ferror
(
stdin
))
{
printf
(
"ERROR: reading from stdin.
\n
"
);
free
(
plist_entire
);
free
(
options
);
return
1
;
}
if
(
read_size
<
8
)
{
printf
(
"ERROR: Input file is too small to contain valid plist data.
\n
"
);
free
(
plist_entire
);
free
(
options
);
return
1
;
}
}
}
else
{
// read input file
iplist
=
fopen
(
options
->
in_file
,
"rb"
);
if
(
!
iplist
)
{
printf
(
"ERROR: Could not open input file '%s': %s
\n
"
,
options
->
in_file
,
strerror
(
errno
));
free
(
options
);
return
1
;
}
memset
(
&
filestats
,
'\0'
,
sizeof
(
struct
stat
));
fstat
(
fileno
(
iplist
),
&
filestats
);
memset
(
&
filestats
,
'\0'
,
sizeof
(
struct
stat
));
if
(
filestats
.
st_size
<
8
)
{
fstat
(
fileno
(
iplist
),
&
filestats
);
printf
(
"ERROR: Input file is too small to contain valid plist data.
\n
"
);
free
(
options
);
fclose
(
iplist
);
return
-
1
;
}
if
(
filestats
.
st_size
<
8
)
{
plist_entire
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
(
filestats
.
st_size
+
1
));
printf
(
"ERROR: Input file is too small to contain valid plist data.
\n
"
);
read_size
=
fread
(
plist_entire
,
sizeof
(
char
),
filestats
.
st_size
,
iplist
);
free
(
options
);
fclose
(
iplist
);
fclose
(
iplist
);
return
-
1
;
}
}
plist_entire
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
(
filestats
.
st_size
+
1
));
read_size
=
fread
(
plist_entire
,
sizeof
(
char
),
filestats
.
st_size
,
iplist
);
fclose
(
iplist
);
// convert from binary to xml or vice-versa
// convert from binary to xml or vice-versa
if
(
plist_is_binary
(
plist_entire
,
read_size
))
if
(
plist_is_binary
(
plist_entire
,
read_size
))
{
{
...
@@ -160,7 +206,7 @@ int main(int argc, char *argv[])
...
@@ -160,7 +206,7 @@ int main(int argc, char *argv[])
if
(
plist_out
)
if
(
plist_out
)
{
{
if
(
options
->
out_file
!=
NULL
)
if
(
options
->
out_file
!=
NULL
&&
strcmp
(
options
->
out_file
,
"-"
)
)
{
{
FILE
*
oplist
=
fopen
(
options
->
out_file
,
"wb"
);
FILE
*
oplist
=
fopen
(
options
->
out_file
,
"wb"
);
if
(
!
oplist
)
{
if
(
!
oplist
)
{
...
...
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