aboutsummaryrefslogtreecommitdiff
path: root/unix/shlib/aout.c
blob: 832fc42eebdbbd434fc333c2f07c5e19e693d2a7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
 */

#include <stdio.h>
#include <a.out.h>

/* AOUT -- Examine the header of a AOUT file.
 */
main (argc, argv)
int	argc;
char	*argv[];
{
	struct	exec fh;
	int	fd;

	if (argc < 2) {
	    fprintf (stderr, "Usage: aout <filename>\n");
	    exit (0);
	}

	if ((fd = open (argv[1], 0)) == -1) {
	    fprintf (stderr, "cannot open %s\n", argv[1]);
	    exit (1);
	}

	/* Show file header. */
	if (read (fd, &fh, sizeof(fh)) != sizeof(fh))
	    goto readerr;
	else if (fh.a_magic != ZMAGIC) {
	    fprintf (stderr, "not a page-aligned executable format file\n");
	    /* exit (2); */
	}

	printf ("File header:\n");
	printf ("%16s: %10d %10x  %012o\n",
	    "a_magic", fh.a_magic, fh.a_magic, fh.a_magic);
	printf ("%16s: %10d %10x  %012o\n",
	    "a_text", fh.a_text, fh.a_text, fh.a_text);
	printf ("%16s: %10d %10x  %012o\n",
	    "a_data", fh.a_data, fh.a_data, fh.a_data);
	printf ("%16s: %10d %10x  %012o\n",
	    "a_bss", fh.a_bss, fh.a_bss, fh.a_bss);
	printf ("%16s: %10d %10x  %012o\n",
	    "a_syms", fh.a_syms, fh.a_syms, fh.a_syms);
	printf ("%16s: %10d %10x  %012o\n",
	    "a_entry", fh.a_entry, fh.a_entry, fh.a_entry);
	printf ("%16s: %10d %10x  %012o\n",
	    "a_trsize", fh.a_trsize, fh.a_trsize, fh.a_trsize);
	printf ("%16s: %10d %10x  %012o\n",
	    "a_drsize", fh.a_drsize, fh.a_drsize, fh.a_drsize);

	fflush (stdout);
	close (fd);
	exit (0);

readerr:
	fprintf (stderr, "file read error\n");
	exit (4);
}