home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IMPLIST.ZIP / IMPLIST.C < prev    next >
C/C++ Source or Header  |  1991-07-28  |  7KB  |  270 lines

  1. /* 
  2.  *
  3.  * SYNOPSIS
  4.  *
  5.  *    implist pathname                                                    
  6.  *
  7.  *
  8.  *
  9.  * DESCRIPTION
  10.  *
  11.  *     IMPLIST  Will list exported function names and cardinal numbers
  12.  *    from a xxx.lib file on OS/2 1.2 and 1.3.  The lib file may be one 
  13.  *    supplied by the compiler vendor such as OS2.LIB or it can be created
  14.  *    from any xxx.DLL by using the IMPLIB utility, such as supplied by
  15.  *    the MICROSOFT C compiler:  implib  xxx.LIB  xxx.DLL .
  16.  *
  17.  *
  18.  *    Aside from simple informational purposes, IMPLIST is intended to build
  19.  *    a simple sequential database of exported function names and cardinal
  20.  *    numbers which can be used by IMPFILT to add the name information to the
  21.  *    output of the MICROSOFT EXEHDR utility.  This can be helpful when 
  22.  *    reverse engineering a software component such as PSTAT.EXE.
  23.  *
  24.  *
  25.  * COMPILATION
  26.  *
  27.  *    See implist.mak for a simple makefile to be used with NMAKE. 
  28.  *
  29.  * AUTHOR
  30.  *
  31.  *     Stephen L. Reed, Stephen Reed Software.  
  32.  *
  33.  *
  34.  *         NET:        70401.3342@compuserve.com
  35.  *         BIX:        sreed
  36.  *         COMPUSERVE: 70401,3342
  37.  *
  38.  *
  39.  *         Your comments are appreciated!
  40.  *
  41.  *
  42.  * COPYRIGHT
  43.  *
  44.  *    Copyright (c) 1990-91  Stephen L. Reed.  All rights reserved.
  45.  *
  46.  *    Redistribution and use in source and binary forms are permitted
  47.  *    provided that the above copyright notice and this paragraph are
  48.  *    duplicated in all such forms and that any documentation,
  49.  *    advertising materials, and other materials related to such
  50.  *    distribution and use acknowledge that the software was developed
  51.  *    by Stephen L. Reed.
  52.  *
  53.  *    THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  54.  *    IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  55.  *    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  56.  *
  57.  */
  58.  
  59.  
  60. #include    <stdio.h>             /* Library I/O routines.    */
  61. #include    <stdlib.h>            /* Library common routines. */
  62. #include    <string.h>            /* Library string routines. */
  63.  
  64. #define     INCL_BASE
  65. #include    <os2.h>
  66.  
  67. #include    "SYMTYPES.H"
  68.  
  69. PCHAR             ErrTxt1           = "Usage: IMPLIST implib-path" ;
  70.  
  71. CHAR              szImpLib [ 20 ]   = "" ;
  72. FILE *            hfImpLib ;
  73.  
  74. USHORT            cInternalNameLen  = 0 ;
  75. UCHAR             szInternalName [ 50 ] ;
  76.  
  77. USHORT            cExternalNameLen  = 0 ;
  78. UCHAR             szExternalName [ 50 ] ;
  79.  
  80. USHORT            cDllNameLen       = 0 ;
  81. UCHAR             szDllName [ 50 ] ;
  82.  
  83. USHORT            usOrdinal         = 0 ;
  84.  
  85. USHORT            i ;
  86. USHORT            cBytes            = 0 ;
  87. SHORT             sChar ;
  88. SHORT             sChar1 ;
  89. SHORT             sChar2 ;
  90. SHORT             sChar3 ;
  91. SHORT             sChar4 ;
  92. SHORT             sChar5 ;
  93. SHORT             sChar6 ;
  94. SHORT             sChar7 ;
  95. SHORT             sChar8 ;
  96.  
  97. SHORT             sLo               = 0 ;
  98. SHORT             sHi               = 0 ;
  99.  
  100.  
  101. USHORT            usStatus          = 0 ;
  102.  
  103.  
  104.  
  105. /*------------------------------------------------------------*/
  106. /* Main function.                                             */
  107. /*------------------------------------------------------------*/
  108.  
  109. main ( USHORT argc, PCHAR argv [] )
  110.    {
  111.  
  112.    if ( argc < 2 )
  113.       {
  114.       printf ( "%s\n", ErrTxt1 ) ;
  115.       DosExit ( 1, 1 ) ;
  116.       }
  117.  
  118.    if ( strlen ( argv [ 1 ] ) < 2 )
  119.       {
  120.       printf ( "%s\n", ErrTxt1 ) ;
  121.       DosExit ( 1, 1 ) ;
  122.       }
  123.  
  124.    strcpy ( szImpLib, argv [ 1 ] ) ;
  125.  
  126.    hfImpLib = fopen ( szImpLib, "rb" ) ;
  127.  
  128.    if ( ! hfImpLib )
  129.       {
  130.       printf ( "\nError - Cannot open %s file\n\n", szImpLib ) ;
  131.  
  132.       DosExit ( 1, 1 ) ;
  133.       }
  134.  
  135.    for ( i  = 0 ; i < 8 ; i++ )
  136.       sChar = fgetc ( hfImpLib ) ;
  137.  
  138.    for ( ; ; )
  139.       {
  140.       sChar1   = fgetc ( hfImpLib ) ;
  141.       sChar2   = fgetc ( hfImpLib ) ;
  142.       sChar3   = fgetc ( hfImpLib ) ;
  143.       sChar4   = fgetc ( hfImpLib ) ;
  144.       sChar5   = fgetc ( hfImpLib ) ;
  145.       sChar6   = fgetc ( hfImpLib ) ;
  146.       sChar7   = fgetc ( hfImpLib ) ;
  147.       sChar8   = fgetc ( hfImpLib ) ;
  148.  
  149.       cBytes   = 8 ;
  150.  
  151.  
  152.                /*---------------------------------------------*/
  153.                /* Parse the identifying character string      */
  154.                /* which proceeds the internal name.           */
  155.                /*---------------------------------------------*/
  156.  
  157.       for ( ; ; )
  158.          {
  159.  
  160.          if (( sChar1 == 0 ) &&
  161.              ( sChar2 == 0 ) &&
  162.              ( sChar3 == 0 ) &&
  163.              ( sChar4 == 0x80 ) &&
  164.              ( sChar7 > 0 ) &&
  165.              ( sChar7 < 40 ) &&
  166.              ( sChar8 >= 'A' ) &&
  167.              ( sChar8 <= 'Z' ))
  168.             break ;
  169.  
  170.          if ( cBytes > 500 )
  171.             DosExit ( EXIT_PROCESS, 0 ) ;
  172.  
  173.          sChar1   = sChar2 ;
  174.          sChar2   = sChar3 ;
  175.          sChar3   = sChar4 ;
  176.          sChar4   = sChar5 ;
  177.          sChar5   = sChar6 ;
  178.          sChar6   = sChar7 ;
  179.          sChar7   = sChar8 ;
  180.          sChar8   = fgetc ( hfImpLib ) ;
  181.  
  182.          cBytes++ ;
  183.          }
  184.  
  185.                /*---------------------------------------------*/
  186.                /* Parse the function internal name.           */
  187.                /*---------------------------------------------*/
  188.  
  189.       cInternalNameLen     = sChar7 ;
  190.       szInternalName [ 0 ] = ( UCHAR ) sChar8 ;
  191.  
  192.       for ( i  = 1 ; i < cInternalNameLen ; i++ )
  193.          {
  194.          szInternalName [ i ] = ( UCHAR ) fgetc ( hfImpLib ) ;
  195.  
  196.          cBytes++ ;
  197.          }
  198.  
  199.       szInternalName [ i ] = '\0' ;
  200.  
  201.       for ( i  = 0 ; i < 8 ; i++ )
  202.          {
  203.          sChar = fgetc ( hfImpLib ) ;
  204.  
  205.          cBytes++ ;
  206.          }
  207.  
  208.                /*---------------------------------------------*/
  209.                /* Parse the function external name.           */
  210.                /*---------------------------------------------*/
  211.  
  212.       cExternalNameLen  = fgetc ( hfImpLib ) ;
  213.  
  214.       cBytes++ ;
  215.  
  216.       for ( i  = 0 ; i < cExternalNameLen ; i++ )
  217.          {
  218.          szExternalName [ i ] = ( UCHAR ) fgetc ( hfImpLib ) ;
  219.  
  220.          cBytes++ ;
  221.          }
  222.  
  223.       szExternalName [ i ] = '\0' ;
  224.  
  225.  
  226.                /*---------------------------------------------*/
  227.                /* Parse the function DLL cardinal name.       */
  228.                /*---------------------------------------------*/
  229.  
  230.       cDllNameLen          = fgetc ( hfImpLib ) ;
  231.  
  232.       cBytes++ ;
  233.  
  234.       for ( i  = 0 ; i < cDllNameLen ; i++ )
  235.          {
  236.          szDllName [ i ]   = ( UCHAR ) fgetc ( hfImpLib ) ;
  237.  
  238.          cBytes++ ;
  239.          }
  240.  
  241.       szDllName [ i ]   = '\0' ;
  242.  
  243.       sLo               = fgetc ( hfImpLib ) ;
  244.  
  245.       cBytes++ ;
  246.  
  247.       sHi               = fgetc ( hfImpLib ) ;
  248.  
  249.       cBytes++ ;
  250.  
  251.       usOrdinal         = MAKEUSHORT ( sLo, sHi ) ;
  252.  
  253.       printf (
  254.          "%-32s %s.%u\n",
  255.          szExternalName,
  256.          szDllName,
  257.          usOrdinal ) ;
  258.  
  259.       }
  260.  
  261.                /* Suppress warning message.                   */
  262.    return ( 0 ) ;
  263.  
  264.    }           /* End of main function.                       */
  265.  
  266.  
  267.  
  268.  
  269.  
  270.