--- /dev/null
+/******************************************************************************
+ * @file elks.h
+ *****************************************************************************/
+#ifndef _ELKS_H
+#define _ELKS_H
+
+struct elks_exec {
+
+ unsigned char a_magic[2];
+ unsigned char a_flags;
+ unsigned char a_cpu;
+ unsigned char a_hdrlen;
+ unsigned char a_unused;
+ unsigned char a_version[2];
+
+ unsigned char a_text[4];
+ unsigned char a_data[4];
+ unsigned char a_bss[4];
+ unsigned char a_entry[4];
+ unsigned char a_total[4];
+ unsigned char a_syms[4];
+
+ unsigned char a_trsize[4];
+ unsigned char a_drsize[4];
+ unsigned char a_trbase[4];
+ unsigned char a_drbase[4];
+
+};
+
+#define ELKS_MAGIC 0403
+
+struct elks_nlist {
+
+ unsigned char n_strx[4];
+ unsigned char n_type;
+
+ unsigned char n_other;
+ unsigned char n_desc[2];
+
+ unsigned char n_value[4];
+
+};
+
+#endif /* _ELKS_H */
#include <string.h>
#include "ar.h"
+#include "elks.h"
#include "lib.h"
#include "report.h"
#define GET_UINT16(arr) ((unsigned long) arr[0] | (((unsigned long) arr[1]) << 8))
#define GET_UINT32(arr) ((unsigned long) arr[0] | (((unsigned long) arr[1]) << 8) | (((unsigned long) arr[2]) << 16) | (((unsigned long) arr[3]) << 24))
-struct aout_exec {
+/*struct aout_exec {
unsigned char a_info[4];
unsigned char a_text[4];
unsigned char n_value[4];
-};
-
-struct nlist {
-
- unsigned char n_strx[4];
- unsigned char n_type;
-
- unsigned char n_value[4];
-
-};
+};*/
struct strtab {
}
-static void aout_get_symbols (void *object, long offset) {
+/*static void aout_get_symbols (void *object, long offset) {
struct aout_exec *hdr = (struct aout_exec *) object;
}
+}*/
+
+static void elks_get_symbols (void *object, long offset) {
+
+ struct elks_exec *hdr = (struct elks_exec *) object;
+
+ long sym_start = sizeof (*hdr) + GET_UINT32 (hdr->a_text) + GET_UINT32 (hdr->a_data) + GET_UINT32 (hdr->a_trsize) + GET_UINT32 (hdr->a_drsize);
+ long strtab_start = sym_start + GET_UINT32 (hdr->a_syms);
+
+ while (sym_start < strtab_start) {
+
+ struct elks_nlist nlist;
+ memcpy (&nlist, (char *) object + sym_start, sizeof (nlist));
+
+ if (nlist.n_type == 5 || nlist.n_type == 7 || nlist.n_type == 9) {
+
+ struct strtab *strtab;
+ char *symname = (char *) object + strtab_start + GET_INT32 (nlist.n_strx);
+
+ strtab = xmalloc (sizeof (*strtab));
+ strtab->length = strlen (symname);
+
+ strtab->name = xstrdup (symname);
+ strtab->offset = offset;
+
+ add_strtab (&gstrtab, strtab);
+
+ }
+
+ sym_start += sizeof (nlist);
+
+ }
+
}
void ranlib (FILE *arfp) {
}
- if (!((object[0] == 0x39 || object[0] == 0x07) && object[1] == 0x01 && object[2] == 0x64 && object[3] == 0x00)) {
-
- free (object);
-
- offset += sizeof (hdr);
- offset += bytes;
-
- fseek (arfp, bytes, SEEK_CUR);
- continue;
-
- }
-
- if ((object[0] == 0x39 || object[0] == 0x07) && object[1] == 0x01 && object[2] == 0x64 && object[3] == 0x00) {
+ /*if ((object[0] == 0x39 || object[0] == 0x07) && object[1] == 0x01 && object[2] == 0x64 && object[3] == 0x00) {
aout_get_symbols (object, offset + 8);
+ }*/
+
+ if (object[0] == ((ELKS_MAGIC >> 8) & 0xff) && object[1] == (ELKS_MAGIC & 0xff)) {
+ elks_get_symbols (object, offset + 8);
}
free (object);