exsym.c
Go to the documentation of this file.
1 /* anal: analyze a.out file
2  date: Dec/24/1985
3  author: T.Matsui
4 */
5 
6 #include <stdio.h>
7 #include <fcntl.h>
8 #include <a.out.h>
9 
10 #define MAXSYMBOLS 1024
11 #define hexch(x) (char)((x<10)?(x+'0'):(x+'0'+7))
12 #define min(x,y) ((x<y)?x:y)
13 
14 extern char *optarg;
15 extern int optind;
16 
17 int infd,outfd;
20 
21 fatal(mes)
22 { puts(mes); exit(2);}
23 
25 int n;
26 { register int ch,i,f;
27  struct {
28  char flag;
29  char dummy;
30  long val;
31  char id[16];} sym;
32 
33  while (n>0) {
34  fread(&sym,6,1,stdin); /*read flags*/
35  n -= 6;
36  i=0;
37  do { /*read symbol id letters*/
38  ch=getchar();
39  sym.id[i++]=ch;
40  n--;}
41  while (ch);
42  if (sym.flag & 0x20) { /*external symbol?*/
43  if (sym.flag==0x23) f=0x28;
44  else if (sym.flag==0x20) f=0x30;
45  else f=sym.flag;
46  if (castabs) sym.flag=0x21;
47  if (rmesect &&
48  (strcmp(sym.id,"_etext")==0 || strcmp(sym.id,"_edata")==0 ||
49  strcmp(sym.id,"_end")==0)) /*remove section name*/ f=0;
50  if (f & fmask) {
51  write(outfd,&sym,6+i);
52  symtabsize += 6+i;}}}
53  }
54 
55 main(argc,argv)
56 int argc;
57 char *argv[];
58 { struct bhdr header,newheader;
59  char *progname,c;
60  progname=argv[0];
61  outfd= -1; fmask=31;
62  while ((c=getopt(argc,argv,"o:dtbuaAE")) != EOF)
63  switch(c) {
64  case 'o': outfd=creat(optarg,0644);
65  if (outfd<0) {
66  fprintf(stderr,"%s: cannot open output file: %s\n",
67  progname,optarg);
68  exit(1);}
69  break;
70  case 'a': fmask&=0x1e; break;
71  case 'd': fmask&=0x17; break;
72  case 't': fmask&=0x1d; break;
73  case 'b': fmask&=0x1b; break;
74  case 'u': fmask&=0x0f; break;
75  case 'A': castabs=1; break;
76  case 'E': rmesect=1; break;
77  case '?': fprintf(stderr,"invalid option %s\n",optarg);
78  break;
79  default: break;}
80 
81  /*set up input files*/
82  if (optind<argc) {
83  infd=open(argv[optind],O_RDONLY);
84  if (infd<0) {
85  fprintf(stderr,"%s: cannot open %s\n",progname,argv[optind]);
86  exit(1);}
87  close(0); /*switch stdin*/
88  dup(infd);}
89  if (outfd<0) outfd=creat("a.out",0644);
90  if (read(0,&header,sizeof(header))<1) fatal("cannot read");
91 
92  newheader=header;
93  newheader.tsize=0; newheader.dsize=0; newheader.bsize=0;
94  newheader.rtsize=newheader.rdsize=0;
95  write(outfd,&newheader,sizeof(newheader));
96 
97  lseek(0,32+header.tsize+header.dsize,0); /*seek to symbol table*/
98  symtabsize=0;
99  readsym(header.ssize);
100  lseek(outfd,0,0); /*move back to the file head*/
101 /* fprintf(stderr,"symtabsize=%d\n",symtabsize); */
102  newheader.ssize=symtabsize;
103  write(outfd,&newheader,sizeof(newheader));
104  exit(0);}
105 
f
char * progname
Definition: eus.c:39
int castabs
Definition: exsym.c:19
int ch[MAXTHREAD]
Definition: eusstream.c:23
char * optarg
int optind
GLfloat n[6][3]
Definition: cube.c:15
int infd
Definition: exsym.c:17
int fmask
Definition: exsym.c:19
static int argc
Definition: transargv.c:56
main(int argc, argv)
Definition: exsym.c:55
int outfd
Definition: exsym.c:17
int rmesect
Definition: exsym.c:19
int symtabsize
Definition: exsym.c:18
fatal(mes)
Definition: exsym.c:21
readsym(int n)
Definition: exsym.c:24


euslisp
Author(s): Toshihiro Matsui
autogenerated on Fri Feb 21 2020 03:20:54