diff options
Diffstat (limited to 'include/libimobiledevice-glue')
-rw-r--r-- | include/libimobiledevice-glue/cbuf.h | 8 | ||||
-rw-r--r-- | include/libimobiledevice-glue/collection.h | 14 | ||||
-rw-r--r-- | include/libimobiledevice-glue/glue.h | 37 | ||||
-rw-r--r-- | include/libimobiledevice-glue/nskeyedarchive.h | 90 | ||||
-rw-r--r-- | include/libimobiledevice-glue/opack.h | 5 | ||||
-rw-r--r-- | include/libimobiledevice-glue/socket.h | 36 | ||||
-rw-r--r-- | include/libimobiledevice-glue/termcolors.h | 11 | ||||
-rw-r--r-- | include/libimobiledevice-glue/thread.h | 53 | ||||
-rw-r--r-- | include/libimobiledevice-glue/tlv.h | 15 | ||||
-rw-r--r-- | include/libimobiledevice-glue/utils.h | 38 |
10 files changed, 220 insertions, 87 deletions
diff --git a/include/libimobiledevice-glue/cbuf.h b/include/libimobiledevice-glue/cbuf.h index 01e2f43..2463af7 100644 --- a/include/libimobiledevice-glue/cbuf.h +++ b/include/libimobiledevice-glue/cbuf.h @@ -22,14 +22,16 @@ #ifndef __CBUF_H #define __CBUF_H +#include <libimobiledevice-glue/glue.h> + struct char_buf { unsigned char* data; unsigned int length; unsigned int capacity; }; -struct char_buf* char_buf_new(); -void char_buf_free(struct char_buf* cbuf); -void char_buf_append(struct char_buf* cbuf, unsigned int length, unsigned char* data); +LIMD_GLUE_API struct char_buf* char_buf_new(); +LIMD_GLUE_API void char_buf_free(struct char_buf* cbuf); +LIMD_GLUE_API void char_buf_append(struct char_buf* cbuf, unsigned int length, unsigned char* data); #endif /* __CBUF_H */ diff --git a/include/libimobiledevice-glue/collection.h b/include/libimobiledevice-glue/collection.h index df1680c..46ef461 100644 --- a/include/libimobiledevice-glue/collection.h +++ b/include/libimobiledevice-glue/collection.h @@ -22,17 +22,19 @@ #ifndef COLLECTION_H #define COLLECTION_H +#include <libimobiledevice-glue/glue.h> + struct collection { void **list; int capacity; }; -void collection_init(struct collection *col); -void collection_add(struct collection *col, void *element); -int collection_remove(struct collection *col, void *element); -int collection_count(struct collection *col); -void collection_free(struct collection *col); -void collection_copy(struct collection *dest, struct collection *src); +LIMD_GLUE_API void collection_init(struct collection *col); +LIMD_GLUE_API void collection_add(struct collection *col, void *element); +LIMD_GLUE_API int collection_remove(struct collection *col, void *element); +LIMD_GLUE_API int collection_count(struct collection *col); +LIMD_GLUE_API void collection_free(struct collection *col); +LIMD_GLUE_API void collection_copy(struct collection *dest, struct collection *src); #define MERGE_(a,b) a ## _ ## b #define LABEL_(a,b) MERGE_(a, b) diff --git a/include/libimobiledevice-glue/glue.h b/include/libimobiledevice-glue/glue.h new file mode 100644 index 0000000..e1e9900 --- /dev/null +++ b/include/libimobiledevice-glue/glue.h @@ -0,0 +1,37 @@ +/* + * glue.h + * Common definitions + * + * Copyright (c) 2024 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 __GLUE_H +#define __GLUE_H + +#ifndef LIMD_GLUE_API + #ifdef LIMD_GLUE_STATIC + #define LIMD_GLUE_API + #elif defined(_WIN32) + #define LIMD_GLUE_API __declspec(dllimport) + #else + #define LIMD_GLUE_API + #endif +#endif + +LIMD_GLUE_API const char* libimobiledevice_glue_version(); + +#endif diff --git a/include/libimobiledevice-glue/nskeyedarchive.h b/include/libimobiledevice-glue/nskeyedarchive.h new file mode 100644 index 0000000..5aad4d6 --- /dev/null +++ b/include/libimobiledevice-glue/nskeyedarchive.h @@ -0,0 +1,90 @@ +/* + * nskeyedarchive.h + * Helper code to work with plist files containing NSKeyedArchiver data. + * + * Copyright (c) 2019 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 __NSKEYEDARCHIVE_H +#define __NSKEYEDARCHIVE_H + +#include <stdint.h> +#include <libimobiledevice-glue/glue.h> +#include <plist/plist.h> + +enum nskeyedarchive_class_type_t { + NSTYPE_INTEGER = 1, + NSTYPE_BOOLEAN, + NSTYPE_CHARS, + NSTYPE_STRING, + NSTYPE_REAL, + NSTYPE_ARRAY, + NSTYPE_DATA, + NSTYPE_INTREF, + NSTYPE_NSMUTABLESTRING, + NSTYPE_NSSTRING, + NSTYPE_NSMUTABLEARRAY, + NSTYPE_NSARRAY, + NSTYPE_NSMUTABLEDICTIONARY, + NSTYPE_NSDICTIONARY, + NSTYPE_NSDATE, + NSTYPE_NSURL, + NSTYPE_NSMUTABLEDATA, + NSTYPE_NSDATA, + NSTYPE_NSKEYEDARCHIVE, + NSTYPE_FROM_PLIST +}; + +typedef struct nskeyedarchive_st *nskeyedarchive_t; + +LIMD_GLUE_API nskeyedarchive_t nskeyedarchive_new(void); +LIMD_GLUE_API nskeyedarchive_t nskeyedarchive_new_from_plist(plist_t plist); +LIMD_GLUE_API nskeyedarchive_t nskeyedarchive_new_from_data(const void* data, uint32_t size); +LIMD_GLUE_API void nskeyedarchive_free(nskeyedarchive_t ka); + +LIMD_GLUE_API void nskeyedarchive_set_top_ref_key_name(nskeyedarchive_t ka, const char* keyname); + +LIMD_GLUE_API uint64_t nskeyedarchive_add_top_class(nskeyedarchive_t ka, const char* classname, ...) __attribute__ ((sentinel(0))); +LIMD_GLUE_API void nskeyedarchive_add_top_class_uid(nskeyedarchive_t ka, uint64_t uid); +LIMD_GLUE_API void nskeyedarchive_append_class(nskeyedarchive_t ka, const char* classname, ...) __attribute__ ((sentinel(0))); +LIMD_GLUE_API void nskeyedarchive_append_object(nskeyedarchive_t ka, plist_t object); + +LIMD_GLUE_API void nskeyedarchive_nsarray_append_item(nskeyedarchive_t ka, uint64_t uid, enum nskeyedarchive_class_type_t type, ...); +LIMD_GLUE_API void nskeyedarchive_nsdictionary_add_item(nskeyedarchive_t ka, uint64_t uid, const char* key, enum nskeyedarchive_class_type_t type, ...); + +LIMD_GLUE_API void nskeyedarchive_append_class_type_v(nskeyedarchive_t ka, enum nskeyedarchive_class_type_t type, va_list* va); +LIMD_GLUE_API void nskeyedarchive_append_class_type(nskeyedarchive_t ka, enum nskeyedarchive_class_type_t type, ...); + +LIMD_GLUE_API void nskeyedarchive_merge_object(nskeyedarchive_t ka, nskeyedarchive_t pka, plist_t object); + +LIMD_GLUE_API void nskeyedarchive_print(nskeyedarchive_t ka); +LIMD_GLUE_API plist_t nskeyedarchive_get_plist_ref(nskeyedarchive_t ka); +LIMD_GLUE_API plist_t nskeyedarchive_get_object_by_uid(nskeyedarchive_t ka, uint64_t uid); +LIMD_GLUE_API plist_t nskeyedarchive_get_class_by_uid(nskeyedarchive_t ka, uint64_t uid); +LIMD_GLUE_API plist_t nskeyedarchive_get_objects(nskeyedarchive_t ka); + +LIMD_GLUE_API uint64_t nskeyedarchive_get_class_uid(nskeyedarchive_t ka, const char* classref); +LIMD_GLUE_API const char* nskeyedarchive_get_classname(nskeyedarchive_t ka, uint64_t uid); + +LIMD_GLUE_API void nskeyedarchive_set_class_property(nskeyedarchive_t ka, uint64_t uid, const char* propname, enum nskeyedarchive_class_type_t proptype, ...); +LIMD_GLUE_API int nskeyedarchive_get_class_uint64_property(nskeyedarchive_t ka, uint64_t uid, const char* propname, uint64_t* value); +LIMD_GLUE_API int nskeyedarchive_get_class_int_property(nskeyedarchive_t ka, uint64_t uid, const char* propname, int* value); +LIMD_GLUE_API int nskeyedarchive_get_class_string_property(nskeyedarchive_t ka, uint64_t uid, const char* propname, char** value); +LIMD_GLUE_API int nskeyedarchive_get_class_property(nskeyedarchive_t ka, uint64_t uid, const char* propname, plist_t* value); + +LIMD_GLUE_API plist_t nskeyedarchive_to_plist(nskeyedarchive_t ka); + +#endif diff --git a/include/libimobiledevice-glue/opack.h b/include/libimobiledevice-glue/opack.h index 43b1d1d..2d7a94a 100644 --- a/include/libimobiledevice-glue/opack.h +++ b/include/libimobiledevice-glue/opack.h @@ -21,9 +21,10 @@ #ifndef __OPACK_H #define __OPACK_H +#include <libimobiledevice-glue/glue.h> #include <plist/plist.h> -void opack_encode_from_plist(plist_t plist, unsigned char** out, unsigned int* out_len); -int opack_decode_to_plist(unsigned char* buf, unsigned int buf_len, plist_t* plist_out); +LIMD_GLUE_API void opack_encode_from_plist(plist_t plist, unsigned char** out, unsigned int* out_len); +LIMD_GLUE_API int opack_decode_to_plist(unsigned char* buf, unsigned int buf_len, plist_t* plist_out); #endif /* __OPACK_H */ diff --git a/include/libimobiledevice-glue/socket.h b/include/libimobiledevice-glue/socket.h index 53f58b8..39391c6 100644 --- a/include/libimobiledevice-glue/socket.h +++ b/include/libimobiledevice-glue/socket.h @@ -41,30 +41,32 @@ typedef enum fd_mode fd_mode; #include <sys/socket.h> #endif +#include <libimobiledevice-glue/glue.h> + #ifndef WIN32 -int socket_create_unix(const char *filename); -int socket_connect_unix(const char *filename); +LIMD_GLUE_API int socket_create_unix(const char *filename); +LIMD_GLUE_API int socket_connect_unix(const char *filename); #endif -int socket_create(const char *addr, uint16_t port); -int socket_connect_addr(struct sockaddr *addr, uint16_t port); -int socket_connect(const char *addr, uint16_t port); -int socket_check_fd(int fd, fd_mode fdm, unsigned int timeout); -int socket_accept(int fd, uint16_t port); +LIMD_GLUE_API int socket_create(const char *addr, uint16_t port); +LIMD_GLUE_API int socket_connect_addr(struct sockaddr *addr, uint16_t port); +LIMD_GLUE_API int socket_connect(const char *addr, uint16_t port); +LIMD_GLUE_API int socket_check_fd(int fd, fd_mode fdm, unsigned int timeout); +LIMD_GLUE_API int socket_accept(int fd, uint16_t port); -int socket_shutdown(int fd, int how); -int socket_close(int fd); +LIMD_GLUE_API int socket_shutdown(int fd, int how); +LIMD_GLUE_API int socket_close(int fd); -int socket_receive(int fd, void *data, size_t length); -int socket_peek(int fd, void *data, size_t length); -int socket_receive_timeout(int fd, void *data, size_t length, int flags, unsigned int timeout); -int socket_send(int fd, void *data, size_t length); +LIMD_GLUE_API int socket_receive(int fd, void *data, size_t length); +LIMD_GLUE_API int socket_peek(int fd, void *data, size_t length); +LIMD_GLUE_API int socket_receive_timeout(int fd, void *data, size_t length, int flags, unsigned int timeout); +LIMD_GLUE_API int socket_send(int fd, void *data, size_t length); -int socket_get_socket_port(int fd, uint16_t *port); +LIMD_GLUE_API int socket_get_socket_port(int fd, uint16_t *port); -void socket_set_verbose(int level); +LIMD_GLUE_API void socket_set_verbose(int level); -const char *socket_addr_to_string(struct sockaddr *addr, char *addr_out, size_t addr_out_size); +LIMD_GLUE_API const char *socket_addr_to_string(struct sockaddr *addr, char *addr_out, size_t addr_out_size); -int get_primary_mac_address(unsigned char mac_addr_buf[6]); +LIMD_GLUE_API int get_primary_mac_address(unsigned char mac_addr_buf[6]); #endif /* SOCKET_SOCKET_H */ diff --git a/include/libimobiledevice-glue/termcolors.h b/include/libimobiledevice-glue/termcolors.h index 3e03e97..d7799c3 100644 --- a/include/libimobiledevice-glue/termcolors.h +++ b/include/libimobiledevice-glue/termcolors.h @@ -26,6 +26,7 @@ #include <stdarg.h> #include <stdio.h> +#include <libimobiledevice-glue/glue.h> #define COLOR_RESET "\e[m" #define STYLE_NORMAL "\e[0m" @@ -74,14 +75,14 @@ #define BG_DEFAULT "\e[49m" /* automatically called by library constructor */ -void term_colors_init(); +LIMD_GLUE_API void term_colors_init(); /* enable / disable terminal colors */ -void term_colors_set_enabled(int en); +LIMD_GLUE_API void term_colors_set_enabled(int en); /* color-aware *printf variants */ -int cprintf(const char* fmt, ...); -int cfprintf(FILE* stream, const char* fmt, ...); -int cvfprintf(FILE* stream, const char* fmt, va_list vargs); +LIMD_GLUE_API int cprintf(const char* fmt, ...); +LIMD_GLUE_API int cfprintf(FILE* stream, const char* fmt, ...); +LIMD_GLUE_API int cvfprintf(FILE* stream, const char* fmt, va_list vargs); #endif diff --git a/include/libimobiledevice-glue/thread.h b/include/libimobiledevice-glue/thread.h index 2aadc6e..76646b8 100644 --- a/include/libimobiledevice-glue/thread.h +++ b/include/libimobiledevice-glue/thread.h @@ -23,16 +23,31 @@ #define __THREAD_H #include <stddef.h> +#include <libimobiledevice-glue/glue.h> #ifdef WIN32 -#include <windows.h> +typedef void* HANDLE; typedef HANDLE THREAD_T; -typedef CRITICAL_SECTION mutex_t; +#pragma pack(push, 8) +struct _CRITICAL_SECTION_ST { + void* DebugInfo; + long LockCount; + long RecursionCount; + HANDLE OwningThread; + HANDLE LockSemaphore; +#if defined(_WIN64) + unsigned __int64 SpinCount; +#else + unsigned long SpinCount; +#endif +}; +#pragma pack(pop) +typedef struct _CRITICAL_SECTION_ST mutex_t; typedef struct { HANDLE sem; } cond_t; typedef volatile struct { - LONG lock; + long lock; int state; } thread_once_t; #define THREAD_ONCE_INIT {0, 0} @@ -53,13 +68,13 @@ typedef pthread_once_t thread_once_t; typedef void* (*thread_func_t)(void* data); -int thread_new(THREAD_T* thread, thread_func_t thread_func, void* data); -void thread_detach(THREAD_T thread); -void thread_free(THREAD_T thread); -int thread_join(THREAD_T thread); -int thread_alive(THREAD_T thread); +LIMD_GLUE_API int thread_new(THREAD_T* thread, thread_func_t thread_func, void* data); +LIMD_GLUE_API void thread_detach(THREAD_T thread); +LIMD_GLUE_API void thread_free(THREAD_T thread); +LIMD_GLUE_API int thread_join(THREAD_T thread); +LIMD_GLUE_API int thread_alive(THREAD_T thread); -int thread_cancel(THREAD_T thread); +LIMD_GLUE_API int thread_cancel(THREAD_T thread); #ifdef WIN32 #undef HAVE_THREAD_CLEANUP @@ -71,17 +86,17 @@ int thread_cancel(THREAD_T thread); #endif #endif -void mutex_init(mutex_t* mutex); -void mutex_destroy(mutex_t* mutex); -void mutex_lock(mutex_t* mutex); -void mutex_unlock(mutex_t* mutex); +LIMD_GLUE_API void mutex_init(mutex_t* mutex); +LIMD_GLUE_API void mutex_destroy(mutex_t* mutex); +LIMD_GLUE_API void mutex_lock(mutex_t* mutex); +LIMD_GLUE_API void mutex_unlock(mutex_t* mutex); -void thread_once(thread_once_t *once_control, void (*init_routine)(void)); +LIMD_GLUE_API void thread_once(thread_once_t *once_control, void (*init_routine)(void)); -void cond_init(cond_t* cond); -void cond_destroy(cond_t* cond); -int cond_signal(cond_t* cond); -int cond_wait(cond_t* cond, mutex_t* mutex); -int cond_wait_timeout(cond_t* cond, mutex_t* mutex, unsigned int timeout_ms); +LIMD_GLUE_API void cond_init(cond_t* cond); +LIMD_GLUE_API void cond_destroy(cond_t* cond); +LIMD_GLUE_API int cond_signal(cond_t* cond); +LIMD_GLUE_API int cond_wait(cond_t* cond, mutex_t* mutex); +LIMD_GLUE_API int cond_wait_timeout(cond_t* cond, mutex_t* mutex, unsigned int timeout_ms); #endif diff --git a/include/libimobiledevice-glue/tlv.h b/include/libimobiledevice-glue/tlv.h index 895c883..42be4f6 100644 --- a/include/libimobiledevice-glue/tlv.h +++ b/include/libimobiledevice-glue/tlv.h @@ -22,6 +22,7 @@ #define __TLV_H #include <stdint.h> +#include <libimobiledevice-glue/glue.h> struct tlv_buf { unsigned char* data; @@ -30,13 +31,13 @@ struct tlv_buf { }; typedef struct tlv_buf* tlv_buf_t; -tlv_buf_t tlv_buf_new(); -void tlv_buf_free(tlv_buf_t tlv); +LIMD_GLUE_API tlv_buf_t tlv_buf_new(); +LIMD_GLUE_API void tlv_buf_free(tlv_buf_t tlv); -void tlv_buf_append(tlv_buf_t tlv, uint8_t tag, unsigned int length, void* data); -unsigned char* tlv_get_data_ptr(const void* tlv_data, void* tlv_end, uint8_t tag, uint8_t* length); -int tlv_data_get_uint(const void* tlv_data, unsigned int tlv_length, uint8_t tag, uint64_t* value); -int tlv_data_get_uint8(const void* tlv_data, unsigned int tlv_length, uint8_t tag, uint8_t* value); -int tlv_data_copy_data(const void* tlv_data, unsigned int tlv_length, uint8_t tag, void** out, unsigned int* out_len); +LIMD_GLUE_API void tlv_buf_append(tlv_buf_t tlv, uint8_t tag, unsigned int length, void* data); +LIMD_GLUE_API unsigned char* tlv_get_data_ptr(const void* tlv_data, void* tlv_end, uint8_t tag, uint8_t* length); +LIMD_GLUE_API int tlv_data_get_uint(const void* tlv_data, unsigned int tlv_length, uint8_t tag, uint64_t* value); +LIMD_GLUE_API int tlv_data_get_uint8(const void* tlv_data, unsigned int tlv_length, uint8_t tag, uint8_t* value); +LIMD_GLUE_API int tlv_data_copy_data(const void* tlv_data, unsigned int tlv_length, uint8_t tag, void** out, unsigned int* out_len); #endif /* __TLV_H */ diff --git a/include/libimobiledevice-glue/utils.h b/include/libimobiledevice-glue/utils.h index b8513c0..355f1da 100644 --- a/include/libimobiledevice-glue/utils.h +++ b/include/libimobiledevice-glue/utils.h @@ -25,38 +25,20 @@ #ifndef __UTILS_H #define __UTILS_H -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#ifdef WIN32 -#include <windows.h> -#endif - #include <stdio.h> -#include <plist/plist.h> +#include <stdint.h> +#include <libimobiledevice-glue/glue.h> #define MAC_EPOCH 978307200 -char *string_concat(const char *str, ...); -char *string_append(char *str, ...); -char *string_build_path(const char *elem, ...); -char *string_format_size(uint64_t size); -char *string_toupper(char *str); -char *generate_uuid(void); - -int buffer_read_from_filename(const char *filename, char **buffer, uint64_t *length); -int buffer_write_to_filename(const char *filename, const char *buffer, uint64_t length); - -enum plist_format_t { - PLIST_FORMAT_XML, - PLIST_FORMAT_BINARY -}; - -int plist_read_from_filename(plist_t *plist, const char *filename); -int plist_write_to_filename(plist_t plist, const char *filename, enum plist_format_t format); +LIMD_GLUE_API char *string_concat(const char *str, ...); +LIMD_GLUE_API char *string_append(char *str, ...); +LIMD_GLUE_API char *string_build_path(const char *elem, ...); +LIMD_GLUE_API char *string_format_size(uint64_t size); +LIMD_GLUE_API char *string_toupper(char *str); +LIMD_GLUE_API char *generate_uuid(void); -void plist_print_to_stream(plist_t plist, FILE* stream); -void plist_print_to_stream_with_indentation(plist_t plist, FILE* stream, unsigned int indentation); +LIMD_GLUE_API int buffer_read_from_filename(const char *filename, char **buffer, uint64_t *length); +LIMD_GLUE_API int buffer_write_to_filename(const char *filename, const char *buffer, uint64_t length); #endif |