home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / APR94_2.ZIP / LISTINST / INSTWALK.C next >
C/C++ Source or Header  |  1994-03-01  |  4KB  |  125 lines

  1. /*
  2. INSTWALK.C
  3. From Dr. Dobbs Journal, April 1994.
  4. Klaus Mueller 1994, All Rights Reserved.
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <dos.h>
  10. #include <alloc.h>
  11. #include <listinst.h>
  12.  
  13.  
  14.  
  15. Inst_Owner      far     *Owner_Buf;
  16. Inst_Desc_Buf   far     *Desc_Buf;      
  17. Inst_Hook_Struc far     *Inst_Hook;
  18.  
  19. long int i, Map_Size, Inst_Map_Count, Desc_Size;
  20. int Desc_Flag;
  21.  
  22. /* Get entry point for the VxD API using Int 2Fh AX=1684h */
  23. typedef void (far *api_entry)(void);
  24.  
  25.  
  26. api_entry get_vxd_api(int vxd_id)
  27. {   
  28.     asm {
  29.             push es
  30.             push di
  31.             mov ax,1684h
  32.             mov bx,vxd_id
  33.             mov di,0
  34.             mov es,di
  35.             int 2fh
  36.             mov ax,di
  37.             mov dx,es
  38.             pop di
  39.             pop es
  40.         }
  41. }
  42.  
  43. void main(int argc, char *argv[])
  44. {
  45.   static api_entry api = NULL;
  46.   api = get_vxd_api(ListInst_ID);
  47.   if (api == 0)
  48.     {
  49.         printf("Error: ListInst.386 not loaded.");
  50.         exit(1);
  51.     }   
  52.   Desc_Flag=0;
  53.   asm { mov bx,offset Desc_Size
  54.         mov ax,Desc_Buf_Size        /* Determine size of Description buffer */                      
  55.       }
  56.   (*api)();                         /* Call V86API of ListInst.386 */
  57.   asm jnc alloc
  58.   printf("Error: Cannot create Instance Description Buffer."); 
  59.   Desc_Flag=1;
  60. alloc:  
  61.   asm { mov bx,offset Map_Size
  62.         mov ax,Inst_Map_Size        /* Determine size of Instance Map */                        
  63.       }
  64.   (*api)();                         /* Call V86API of ListInst.386 */
  65.   Inst_Map_Count=Map_Size/sizeof(Inst_Hook_Struc);
  66.   if ( (Owner_Buf=malloc(max_v86_pages)) == 0)          
  67.    {
  68.     printf("Memory allocation error");
  69.     exit (1);
  70.    };   
  71.  
  72.   if ( (Desc_Buf=malloc(Desc_Size)) == 0)           
  73.    {
  74.     printf("Memory allocation error");
  75.     exit (1);
  76.    };   
  77.   if ( (Inst_Hook=malloc(Map_Size)) == 0)           
  78.    {
  79.     printf("Memory allocation error");
  80.     exit (1);
  81.    };   
  82.   printf("\nCalling ListInst.386 ... \n");
  83.  
  84.   if ( *argv[1] == '-' && *(argv[1]+1) == 'p' ){
  85.     asm {   mov bx,offset Desc_Buf
  86.             mov dx,offset Owner_Buf
  87.             mov ax,Inst_Ownership       /* Request Instance Page Ownership */                       
  88.         }
  89.     (*api)();                           /* Call V86API of ListInst.386 */
  90.                                         /* Print received VxD data */
  91.    printf("\nDump of Instance Page Ownership Array\n");
  92.    printf("\nInstance Page\tOwned by VM\tFlags\t\tID\n\n");
  93.     for ( i=0; Owner_Buf[i].Inst_PG_No != 0xffffffff; i++)
  94.       printf ("0x%lX\t\t0x%lX\t0x%08lX\t0x%lX\n",Owner_Buf[i]);
  95.  
  96.     if ( !Desc_Flag){
  97.       printf("\nDump of Instance Description Buffer.\n");
  98.       printf("\nLinear Address in VM\tOffset in Instance Buffer\tInstance");
  99.       printf(" Item Size\n\n");
  100.       for ( i=0; Desc_Buf[i].Item_Size != 0; i++)
  101.         printf ("0x%08lX\t\t0x%08lX\t\t\t0x%08lX\n",Desc_Buf[i].VM_Lin_Address,\
  102.         Desc_Buf[i].Inst_Buf_Off, Desc_Buf[i].Item_Size); 
  103.       }
  104.     
  105.     
  106.   }else{ 
  107.     asm {   
  108.             mov dx,offset Inst_Hook
  109.             mov ax,Inst_Map
  110.         }   
  111.     (*api)();                                   /* Call V86API of ListInst.386 */
  112.     asm jnc ok
  113.     printf("\nError: VxDQuery.386 not loaded"); 
  114.     exit(1);
  115. ok: printf("\nV86 API from ListInst.386: Result of _AddInstanceItem Hook.\n");
  116.     printf("Summary of allocation calls to the Instance Data Manager.\n");
  117.     printf("\nName of VxD\t\t\t\tInstLinAddr\t\tInstSize\n");
  118.     for ( i=0;  i < Inst_Map_Count; i++)        /* print received VxD data */
  119.       printf("\n%s\t0x%08lX\t\t0x%08lX",&Inst_Hook[i].Caller_String, \
  120.                 Inst_Hook[i].Inst_Lin_Addr, Inst_Hook[i].Inst_Size);    
  121.     printf("\n\nType instwalk -p for dump of Page Ownership Array.\n");
  122.   }
  123.  
  124. }
  125.