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
392135c7
Commit
392135c7
authored
Oct 22, 2016
by
Nikias Bassen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove libxml2 dependency in favor of custom XML parsing
parent
a3263ad3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
798 additions
and
407 deletions
+798
-407
configure.ac
configure.ac
+18
-9
plist.h
include/plist/plist.h
+0
-13
Makefile.am
src/Makefile.am
+3
-2
base64.c
src/base64.c
+11
-11
base64.h
src/base64.h
+1
-1
bplist.c
src/bplist.c
+1
-2
bytearray.c
src/bytearray.c
+8
-4
plist.c
src/plist.c
+71
-15
strbuf.h
src/strbuf.h
+33
-0
xplist.c
src/xplist.c
+652
-350
No files found.
configure.ac
View file @
392135c7
...
...
@@ -19,11 +19,6 @@ LIBPLIST_SO_VERSION=3:0:0
AC_SUBST(LIBPLIST_SO_VERSION)
dnl Minimum package versions
LIBXML2_VERSION=2.7.8
AC_SUBST(LIBXML2_VERSION)
# Checks for programs.
AC_PROG_CC
AC_PROG_CXX
...
...
@@ -40,9 +35,6 @@ AC_LANG_POP
AM_PROG_CC_C_O
AC_PROG_LIBTOOL
# Checks for libraries.
PKG_CHECK_MODULES(libxml2, libxml-2.0 >= $LIBXML2_VERSION)
# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([stdint.h stdlib.h string.h])
...
...
@@ -139,6 +131,22 @@ AM_CONDITIONAL([HAVE_CYTHON],[test "x$CYTHON_SUB" = "xcython"])
AC_SUBST([CYTHON_SUB])
AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wmissing-declarations -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default -Wno-unused-parameter -fvisibility=hidden")
AC_ARG_ENABLE(debug,
AS_HELP_STRING([--enable-debug],
[enable debugging, default: no]),
[case "${enableval}" in
yes) debug=yes ;;
no) debug=no ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;;
esac],
[debug=no])
if (test "x$debug" = "xyes"); then
AC_DEFINE(DEBUG, 1, [Define if debug code should be enabled.])
GLOBAL_CFLAGS+=" -g"
fi
AC_SUBST(GLOBAL_CFLAGS)
case "$GLOBAL_CFLAGS" in
...
...
@@ -165,7 +173,8 @@ echo "
Configuration for $PACKAGE $VERSION:
-------------------------------------------
Install prefix: .........: $prefix
Install prefix ..........: $prefix
Debug code ..............: $debug
Python bindings .........: $cython_python_bindings
Now type 'make' to build $PACKAGE $VERSION,
...
...
include/plist/plist.h
View file @
392135c7
...
...
@@ -111,19 +111,6 @@ extern "C"
}
plist_type
;
/********************************************
* *
* Library Initialization & Cleanup *
* *
********************************************/
/**
* Frees memory used globally by listplist, in
* particular the libxml parser
*/
void
plist_cleanup
(
void
);
/********************************************
* *
* Creation & Destruction *
...
...
src/Makefile.am
View file @
392135c7
AM_CPPFLAGS
=
-I
$(top_srcdir)
/include
-I
$(top_srcdir)
-I
$(top_srcdir)
/libcnary/include
AM_CFLAGS
=
$(GLOBAL_CFLAGS)
$(libxml2_CFLAGS)
AM_LDFLAGS
=
$(libxml2_LIBS)
AM_CFLAGS
=
$(GLOBAL_CFLAGS)
AM_LDFLAGS
=
lib_LTLIBRARIES
=
libplist.la libplist++.la
libplist_la_LIBADD
=
$(top_builddir)
/libcnary/libcnary.la
libplist_la_LDFLAGS
=
$(AM_LDFLAGS)
-version-info
$(LIBPLIST_SO_VERSION)
-no-undefined
libplist_la_SOURCES
=
base64.c base64.h
\
bytearray.c bytearray.h
\
strbuf.h
\
hashtable.c hashtable.h
\
ptrarray.c ptrarray.h
\
time64.c time64.h time64_limits.h
\
...
...
src/base64.c
View file @
392135c7
...
...
@@ -43,32 +43,32 @@ static const signed char base64_table[256] = {
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
};
char
*
base64encode
(
const
unsigned
char
*
buf
,
size_t
*
size
)
size_t
base64encode
(
char
*
outbuf
,
const
unsigned
char
*
buf
,
size_t
size
)
{
if
(
!
buf
||
!
size
||
!
(
*
size
>
0
))
return
NULL
;
int
outlen
=
(
*
size
/
3
)
*
4
;
char
*
outbuf
=
(
char
*
)
malloc
(
outlen
+
5
);
// 4 spare bytes + 1 for '\0'
if
(
!
outbuf
||
!
buf
||
(
size
<=
0
))
{
return
0
;
}
size_t
n
=
0
;
size_t
m
=
0
;
unsigned
char
input
[
3
];
unsigned
int
output
[
4
];
while
(
n
<
*
size
)
{
while
(
n
<
size
)
{
input
[
0
]
=
buf
[
n
];
input
[
1
]
=
(
n
+
1
<
*
size
)
?
buf
[
n
+
1
]
:
0
;
input
[
2
]
=
(
n
+
2
<
*
size
)
?
buf
[
n
+
2
]
:
0
;
input
[
1
]
=
(
n
+
1
<
size
)
?
buf
[
n
+
1
]
:
0
;
input
[
2
]
=
(
n
+
2
<
size
)
?
buf
[
n
+
2
]
:
0
;
output
[
0
]
=
input
[
0
]
>>
2
;
output
[
1
]
=
((
input
[
0
]
&
3
)
<<
4
)
+
(
input
[
1
]
>>
4
);
output
[
2
]
=
((
input
[
1
]
&
15
)
<<
2
)
+
(
input
[
2
]
>>
6
);
output
[
3
]
=
input
[
2
]
&
63
;
outbuf
[
m
++
]
=
base64_str
[(
int
)
output
[
0
]];
outbuf
[
m
++
]
=
base64_str
[(
int
)
output
[
1
]];
outbuf
[
m
++
]
=
(
n
+
1
<
*
size
)
?
base64_str
[(
int
)
output
[
2
]]
:
base64_pad
;
outbuf
[
m
++
]
=
(
n
+
2
<
*
size
)
?
base64_str
[(
int
)
output
[
3
]]
:
base64_pad
;
outbuf
[
m
++
]
=
(
n
+
1
<
size
)
?
base64_str
[(
int
)
output
[
2
]]
:
base64_pad
;
outbuf
[
m
++
]
=
(
n
+
2
<
size
)
?
base64_str
[(
int
)
output
[
3
]]
:
base64_pad
;
n
+=
3
;
}
outbuf
[
m
]
=
0
;
// 0-termination!
*
size
=
m
;
return
outbuf
;
return
m
;
}
static
int
base64decode_block
(
unsigned
char
*
target
,
const
char
*
data
,
size_t
data_size
)
...
...
src/base64.h
View file @
392135c7
...
...
@@ -22,7 +22,7 @@
#define BASE64_H
#include <stdlib.h>
char
*
base64encode
(
const
unsigned
char
*
buf
,
size_t
*
size
);
size_t
base64encode
(
char
*
outbuf
,
const
unsigned
char
*
buf
,
size_t
size
);
unsigned
char
*
base64decode
(
const
char
*
buf
,
size_t
*
size
);
#endif
src/bplist.c
View file @
392135c7
...
...
@@ -2,7 +2,7 @@
* bplist.c
* Binary plist implementation
*
* Copyright (c) 2011-201
5
Nikias Bassen, All Rights Reserved.
* Copyright (c) 2011-201
6
Nikias Bassen, All Rights Reserved.
* Copyright (c) 2008-2010 Jonathan Beck, All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
...
...
@@ -28,7 +28,6 @@
#include <stdio.h>
#include <string.h>
#include <libxml/encoding.h>
#include <ctype.h>
#include <plist/plist.h>
...
...
src/bytearray.c
View file @
392135c7
...
...
@@ -21,12 +21,14 @@
#include <string.h>
#include "bytearray.h"
#define PAGE_SIZE 4096
bytearray_t
*
byte_array_new
()
{
bytearray_t
*
a
=
(
bytearray_t
*
)
malloc
(
sizeof
(
bytearray_t
));
a
->
data
=
malloc
(
256
);
a
->
capacity
=
PAGE_SIZE
*
8
;
a
->
data
=
malloc
(
a
->
capacity
);
a
->
len
=
0
;
a
->
capacity
=
256
;
return
a
;
}
...
...
@@ -44,8 +46,10 @@ void byte_array_append(bytearray_t *ba, void *buf, size_t len)
if
(
!
ba
||
!
ba
->
data
||
(
len
<=
0
))
return
;
size_t
remaining
=
ba
->
capacity
-
ba
->
len
;
if
(
len
>
remaining
)
{
ba
->
data
=
realloc
(
ba
->
data
,
ba
->
capacity
+
(
len
-
remaining
));
ba
->
capacity
+=
(
len
-
remaining
);
size_t
needed
=
len
-
remaining
;
size_t
increase
=
(
needed
>
PAGE_SIZE
)
?
(
needed
+
(
PAGE_SIZE
-
1
))
&
(
~
(
PAGE_SIZE
-
1
))
:
PAGE_SIZE
;
ba
->
data
=
realloc
(
ba
->
data
,
ba
->
capacity
+
increase
);
ba
->
capacity
+=
increase
;
}
memcpy
(((
char
*
)
ba
->
data
)
+
ba
->
len
,
buf
,
len
);
ba
->
len
+=
len
;
...
...
src/plist.c
View file @
392135c7
...
...
@@ -2,8 +2,8 @@
* plist.c
* Builds plist XML structures
*
* Copyright (c) 2009-2016 Nikias Bassen All Rights Reserved.
* Copyright (c) 2010-2015 Martin Szulecki All Rights Reserved.
* Copyright (c) 2009-2014 Nikias Bassen All Rights Reserved.
* Copyright (c) 2008 Zach C. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
...
...
@@ -29,27 +29,83 @@
#include <stdio.h>
#include <math.h>
#ifdef WIN32
#include <windows.h>
#else
#include <pthread.h>
#endif
#include <node.h>
#include <node_iterator.h>
#include <libxml/encoding.h>
#include <libxml/dict.h>
#include <libxml/xmlerror.h>
#include <libxml/globals.h>
#include <libxml/threads.h>
#include <libxml/xmlmemory.h>
extern
void
plist_xml_init
(
void
);
extern
void
plist_xml_deinit
(
void
);
static
void
internal_plist_init
(
void
)
{
plist_xml_init
();
}
static
void
internal_plist_deinit
(
void
)
{
plist_xml_deinit
();
}
#ifdef WIN32
typedef
volatile
struct
{
LONG
lock
;
int
state
;
}
thread_once_t
;
static
thread_once_t
init_once
=
{
0
,
0
};
static
thread_once_t
deinit_once
=
{
0
,
0
};
void
thread_once
(
thread_once_t
*
once_control
,
void
(
*
init_routine
)(
void
))
{
while
(
InterlockedExchange
(
&
(
once_control
->
lock
),
1
)
!=
0
)
{
Sleep
(
1
);
}
if
(
!
once_control
->
state
)
{
once_control
->
state
=
1
;
init_routine
();
}
InterlockedExchange
(
&
(
once_control
->
lock
),
0
);
}
BOOL
WINAPI
DllMain
(
HINSTANCE
hModule
,
DWORD
dwReason
,
LPVOID
lpReserved
)
{
switch
(
dwReason
)
{
case
DLL_PROCESS_ATTACH
:
thread_once
(
&
init_once
,
internal_plist_init
);
break
;
case
DLL_PROCESS_DETACH
:
thread_once
(
&
deinit_once
,
internal_plist_deinit
);
break
;
default:
break
;
}
return
1
;
}
PLIST_API
void
plist_cleanup
(
void
)
#else
static
pthread_once_t
init_once
=
PTHREAD_ONCE_INIT
;
static
pthread_once_t
deinit_once
=
PTHREAD_ONCE_INIT
;
static
void
__attribute__
((
constructor
))
libplist_initialize
(
void
)
{
/* free memory from parser initialization */
xmlCleanupCharEncodingHandlers
();
xmlDictCleanup
();
xmlResetLastError
();
xmlCleanupGlobals
();
xmlCleanupThreads
();
xmlCleanupMemory
();
pthread_once
(
&
init_once
,
internal_plist_init
);
}
static
void
__attribute__
((
destructor
))
libplist_deinitialize
(
void
)
{
pthread_once
(
&
deinit_once
,
internal_plist_deinit
);
}
#endif
PLIST_API
int
plist_is_binary
(
const
char
*
plist_data
,
uint32_t
length
)
{
if
(
length
<
8
)
{
...
...
src/strbuf.h
0 → 100644
View file @
392135c7
/*
* strbuf.h
* header file for simple string buffer, using the bytearray as underlying
* structure.
*
* Copyright (c) 2016 Nikias Bassen, 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 STRBUF_H
#define STRBUF_H
#include <stdlib.h>
#include "bytearray.h"
typedef
struct
bytearray_t
strbuf_t
;
#define str_buf_new() byte_array_new()
#define str_buf_free(__ba) byte_array_free(__ba)
#define str_buf_append(__ba, __str, __len) byte_array_append(__ba, (void*)(__str), __len)
#endif
src/xplist.c
View file @
392135c7
This diff is collapsed.
Click to expand it.
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