home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / LXDUMP.ZIP / LXDUMP.C next >
C/C++ Source or Header  |  1993-03-27  |  4KB  |  153 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct LXHdr
  6. {
  7.     char    LXID[2];
  8.     char    ByteOrder;
  9.     char    WordOrder;
  10.     long    FormatLevel;
  11.     short    CPUType;
  12.     short    OSType;
  13.     long    ModVersion;
  14.     long    ModFlags;
  15.     long    ModNumPages;
  16.     long    EIPObjNum;
  17.     long    EIP;
  18.     long    ESPObjNum;
  19.     long    ESP;
  20.     long    PageSize;
  21.     long    PageOffShift;
  22.     long    FixupSectionSize;
  23.     long    FixupSectionChksum;
  24.     long    LoaderSectionSize;
  25.     long    LoaderSectionChksum;
  26.     long    ObjTblOff;
  27.     long    NumOjbsInModule;
  28.     long    ObjPageTblOff;
  29.     long    ObjIterPagesOff;
  30.     long    ResTblOff;
  31.     long    NumResTblEntries;
  32.     long    ResNameTblOff;
  33.     long    EntryTblOff;
  34.     long    ModDirectivesOff;
  35.     long    NumModDirectives;
  36.     long    FixupPageTblOff;
  37.     long    FixupRecordTblOff;
  38.     long    ImpModTblOff;
  39.     long    NumImpModEntries;
  40.     long    ImpProcTblOff;
  41.     long    PerPageChksumOff;
  42.     long    DataPagesOff;
  43.     long    NumPreloadPages;
  44.     long    NonResNameTblOff;
  45.     long    NonresNameTblLen;
  46.     long    NonResNameTblChksum;
  47.     long    AutoDSObjNum;
  48.     long    DebugInfoOff;
  49.     long    DebugInfoLen;
  50.     long    NumInstancePreload;
  51.     long    NumInstanceDemand;
  52.     long    HeapSize;
  53. } LXHeader;
  54.  
  55.  
  56. int main(int argc, char *argv[])
  57. {
  58.     char *filename, NameLen, nameBuf[130];
  59.     FILE *exefile;
  60.     long LXHdrOff, otherSeek;
  61.     int z = 1, i=0, impTblLen;
  62.     short ordinal;
  63.  
  64. /*
  65.     For some reason gcc (emx) doesn't like if (argc < 2). Reported to EM.
  66.     if ( argc < 2)
  67. */
  68.     if (!(argc > 1))
  69.         {
  70.         printf("Usage: lxdump <exefilename>\n");
  71.         exit(1);
  72.         }
  73.  
  74.     filename = strdup(argv[1]);
  75.  
  76.     exefile = fopen(filename,"rb");
  77.     if (exefile==NULL)
  78.         {
  79.         printf("Unable to open file %s\n",filename);
  80.         exit(2);
  81.         }
  82.     fseek(exefile,0x3C,0);
  83.     fread((void *)&LXHdrOff,4,1,exefile);
  84.     fseek(exefile,LXHdrOff,0);
  85.     fread((void *)    &LXHeader,  sizeof(struct LXHdr),1,exefile);
  86.     printf("EXE Type: %c%c\n",LXHeader.LXID[0],LXHeader.LXID[1]);
  87.     if (LXHeader.LXID[0] != 'L' || LXHeader.LXID[1] != 'X')
  88.         {
  89.         printf("\nNot an LX file.");
  90.         fclose(exefile);
  91.         exit(1);
  92.         }
  93.     printf("CPU Type: %s\n",LXHeader.CPUType == 1 ? "80286" :
  94.             LXHeader.CPUType == 2 ? "80386" : "80486" );
  95.     printf("OS Type: %s\n",
  96.         LXHeader.OSType == 0 ? "Unknown" : LXHeader.OSType == 1 ? "OS/2" :
  97.         LXHeader.OSType == 2 ? "Windows" : LXHeader.OSType == 3 ? "DOS4" :
  98.         "Windows/386");
  99.  
  100.     otherSeek = LXHdrOff + LXHeader.ResNameTblOff;
  101.     fseek(exefile,otherSeek,0);
  102.     fread((void *)&NameLen,sizeof(char),1,exefile);
  103.     printf("Resident Name Table: (%lx)\n",otherSeek);
  104.     while(NameLen)
  105.         {
  106.         fread((void *)nameBuf,sizeof(char),NameLen,exefile);
  107.         nameBuf[NameLen] = '\0';
  108.         fread((void *)&ordinal,sizeof(short),1,exefile);
  109.         printf("%-s  (@%d)\n",nameBuf,ordinal);
  110.         fread((void *)&NameLen,sizeof(char),1,exefile);
  111.         }
  112.     otherSeek = LXHdrOff + LXHeader.ImpModTblOff;
  113.     impTblLen = (LXHdrOff + LXHeader.ImpProcTblOff) - otherSeek;
  114.     fseek(exefile,otherSeek,0);
  115.     printf("Import Module Table: (%lx)\n",otherSeek);
  116.     for (i=0; i<LXHeader.NumImpModEntries; i++)
  117.         {
  118.         fread((void *)&NameLen,sizeof(char),1,exefile);
  119.         fread((void *)nameBuf,sizeof(char),NameLen,exefile);
  120.         nameBuf[NameLen]='\0';
  121.         printf("%-s\n",nameBuf);
  122.         }
  123.     otherSeek = LXHdrOff + LXHeader.ImpProcTblOff;
  124.     fseek(exefile,otherSeek,0);
  125.     fread((void *)&NameLen,sizeof(char),1,exefile);
  126.     printf("Import Procedure Name Table: (%lx)\n",otherSeek);
  127.     while(NameLen)
  128.         {
  129.         fread((void *)nameBuf,sizeof(char),NameLen,exefile);
  130.         nameBuf[NameLen]='\0';
  131.         printf("%-s\n",nameBuf);
  132.         fread((void *)&NameLen,sizeof(char),1,exefile);
  133.         }
  134.     otherSeek = LXHeader.NonResNameTblOff;
  135.     if (otherSeek > 0)
  136.         {
  137.         fseek(exefile,otherSeek,0);
  138.         printf("Non-Resident Name Table: (%lx)\n",otherSeek);
  139.         fread((void *)&NameLen,sizeof(char),1,exefile);
  140.         while(NameLen)
  141.             {
  142.             fread((void *)nameBuf,sizeof(char),NameLen,exefile);
  143.             nameBuf[NameLen] = '\0';
  144.             fread((void *)&ordinal,sizeof(short),1,exefile);
  145.             printf("%-s  (@%d)\n",nameBuf,ordinal);
  146.             fread((void *)&NameLen,sizeof(char),1,exefile);
  147.             }
  148.         }
  149.     printf("\n");
  150.     fclose(exefile);
  151.     exit(0);
  152. }
  153.