changeset 171:ddbfc1a1a811

objgrep: -s implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 04 Jul 2014 03:07:09 +0000
parents 13a9ce1590fc
children 452baa748747
files objgrep/Makefile objgrep/dumpmatch.c objgrep/main.c
diffstat 3 files changed, 43 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/objgrep/Makefile	Fri Jul 04 02:56:21 2014 +0000
+++ b/objgrep/Makefile	Fri Jul 04 03:07:09 2014 +0000
@@ -1,7 +1,7 @@
 CC=	gcc
 CFLAGS=	-O2
 PROG=	objgrep
-OBJS=	globals.o grep.o lowlevel.o main.o mkpattern.o tables.o
+OBJS=	dumpmatch.o globals.o grep.o lowlevel.o main.o mkpattern.o tables.o
 HDRS=	coffconst.h filestruct.h globals.h intstruct.h
 
 all:	${PROG}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/objgrep/dumpmatch.c	Fri Jul 04 03:07:09 2014 +0000
@@ -0,0 +1,40 @@
+/*
+ * objgrep: output on matches
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "intstruct.h"
+#include "coffconst.h"
+#include "globals.h"
+
+extern unsigned get_u16(), get_u32();
+
+dump_symtab_on_match()
+{
+	unsigned n;
+	struct internal_syment *sym;
+
+	printf("\nThis source section's symbols:\n\n");
+	for (n = 0; n < nsymtab; n++) {
+		sym = symtab[n];
+		if (!sym)
+			continue;
+		if (sym->section != grep_section)
+			continue;
+		switch (sym->class) {
+		case C_EXT:
+			printf("%s = %08X\n", sym->name,
+				sym->value + match_offset);
+			continue;
+		case C_STAT:
+			printf("%s:%s = %08X\n", objfilename, sym->name,
+				sym->value + match_offset);
+			continue;
+		}
+	}
+}
--- a/objgrep/main.c	Fri Jul 04 02:56:21 2014 +0000
+++ b/objgrep/main.c	Fri Jul 04 03:07:09 2014 +0000
@@ -66,5 +66,7 @@
 	}
 	printf("%s:%s found in %s at 0x%x\n", objfilename, grep_section->name,
 		binfilename, match_offset);
+	if (sflag)
+		dump_symtab_on_match();
 	exit(0);
 }