Retail products


Traffic interception SDK

Control every TCP/IP network connection

  • Route connections via proxy
  • Redirect connections and modify the data
  • Block connections and applications
SSL interception SDK

View SSL in plaintext and modify it

  • View the SSL stream decrypted in plaintext
  • Redirect SSL connection and modify decrypted data
  • Browser shows "SSL lock" without warnings

Documentation


instlsp.cpp File Reference

#include "instlsp.h"

Include dependency graph for instlsp.cpp:

Go to the source code of this file.


Functions

void usage (__in_z char *progname)
int _cdecl main (int argc, char *argv[])

Variables

LPWSCUPDATEPROVIDER fnWscUpdateProvider = NULL
LPWSCUPDATEPROVIDER fnWscUpdateProvider32 = NULL
HMODULE gModule = NULL
GUID gProviderGuid

Function Documentation

int _cdecl main ( int  argc,
char *  argv[] 
)

Definition at line 117 of file instlsp.cpp.

00118 {
00119     WSADATA             wsd;
00120     LPWSAPROTOCOL_INFOW pProtocolInfo   = NULL;
00121     LSP_ENTRY          *pLspMap=NULL;
00122 #ifdef _WIN64
00123     WINSOCK_CATALOG     eCatalog        = LspCatalog64Only;
00124 #else
00125     WINSOCK_CATALOG     eCatalog        = LspCatalog32Only;
00126 #endif
00127     INT                 iTotalProtocols = 0,
00128                         iLspCount       = 0,
00129                         i;
00130     DWORD              *pdwCatalogIdArray = NULL,
00131                         dwCatalogIdArrayCount = 0,       // How many to install over
00132                         dwRemoveCatalogId = 0;
00133     BOOL                bInstall                   = TRUE,
00134                         bInstallOverAll            = FALSE,
00135                         bRemoveAllLayeredEntries   = FALSE,
00136                         bPrintProviders            = FALSE,
00137                         bDisplayOnlyLayeredEntries = FALSE,
00138                         bVerbose                   = FALSE,
00139                         bMapLsp                    = FALSE,
00140                         bArgsOkay                  = FALSE,
00141                         bIFSProvider               = FALSE;
00142     char               *lpszLspName = NULL,
00143                        *lpszLspPathAndFile = NULL;
00144     int                 rc;
00145 
00146     ////////////////////////////////////////////////////////////////////////////
00147     //
00148     // Initialization and Command Line Parsing
00149     //
00150     ////////////////////////////////////////////////////////////////////////////
00151 
00152     // Load Winsock
00153     rc = WSAStartup( MAKEWORD(2,2), &wsd );
00154     if ( 0 != rc )
00155     {
00156         fprintf( stderr, "Unable to load Winsock: %d\n", rc );
00157         return -1;
00158     }
00159 
00160     // Initialize data structures
00161     LspCreateHeap( &rc );
00162 
00163     __try
00164     {
00165         InitializeCriticalSection( &gDebugCritSec );
00166     }
00167     __except( EXCEPTION_EXECUTE_HANDLER )
00168     {
00169         goto cleanup;
00170     }
00171 
00172 
00173     // First count how many catalog parameters are supplied so we can dynamically
00174     // allocate the right sized buffer
00175     for(i=1; i < argc ;i++)
00176     {
00177         if ( strncmp( argv[ i ], "-o", 2 ) == 0 )
00178             dwCatalogIdArrayCount++;
00179     }
00180 
00181     // Allocate space for the array of catalog IDs
00182     if ( 0 < dwCatalogIdArrayCount )
00183     {
00184         pdwCatalogIdArray = (DWORD *) LspAlloc(
00185                 sizeof( DWORD ) * dwCatalogIdArrayCount,
00186                 &rc
00187                 );
00188         if ( NULL == pdwCatalogIdArray )
00189         {
00190             goto cleanup;
00191         }
00192     }
00193 
00194     // Set back to zero so we can use it as the index into our array
00195     dwCatalogIdArrayCount = 0;
00196 
00197     // Parse the command line
00198     for(i=1; i < argc ;i++)
00199     {
00200         if ( ( 2   != strlen( argv[i] ) ) && 
00201              ( '-' != argv[i][0] ) && 
00202              ( '/' != argv[i][0] )
00203            )
00204         {
00205             goto cleanup;
00206         }
00207 
00208         switch ( tolower( argv[i][1] ) )
00209         {
00210             case 'a':               // Install LSP over all currently installed providers
00211                 bInstallOverAll = TRUE;
00212                 break;
00213 
00214             case 'c':               // For 64-bit: which catalog to operate on?
00215                 if (i+1 >= argc)
00216                     goto cleanup;
00217 
00218                 switch (tolower(argv[i+1][0]))
00219                 {
00220                     case 'b':       // Both Winsock catalogs
00221                         eCatalog = LspCatalogBoth;
00222                         break;
00223                     case '6':       // 64-bit Winsock catalog only
00224                         eCatalog = LspCatalog64Only;
00225                         break;
00226                     case '3':       // 32-bit Winsock catalog only
00227                         eCatalog = LspCatalog32Only;
00228                         break;
00229                     default:
00230                         goto cleanup;
00231                         break;
00232                 }
00233                 i++;
00234                 break;
00235 
00236             case 'd':               // Full path and filename to LSP
00237                 if ( i+1 >= argc )
00238                     goto cleanup;
00239                 lpszLspPathAndFile = argv[ ++i ];
00240                 break;
00241 
00242             case 'f':               // Uninstall all layered providers
00243                 bRemoveAllLayeredEntries = TRUE;
00244                 bInstall = FALSE;
00245                 break;
00246 
00247             case 'h':               // Install as an IFS provider
00248                 bIFSProvider = TRUE;
00249                 break;
00250 
00251             case 'i':               // install
00252                 bInstall = TRUE;
00253                 break;
00254 
00255             case 'l':               // print the layered providers only
00256                 bPrintProviders = TRUE;
00257                 bDisplayOnlyLayeredEntries = TRUE;
00258                 break;
00259 
00260             case 'm':               // Map and print the LSP structure
00261                 bMapLsp = TRUE;
00262                 bInstall = FALSE;
00263                 break;
00264 
00265             case 'n':               // name of the LSP to install (not the DLL name)
00266                 if (i+1 >= argc)
00267                     goto cleanup;
00268 
00269                 lpszLspName = argv[++i];
00270                 break;
00271 
00272             case 'o':               // catalog id (to install over)
00273                 if (i+1 >= argc)
00274                     goto cleanup;
00275 
00276                 pdwCatalogIdArray[dwCatalogIdArrayCount++] = atoi(argv[++i]);
00277                 break;
00278 
00279             case 'p':               // print the catalog
00280                 bPrintProviders = TRUE;
00281                 bDisplayOnlyLayeredEntries = FALSE;
00282                 break;
00283 
00284             case 'r':               // remove an LSP
00285                 bInstall = FALSE;
00286                 if (i+1 >= argc)
00287                     goto cleanup;
00288                 dwRemoveCatalogId = atol(argv[++i]);
00289                 break;
00290 
00291             case 'v':               // verbose mode (when printing with -p option)
00292                 bVerbose = TRUE;
00293                 break;
00294 
00295             default:
00296                 goto cleanup;
00297                 break;
00298         }
00299     }
00300 
00301 #ifndef _WIN64
00302     if ( LspCatalog64Only == eCatalog )
00303     {
00304         fprintf(stderr, "\n\nUnable to manipulate 64-bit Winsock catalog from 32-bit process!\n\n");
00305         goto cleanup;
00306     }
00307 #endif
00308 
00309     bArgsOkay = TRUE;
00310 
00311     gModule = LoadUpdateProviderFunction();
00312 
00313     if ( TRUE == bPrintProviders )
00314     {
00315         // Print the 32-bit catalog
00316         if ( ( LspCatalogBoth == eCatalog ) || ( LspCatalog32Only == eCatalog ) )
00317         {
00318             printf( "\n\nWinsock 32-bit Catalog:\n" );
00319             printf( "=======================\n" );
00320             PrintProviders( LspCatalog32Only, bDisplayOnlyLayeredEntries, bVerbose );
00321         }
00322         // Print the 64-bit catalog
00323         if ( ( LspCatalogBoth == eCatalog ) || ( LspCatalog64Only == eCatalog ) )
00324         {
00325             printf( "\n\nWinsock 64-bit Catalog:\n" );
00326             printf( "=======================\n" );
00327             PrintProviders( LspCatalog64Only, bDisplayOnlyLayeredEntries, bVerbose );
00328         }
00329     }
00330     else if ( TRUE == bInstall )
00331     {
00332         if ( NULL == lpszLspPathAndFile )
00333         {
00334             fprintf( stderr, "\n\nError! Please specify path and filename of LSP!\n\n");
00335             bArgsOkay = FALSE;
00336             goto cleanup;
00337         }
00338 
00339         if ( TRUE == bInstallOverAll )
00340         {
00341             // Make sure user didn't specify '-a' and '-o' flags
00342             if ( 0 != dwCatalogIdArrayCount )
00343             {
00344                 fprintf( stderr, "\n\nError! Cannot specify both '-a' and '-o' flags!\n\n" );
00345                 goto cleanup;
00346             }
00347 
00348             // Enumerate the appropriate catalog we will be working on
00349             pProtocolInfo = EnumerateProviders( eCatalog, &iTotalProtocols );
00350             if ( NULL == pProtocolInfo )
00351             {
00352                 fprintf( stderr, "%s: EnumerateProviders: Unable to enumerate Winsock catalog\n",
00353                         argv[ 0 ]
00354                         );
00355                 goto cleanup;
00356             }
00357 
00358             // Count how many non layered protocol entries there are
00359             for(i=0; i < iTotalProtocols ;i++)
00360             {
00361                 if ( LAYERED_PROTOCOL != pProtocolInfo[ i ].ProtocolChain.ChainLen )
00362                     dwCatalogIdArrayCount++;
00363             }
00364 
00365             // Allocate space for all the entries
00366             pdwCatalogIdArray = (DWORD *) LspAlloc(
00367                     sizeof( DWORD ) * dwCatalogIdArrayCount,
00368                    &rc
00369                     );
00370             if ( NULL == pdwCatalogIdArray )
00371             {
00372                 fprintf( stderr, "%s: LspAlloc failed: %d\n", argv[ 0 ], rc );
00373                 goto cleanup;
00374             }
00375 
00376             // Get the catalog IDs for all existing providers
00377             dwCatalogIdArrayCount = 0 ;
00378             for(i=0; i < iTotalProtocols ;i++)
00379             {
00380                 if ( LAYERED_PROTOCOL != pProtocolInfo[ i ].ProtocolChain.ChainLen )
00381                 {
00382                     pdwCatalogIdArray[ dwCatalogIdArrayCount++ ] = pProtocolInfo[ i ].dwCatalogEntryId;
00383                 }
00384             }
00385 
00386             FreeProviders( pProtocolInfo );
00387             pProtocolInfo = NULL;
00388         }
00389 
00390         // Install the LSP with the supplied parameters
00391         rc = InstallLsp(
00392                 eCatalog,
00393                 lpszLspName,
00394                 lpszLspPathAndFile,
00395                 dwCatalogIdArrayCount,
00396                 pdwCatalogIdArray,
00397                 bIFSProvider,
00398                 bInstallOverAll
00399                 );
00400     }
00401     else if ( TRUE == bMapLsp )
00402     {
00403         // Display the 32-bit LSP catalog map
00404         if ( ( LspCatalogBoth == eCatalog ) || ( LspCatalog32Only == eCatalog ) )
00405         {
00406             printf("\n32-bit Winsock LSP Map:\n\n");
00407 
00408             pProtocolInfo = EnumerateProviders( LspCatalog32Only, &iTotalProtocols );
00409             if ( NULL == pProtocolInfo )
00410             {
00411                 fprintf(stderr, "%s: EnumerateProviders: Unable to enumerate Winsock catalog\n",
00412                         argv[ 0 ] 
00413                         );
00414                 goto cleanup;
00415             }
00416 
00417             pLspMap = BuildLspMap( pProtocolInfo, iTotalProtocols, &iLspCount );
00418             if ( NULL == pLspMap )
00419             {
00420                 printf( "\nNo LSPs are installed\n\n" );
00421             }
00422             else
00423             {
00424                 PrintLspMap( pLspMap, iLspCount );
00425 
00426                 FreeLspMap( pLspMap, iLspCount );
00427                 pLspMap = NULL;
00428             }
00429            
00430             FreeProviders( pProtocolInfo );
00431             pProtocolInfo = NULL;
00432         }
00433 
00434         // Display the 64-bit LSP catalog map
00435         if ( ( LspCatalogBoth == eCatalog ) || ( LspCatalog64Only == eCatalog ) )
00436         {
00437             printf("\n64-bit Winsock LSP Map:\n\n");
00438 
00439             pProtocolInfo = EnumerateProviders( LspCatalog64Only, &iTotalProtocols );
00440             if ( NULL == pProtocolInfo )
00441             {
00442                 fprintf(stderr, "%s: EnumerateProviders: Unable to enumerate Winsock catalog\n",
00443                         argv[ 0 ]
00444                         );
00445                 goto cleanup;
00446             }
00447 
00448             pLspMap = BuildLspMap( pProtocolInfo, iTotalProtocols, &iLspCount );
00449             if ( NULL == pLspMap )
00450             {
00451                 printf( "\nNo LSPs are installed\n\n" );
00452             }
00453             else
00454             {
00455                 PrintLspMap( pLspMap, iLspCount );
00456 
00457                 FreeLspMap( pLspMap, iLspCount );
00458                 pLspMap = NULL;
00459             }
00460 
00461             FreeProviders( pProtocolInfo );
00462             pProtocolInfo = NULL;
00463         }
00464     }
00465     else
00466     {
00467         // We must be removing an LSP
00468 
00469         if ( TRUE == bRemoveAllLayeredEntries )
00470         {
00471             if ( ( LspCatalogBoth == eCatalog ) || ( LspCatalog32Only == eCatalog ) )
00472                 RemoveAllLayeredEntries( LspCatalog32Only );
00473 
00474             if ( ( LspCatalogBoth == eCatalog ) || ( LspCatalog64Only == eCatalog ) )
00475                 RemoveAllLayeredEntries( LspCatalog64Only );
00476         }
00477         else
00478         {
00479 
00480             // Make sure a catalog entry to remove was supplied
00481             if ( dwRemoveCatalogId == 0 )
00482             {
00483                 bArgsOkay = FALSE;
00484                 goto cleanup;
00485             }
00486 
00487             if ( ( LspCatalogBoth == eCatalog ) || ( LspCatalog32Only == eCatalog ) )
00488                 RemoveProvider( LspCatalog32Only, dwRemoveCatalogId );
00489 
00490             if ( ( LspCatalogBoth == eCatalog ) || ( LspCatalog64Only == eCatalog ) )
00491                 RemoveProvider( LspCatalog64Only, dwRemoveCatalogId );
00492 
00493         }
00494     }
00495 
00496 cleanup:
00497 
00498     if ( FALSE == bArgsOkay )
00499         usage( argv[ 0 ] );
00500 
00501     //
00502     // Free any dynamic allocations and/or handles
00503     //
00504 
00505     if ( NULL != pdwCatalogIdArray )
00506         LspFree( pdwCatalogIdArray );
00507 
00508     if ( NULL != pProtocolInfo)
00509         FreeProviders( pProtocolInfo );
00510 
00511     if ( NULL != pLspMap )
00512         FreeLspMap( pLspMap, iLspCount );
00513 
00514     if ( NULL != gModule )
00515         FreeLibrary( gModule );
00516 
00517     LspDestroyHeap( );
00518 
00519     DeleteCriticalSection( &gDebugCritSec );
00520 
00521     WSACleanup();
00522 
00523     return 0;
00524 }

