shithub: scc

Download patch

ref: 893983575da0f76075ffd8f3d60cb23d6c3475e6
parent: 5ee2e8b13124750a58dc720afbc16d4d0a6f71f4
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Oct 30 07:19:30 EDT 2021

libmach: Add elf64str()

Elf64str() deals with all the cases to obtain a string related to
a section or to a symbol.

--- a/src/libmach/elf64/elf64.c
+++ b/src/libmach/elf64/elf64.c
@@ -19,3 +19,20 @@
 	.getsec = NULL,
 	.loadmap = NULL,
 };
+
+char *
+elf64str(Obj *obj, int n, long stroff)
+{
+	char *tbl;
+	size_t siz;
+	struct elf64 *elf;
+
+	elf = obj->data;
+
+	tbl = elf->strtbl[n];
+	siz = elf->strsiz[n];
+
+	if (!tbl || siz < stroff)
+		return "";
+	return &tbl[stroff];
+}
--- a/src/libmach/elf64/elf64.h
+++ b/src/libmach/elf64/elf64.h
@@ -51,3 +51,5 @@
 extern Symbol *elf64getsym(Obj *, int *, Symbol *);
 extern Section *elf64getsec(Obj *, int *, Section *);
 extern Map *elf64loadmap(Obj *, FILE *);
+
+extern char *elf64str(Obj *, int n, long);