home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
WHATFN.ZIP
/
WHATFUNC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-01-22
|
14KB
|
431 lines
/* whatfunc.c */
/* based on previous code in ENUMDLL.C, ENUMPROC.C, and GDT.C */
/* Andrew Schulman 14-Jan-1989 */
/*
example:
C>whatfunc 0f6b 0357:0937 01b7:0fc2 0637:0614 817:1098
0F6B:0000 DOSGETVERSION
0357:0937 MOUSETSCALEFACT
01B7:0FC2 VIOSETSTATE
0637:0614 KBDSETCP
0817:1098 _printf
*/
/*
if no args, print help
else, for each arg, print arg and its ASCIIZ name
to get ASCIIZ name:
see if in DOSCALLS (ASCIIZ names hard-wired)
else, see if in VIOCALLS, KBDCALLS, MOUCALLS (ASCIIZ names from ENUMPROC)
if all else fails:
see what DLL's in memory (ENUMDLL loop)
for each one, call search_dll
to do:
1 -- since search_dll is slow, should be using threads. Either one thread
per command-line arg, or one thread per module to search
2 -- should be "TSR" monitor. But then tables should be built and kept
so that searches get faster
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define INCL_DOS
#define INCL_DOSDEVICES
#define INCL_DOSSIGNALS
#include "os2.h"
typedef unsigned USHORT;
typedef unsigned long ULONG;
typedef void far *FP;
#pragma pack(1)
typedef struct {
char *name;
ULONG procaddr; /* USHORT (far pascal *procaddr)(); */
} DOSCALLS;
#define REG /*register*/ /*compiler does a better job*/
#define MK_FP(seg,off) ((FP)(((ULONG)(seg) << 16) | (off)))
#define FAILBUFSIZE 128
char failbuffer[FAILBUFSIZE];
USHORT doscalls;
BOOL verbose = FALSE;
extern char *enumproc(char *dll, char *buf, USHORT *ord);
char *search_doscalls(FP fp);
char *search_dll(char *dll, FP fp);
char *enumdll(USHORT iter, FP fp);
USHORT htoi(char *s);
void init_doscalls(void);
main(int argc, char *argv[])
{
REG int i;
if (argc < 2)
{
printf("WHATFUNC(func) --> ASCIIZ name for func\n");
printf("syntax: %s XXXX:XXXX\n", argv[0]);
printf("within CVP: ! %s XXXX:XXXX\n", argv[0]);
exit(1);
}
DosLoadModule(failbuffer, FAILBUFSIZE, "DOSCALLS", &doscalls);
init_doscalls();
/* perhapse use separate thread for each command-line argument */
for (i=1; i<argc; i++)
{
FP fp;
char *s;
USHORT seg, off;
if (argv[i][0] == '-' && (argv[i][1] == 'v' || argv[i][1] == 'V'))
{
verbose = TRUE;
continue;
}
seg = htoi(strtok(argv[i], ":"));
off = htoi(strtok(0, ":"));
fp = MK_FP(seg,off);
if (s = search_doscalls(fp))
{
if (*s == '*')
printf("%04X:%04X\t%s\n", seg,off, s+1);
else
printf("%04X:%04X\tDOS%s\n", seg, off, s);
}
else
{
char *s = search_dll("VIOCALLS", fp);
if (! s) s = search_dll("KBDCALLS", fp);
if (! s) s = search_dll("MOUCALLS", fp);
if (! s) s = search_dll("DOSCALL1", fp);
if (! s) s = enumdll(4000, fp);
if (! s) s = "????";
printf("%04X:%04X\t%s\n", seg, off, s);
}
}
return 0;
}
USHORT htoi(char *s)
{
USHORT i = 0, t;
while (*s == ' ' || *s == '\t')
s++;
while (1)
{
char c = *s;
if (c >= '0' && c <= '9') t = 48;
else if (c >= 'A' && c <= 'F') t = 55;
else if (c >= 'a' && c <= 'f') t = 87;
else break;
i = (i << 4) + (c - t);
s++;
}
return i;
}
/**********************************************************************/
#define NUM_DOSCALLS 111
extern USHORT far pascal DOSPTRACE();
extern USHORT far pascal DOSSGSWITCH();
extern USHORT far pascal DOSSGSWITCHME();
extern USHORT far pascal DOSSYSTRACE();
static DOSCALLS dosfuncs[NUM_DOSCALLS] = {
"ALLOCHUGE", (ULONG) DosAllocHuge,
"ALLOCSEG", (ULONG) DosAllocSeg,
"ALLOCSHRSEG", (ULONG) DosAllocShrSeg,
"BEEP", (ULONG) DosBeep,
"BUFRESET", (ULONG) DosBufReset,
"CHDIR", (ULONG) DosChdir,
"CHGFILEPTR", (ULONG) DosChgFilePtr,
"CLIACCESS", (ULONG) DosCLIAccess,
"CLOSE", (ULONG) DosClose,
"CLOSESEM", (ULONG) DosCloseSem,
"CREATECSALIAS", (ULONG) DosCreateCSAlias,
"CREATESEM", (ULONG) DosCreateSem,
"CREATETHREAD", (ULONG) DosCreateThread,
"CWAIT", (ULONG) DosCWait,
"DELETE", (ULONG) DosDelete,
"DEVCONFIG", (ULONG) DosDevConfig,
"DEVIOCTL", (ULONG) DosDevIOCtl,
"DUPHANDLE", (ULONG) DosDupHandle,
"ENTERCRITSEC", (ULONG) DosEnterCritSec,
"ERRCLASS", (ULONG) DosErrClass,
"ERROR", (ULONG) DosError,
"EXECPGM", (ULONG) DosExecPgm,
"EXIT", (ULONG) DosExit,
"EXITCRITSEC", (ULONG) DosExitCritSec,
"EXITLIST", (ULONG) DosExitList,
"FILELOCKS", (ULONG) DosFileLocks,
"FINDCLOSE", (ULONG) DosFindClose,
"FINDFIRST", (ULONG) DosFindFirst,
"FINDNEXT", (ULONG) DosFindNext,
"FLAGPROCESS", (ULONG) DosFlagProcess,
"FREEMODULE", (ULONG) DosFreeModule,
"FREESEG", (ULONG) DosFreeSeg,
"GETCP", (ULONG) DosGetCp,
"GETDATETIME", (ULONG) DosGetDateTime,
"GETENV", (ULONG) DosGetEnv,
"GETHUGESHIFT", (ULONG) DosGetHugeShift,
"GETINFOSEG", (ULONG) DosGetInfoSeg,
"GETMACHINEMODE", (ULONG) DosGetMachineMode,
"GETMODHANDLE", (ULONG) DosGetModHandle,
"GETMODNAME", (ULONG) DosGetModName,
"GETPID", (ULONG) DosGetPid,
"GETPROCADDR", (ULONG) DosGetProcAddr,
"GETPRTY", (ULONG) DosGetPrty,
"GETSEG", (ULONG) DosGetSeg,
"GETSHRSEG", (ULONG) DosGetShrSeg,
"GETVERSION", (ULONG) DosGetVersion,
"GIVESEG", (ULONG) DosGiveSeg,
"HOLDSIGNAL", (ULONG) DosHoldSignal,
"KILLPROCESS", (ULONG) DosKillProcess,
"LOADMODULE", (ULONG) DosLoadModule,
"LOCKSEG", (ULONG) DosLockSeg,
"MAKEPIPE", (ULONG) DosMakePipe,
"MEMAVAIL", (ULONG) DosMemAvail,
"MKDIR", (ULONG) DosMkdir,
"MOVE", (ULONG) DosMove,
"MUXSEMWAIT", (ULONG) DosMuxSemWait,
"NEWSIZE", (ULONG) DosNewSize,
"OPEN", (ULONG) DosOpen,
"OPENSEM", (ULONG) DosOpenSem,
"PHYSICALDISK", (ULONG) DosPhysicalDisk,
"PORTACCESS", (ULONG) DosPortAccess,
"PTRACE", (ULONG) DOSPTRACE,
"QCURDIR", (ULONG) DosQCurDir,
"QCURDISK", (ULONG) DosQCurDisk,
"QFHANDSTATE", (ULONG) DosQFHandState,
"QFILEINFO", (ULONG) DosQFileInfo,
"QFILEMODE", (ULONG) DosQFileMode,
"QFSINFO", (ULONG) DosQFSInfo,
"QHANDTYPE", (ULONG) DosQHandType,
"QVERIFY", (ULONG) DosQVerify,
"READ", (ULONG) DosRead,
"READASYNC", (ULONG) DosReadAsync,
"REALLOCHUGE", (ULONG) DosReallocHuge,
"REALLOCSEG", (ULONG) DosReallocSeg,
"RESUMETHREAD", (ULONG) DosResumeThread,
"RMDIR", (ULONG) DosRmdir,
"SCANENV", (ULONG) DosScanEnv,
"SEARCHPATH", (ULONG) DosSearchPath,
"SELECTDISK", (ULONG) DosSelectDisk,
"SEMCLEAR", (ULONG) DosSemClear,
"SEMREQUEST", (ULONG) DosSemRequest,
"SEMSET", (ULONG) DosSemSet,
"SEMSETWAIT", (ULONG) DosSemSetWait,
"SEMWAIT", (ULONG) DosSemWait,
"SENDSIGNAL", (ULONG) DosSendSignal,
"SETCP", (ULONG) DosSetCp,
"SETDATETIME", (ULONG) DosSetDateTime,
"SETFHANDSTATE", (ULONG) DosSetFHandState,
"SETFILEINFO", (ULONG) DosSetFileInfo,
"SETFILEMODE", (ULONG) DosSetFileMode,
"SETFSINFO", (ULONG) DosSetFSInfo,
"SETMAXFH", (ULONG) DosSetMaxFH,
"SETPRTY", (ULONG) DosSetPrty,
"SETSIGHANDLER", (ULONG) DosSetSigHandler,
"SETVEC", (ULONG) DosSetVec,
"SETVERIFY", (ULONG) DosSetVerify,
"SGSWITCH", (ULONG) DOSSGSWITCH,
"SGSWITCHME", (ULONG) DOSSGSWITCHME,
"SLEEP", (ULONG) DosSleep,
"SUBALLOC", (ULONG) DosSubAlloc,
"SUBFREE", (ULONG) DosSubFree,
"SUBSET", (ULONG) DosSubSet,
"SUSPENDTHREAD", (ULONG) DosSuspendThread,
"SYSTEMSERVICE", (ULONG) DosSystemService,
"SYSTRACE", (ULONG) DOSSYSTRACE,
"TIMERASYNC", (ULONG) DosTimerAsync,
"TIMERSTART", (ULONG) DosTimerStart,
"TIMERSTOP", (ULONG) DosTimerStop,
"UNLOCKSEG", (ULONG) DosUnlockSeg,
"WRITE", (ULONG) DosWrite,
"WRITEASYNC", (ULONG) DosWriteAsync,
} ;
#define NUM_NEWCALLS 51
/* table stores ordinal numbers, until replaced by procaddr */
static DOSCALLS newcalls[NUM_NEWCALLS] = {
"CALLBACK", 157L,
"FSRAMSEMCLEAR", 162L,
"FSRAMSEMREQUEST", 161L,
"GETSTDA", 119L, /* 3 wds */
"GLOBALSEG", 132L,
"HUGEINCR", 136L,
"HUGESHIFT", 135L,
"ICANONICALIZE", 100L, /* 7 wds */
"ICREATETHREAD", 1L, /* 4 wds */
"IEXECPGM", 4L, /* 12 wds */
"IRAMSEMWAKE", 125L, /* 3 wds */
"IREAD", 79L, /* 6 wds */
"ISEMREQUEST", 18L, /* 4 wds */
"ISEMWAIT", 21L, /* 4 wds */
"ISETCP", 131L, /* 2 wds */
"ISYSSEMCLEAR", 17L, /* 2 wds */
"ISYSSEMSET", 19L, /* 2 wds */
"IWRITE", 87L, /* 6 wds */
"LIBINIT", 96L, /* 2 wds */
"PROFILE", 133L, /* 9 wds */
"QAPPTYPE", 163L,
"QPROCSTATUS", 184L,
"QSYSINFO", 166L, /* 4 wds */
"QTRACEINFO", 93L,
"R2STACKREALLOC", 160L, /* 1 wds */
"READPHYS", 103L,
"SETFGND", 101L, /* 2 wds */
"SETPROCCP", 155L, /* 5 wds */
"SGSWITCHPROC", 124L,
"SIZESEG", 126L, /* 3 wds */
"SWAPTASKINIT", 102L,
/* names that don't have DOS in front of them */
"*GETADDR", 111L,
"*GETHEADERS", 108L,
"*GETSELADDR", 110L,
"*STRUCHECK", 106L,
"*STRURESUPDATE", 107L,
"*UNUSEDA", 98L,
"*UNUSEDB", 99L,
"*UNUSEDC", 126L,
"*UNUSEDD", 128L,
"*UNUSEDE", 104L,
"*UNUSEDF", 105L,
"*UNUSEDG", 95L,
"*DBGETKVAR", 109L,
"*DBGETOWNER", 117L,
"*DBMEMFREE", 116L,
"*DBMEMLOCK", 112L,
"*DBMEMREALLOC", 15L,
"*DBMEMUNLOCK", 113L,
"*DBPHYSINFO", 118L,
"*DBSEGALLOC", 114L,
} ;
void init_doscalls(void)
{
/* try to install new functions */
ULONG procaddr;
REG DOSCALLS *p;
REG USHORT i;
/* before loop, newcalls[i].procaddr contains DOSCALLS.ord# */
for (i=0, p=newcalls; i<NUM_NEWCALLS; i++, p++)
p->procaddr = (DosGetProcAddr(doscalls, p->procaddr, &procaddr)) ?
0L : procaddr;
}
char *search_doscalls(FP fp)
{
REG DOSCALLS *p;
REG USHORT i;
for (i=0, p=dosfuncs; i<NUM_DOSCALLS; i++, p++)
{
if (fp == p->procaddr)
return p->name;
else if (verbose)
printf("DOSCALLS.DOS%s\t%Fp\n", p->name, p->procaddr);
}
/*still here*/
for (i=0, p=newcalls; i<NUM_NEWCALLS; i++, p++)
{
if (fp == p->procaddr)
return p->name;
else if (verbose && p->procaddr)
{
if (* p->name == '*')
printf("DOSCALLS.%s\t%Fp\n", p->name + 1, p->procaddr);
else
printf("DOSCALLS.DOS%s\t%Fp\n", p->name, p->procaddr);
}
}
/*still here*/
return (char *) 0;
}
char *search_dll(char *dll, FP fp)
{
char buf[128], *funcname=buf;
char *dllname;
char *ret = (char *) 0;
FP procaddr;
USHORT ord;
USHORT mod;
/* possibly turn full pathname into module name, for DosLoadModule */
if (strchr(dll, '\\') && strchr(dll, '.'))
{
char buf[128], *p;
if (! strstr(dll, ".DLL")) /* DosQAppType is unreliable */
return (char *) 0;
strcpy(buf, dll);
if (p = strchr(buf, '.'))
*p = '\0';
if (p = strrchr(buf, '\\'))
p++;
if (strstr("VIOCALLS KBDCALLS MOUCALLS DOSCALL1", p))
return (char *) 0;
dllname = p;
}
else dllname = dll;
/* to get module handle */
if (DosLoadModule(failbuffer, FAILBUFSIZE, dllname, &mod))
return (char *) 0;
/* get full pathname of DLL */
if (DosGetModName(mod, 128, buf))
return (char *) 0;
if (enumproc(buf, funcname, &ord))
while (enumproc(0, funcname, &ord))
if (! DosGetProcAddr(mod, funcname, &procaddr))
{
if (procaddr == fp)
{
ret = funcname;
break;
}
else if (verbose)
printf("%s.%s\t%Fp\n", dllname, funcname, procaddr);
}
DosFreeModule(mod);
return ret;
}
/* see if it's in any other currently loaded DLL */
char *enumdll(USHORT iter, FP fp)
{
char buf[128];
char *ret = (char *) 0;
REG USHORT i;
for (i=0; i<iter; i++)
if (! DosGetModName(i, 128, buf))
{
if (verbose)
printf("%u\t%s\n", i, buf);
if (ret = search_dll(buf, fp))
break;
}
return ret;
}