void usage ( __in_z char *  progname  ) 

Definition at line 532 of file instlsp.cpp.

00533 {
00534     printf("usage: %s -i -r [CatId] -o [CatId] -p ...\n", progname);
00535     printf(
00536            "       -a           Install over all providers (base or layered)\n"
00537            "                       Cannot be combined with '-o' option\n"
00538            "       -c Catalog   Indicates which catalog to operate on\n"
00539            "          b            Both 64-bit and 32-bit Winsock catalogs\n"
00540            "          6            64-bit Winsock catalog only\n"
00541            "          3            32-bit Winsock catalog only\n"
00542            "       -d           Full path and filename of LSP DLL to install\n"
00543            "       -h           LSP is an IFS provider (by default its non-IFS)\n"
00544            "       -i           Install LSP\n"
00545            "       -f           Remove all layered entries\n"
00546            "       -l           Print layered providers only\n"
00547            "       -m           Display a map of the LSPs and the order they are\n"
00548            "                       installed in\n"
00549            "       -n Str       Name of LSP\n"
00550            "       -o CatId     Install over specified LSP\n"
00551            "                       This option may be specified multiple times\n"
00552            "                       Cannot be combined with '-a' option\n"
00553            "       -p           Print all layers and their catalog IDs\n"
00554            "       -r CatId     Remove LSP\n"
00555            "       -v           Print verbose catalog information (used with -p)\n"
00556            "\n"
00557            "Example:\n\n"
00558            "   install:\n\tinstlsp.exe -i -o 1001 -o 1002 -n \"MyLsp\" -d c:\\lsp\\mylsp.dll\n\n"
00559            "   remove:\n\tinstlsp.exe -r <DUMMY_CATALOG_ID>\n\n"
00560            "   remove all LSPs:\n\tinstlsp.exe -f\n"
00561            );
00562 }


Variable Documentation

LPWSCUPDATEPROVIDER fnWscUpdateProvider = NULL

Definition at line 96 of file instlsp.cpp.

LPWSCUPDATEPROVIDER fnWscUpdateProvider32 = NULL

Definition at line 97 of file instlsp.cpp.

HMODULE gModule = NULL

Definition at line 98 of file instlsp.cpp.

Definition at line 99 of file instlsp.cpp.