OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [win/] [winDumpExts.c] - Diff between revs 578 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 578 Rev 1765
/*
/*
 * winDumpExts.c --
 * winDumpExts.c --
 * Author:   Gordon Chaffee, Scott Stanton
 * Author:   Gordon Chaffee, Scott Stanton
 *
 *
 * History:  The real functionality of this file was written by
 * History:  The real functionality of this file was written by
 *           Matt Pietrek in 1993 in his pedump utility.  I've
 *           Matt Pietrek in 1993 in his pedump utility.  I've
 *           modified it to dump the externals in a bunch of object
 *           modified it to dump the externals in a bunch of object
 *           files to create a .def file.
 *           files to create a .def file.
 *
 *
 * 10/12/95  Modified by Scott Stanton to support Relocatable Object Module
 * 10/12/95  Modified by Scott Stanton to support Relocatable Object Module
 *           Format files for Borland C++ 4.5.
 *           Format files for Borland C++ 4.5.
 *
 *
 * Notes:    Visual C++ puts an underscore before each exported symbol.
 * Notes:    Visual C++ puts an underscore before each exported symbol.
 *           This file removes them.  I don't know if this is a problem
 *           This file removes them.  I don't know if this is a problem
 *           this other compilers.  If _MSC_VER is defined,
 *           this other compilers.  If _MSC_VER is defined,
 *           the underscore is removed.  If not, it isn't.  To get a
 *           the underscore is removed.  If not, it isn't.  To get a
 *           full dump of an object file, use the -f option.  This can
 *           full dump of an object file, use the -f option.  This can
 *           help determine the something that may be different with a
 *           help determine the something that may be different with a
 *           compiler other than Visual C++.
 *           compiler other than Visual C++.
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * RCS: @(#) $Id: winDumpExts.c,v 1.1.1.1 2002-01-16 10:25:39 markom Exp $
 * RCS: @(#) $Id: winDumpExts.c,v 1.1.1.1 2002-01-16 10:25:39 markom Exp $
 */
 */
 
 
#include <windows.h>
#include <windows.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include <process.h>
#include <process.h>
 
 
#ifdef _ALPHA_
#ifdef _ALPHA_
#define e_magic_number IMAGE_FILE_MACHINE_ALPHA
#define e_magic_number IMAGE_FILE_MACHINE_ALPHA
#else
#else
#define e_magic_number IMAGE_FILE_MACHINE_I386
#define e_magic_number IMAGE_FILE_MACHINE_I386
#endif
#endif
 
 
/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 * GetArgcArgv --
 * GetArgcArgv --
 *
 *
 *      Break up a line into argc argv
 *      Break up a line into argc argv
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
int
int
GetArgcArgv(char *s, char **argv)
GetArgcArgv(char *s, char **argv)
{
{
    int quote = 0;
    int quote = 0;
    int argc = 0;
    int argc = 0;
    char *bp;
    char *bp;
 
 
    bp = s;
    bp = s;
    while (1) {
    while (1) {
        while (isspace(*bp)) {
        while (isspace(*bp)) {
            bp++;
            bp++;
        }
        }
        if (*bp == '\n' || *bp == '\0') {
        if (*bp == '\n' || *bp == '\0') {
            *bp = '\0';
            *bp = '\0';
            return argc;
            return argc;
        }
        }
        if (*bp == '\"') {
        if (*bp == '\"') {
            quote = 1;
            quote = 1;
            bp++;
            bp++;
        }
        }
        argv[argc++] = bp;
        argv[argc++] = bp;
 
 
        while (*bp != '\0') {
        while (*bp != '\0') {
            if (quote) {
            if (quote) {
                if (*bp == '\"') {
                if (*bp == '\"') {
                    quote = 0;
                    quote = 0;
                    *bp = '\0';
                    *bp = '\0';
                    bp++;
                    bp++;
                    break;
                    break;
                }
                }
                bp++;
                bp++;
                continue;
                continue;
            }
            }
            if (isspace(*bp)) {
            if (isspace(*bp)) {
                *bp = '\0';
                *bp = '\0';
                bp++;
                bp++;
                break;
                break;
            }
            }
            bp++;
            bp++;
        }
        }
    }
    }
}
}
 
 
/*
/*
 *  The names of the first group of possible symbol table storage classes
 *  The names of the first group of possible symbol table storage classes
 */
 */
