home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 13
/
mediashare_13.zip
/
mediashare_13
/
ZIPPED
/
PROGRAM
/
APR94_2.ZIP
/
LISTINST
/
INSTWALK.C
next >
Wrap
C/C++ Source or Header
|
1994-03-01
|
4KB
|
125 lines
/*
INSTWALK.C
From Dr. Dobbs Journal, April 1994.
Klaus Mueller 1994, All Rights Reserved.
*/
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <alloc.h>
#include <listinst.h>
Inst_Owner far *Owner_Buf;
Inst_Desc_Buf far *Desc_Buf;
Inst_Hook_Struc far *Inst_Hook;
long int i, Map_Size, Inst_Map_Count, Desc_Size;
int Desc_Flag;
/* Get entry point for the VxD API using Int 2Fh AX=1684h */
typedef void (far *api_entry)(void);
api_entry get_vxd_api(int vxd_id)
{
asm {
push es
push di
mov ax,1684h
mov bx,vxd_id
mov di,0
mov es,di
int 2fh
mov ax,di
mov dx,es
pop di
pop es
}
}
void main(int argc, char *argv[])
{
static api_entry api = NULL;
api = get_vxd_api(ListInst_ID);
if (api == 0)
{
printf("Error: ListInst.386 not loaded.");
exit(1);
}
Desc_Flag=0;
asm { mov bx,offset Desc_Size
mov ax,Desc_Buf_Size /* Determine size of Description buffer */
}
(*api)(); /* Call V86API of ListInst.386 */
asm jnc alloc
printf("Error: Cannot create Instance Description Buffer.");
Desc_Flag=1;
alloc:
asm { mov bx,offset Map_Size
mov ax,Inst_Map_Size /* Determine size of Instance Map */
}
(*api)(); /* Call V86API of ListInst.386 */
Inst_Map_Count=Map_Size/sizeof(Inst_Hook_Struc);
if ( (Owner_Buf=malloc(max_v86_pages)) == 0)
{
printf("Memory allocation error");
exit (1);
};
if ( (Desc_Buf=malloc(Desc_Size)) == 0)
{
printf("Memory allocation error");
exit (1);
};
if ( (Inst_Hook=malloc(Map_Size)) == 0)
{
printf("Memory allocation error");
exit (1);
};
printf("\nCalling ListInst.386 ... \n");
if ( *argv[1] == '-' && *(argv[1]+1) == 'p' ){
asm { mov bx,offset Desc_Buf
mov dx,offset Owner_Buf
mov ax,Inst_Ownership /* Request Instance Page Ownership */
}
(*api)(); /* Call V86API of ListInst.386 */
/* Print received VxD data */
printf("\nDump of Instance Page Ownership Array\n");
printf("\nInstance Page\tOwned by VM\tFlags\t\tID\n\n");
for ( i=0; Owner_Buf[i].Inst_PG_No != 0xffffffff; i++)
printf ("0x%lX\t\t0x%lX\t0x%08lX\t0x%lX\n",Owner_Buf[i]);
if ( !Desc_Flag){
printf("\nDump of Instance Description Buffer.\n");
printf("\nLinear Address in VM\tOffset in Instance Buffer\tInstance");
printf(" Item Size\n\n");
for ( i=0; Desc_Buf[i].Item_Size != 0; i++)
printf ("0x%08lX\t\t0x%08lX\t\t\t0x%08lX\n",Desc_Buf[i].VM_Lin_Address,\
Desc_Buf[i].Inst_Buf_Off, Desc_Buf[i].Item_Size);
}
}else{
asm {
mov dx,offset Inst_Hook
mov ax,Inst_Map
}
(*api)(); /* Call V86API of ListInst.386 */
asm jnc ok
printf("\nError: VxDQuery.386 not loaded");
exit(1);
ok: printf("\nV86 API from ListInst.386: Result of _AddInstanceItem Hook.\n");
printf("Summary of allocation calls to the Instance Data Manager.\n");
printf("\nName of VxD\t\t\t\tInstLinAddr\t\tInstSize\n");
for ( i=0; i < Inst_Map_Count; i++) /* print received VxD data */
printf("\n%s\t0x%08lX\t\t0x%08lX",&Inst_Hook[i].Caller_String, \
Inst_Hook[i].Inst_Lin_Addr, Inst_Hook[i].Inst_Size);
printf("\n\nType instwalk -p for dump of Page Ownership Array.\n");
}
}