-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSYM.C
executable file
·222 lines (196 loc) · 5.28 KB
/
SYM.C
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#include <stdio.h>
#define LONG long
#define WORD unsigned short
int read_name(
FILE *filehandle,
char *pch
) {
char length;
int rc;
rc = fread( &length, sizeof(length), 1, filehandle );
if ( rc != 1 ) {
printf("Could not read name length\n");
*pch = '\0';
return( 0 );
}
rc = fread( pch, length, 1, filehandle );
if ( rc != 1 ) {
printf("Could not read name\n");
*pch = '\0';
return( 0 );
}
*(pch + length) = '\0';
return( (int)length );
}
int read_symbol(
FILE *filehandle,
char *pch,
LONG *offset
) {
int rc;
WORD word;
rc = fread( &word, sizeof(WORD), 1, filehandle );
if ( rc != 1 ) {
printf("Could not read symbol offset\n");
*pch = '\0';
*offset = 0L;
return(0);
}
*offset = (LONG)word;
rc = read_name( filehandle, pch );
return( rc );
}
int main(
int argc,
char *argv[]
) {
FILE *symfile;
LONG filesize;
LONG start_position;
LONG position;
WORD w1;
WORD num_syms;
WORD w3;
WORD w4;
WORD next_off;
WORD index;
char c1;
char c2;
int rc;
int cnt;
LONG offset;
WORD r2;
WORD seg_num;
char b[12];
char name_buff[128];
if ( argc == 3 ) {
_asm {
int 3
}
}
symfile = fopen( argv[1], "rb" );
if ( symfile == NULL ) {
printf("Could not open sym file\n");
exit(1);
}
rc = fread( &filesize, sizeof(filesize), 1, symfile );
if ( rc != 1 ) {
printf("Could not read file size\n");
exit(1);
}
filesize <<= 4;
rc = fread( &w1, sizeof(w1), 1, symfile );
if ( rc != 1 ) {
printf("Could not read w1\n");
exit(1);
}
rc = fread( &num_syms, sizeof(num_syms), 1, symfile );
if ( rc != 1 ) {
printf("Could not read num_syms\n");
exit(1);
}
rc = fread( &w3, sizeof(w3), 1, symfile );
if ( rc != 1 ) {
printf("Could not read w3\n");
exit(1);
}
rc = fread( &w4, sizeof(w4), 1, symfile );
if ( rc != 1 ) {
printf("Could not read w4\n");
exit(1);
}
rc = fread( &next_off, sizeof(next_off), 1, symfile );
if ( rc != 1 ) {
printf("Could not read next_off\n");
exit(1);
}
start_position = ((LONG)next_off) << 4;
rc = fread( &c1, sizeof(c1), 1, symfile );
if ( rc != 1 ) {
printf("Could not read c1\n");
exit(1);
}
read_name( symfile, name_buff );
printf("Symbols are for file: <%s>\n", name_buff );
rc = fread( &c2, sizeof(c2), 1, symfile );
if ( rc != 1 ) {
printf("Could not read c2\n");
exit(1);
}
cnt = num_syms;
while ( cnt ) {
read_symbol( symfile, name_buff, &offset );
printf("Symbol: %08lX:<%s>\n", offset, name_buff );
--cnt;
}
#ifdef NEED_INDICES
cnt = num_syms;
while ( cnt ) {
rc = fread( &index, sizeof(index), 1, symfile );
if ( rc != 1 ) {
printf("Could not read index table entry\n");
exit(1);
}
printf("Index: %04X\n", index );
--cnt;
}
#endif
position = start_position;
do {
rc = fseek( symfile, position, SEEK_SET );
if ( rc != 0 ) {
printf("Failed to seek to next record\n");
exit(1);
}
rc = fread( &next_off, sizeof(next_off), 1, symfile );
if ( rc != 1 ) {
printf("Could not read next_off\n");
exit(1);
}
position = ((LONG)next_off) << 4;
rc = fread( &num_syms, sizeof(num_syms), 1, symfile );
if ( rc != 1 ) {
printf("Could not read num_syms\n");
exit(1);
}
rc = fread( &r2, sizeof(r2), 1, symfile );
if ( rc != 1 ) {
printf("Could not read r2\n");
exit(1);
}
rc = fread( &seg_num, sizeof(seg_num), 1, symfile );
if ( rc != 1 ) {
printf("Could not read seg_num\n");
exit(1);
}
cnt = 0;
while ( cnt < 12 ) {
rc = fread( &b[cnt], sizeof(b[0]), 1, symfile );
if ( rc != 1 ) {
printf("Could not read 12 byte b array\n");
exit(1);
}
cnt++;
}
read_name( symfile, name_buff );
printf("Symbols are for file: <%s>\n", name_buff );
cnt = num_syms;
while ( cnt ) {
read_symbol( symfile, name_buff, &offset );
printf("Symbol: %04X:%08lX:<%s>\n", seg_num, offset, name_buff );
--cnt;
}
#ifdef NEED_INDICES
cnt = num_syms;
while ( cnt ) {
rc = fread( &index, sizeof(index), 1, symfile );
if ( rc != 1 ) {
printf("Could not read index table entry\n");
exit(1);
}
--cnt;
}
#endif
} while ( position != start_position && position != 0 );
fclose( symfile );
}