char * SzStorageClass1[] = {
char * SzStorageClass1[] = {
    "NULL","AUTOMATIC","EXTERNAL","STATIC","REGISTER","EXTERNAL_DEF","LABEL",
    "NULL","AUTOMATIC","EXTERNAL","STATIC","REGISTER","EXTERNAL_DEF","LABEL",
    "UNDEFINED_LABEL","MEMBER_OF_STRUCT","ARGUMENT","STRUCT_TAG",
    "UNDEFINED_LABEL","MEMBER_OF_STRUCT","ARGUMENT","STRUCT_TAG",
    "MEMBER_OF_UNION","UNION_TAG","TYPE_DEFINITION","UNDEFINED_STATIC",
    "MEMBER_OF_UNION","UNION_TAG","TYPE_DEFINITION","UNDEFINED_STATIC",
    "ENUM_TAG","MEMBER_OF_ENUM","REGISTER_PARAM","BIT_FIELD"
    "ENUM_TAG","MEMBER_OF_ENUM","REGISTER_PARAM","BIT_FIELD"
};
};
 
 
/*
/*
 * The names of the second group of possible symbol table storage classes
 * The names of the second group of possible symbol table storage classes
 */
 */
char * SzStorageClass2[] = {
char * SzStorageClass2[] = {
    "BLOCK","FUNCTION","END_OF_STRUCT","FILE","SECTION","WEAK_EXTERNAL"
    "BLOCK","FUNCTION","END_OF_STRUCT","FILE","SECTION","WEAK_EXTERNAL"
};
};
 
 
/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 * GetSZStorageClass --
 * GetSZStorageClass --
 *
 *
 *      Given a symbol storage class value, return a descriptive
 *      Given a symbol storage class value, return a descriptive
 *      ASCII string
 *      ASCII string
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
PSTR
PSTR
GetSZStorageClass(BYTE storageClass)
GetSZStorageClass(BYTE storageClass)
{
{
        if ( storageClass <= IMAGE_SYM_CLASS_BIT_FIELD )
        if ( storageClass <= IMAGE_SYM_CLASS_BIT_FIELD )
                return SzStorageClass1[storageClass];
                return SzStorageClass1[storageClass];
        else if ( (storageClass >= IMAGE_SYM_CLASS_BLOCK)
        else if ( (storageClass >= IMAGE_SYM_CLASS_BLOCK)
                      && (storageClass <= IMAGE_SYM_CLASS_WEAK_EXTERNAL) )
                      && (storageClass <= IMAGE_SYM_CLASS_WEAK_EXTERNAL) )
                return SzStorageClass2[storageClass-IMAGE_SYM_CLASS_BLOCK];
                return SzStorageClass2[storageClass-IMAGE_SYM_CLASS_BLOCK];
        else
        else
                return "???";
                return "???";
}
}
 
 
/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 * GetSectionName --
 * GetSectionName --
 *
 *
 *      Used by DumpSymbolTable, it gives meaningful names to
 *      Used by DumpSymbolTable, it gives meaningful names to
 *      the non-normal section number.
 *      the non-normal section number.
 *
 *
 * Results:
 * Results:
 *      A name is returned in buffer
 *      A name is returned in buffer
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
void
void
GetSectionName(WORD section, PSTR buffer, unsigned cbBuffer)
GetSectionName(WORD section, PSTR buffer, unsigned cbBuffer)
{
{
    char tempbuffer[10];
    char tempbuffer[10];
 
 
    switch ( (SHORT)section )
    switch ( (SHORT)section )
    {
    {
      case IMAGE_SYM_UNDEFINED: strcpy(tempbuffer, "UNDEF"); break;
      case IMAGE_SYM_UNDEFINED: strcpy(tempbuffer, "UNDEF"); break;
      case IMAGE_SYM_ABSOLUTE:  strcpy(tempbuffer, "ABS  "); break;
      case IMAGE_SYM_ABSOLUTE:  strcpy(tempbuffer, "ABS  "); break;
      case IMAGE_SYM_DEBUG:       strcpy(tempbuffer, "DEBUG"); break;
      case IMAGE_SYM_DEBUG:       strcpy(tempbuffer, "DEBUG"); break;
      default: wsprintf(tempbuffer, "%-5X", section);
      default: wsprintf(tempbuffer, "%-5X", section);
    }
    }
 
 
    strncpy(buffer, tempbuffer, cbBuffer-1);
    strncpy(buffer, tempbuffer, cbBuffer-1);
}
}
 
 
/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 * DumpSymbolTable --
 * DumpSymbolTable --
 *
 *
 *      Dumps a COFF symbol table from an EXE or OBJ.  We only use
 *      Dumps a COFF symbol table from an EXE or OBJ.  We only use
 *      it to dump tables from OBJs.
 *      it to dump tables from OBJs.
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
void
void
DumpSymbolTable(PIMAGE_SYMBOL pSymbolTable, FILE *fout, unsigned cSymbols)
DumpSymbolTable(PIMAGE_SYMBOL pSymbolTable, FILE *fout, unsigned cSymbols)
{
{
    unsigned i;
    unsigned i;
    PSTR stringTable;
    PSTR stringTable;
    char sectionName[10];
    char sectionName[10];
 
 
    fprintf(fout, "Symbol Table - %X entries  (* = auxillary symbol)\n",
    fprintf(fout, "Symbol Table - %X entries  (* = auxillary symbol)\n",
            cSymbols);
            cSymbols);
 
 
    fprintf(fout,
    fprintf(fout,
     "Indx Name                 Value    Section    cAux  Type    Storage\n"
     "Indx Name                 Value    Section    cAux  Type    Storage\n"
     "---- -------------------- -------- ---------- ----- ------- --------\n");
     "---- -------------------- -------- ---------- ----- ------- --------\n");
 
 
    /*
    /*
     * The string table apparently starts right after the symbol table
     * The string table apparently starts right after the symbol table
     */
     */
    stringTable = (PSTR)&pSymbolTable[cSymbols];
    stringTable = (PSTR)&pSymbolTable[cSymbols];
 
 
    for ( i=0; i < cSymbols; i++ ) {
    for ( i=0; i < cSymbols; i++ ) {
        fprintf(fout, "%04X ", i);
        fprintf(fout, "%04X ", i);
        if ( pSymbolTable->N.Name.Short != 0 )
        if ( pSymbolTable->N.Name.Short != 0 )
            fprintf(fout, "%-20.8s", pSymbolTable->N.ShortName);
            fprintf(fout, "%-20.8s", pSymbolTable->N.ShortName);
        else
        else
            fprintf(fout, "%-20s", stringTable + pSymbolTable->N.Name.Long);
            fprintf(fout, "%-20s", stringTable + pSymbolTable->N.Name.Long);
 
 
        fprintf(fout, " %08X", pSymbolTable->Value);
        fprintf(fout, " %08X", pSymbolTable->Value);
 
 
        GetSectionName(pSymbolTable->SectionNumber, sectionName,
        GetSectionName(pSymbolTable->SectionNumber, sectionName,
                       sizeof(sectionName));
                       sizeof(sectionName));
        fprintf(fout, " sect:%s aux:%X type:%02X st:%s\n",
        fprintf(fout, " sect:%s aux:%X type:%02X st:%s\n",
               sectionName,
               sectionName,
               pSymbolTable->NumberOfAuxSymbols,
               pSymbolTable->NumberOfAuxSymbols,
               pSymbolTable->Type,
               pSymbolTable->Type,
               GetSZStorageClass(pSymbolTable->StorageClass) );
               GetSZStorageClass(pSymbolTable->StorageClass) );
#if 0
#if 0
        if ( pSymbolTable->NumberOfAuxSymbols )
        if ( pSymbolTable->NumberOfAuxSymbols )
            DumpAuxSymbols(pSymbolTable);
            DumpAuxSymbols(pSymbolTable);
#endif
#endif
 
 
        /*
        /*
         * Take into account any aux symbols
         * Take into account any aux symbols
         */
         */
        i += pSymbolTable->NumberOfAuxSymbols;
        i += pSymbolTable->NumberOfAuxSymbols;
        pSymbolTable += pSymbolTable->NumberOfAuxSymbols;
        pSymbolTable += pSymbolTable->NumberOfAuxSymbols;
        pSymbolTable++;
        pSymbolTable++;
    }
    }
}
}
 
 
/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 * DumpExternals --
 * DumpExternals --
 *
 *
 *      Dumps a COFF symbol table from an EXE or OBJ.  We only use
 *      Dumps a COFF symbol table from an EXE or OBJ.  We only use
 *      it to dump tables from OBJs.
 *      it to dump tables from OBJs.
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
void
void
DumpExternals(PIMAGE_SYMBOL pSymbolTable, FILE *fout, unsigned cSymbols)
DumpExternals(PIMAGE_SYMBOL pSymbolTable, FILE *fout, unsigned cSymbols)
{
{
    unsigned i;
    unsigned i;
    PSTR stringTable;
    PSTR stringTable;
    char *s, *f;
    char *s, *f;
    char symbol[1024];
    char symbol[1024];
 
 
    /*
    /*
     * The string table apparently starts right after the symbol table
     * The string table apparently starts right after the symbol table
     */
     */
    stringTable = (PSTR)&pSymbolTable[cSymbols];
    stringTable = (PSTR)&pSymbolTable[cSymbols];
 
 
    for ( i=0; i < cSymbols; i++ ) {
    for ( i=0; i < cSymbols; i++ ) {
        if (pSymbolTable->SectionNumber > 0 && pSymbolTable->Type == 0x20) {
        if (pSymbolTable->SectionNumber > 0 && pSymbolTable->Type == 0x20) {
            if (pSymbolTable->StorageClass == IMAGE_SYM_CLASS_EXTERNAL) {
            if (pSymbolTable->StorageClass == IMAGE_SYM_CLASS_EXTERNAL) {
                if (pSymbolTable->N.Name.Short != 0) {
                if (pSymbolTable->N.Name.Short != 0) {
                    strncpy(symbol, pSymbolTable->N.ShortName, 8);
                    strncpy(symbol, pSymbolTable->N.ShortName, 8);
                    symbol[8] = 0;
                    symbol[8] = 0;
                } else {
                } else {
                    s = stringTable + pSymbolTable->N.Name.Long;
                    s = stringTable + pSymbolTable->N.Name.Long;
                    strcpy(symbol, s);
                    strcpy(symbol, s);
                }
                }
                s = symbol;
                s = symbol;
                f = strchr(s, '@');
                f = strchr(s, '@');
                if (f) {
                if (f) {
                    *f = 0;
                    *f = 0;
                }
                }
#if defined(_MSC_VER) && defined(_X86_)
#if defined(_MSC_VER) && defined(_X86_)
                if (symbol[0] == '_') {
                if (symbol[0] == '_') {
                    s = &symbol[1];
                    s = &symbol[1];
                }
                }
#endif
#endif
                if ((stricmp(s, "DllEntryPoint") != 0)
                if ((stricmp(s, "DllEntryPoint") != 0)
                        && (stricmp(s, "DllMain") != 0)) {
                        && (stricmp(s, "DllMain") != 0)) {
                    fprintf(fout, "\t%s\n", s);
                    fprintf(fout, "\t%s\n", s);
                }
                }
            }
            }
        }
        }
 
 
        /*
        /*
         * Take into account any aux symbols
         * Take into account any aux symbols
         */
         */
        i += pSymbolTable->NumberOfAuxSymbols;
        i += pSymbolTable->NumberOfAuxSymbols;
        pSymbolTable += pSymbolTable->NumberOfAuxSymbols;
        pSymbolTable += pSymbolTable->NumberOfAuxSymbols;
        pSymbolTable++;
        pSymbolTable++;
    }
    }
}
}
 
 
/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 * DumpObjFile --
 * DumpObjFile --
 *
 *
 *      Dump an object file--either a full listing or just the exported
 *      Dump an object file--either a full listing or just the exported
 *      symbols.
 *      symbols.
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
void
void
DumpObjFile(PIMAGE_FILE_HEADER pImageFileHeader, FILE *fout, int full)
DumpObjFile(PIMAGE_FILE_HEADER pImageFileHeader, FILE *fout, int full)
{
{
    PIMAGE_SYMBOL PCOFFSymbolTable;
    PIMAGE_SYMBOL PCOFFSymbolTable;
    DWORD COFFSymbolCount;
    DWORD COFFSymbolCount;
 
 
    PCOFFSymbolTable = (PIMAGE_SYMBOL)
    PCOFFSymbolTable = (PIMAGE_SYMBOL)
        ((DWORD)pImageFileHeader + pImageFileHeader->PointerToSymbolTable);
        ((DWORD)pImageFileHeader + pImageFileHeader->PointerToSymbolTable);
    COFFSymbolCount = pImageFileHeader->NumberOfSymbols;
    COFFSymbolCount = pImageFileHeader->NumberOfSymbols;
 
 
    if (full) {
    if (full) {
        DumpSymbolTable(PCOFFSymbolTable, fout, COFFSymbolCount);
        DumpSymbolTable(PCOFFSymbolTable, fout, COFFSymbolCount);
    } else {
    } else {
        DumpExternals(PCOFFSymbolTable, fout, COFFSymbolCount);
        DumpExternals(PCOFFSymbolTable, fout, COFFSymbolCount);
    }
    }
}
}
 
 
/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 * SkipToNextRecord --
 * SkipToNextRecord --
 *
 *
 *      Skip over the current ROMF record and return the type of the
 *      Skip over the current ROMF record and return the type of the
 *      next record.
 *      next record.
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
BYTE
BYTE
SkipToNextRecord(BYTE **ppBuffer)
SkipToNextRecord(BYTE **ppBuffer)
{
{
    int length;
    int length;
    (*ppBuffer)++;              /* Skip over the type.*/
    (*ppBuffer)++;              /* Skip over the type.*/
    length = *((WORD*)(*ppBuffer))++; /* Retrieve the length. */
    length = *((WORD*)(*ppBuffer))++; /* Retrieve the length. */
    *ppBuffer += length;        /* Skip over the rest. */
    *ppBuffer += length;        /* Skip over the rest. */
    return **ppBuffer;          /* Return the type. */
    return **ppBuffer;          /* Return the type. */
}
}
 
 
/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 * DumpROMFObjFile --
 * DumpROMFObjFile --
 *
 *
 *      Dump a Relocatable Object Module Format file, displaying only
 *      Dump a Relocatable Object Module Format file, displaying only
 *      the exported symbols.
 *      the exported symbols.
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
void
void
DumpROMFObjFile(LPVOID pBuffer, FILE *fout)
DumpROMFObjFile(LPVOID pBuffer, FILE *fout)
{
{
    BYTE type, length;
    BYTE type, length;
    char symbol[1024], *s;
    char symbol[1024], *s;
 
 
    while (1) {
    while (1) {
        type = SkipToNextRecord(&(BYTE*)pBuffer);
        type = SkipToNextRecord(&(BYTE*)pBuffer);
        if (type == 0x90) {     /* PUBDEF */
        if (type == 0x90) {     /* PUBDEF */
            if (((BYTE*)pBuffer)[4] != 0) {
            if (((BYTE*)pBuffer)[4] != 0) {
                length = ((BYTE*)pBuffer)[5];
                length = ((BYTE*)pBuffer)[5];
                strncpy(symbol, ((char*)pBuffer) + 6, length);
                strncpy(symbol, ((char*)pBuffer) + 6, length);
                symbol[length] = '\0';
                symbol[length] = '\0';
                s = symbol;
                s = symbol;
                if ((stricmp(s, "DllEntryPoint") != 0)
                if ((stricmp(s, "DllEntryPoint") != 0)
                        && (stricmp(s, "DllMain") != 0)) {
                        && (stricmp(s, "DllMain") != 0)) {
                    if (s[0] == '_') {
                    if (s[0] == '_') {
                        s++;
                        s++;
                        fprintf(fout, "\t_%s\n\t%s=_%s\n", s, s, s);
                        fprintf(fout, "\t_%s\n\t%s=_%s\n", s, s, s);
                    } else {
                    } else {
                        fprintf(fout, "\t%s\n", s);
                        fprintf(fout, "\t%s\n", s);
                    }
                    }
                }
                }
            }
            }
        } else if (type == 0x8B || type == 0x8A) { /* MODEND */
        } else if (type == 0x8B || type == 0x8A) { /* MODEND */
            break;
            break;
        }
        }
    }
    }
}
}
 
 
/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 * DumpFile --
 * DumpFile --
 *
 *
 *      Open up a file, memory map it, and call the appropriate
 *      Open up a file, memory map it, and call the appropriate
 *      dumping routine
 *      dumping routine
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
void
void
DumpFile(LPSTR filename, FILE *fout, int full)
DumpFile(LPSTR filename, FILE *fout, int full)
{
{
    HANDLE hFile;
    HANDLE hFile;
    HANDLE hFileMapping;
    HANDLE hFileMapping;
    LPVOID lpFileBase;
    LPVOID lpFileBase;
    PIMAGE_DOS_HEADER dosHeader;
    PIMAGE_DOS_HEADER dosHeader;
 
 
    hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL,
    hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL,
                       OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
                       OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
 
 
    if (hFile == INVALID_HANDLE_VALUE) {
    if (hFile == INVALID_HANDLE_VALUE) {
        fprintf(stderr, "Couldn't open file with CreateFile()\n");
        fprintf(stderr, "Couldn't open file with CreateFile()\n");
        return;
        return;
    }
    }
 
 
    hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
    hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
    if (hFileMapping == 0) {
    if (hFileMapping == 0) {
        CloseHandle(hFile);
        CloseHandle(hFile);
        fprintf(stderr, "Couldn't open file mapping with CreateFileMapping()\n");
        fprintf(stderr, "Couldn't open file mapping with CreateFileMapping()\n");
        return;
        return;
    }
    }
 
 
    lpFileBase = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
    lpFileBase = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
    if (lpFileBase == 0) {
    if (lpFileBase == 0) {
        CloseHandle(hFileMapping);
        CloseHandle(hFileMapping);
        CloseHandle(hFile);
        CloseHandle(hFile);
        fprintf(stderr, "Couldn't map view of file with MapViewOfFile()\n");
        fprintf(stderr, "Couldn't map view of file with MapViewOfFile()\n");
        return;
        return;
    }
    }
 
 
    dosHeader = (PIMAGE_DOS_HEADER)lpFileBase;
    dosHeader = (PIMAGE_DOS_HEADER)lpFileBase;
    if (dosHeader->e_magic == IMAGE_DOS_SIGNATURE) {
    if (dosHeader->e_magic == IMAGE_DOS_SIGNATURE) {
#if 0
#if 0
        DumpExeFile( dosHeader );
        DumpExeFile( dosHeader );
#else
#else
        fprintf(stderr, "File is an executable.  I don't dump those.\n");
        fprintf(stderr, "File is an executable.  I don't dump those.\n");
        return;
        return;
#endif
#endif
    }
    }
    /* Does it look like a i386 COFF OBJ file??? */
    /* Does it look like a i386 COFF OBJ file??? */
    else if ((dosHeader->e_magic == e_magic_number)
    else if ((dosHeader->e_magic == e_magic_number)
            && (dosHeader->e_sp == 0)) {
            && (dosHeader->e_sp == 0)) {
        /*
        /*
         * The two tests above aren't what they look like.  They're
         * The two tests above aren't what they look like.  They're
         * really checking for IMAGE_FILE_HEADER.Machine == i386 (0x14C)
         * really checking for IMAGE_FILE_HEADER.Machine == i386 (0x14C)
         * and IMAGE_FILE_HEADER.SizeOfOptionalHeader == 0;
         * and IMAGE_FILE_HEADER.SizeOfOptionalHeader == 0;
         */
         */
        DumpObjFile((PIMAGE_FILE_HEADER) lpFileBase, fout, full);
        DumpObjFile((PIMAGE_FILE_HEADER) lpFileBase, fout, full);
    } else if (*((BYTE *)lpFileBase) == 0x80) {
    } else if (*((BYTE *)lpFileBase) == 0x80) {
        /*
        /*
         * This file looks like it might be a ROMF file.
         * This file looks like it might be a ROMF file.
         */
         */
        DumpROMFObjFile(lpFileBase, fout);
        DumpROMFObjFile(lpFileBase, fout);
    } else {
    } else {
        printf("unrecognized file format\n");
        printf("unrecognized file format\n");
    }
    }
    UnmapViewOfFile(lpFileBase);
    UnmapViewOfFile(lpFileBase);
    CloseHandle(hFileMapping);
    CloseHandle(hFileMapping);
    CloseHandle(hFile);
    CloseHandle(hFile);
}
}
 
 
void
void
main(int argc, char **argv)
main(int argc, char **argv)
{
{
    char *fargv[1000];
    char *fargv[1000];
    char cmdline[10000];
    char cmdline[10000];
    int i, arg;
    int i, arg;
    FILE *fout;
    FILE *fout;
    int pos;
    int pos;
    int full = 0;
    int full = 0;
    char *outfile = NULL;
    char *outfile = NULL;
 
 
    if (argc < 3) {
    if (argc < 3) {
      Usage:
      Usage:
        fprintf(stderr, "Usage: %s ?-o outfile? ?-f(ull)? <dllname> <object filenames> ..\n", argv[0]);
        fprintf(stderr, "Usage: %s ?-o outfile? ?-f(ull)? <dllname> <object filenames> ..\n", argv[0]);
        exit(1);
        exit(1);
    }
    }
 
 
    arg = 1;
    arg = 1;
    while (argv[arg][0] == '-') {
    while (argv[arg][0] == '-') {
        if (strcmp(argv[arg], "--") == 0) {
        if (strcmp(argv[arg], "--") == 0) {
            arg++;
            arg++;
            break;
            break;
        } else if (strcmp(argv[arg], "-f") == 0) {
        } else if (strcmp(argv[arg], "-f") == 0) {
            full = 1;
            full = 1;
        } else if (strcmp(argv[arg], "-o") == 0) {
        } else if (strcmp(argv[arg], "-o") == 0) {
            arg++;
            arg++;
            if (arg == argc) {
            if (arg == argc) {
                goto Usage;
                goto Usage;
            }
            }
            outfile = argv[arg];
            outfile = argv[arg];
        }
        }
        arg++;
        arg++;
    }
    }
    if (arg == argc) {
    if (arg == argc) {
        goto Usage;
        goto Usage;
    }
    }
 
 
    if (outfile) {
    if (outfile) {
        fout = fopen(outfile, "w+");
        fout = fopen(outfile, "w+");
        if (fout == NULL) {
        if (fout == NULL) {
            fprintf(stderr, "Unable to open \'%s\' for writing:\n",
            fprintf(stderr, "Unable to open \'%s\' for writing:\n",
                    argv[arg]);
                    argv[arg]);
            perror("");
            perror("");
            exit(1);
            exit(1);
        }
        }
    } else {
    } else {
        fout = stdout;
        fout = stdout;
    }
    }
 
 
    if (! full) {
    if (! full) {
        char *dllname = argv[arg];
        char *dllname = argv[arg];
        arg++;
        arg++;
        if (arg == argc) {
        if (arg == argc) {
            goto Usage;
            goto Usage;
        }
        }
        fprintf(fout, "LIBRARY    %s\n", dllname);
        fprintf(fout, "LIBRARY    %s\n", dllname);
        fprintf(fout, "EXETYPE WINDOWS\n");
        fprintf(fout, "EXETYPE WINDOWS\n");
        fprintf(fout, "CODE PRELOAD MOVEABLE DISCARDABLE\n");
        fprintf(fout, "CODE PRELOAD MOVEABLE DISCARDABLE\n");
        fprintf(fout, "DATA PRELOAD MOVEABLE MULTIPLE\n\n");
        fprintf(fout, "DATA PRELOAD MOVEABLE MULTIPLE\n\n");
        fprintf(fout, "EXPORTS\n");
        fprintf(fout, "EXPORTS\n");
    }
    }
 
 
    for (; arg < argc; arg++) {
    for (; arg < argc; arg++) {
        if (argv[arg][0] == '@') {
        if (argv[arg][0] == '@') {
            FILE *fargs = fopen(&argv[arg][1], "r");
            FILE *fargs = fopen(&argv[arg][1], "r");
            if (fargs == NULL) {
            if (fargs == NULL) {
                fprintf(stderr, "Unable to open \'%s\' for reading:\n",
                fprintf(stderr, "Unable to open \'%s\' for reading:\n",
                        argv[arg]);
                        argv[arg]);
                perror("");
                perror("");
                exit(1);
                exit(1);
            }
            }
            pos = 0;
            pos = 0;
            for (i = 0; i < arg; i++) {
            for (i = 0; i < arg; i++) {
                strcpy(&cmdline[pos], argv[i]);
                strcpy(&cmdline[pos], argv[i]);
                pos += strlen(&cmdline[pos]) + 1;
                pos += strlen(&cmdline[pos]) + 1;
                fargv[i] = argv[i];
                fargv[i] = argv[i];
            }
            }
            fgets(&cmdline[pos], sizeof(cmdline), fargs);
            fgets(&cmdline[pos], sizeof(cmdline), fargs);
            fprintf(stderr, "%s\n", &cmdline[pos]);
            fprintf(stderr, "%s\n", &cmdline[pos]);
            fclose(fargs);
            fclose(fargs);
            i += GetArgcArgv(&cmdline[pos], &fargv[i]);
            i += GetArgcArgv(&cmdline[pos], &fargv[i]);
            argc = i;
            argc = i;
            argv = fargv;
            argv = fargv;
        }
        }
        DumpFile(argv[arg], fout, full);
        DumpFile(argv[arg], fout, full);
    }
    }
    exit(0);
    exit(0);
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.