History

win64: update tiny_impdef, tiny_libmaker (Elf64)

grischka committed 17 years ago

Commit 06aed3d1 parent 09ac9fa2 files · +146 −385Browse files

Unified · Split

2 files
  1. win32/tools/tiny_impdef.c +121 −280
  2. win32/tools/tiny_libmaker.c +25 −105
win32/tools/tiny_impdef.c+121−280
@@ -23,201 +23,92 @@ · 22 unmodified lines
23#define WIN32_LEAN_AND_MEAN23#define WIN32_LEAN_AND_MEAN
24#include <windows.h>24#include <windows.h>
25#include <stdio.h>25#include <stdio.h>
26#include <malloc.h>
27#include "../../config.h"
26 28
27/* Offset to PE file signature */29int read_mem(FILE *fp, unsigned offset, void *buffer, unsigned len)
28#define NTSIGNATURE(a) ((LPVOID)((BYTE *)a + \
29 ((PIMAGE_DOS_HEADER)a)->e_lfanew))
30
31/* MS-OS header identifies the NT PEFile signature dword;
32 the PEFILE header exists just after that dword. */
33#define PEFHDROFFSET(a) ((LPVOID)((BYTE *)a + \
34 ((PIMAGE_DOS_HEADER)a)->e_lfanew + \
35 SIZE_OF_NT_SIGNATURE))
36
37/* PE optional header is immediately after PEFile header. */
38#define OPTHDROFFSET(a) ((LPVOID)((BYTE *)a + \
39 ((PIMAGE_DOS_HEADER)a)->e_lfanew + \
40 SIZE_OF_NT_SIGNATURE + \
41 sizeof (IMAGE_FILE_HEADER)))
42
43/* Section headers are immediately after PE optional header. */
44#define SECHDROFFSET(a) ((LPVOID)((BYTE *)a + \
45 ((PIMAGE_DOS_HEADER)a)->e_lfanew + \
46 SIZE_OF_NT_SIGNATURE + \
47 sizeof (IMAGE_FILE_HEADER) + \
48 sizeof (IMAGE_OPTIONAL_HEADER)))
49
50
51#define SIZE_OF_NT_SIGNATURE 4
52
53/* -------------------------------------------------------------- */
54
55int WINAPI NumOfSections (
56 LPVOID lpFile)
57{30{
58 /* Number of sections is indicated in file header. */31 fseek(fp, offset, 0);
59 return (int)32 return len == fread(buffer, 1, len, fp);
60 ((PIMAGE_FILE_HEADER)
61 PEFHDROFFSET(lpFile))->NumberOfSections;
62}33}
63 34
64 35char *get_export_names(FILE *fp)
65/* -------------------------------------------------------------- */
66
67LPVOID WINAPI ImageDirectoryOffset (
68 LPVOID lpFile,
69 DWORD dwIMAGE_DIRECTORY)
70{36{
71 PIMAGE_OPTIONAL_HEADER poh;37 int l, i, n, n0;
72 PIMAGE_SECTION_HEADER psh;38 char *p;
73 int nSections = NumOfSections (lpFile);
74 int i = 0;
75 LPVOID VAImageDir;
76
77 /* Retrieve offsets to optional and section headers. */
78 poh = (PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET (lpFile);
79 psh = (PIMAGE_SECTION_HEADER)SECHDROFFSET (lpFile);
80
81 /* Must be 0 thru (NumberOfRvaAndSizes-1). */
82 if (dwIMAGE_DIRECTORY >= poh->NumberOfRvaAndSizes)
83 return NULL;
84
85 /* Locate image directory's relative virtual address. */
86 VAImageDir = (LPVOID)poh->DataDirectory[dwIMAGE_DIRECTORY].VirtualAddress;
87
88 /* Locate section containing image directory. */
89 while (i++<nSections)
90 {
91 if (psh->VirtualAddress <= (DWORD)VAImageDir
92 && psh->VirtualAddress + psh->SizeOfRawData > (DWORD)VAImageDir)
93 break;
94 psh++;
95 }
96
97 if (i > nSections)
98 return NULL;
99
100 /* Return image import directory offset. */
101 return (LPVOID)(((int)lpFile +
102 (int)VAImageDir - psh->VirtualAddress) +
103 (int)psh->PointerToRawData);
104}
105 39
106/* -------------------------------------------------------------- */40 IMAGE_SECTION_HEADER ish;
41 IMAGE_EXPORT_DIRECTORY ied;
42 IMAGE_DOS_HEADER dh;
43 IMAGE_FILE_HEADER ih;
44 DWORD sig, ref, addr, ptr, namep;
45#ifdef TCC_TARGET_X86_64
46 IMAGE_OPTIONAL_HEADER64 oh;
47 const int MACHINE = 0x8664;
48#else
49 IMAGE_OPTIONAL_HEADER32 oh;
50 const int MACHINE = 0x014C;
51#endif
52 int pef_hdroffset, opt_hdroffset, sec_hdroffset;
53
54 n = n0 = 0;
55 p = NULL;
56
57 if (!read_mem(fp, 0, &dh, sizeof dh))
58 goto the_end;
59 if (!read_mem(fp, dh.e_lfanew, &sig, sizeof sig))
60 goto the_end;
61 if (sig != 0x00004550)
62 goto the_end;
63 pef_hdroffset = dh.e_lfanew + sizeof sig;
64 if (!read_mem(fp, pef_hdroffset, &ih, sizeof ih))
65 goto the_end;
66 if (MACHINE != ih.Machine)
67 goto the_end;
68 opt_hdroffset = pef_hdroffset + sizeof ih;
69 sec_hdroffset = opt_hdroffset + sizeof oh;
70 if (!read_mem(fp, opt_hdroffset, &oh, sizeof oh))
71 goto the_end;
107 72
108BOOL WINAPI GetSectionHdrByName (73 if (IMAGE_DIRECTORY_ENTRY_EXPORT >= oh.NumberOfRvaAndSizes)
109 LPVOID lpFile,74 goto the_end;
110 IMAGE_SECTION_HEADER *sh,
111 char *szSection)
112{
113 PIMAGE_SECTION_HEADER psh;
114 int nSections = NumOfSections (lpFile);
115 int i;
116 75
117 if ((psh = (PIMAGE_SECTION_HEADER)SECHDROFFSET (lpFile)) != NULL)76 addr = oh.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
118 {77 //printf("addr: %08x\n", addr);
119 /* find the section by name */78 for (i = 0; i < ih.NumberOfSections; ++i) {
120 for (i=0; i<nSections; i++)79 if (!read_mem(fp, sec_hdroffset + i * sizeof ish, &ish, sizeof ish))
121 {80 goto the_end;
122 if (!strcmp (psh->Name, szSection))81 //printf("vaddr: %08x\n", ish.VirtualAddress);
123 {82 if (addr >= ish.VirtualAddress && addr < ish.VirtualAddress + ish.SizeOfRawData)
124 /* copy data to header */83 goto found;
125 memcpy ((LPVOID)sh, (LPVOID)psh, sizeof (IMAGE_SECTION_HEADER));
126 return TRUE;
127 }
128 else
129 psh++;
130 }
131 }84 }
132 return FALSE;85 goto the_end;
133}
134 86
135/* -------------------------------------------------------------- */87found:
136 88 ref = ish.VirtualAddress - ish.PointerToRawData;
137BOOL WINAPI GetSectionHdrByAddress (89 if (!read_mem(fp, addr - ref, &ied, sizeof ied))
138 LPVOID lpFile,90 goto the_end;
139 IMAGE_SECTION_HEADER *sh,
140 DWORD addr)
141{
142 PIMAGE_SECTION_HEADER psh;
143 int nSections = NumOfSections (lpFile);
144 int i;
145 91
146 if ((psh = (PIMAGE_SECTION_HEADER)SECHDROFFSET (lpFile)) != NULL)92 namep = ied.AddressOfNames - ref;
147 {93 for (i = 0; i < ied.NumberOfNames; ++i) {
148 /* find the section by name */94 if (!read_mem(fp, namep, &ptr, sizeof ptr))
149 for (i=0; i<nSections; i++)95 goto the_end;
150 {96 namep += sizeof ptr;
151 if (addr >= psh->VirtualAddress97 for (l = 0;;) {
152 && addr < psh->VirtualAddress + psh->SizeOfRawData)98 if (n+1 >= n0)
153 {99 p = realloc(p, n0 = n0 ? n0 * 2 : 256);
154 /* copy data to header */100 if (!read_mem(fp, ptr - ref + l, p + n, 1) || ++l >= 80) {
155 memcpy ((LPVOID)sh, (LPVOID)psh, sizeof (IMAGE_SECTION_HEADER));101 free(p), p = NULL;
156 return TRUE;102 goto the_end;
157 }103 }
158 else104 if (p[n++] == 0)
159 psh++;105 break;
160 }
161 }
162 return FALSE;
163}
164
165/* -------------------------------------------------------------- */
166
167int WINAPI GetExportFunctionNames (
168 LPVOID lpFile,
169 HANDLE hHeap,
170 char **pszFunctions)
171{
172 IMAGE_SECTION_HEADER sh;
173 PIMAGE_EXPORT_DIRECTORY ped;
174 int *pNames, *pCnt;
175 char *pSrc, *pDest;
176 int i, nCnt;
177 DWORD VAImageDir;
178 PIMAGE_OPTIONAL_HEADER poh;
179 char *pOffset;
180
181 /* Get section header and pointer to data directory
182 for .edata section. */
183 if (NULL == (ped = (PIMAGE_EXPORT_DIRECTORY)
184 ImageDirectoryOffset (lpFile, IMAGE_DIRECTORY_ENTRY_EXPORT)))
185 return 0;
186
187 poh = (PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET (lpFile);
188 VAImageDir = poh->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
189
190 if (FALSE == GetSectionHdrByAddress (lpFile, &sh, VAImageDir))
191 return 0;
192
193 pOffset = (char *)lpFile + (sh.PointerToRawData - sh.VirtualAddress);
194
195 pNames = (int *)(pOffset + (DWORD)ped->AddressOfNames);
196
197 /* Figure out how much memory to allocate for all strings. */
198 nCnt = 1;
199 for (i=0, pCnt = pNames; i<(int)ped->NumberOfNames; i++)
200 {
201 pSrc = (pOffset + *pCnt++);
202 if (pSrc)
203 nCnt += strlen(pSrc)+1;
204 }
205
206 /* Allocate memory off heap for function names. */
207 pDest = *pszFunctions = HeapAlloc (hHeap, HEAP_ZERO_MEMORY, nCnt);
208
209 /* Copy all strings to buffer. */
210 for (i=0, pCnt = pNames; i<(int)ped->NumberOfNames; i++)
211 {
212 pSrc = (pOffset + *pCnt++);
213 if (pSrc) {
214 strcpy(pDest, pSrc);
215 pDest += strlen(pSrc)+1;
216 }106 }
217 }107 }
218 *pDest = 0;108 if (p)
219 109 p[n] = 0;
220 return ped->NumberOfNames;110the_end:
111 return p;
221}112}
222 113
223/* -------------------------------------------------------------- */114/* -------------------------------------------------------------- */
@@ -238,61 +129,49 @@ static char *file_basename(const char *name) · 14 unmodified lines
238 129
239int main(int argc, char **argv)130int main(int argc, char **argv)
240{131{
241 HANDLE hHeap;132 int ret, v, i;
242 HANDLE hFile;
243 HANDLE hMapObject;
244 VOID *pMem;
245
246 int nCnt, ret, n;
247 char *pNames;
248 char infile[MAX_PATH];133 char infile[MAX_PATH];
249 char buffer[MAX_PATH];
250 char outfile[MAX_PATH];134 char outfile[MAX_PATH];
251 FILE *op;
252 char *p;
253 135
254 hHeap = NULL;136 static const char *ext[] = { ".dll", ".exe", NULL };
255 hFile = NULL;137 const char *file, **pp;
256 hMapObject = NULL;138 char path[MAX_PATH], *p, *q;
257 pMem = NULL;139 FILE *fp, *op;
140
258 infile[0] = 0;141 infile[0] = 0;
259 outfile[0] = 0;142 outfile[0] = 0;
143 fp = op = NULL;
144 v = 0;
260 ret = 1;145 ret = 1;
261 146
262 for (n = 1; n < argc; ++n)147 for (i = 1; i < argc; ++i) {
263 {148 const char *a = argv[i];
264 const char *a = argv[n];
265 if ('-' == a[0]) {149 if ('-' == a[0]) {
266 if (0 == strcmp(a, "-o")) {150 if (0 == strcmp(a, "-v")) {
267 if (++n == argc)151 v = 1;
152 } else if (0 == strcmp(a, "-o")) {
153 if (++i == argc)
268 goto usage;154 goto usage;
269 strcpy(outfile, argv[n]);155 strcpy(outfile, argv[i]);
270 }156 } else
271 else
272 goto usage;157 goto usage;
273
274 } else if (0 == infile[0])158 } else if (0 == infile[0])
275 strcpy(infile, a);159 strcpy(infile, a);
276 else160 else
277 goto usage;161 goto usage;
278 }162 }
279 163
280 if (0 == infile[0])164 if (0 == infile[0]) {
281 {
282usage:165usage:
283 fprintf(stderr,166 fprintf(stderr,
284 "tiny_impdef creates an export definition file (.def) from a dll\n"167 "tiny_impdef: create export definition file (.def) from a dll\n"
285 "Usage: tiny_impdef library.dll [-o outputfile]\n"168 "Usage: tiny_impdef library.dll [-o outputfile]\n"
286 );169 );
287 goto the_end;170 goto the_end;
288 }171 }
289 172
290 if (SearchPath(NULL, infile, ".dll", sizeof buffer, buffer, NULL))
291 strcpy(infile, buffer);
292
293 if (0 == outfile[0])173 if (0 == outfile[0])
294 {174 {
295 char *p;
296 strcpy(outfile, file_basename(infile));175 strcpy(outfile, file_basename(infile));
297 p = strrchr(outfile, '.');176 p = strrchr(outfile, '.');
298 if (NULL == p)177 if (NULL == p)
@@ -300,93 +179,55 @@ usage: · 1 unmodified line
300 strcpy(p, ".def");179 strcpy(p, ".def");
301 }180 }
302 181
303 hFile = CreateFile(182 file = infile;
304 infile,183#ifdef _WIN32
305 GENERIC_READ,184 for (pp = ext; *pp; ++pp)
306 FILE_SHARE_READ,185 if (SearchPath(NULL, file, *pp, sizeof path, path, NULL)) {
307 NULL,186 file = path;
308 OPEN_EXISTING,187 break;
309 0,188 }
310 NULL189#endif
311 );
312 190
313 if (hFile == INVALID_HANDLE_VALUE)191 fp = fopen(file, "rb");
314 {192 if (NULL == fp) {
315 fprintf(stderr, "No such file: %s\n", infile);193 fprintf(stderr, "tiny_impdef: no such file: %s\n", infile);
316 goto the_end;194 goto the_end;
317 }195 }
318 196
319 197 op = fopen(outfile, "w");
320 hMapObject = CreateFileMapping(198 if (NULL == op) {
321 hFile,199 fprintf(stderr, "tiny_impdef: could not create output file: %s\n", outfile);
322 NULL,
323 PAGE_READONLY,
324 0, 0,
325 NULL
326 );
327
328 if (NULL == hMapObject)
329 {
330 fprintf(stderr, "Could not create file mapping: %s\n", infile);
331 goto the_end;200 goto the_end;
332 }201 }
333 202
334 pMem = MapViewOfFile(203 if (v)
335 hMapObject, // object to map view of204 printf("--> %s\n", infile);
336 FILE_MAP_READ, // read access
337 0, // high offset: map from
338 0, // low offset: beginning
339 0); // default: map entire file
340 205
341 if (NULL == pMem)206 fprintf(op, "LIBRARY %s\n\nEXPORTS\n", file_basename(infile));
342 {207 p = get_export_names(fp);
343 fprintf(stderr, "Could not map view of file: %s\n", infile);208 if (NULL == p) {
209 fprintf(stderr, "tiny_impdef: could not get exported function names.\n");
344 goto the_end;210 goto the_end;
345 }211 }
346 212
347 if (0 != strncmp(NTSIGNATURE(pMem), "PE", 2))213 for (q = p, i = 0; *q; ++i) {
348 {214 fprintf(op, "%s\n", q);
349 fprintf(stderr, "Not a PE file: %s\n", infile);215 q += strlen(q) + 1;
350 goto the_end;
351 }216 }
217 free(p);
352 218
353 219 if (v) {
354 hHeap = GetProcessHeap();220 printf("<-- %s\n", outfile);
355 nCnt = GetExportFunctionNames(pMem, hHeap, &pNames);221 printf("%d symbol(s) found\n", i);
356 if (0 == nCnt) {
357 fprintf(stderr, "Could not get exported function names: %s\n", infile);
358 goto the_end;
359 }222 }
360 223
361 printf("--> %s\n", infile);
362
363 op = fopen(outfile, "w");
364 if (NULL == op)
365 {
366 fprintf(stderr, "Could not create file: %s\n", outfile);
367 goto the_end;
368 }
369
370 printf("<-- %s\n", outfile);
371
372 fprintf(op, "LIBRARY %s\n\nEXPORTS\n", file_basename(infile));
373 for (n = 0, p = pNames; n < nCnt; ++n)
374 {
375 fprintf(op, "%s\n", p);
376 while (*p++);
377 }
378 ret = 0;224 ret = 0;
379 225
380the_end:226the_end:
381 if (pMem)227 if (fp)
382 UnmapViewOfFile(pMem);228 fclose(fp);
383 229 if (op)
384 if (hMapObject)230 fclose(op);
385 CloseHandle(hMapObject);
386
387 if (hFile)
388 CloseHandle(hFile);
389
390 return ret;231 return ret;
391}232}
392 233
win32/tools/tiny_libmaker.c+25−105
@@ -13,98 +13,8 @@ · 12 unmodified lines
13#include <io.h> /* for mktemp */13#include <io.h> /* for mktemp */
14#endif14#endif
15 15
16/* #include "ar-elf.h" */16#include "../../config.h"
17/* "ar-elf.h" */17#include "../../elf.h"
18/* ELF_v1.2.pdf */
19typedef unsigned short int Elf32_Half;
20typedef int Elf32_Sword;
21typedef unsigned int Elf32_Word;
22typedef unsigned int Elf32_Addr;
23typedef unsigned int Elf32_Off;
24typedef unsigned short int Elf32_Section;
25
26#define EI_NIDENT 16
27typedef struct {
28 unsigned char e_ident[EI_NIDENT];
29 Elf32_Half e_type;
30 Elf32_Half e_machine;
31 Elf32_Word e_version;
32 Elf32_Addr e_entry;
33 Elf32_Off e_phoff;
34 Elf32_Off e_shoff;
35 Elf32_Word e_flags;
36 Elf32_Half e_ehsize;
37 Elf32_Half e_phentsize;
38 Elf32_Half e_phnum;
39 Elf32_Half e_shentsize;
40 Elf32_Half e_shnum;
41 Elf32_Half e_shstrndx;
42} Elf32_Ehdr;
43
44typedef struct {
45 Elf32_Word sh_name;
46 Elf32_Word sh_type;
47 Elf32_Word sh_flags;
48 Elf32_Addr sh_addr;
49 Elf32_Off sh_offset;
50 Elf32_Word sh_size;
51 Elf32_Word sh_link;
52 Elf32_Word sh_info;
53 Elf32_Word sh_addralign;
54 Elf32_Word sh_entsize;
55} Elf32_Shdr;
56
57#define SHT_NULL 0
58#define SHT_PROGBITS 1
59#define SHT_SYMTAB 2
60#define SHT_STRTAB 3
61#define SHT_RELA 4
62#define SHT_HASH 5
63#define SHT_DYNAMIC 6
64#define SHT_NOTE 7
65#define SHT_NOBITS 8
66#define SHT_REL 9
67#define SHT_SHLIB 10
68#define SHT_DYNSYM 11
69
70typedef struct {
71 Elf32_Word st_name;
72 Elf32_Addr st_value;
73 Elf32_Word st_size;
74 unsigned char st_info;
75 unsigned char st_other;
76 Elf32_Half st_shndx;
77} Elf32_Sym;
78
79#define ELF32_ST_BIND(i) ((i)>>4)
80#define ELF32_ST_TYPE(i) ((i)&0xf)
81#define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
82
83#define STT_NOTYPE 0
84#define STT_OBJECT 1
85#define STT_FUNC 2
86#define STT_SECTION 3
87#define STT_FILE 4
88#define STT_LOPROC 13
89#define STT_HIPROC 15
90
91#define STB_LOCAL 0
92#define STB_GLOBAL 1
93#define STB_WEAK 2
94#define STB_LOPROC 13
95#define STB_HIPROC 15
96
97typedef struct {
98 Elf32_Word p_type;
99 Elf32_Off p_offset;
100 Elf32_Addr p_vaddr;
101 Elf32_Addr p_paddr;
102 Elf32_Word p_filesz;
103 Elf32_Word p_memsz;
104 Elf32_Word p_flags;
105 Elf32_Word p_align;
106} Elf32_Phdr;
107/* "ar-elf.h" ends */
108 18
109#define ARMAG "!<arch>\n"19#define ARMAG "!<arch>\n"
110#define ARFMAG "`\n"20#define ARFMAG "`\n"
@@ -119,7 +29,6 @@ typedef struct ArHdr { · 8 unmodified lines
119 char ar_fmag[2];29 char ar_fmag[2];
120} ArHdr;30} ArHdr;
121 31
122
123unsigned long le2belong(unsigned long ul) {32unsigned long le2belong(unsigned long ul) {
124 return ((ul & 0xFF0000)>>8)+((ul & 0xFF000000)>>24) +33 return ((ul & 0xFF0000)>>8)+((ul & 0xFF000000)>>24) +
125 ((ul & 0xFF)<<24)+((ul & 0xFF00)<<8);34 ((ul & 0xFF)<<24)+((ul & 0xFF00)<<8);
@@ -148,9 +57,9 @@ ArHdr arhdro = { · 22 unmodified lines
148int main(int argc, char **argv)57int main(int argc, char **argv)
149{58{
150 FILE *fi, *fh, *fo;59 FILE *fi, *fh, *fo;
151 Elf32_Ehdr *ehdr;60 ElfW(Ehdr) *ehdr;
152 Elf32_Shdr *shdr;61 ElfW(Shdr) *shdr;
153 Elf32_Sym *sym;62 ElfW(Sym) *sym;
154 int i, fsize, iarg;63 int i, fsize, iarg;
155 char *buf, *shstr, *symtab = NULL, *strtab = NULL;64 char *buf, *shstr, *symtab = NULL, *strtab = NULL;
156 int symtabsize = 0, strtabsize = 0;65 int symtabsize = 0, strtabsize = 0;
@@ -207,7 +116,7 @@ int main(int argc, char **argv) · 50 unmodified lines
207 }116 }
208 if ((fi = fopen(argv[iarg], "rb")) == NULL)117 if ((fi = fopen(argv[iarg], "rb")) == NULL)
209 {118 {
210 fprintf(stderr, "Can't open file %s \n", argv[iarg]);119 fprintf(stderr, "Can't open file %s \n", argv[iarg]);
211 remove(tfile);120 remove(tfile);
212 return 2;121 return 2;
213 }122 }
@@ -218,14 +127,21 @@ int main(int argc, char **argv) · 4 unmodified lines
218 fread(buf, fsize, 1, fi);127 fread(buf, fsize, 1, fi);
219 fclose(fi);128 fclose(fi);
220 129
221 printf("%s:\n", argv[iarg]);130 //printf("%s:\n", argv[iarg]);
222 // elf header131 // elf header
223 ehdr = (Elf32_Ehdr *)buf;132 ehdr = (ElfW(Ehdr) *)buf;
224 shdr = (Elf32_Shdr *) (buf + ehdr->e_shoff + ehdr->e_shstrndx * ehdr->e_shentsize);133 if (ehdr->e_ident[4] != TCC_ELFCLASS)
134 {
135 fprintf(stderr, "Unsupported Elf Class: %s\n", argv[iarg]);
136 remove(tfile);
137 return 2;
138 }
139
140 shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + ehdr->e_shstrndx * ehdr->e_shentsize);
225 shstr = (char *)(buf + shdr->sh_offset);141 shstr = (char *)(buf + shdr->sh_offset);
226 for (i = 0; i < ehdr->e_shnum; i++)142 for (i = 0; i < ehdr->e_shnum; i++)
227 {143 {
228 shdr = (Elf32_Shdr *) (buf + ehdr->e_shoff + i * ehdr->e_shentsize);144 shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + i * ehdr->e_shentsize);
229 if (!shdr->sh_offset) continue;145 if (!shdr->sh_offset) continue;
230 if (shdr->sh_type == SHT_SYMTAB)146 if (shdr->sh_type == SHT_SYMTAB)
231 {147 {
@@ -244,12 +160,16 @@ int main(int argc, char **argv) · 12 unmodified lines
244 160
245 if (symtab && symtabsize)161 if (symtab && symtabsize)
246 {162 {
247 int nsym = symtabsize / sizeof(Elf32_Sym);163 int nsym = symtabsize / sizeof(ElfW(Sym));
248 //printf("symtab: info size shndx name\n");164 //printf("symtab: info size shndx name\n");
249 for (i = 1; i < nsym; i++)165 for (i = 1; i < nsym; i++)
250 {166 {
251 sym = (Elf32_Sym *) (symtab + i * sizeof(Elf32_Sym));167 sym = (ElfW(Sym) *) (symtab + i * sizeof(ElfW(Sym)));
252 if (sym->st_shndx && (sym->st_info == 0x11 || sym->st_info == 0x12)) {168 if (sym->st_shndx &&
169 (sym->st_info == 0x10
170 || sym->st_info == 0x11
171 || sym->st_info == 0x12
172 )) {
253 //printf("symtab: %2Xh %4Xh %2Xh %s\n", sym->st_info, sym->st_size, sym->st_shndx, strtab + sym->st_name);173 //printf("symtab: %2Xh %4Xh %2Xh %s\n", sym->st_info, sym->st_size, sym->st_shndx, strtab + sym->st_name);
254 istrlen = strlen(strtab + sym->st_name)+1;174 istrlen = strlen(strtab + sym->st_name)+1;
255 anames = realloc(anames, strpos+istrlen);175 anames = realloc(anames, strpos+istrlen);
@@ -281,7 +201,7 @@ int main(int argc, char **argv) · 25 unmodified lines
281 } else fpos = 0;201 } else fpos = 0;
282 // write header202 // write header
283 fwrite("!<arch>\n", 8, 1, fh);203 fwrite("!<arch>\n", 8, 1, fh);
284 sprintf(stmp, "%-10d", strpos + (funccnt+1) * sizeof(int));204 sprintf(stmp, "%-10d", (int)(strpos + (funccnt+1) * sizeof(int)));
285 memcpy(&arhdr.ar_size, stmp, 10);205 memcpy(&arhdr.ar_size, stmp, 10);
286 fwrite(&arhdr, sizeof(arhdr), 1, fh);206 fwrite(&arhdr, sizeof(arhdr), 1, fh);
287 afpos[0] = le2belong(funccnt);207 afpos[0] = le2belong(funccnt);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t