⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utilrtns.c

📁 James Antognini和Tom Divine提供的PASSTHRU的编成实例。
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "precomp.h"
#pragma hdrstop

#include "PktHdr.h"

#define JADrvNm         "JApassthru"     
#define JADrvRtnsName   "UtilRtns"        
#define JADrvRtnsVer    "1.01"           

#pragma comment(exestr,                                                      \
                JADrvNm " " JADrvRtnsName " v" JADrvRtnsVer " compiled on " __DATE__ " at " __TIME__)         

/**************************************************************************************************/      
/*                                                                                                */      
/* Copy the payload of the specified packet into the specified buffer.                            */      
/*                                                                                                */      
/* Adapted from http://www.ndis.com/papers/ndispacket/readonpacket.htm, 12 May 2003.              */      
/*                                                                                                */      
/**************************************************************************************************/      

VOID
GetPktPayload(
              PNDIS_PACKET     pPacket,               // Address of packet descriptor.
              PUCHAR           pOutBfr,               // Address of output buffer, to get copied packet payload.
              ULONG            ulOutBfrAvail,         // Size of output buffer.
              PULONG           pUlBytesCopied         // Output variable for number of bytes copied.
             )
{
   PNDIS_BUFFER    pNdisBfr;
   ULONG           ulBfrCnt,
                   ulTotPktLen,
                   ulCurrBfr,
                   ulAmtToMove;
   PUCHAR          pCurrBfr;

   *pUlBytesCopied = 0;                               // Set 0 bytes copied.

   if (0==ulOutBfrAvail)                              // Is output buffer 0 bytes in length?
     goto Done;

   NdisQueryPacket(pPacket,                           // Get information from packet descriptor.
                   NULL,                      
                   NULL,
                   &pNdisBfr,                         // Output variable for address of first buffer descriptor.
                   &ulTotPktLen                       // Output variable for number of bytes in packet payload.
                  );

   NdisQueryBuffer(pNdisBfr,                          // Get information from first buffer descriptor.
                   &pCurrBfr,                         // Output variable for address of described virtual area.
                   &ulCurrBfr                         // Output variable for size of virtual area.
                  );

   while (ulOutBfrAvail>0)                            // Space remaining in output buffer?
     {
      while (0==ulCurrBfr)                            // While the current buffer has zero length.
        {
         NdisGetNextBuffer(pNdisBfr,                  // Get next buffer descriptor.
                           &pNdisBfr
                          );

         if (NULL==pNdisBfr)                          // None?
           goto Done;

         NdisQueryBuffer(pNdisBfr,                    // Get information from next buffer descriptor.
                         &pCurrBfr,                   // Output variable for address of current buffer.
                         &ulCurrBfr                   // Output variable for size of current buffer.
                        );
        }

      if (ulCurrBfr>ulOutBfrAvail)                    // Does current buffer's usable size exceed space remaining in output buffer?
        ulAmtToMove = ulOutBfrAvail;                  // Use only amount remaining in output buffer.
      else
        ulAmtToMove = ulCurrBfr;                      // Use full size of current buffer.

      NdisMoveMemory(pOutBfr,                         // Copy packet data to output buffer.
                     pCurrBfr,
                     ulAmtToMove
                    );

      *pUlBytesCopied += ulAmtToMove;                 // Update output variable of bytes copied.
      pOutBfr += ulAmtToMove;                         // Update pointer to output buffer.
      ulOutBfrAvail -= ulAmtToMove;                   // Update number of bytes available in output buffer.

      ulCurrBfr = 0;                                  // Force search for next buffer.
     }                                                // End 'while' copy bytes to output buffer.

Done:
  ;
}

/**************************************************************************************************/      
/*                                                                                                */      
/* Derived from mp_dbg.c in DDK's \src\network\ndis\e100bex\.                                     */      
/*                                                                                                */      
/**************************************************************************************************/      

// Bytes to appear on each line of dump output.
  
#define DUMP_BytesPerLine 16

VOID
DumpLine(
         IN CHAR    * p,
         IN ULONG     cb,
         IN BOOLEAN   fAddress,
         IN ULONG     ulGroup 
        )
{

    CHAR * pszDigits = "0123456789ABCDEF";
    CHAR   szHex[ ((2 + 1) * DUMP_BytesPerLine) + 1 ];
    CHAR * pszHex = szHex;
    CHAR   szAscii[ DUMP_BytesPerLine + 1 ];
    CHAR * pszAscii = szAscii;
    ULONG  ulGrouped = 0;

    if (fAddress) 
    {
        DbgPrint( "%p: ", p );
    }
    else 
    {
        DbgPrint( "" );
    }

    while (cb)
    {
        *pszHex++ = pszDigits[ ((UCHAR )*p) / 16 ];
        *pszHex++ = pszDigits[ ((UCHAR )*p) % 16 ];

        if (++ulGrouped >= ulGroup)
        {
            *pszHex++ = ' ';
            ulGrouped = 0;
        }

        *pszAscii++ = (*p >= 32 && *p < 128) ? *p : '.';

        ++p;
        --cb;
    }

    *pszHex = '\0';
    *pszAscii = '\0';

    DbgPrint(
        "%-*s|%-*s|\n",
        (2 * DUMP_BytesPerLine) + (DUMP_BytesPerLine / ulGroup), szHex,
        DUMP_BytesPerLine, szAscii );
}

/**************************************************************************************************/      
/*                                                                                                */      
/* Taken from mp_dbg.c in DDK's \src\network\ndis\e100bex\.                                       */      
/*                                                                                                */      
/**************************************************************************************************/      

// Hex dump 'cb' bytes starting at 'p' grouping 'ulGroup' bytes together.
// For example, with 'ulGroup' of 1, 2, and 4:
//
// 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
// 0000 0000 0000 0000 0000 0000 0000 0000 |................|
// 00000000 00000000 00000000 00000000 |................|
//
// If 'bPrependWAddr' is true, the memory address dumped is prepended to each
// line.
//
VOID
DumpMem(
        IN CHAR    * p,                               // Address of memory to be dumped.
        IN ULONG     cb,                              // Amount to dump.
        IN BOOLEAN   bPrependWAddr,                   // Prepend dump with memory address.  1 => yes.
        IN ULONG     ulGroup                          // Grouping of bytes, eg, 1 for each separately.
       )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -