summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-01-06 09:15:26 +0000
committermidipix <writeonce@midipix.org>2024-01-22 03:49:50 +0000
commitd4473b3be02d429a72347914a6fc7e5688ad98e5 (patch)
tree138d10289bb4f7b5dc42da466447807591ba1836 /include
parent8a9ab12c467fe48944272ae9bd073f90854b13f8 (diff)
downloadslibtool-d4473b3be02d429a72347914a6fc7e5688ad98e5.tar.bz2
slibtool-d4473b3be02d429a72347914a6fc7e5688ad98e5.tar.xz
slbt_get_archive_meta(): initial implementation.
Diffstat (limited to 'include')
-rw-r--r--include/slibtool/slibtool.h40
-rw-r--r--include/slibtool/slibtool_arbits.h176
2 files changed, 216 insertions, 0 deletions
diff --git a/include/slibtool/slibtool.h b/include/slibtool/slibtool.h
index a742037..1743262 100644
--- a/include/slibtool/slibtool.h
+++ b/include/slibtool/slibtool.h
@@ -7,6 +7,7 @@
#include <unistd.h>
#include "slibtool_api.h"
+#include "slibtool_arbits.h"
#ifdef __cplusplus
extern "C" {
@@ -96,6 +97,13 @@ enum slbt_custom_error {
SLBT_ERR_LCONF_MAP,
SLBT_ERR_LCONF_PARSE,
SLBT_ERR_AR_FAIL,
+ SLBT_ERR_AR_EMPTY_FILE,
+ SLBT_ERR_AR_INVALID_SIGNATURE,
+ SLBT_ERR_AR_INVALID_HEADER,
+ SLBT_ERR_AR_TRUNCATED_DATA,
+ SLBT_ERR_AR_DUPLICATE_LONG_NAMES,
+ SLBT_ERR_AR_DUPLICATE_ARMAP_MEMBER,
+ SLBT_ERR_AR_MISPLACED_ARMAP_MEMBER,
};
/* execution modes */
@@ -277,6 +285,31 @@ struct slbt_driver_ctx {
void * any;
};
+struct slbt_raw_archive {
+ void * map_addr;
+ size_t map_size;
+};
+
+struct slbt_archive_meta {
+ struct slbt_raw_archive r_archive;
+ struct ar_raw_signature * r_signature;
+
+ struct ar_meta_signature * m_signature;
+
+ struct ar_meta_member_info ** a_memberv;
+ struct ar_meta_member_info * a_namestrs;
+
+ struct ar_meta_armap_info a_armap_primary;
+ struct ar_meta_armap_info a_armap_pecoff;
+};
+
+struct slbt_archive_ctx {
+ const char * const * path;
+ const struct slbt_raw_archive * map;
+ const struct slbt_archive_meta *meta;
+ void * any;
+};
+
/* raw input api */
slbt_api int slbt_map_input (const struct slbt_driver_ctx *,
int, const char *, int,
@@ -323,6 +356,13 @@ slbt_api int slbt_copy_file (const struct slbt_driver_ctx *, struct
slbt_api int slbt_dump_machine (const char * compiler, char * machine, size_t bufsize);
slbt_api int slbt_realpath (int, const char *, int, char *, size_t);
+/* archiver api */
+slbt_api int slbt_get_archive_meta (const struct slbt_driver_ctx *,
+ const struct slbt_raw_archive *,
+ struct slbt_archive_meta **);
+
+slbt_api void slbt_free_archive_meta (struct slbt_archive_meta *);
+
/* utility api */
slbt_api int slbt_main (char **, char **,
const struct slbt_fd_ctx *);
diff --git a/include/slibtool/slibtool_arbits.h b/include/slibtool/slibtool_arbits.h
new file mode 100644
index 0000000..9a5ab4d
--- /dev/null
+++ b/include/slibtool/slibtool_arbits.h
@@ -0,0 +1,176 @@
+#ifndef SLIBTOOL_ARBITS_H
+#define SLIBTOOL_ARBITS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stddef.h>
+
+#define AR_SIGNATURE "!<arch>\n"
+
+#define AR_MEMBER_ATTR_DEFAULT (0x00)
+#define AR_MEMBER_ATTR_ASCII (0x01)
+#define AR_MEMBER_ATTR_UTF8 (0x02)
+#define AR_MEMBER_ATTR_ARMAP (0x04)
+#define AR_MEMBER_ATTR_OBJECT (0x08)
+#define AR_MEMBER_ATTR_SYMDEFS (0x10)
+#define AR_MEMBER_ATTR_NAMESTRS (0x20)
+#define AR_MEMBER_ATTR_LINKINFO (0x40)
+#define AR_MEMBER_ATTR_ARCHIVE (0x80)
+
+#define AR_HEADER_ATTR_DEFAULT (0x00)
+#define AR_HEADER_ATTR_FILE_ID (0x01)
+#define AR_HEADER_ATTR_NAME_REF (0x02)
+#define AR_HEADER_ATTR_BSD (0x10)
+#define AR_HEADER_ATTR_SYSV (0x20)
+
+#define AR_ARMAP_ATTR_PLAIN (0x0000)
+#define AR_ARMAP_ATTR_SORTED (0x0001)
+#define AR_ARMAP_ATTR_BSD (0x0010)
+#define AR_ARMAP_ATTR_SYSV (0x0020)
+#define AR_ARMAP_ATTR_COFF (0x0040)
+#define AR_ARMAP_ATTR_LE_32 (0x0100)
+#define AR_ARMAP_ATTR_LE_64 (0x0200)
+#define AR_ARMAP_ATTR_BE_32 (0x0400)
+#define AR_ARMAP_ATTR_BE_64 (0x0800)
+
+#define AR_OBJECT_ATTR_NONE (0X0000)
+#define AR_OBJECT_ATTR_ELF (0x0001)
+#define AR_OBJECT_ATTR_COFF (0x0002)
+#define AR_OBJECT_ATTR_MACHO (0x0004)
+#define AR_OBJECT_ATTR_LE_32 (0x0100)
+#define AR_OBJECT_ATTR_LE_64 (0x0200)
+#define AR_OBJECT_ATTR_BE_32 (0x0400)
+#define AR_OBJECT_ATTR_BE_64 (0x0800)
+
+struct ar_raw_signature {
+ char ar_signature [0x08]; /* 0x00 */
+};
+
+struct ar_raw_file_header {
+ char ar_file_id [0x10]; /* 0x00 */
+ char ar_time_date_stamp [0x0c]; /* 0x10 */
+ char ar_uid [0x06]; /* 0x1c */
+ char ar_gid [0x06]; /* 0x22 */
+ char ar_file_mode [0x08]; /* 0x28 */
+ char ar_file_size [0x0a]; /* 0x30 */
+ char ar_end_tag [0x02]; /* 0x3a */
+};
+
+struct ar_raw_armap_ref_32 {
+ unsigned char ar_name_offset [0x04]; /* 0x00 */
+ unsigned char ar_member_offset [0x04]; /* 0x04 */
+};
+
+struct ar_raw_armap_ref_64 {
+ unsigned char ar_name_offset [0x08]; /* 0x00 */
+ unsigned char ar_member_offset [0x08]; /* 0x08 */
+};
+
+struct ar_raw_armap_bsd_32 {
+ unsigned char (*ar_size_of_refs) [0x04];
+ unsigned char (*ar_first_name_offset) [0x04];
+ unsigned char (*ar_size_of_strs) [0x04];
+ const char * (*ar_string_table);
+};
+
+struct ar_raw_armap_bsd_64 {
+ unsigned char (*ar_size_of_refs) [0x08];
+ unsigned char (*ar_first_name_offset) [0x08];
+ unsigned char (*ar_size_of_strs) [0x08];
+ const char * (*ar_string_table);
+};
+
+struct ar_raw_armap_sysv_32 {
+ unsigned char (*ar_num_of_syms) [0x04];
+ unsigned char (*ar_first_ref_offset) [0x04];
+ const char * (*ar_string_table);
+};
+
+struct ar_raw_armap_sysv_64 {
+ unsigned char (*ar_num_of_syms) [0x08];
+ unsigned char (*ar_first_ref_offset) [0x08];
+ const char * (*ar_string_table);
+};
+
+struct ar_raw_armap_xcoff_32 {
+ unsigned char (*ar_num_of_members) [0x04];
+ unsigned char (*ar_first_member_offset) [0x04];
+ unsigned char (*ar_num_of_symbols) [0x04];
+ unsigned char (*ar_sym_member_indices) [0x02];
+ char (*ar_string_table) [];
+};
+
+struct ar_meta_signature {
+ const char * ar_signature;
+};
+
+struct ar_meta_file_header {
+ const char * ar_member_name;
+ uint64_t ar_time_date_stamp;
+ uint32_t ar_uid;
+ uint32_t ar_gid;
+ uint32_t ar_file_mode;
+ uint64_t ar_file_size;
+ uint32_t ar_header_attr;
+};
+
+struct ar_meta_member_info {
+ struct ar_meta_file_header ar_file_header;
+ uint32_t ar_member_attr;
+ uint32_t ar_object_attr;
+ uint64_t ar_object_size;
+ void * ar_object_data;
+};
+
+struct ar_meta_armap_ref_32 {
+ uint32_t ar_name_offset;
+ uint32_t ar_member_offset;
+};
+
+struct ar_meta_armap_ref_64 {
+ uint64_t ar_name_offset;
+ uint64_t ar_member_offset;
+};
+
+struct ar_meta_armap_common_32 {
+ struct ar_meta_member_info * ar_member;
+ struct ar_raw_armap_bsd_32 * ar_armap_bsd;
+ struct ar_raw_armap_sysv_32 * ar_armap_sysv;
+ struct ar_raw_armap_xcoff_32 * ar_armap_xcoff;
+ uint32_t ar_armap_attr;
+ uint32_t ar_num_of_symbols;
+ uint32_t ar_num_of_members;
+ uint32_t ar_first_member_offset;
+ uint32_t ar_size_of_refs;
+ uint32_t ar_size_of_strs;
+ uint16_t * ar_sym_member_indices;
+ const char * ar_string_table;
+};
+
+struct ar_meta_armap_common_64 {
+ struct ar_meta_member_info * ar_member;
+ struct ar_raw_armap_bsd_64 * ar_armap_bsd;
+ struct ar_raw_armap_sysv_64 * ar_armap_sysv;
+ void * ar_armap_xcoff;
+ uint32_t ar_armap_attr;
+ uint64_t ar_num_of_symbols;
+ uint64_t ar_num_of_members;
+ uint64_t ar_first_member_offset;
+ uint64_t ar_size_of_refs;
+ uint64_t ar_size_of_strs;
+ uint16_t * ar_sym_member_indices;
+ const char * ar_string_table;
+};
+
+struct ar_meta_armap_info {
+ const struct ar_meta_armap_common_32 * ar_armap_common_32;
+ const struct ar_meta_armap_common_64 * ar_armap_common_64;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif