home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
ENUMP2.ZIP
/
ENUMPROC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-06-11
|
2KB
|
78 lines
/* enumproc.c */
/* enumerates all exported procs from DLL file */
/* Andrew Schulman 28-May-1988 */
/* revised 2-Jun-1988 (AS) */
#include <stdio.h>
/* lifted from MSoft newexe.h */
#define ENEWHDR 0x003C /* offset of new EXE header */
#define EMAGIC 0x5A4D /* old EXE magic id: 'MZ' */
#define NEMAGIC 0x454E /* new EXE magic id: 'NE' */
typedef struct
{
unsigned ne_magic;
char ne_ver;
char ne_rev;
unsigned ne_enttab;
unsigned ne_cbenttab;
long ne_crc;
unsigned ne_flags;
unsigned ne_autodata;
unsigned ne_heap;
unsigned ne_stack;
long ne_csip;
long ne_sssp;
unsigned ne_cseg;
unsigned ne_cmod;
unsigned ne_cbnrestab;
unsigned ne_segtab;
unsigned ne_rsrctab;
unsigned ne_restab; /* offset of resident name table */
/* etc. -- we could care less */
} NEWEXE;
char *enumproc(const char *dll, char *buf, unsigned *ord)
{
static FILE *f = (FILE *)0;
unsigned char len;
if (dll == (char *)-1)
goto closeit;
else if (dll)
{
NEWEXE hdr;
unsigned start_newexe;
if (f) fclose(f);
f = fopen(dll, "rb");
if (! f || getw(f) != EMAGIC)
goto closeit;
fseek(f, ENEWHDR, SEEK_SET);
start_newexe = getw(f);
fseek(f, start_newexe, SEEK_SET);
fread(&hdr, sizeof(NEWEXE), 1, f);
if (hdr.ne_magic != NEMAGIC)
goto closeit;
fseek(f, start_newexe, SEEK_SET);
fseek(f, hdr.ne_restab, SEEK_CUR);
}
if (len = fgetc(f))
{
fread(buf, len, 1, f);
buf[len] = '\0';
*ord = getw(f);
return buf;
}
else
{
closeit:
if (f) fclose(f);
f = NULL;
return NULL;
}
/*NOTREACHED*/
}