fillnops.c
1.68 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <stdio.h>
void useage(void)
{
printf("Useage:\n");
printf("fillnops file word file word extra\n");
printf(" file1 = first file to search\n");
printf(" word1 = label whos address to find in file1\n");
printf(" file2 = second file to search\n");
printf(" word2 = label whos address to find in file2\n");
printf(" extra = number of extra nops to print\n");
}
main(int argc, char *argv[])
{
char *word1, *word2, *filename1, *filename2;
int c, num1, num2, numnop, extra;
FILE *fp;
if (argc != 6) {
useage();
exit(1);
}
filename1 = argv[1];
word1 = argv[2];
filename2 = argv[3];
word2 = argv[4];
sscanf(argv[5],"%i",&extra);
if (!(fp=fopen(filename1,"r"))) {
printf("trouble reading %s\n",filename1);
exit(1);
}
if (!findword(fp,word1)) {
printf("could not find label %s in file %s.\n",word1,filename1);
exit(1);
}
fscanf(fp,"%x",&num1);
fclose(fp);
if (!(fp=fopen(filename2,"r"))) {
printf("trouble reading %s\n",filename2);
exit(1);
}
if (!findword(fp,word2)) {
printf("could not find label %s in file %s.\n",word2,filename2);
exit(1);
}
fscanf(fp,"%x",&num2);
fclose(fp);
numnop = (((num1-num2)/4 + extra) +1)&0xfffe;
printf(" # This file is automatically generated by fillnops.s\n");
printf(" # DO NOT EDIT THIS FILE\n");
printf(" # The purpose of this file is to fill in the space between\n");
printf(" # the end of ginit.s and the beginning of gsetup.s which\n");
printf(" # will later be overlayed by gclip.s and gflight.s\n");
while (numnop--) {
printf(" nop\n");
}
exit(0);
}
int findword(FILE *fp,char *s)
{
int c=1,i=0;
while (c!=EOF) {
c=getc(fp);
if (c!=s[i++]) i=0;
if (s[i]=='\0')
return 1;
}
return 0;
}