Ignore:
Timestamp:
Feb 11, 2000, 7:35:55 PM (26 years ago)
Author:
bird
Message:

Odin32 DB.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/database/APIImport.cpp

    r830 r2759  
    1 /* $Id: APIImport.cpp,v 1.1 1999-09-05 02:53:04 bird Exp $ */
     1/* $Id: APIImport.cpp,v 1.2 2000-02-11 18:35:53 bird Exp $ */
    22/*
    33 *
    44 * APIImport - imports a DLL or Dll-.def with functions into the Odin32 database.
    55 *
    6  * Copyright (c) 1999 knut st. osmundsen
     6 * Copyright (c) 1999-2000 knut st. osmundsen
    77 *
    88 */
     
    3434static void openLog(void);
    3535static void closeLog(void);
    36 static long processFile(const char *pszFilename, const POPTIONS pOptions);
     36static long processFile(const char *pszFilename, const POPTIONS pOptions, long &cFunctions);
     37static void demangle(const char *pszMangledName, char *pszDemangled);
    3738
    3839
     
    5455    char   *pszUser     = "root";
    5556    char   *pszPasswd   = "";
     57    long    cFunctions  = 0;
     58
    5659
    5760    /**************************************************************************
     
    127130            if (dbConnect(pszHost, pszUser, pszPasswd, pszDatabase))
    128131            {
    129                 l = processFile(argv[argi], &options);
     132                l = processFile(argv[argi], &options, cFunctions);
    130133                lRc = ((lRc & 0xffff0000UL) | (l & 0xffff0000UL)) | ((lRc & 0x0000ffffUL) + l & 0x0000ffffUL);
    131134                dbDisconnect();
     
    141144        argi++;
    142145    }
     146
     147    /* write function count */
     148    if (phLog != NULL)
     149        fprintf(phLog, "\n %d functions were imported!\n\n", cFunctions);
    143150
    144151    /* close the log */
     
    225232 * @param     pszFilename  Pointer to the filename of the file which is to be processed.
    226233 * @param     pOptions     Pointer to the options-struct.
    227  */
    228 static long processFile(const char *pszFilename, const POPTIONS pOptions)
     234 * @param     cFunctions   Function count which is to be updated when functions are imported.
     235 */
     236static long processFile(const char *pszFilename, const POPTIONS pOptions, long &cFunctions)
    229237{
    230238    kFileFormatBase  *pFile;
     
    275283                        if (!pFile->isDef() || export.ulOrdinal < ORD_START_INTERNAL_FUNCTIONS)
    276284                        {
    277                             if (export.achName[0] != '\0')
    278                             {   /* name */
    279                                 int iName = strncmp(&export.achName[0], "_OS2", 4) != 0 ? 0 : 4;
    280                                 fprintf(phLog, "%s: %08ld %s\n", pszFilename, export.ulOrdinal, &export.achName[iName]);
    281                                 fOk = dbInsertUpdateFunction(sDll, &export.achName[iName], export.ulOrdinal,
    282                                                              pOptions->fIgnoreOrdinals && export.ulOrdinal != 0xffffffffUL);
    283                             }
     285                            char szIntName[64];
     286                            char szName[64];
     287
     288                            demangle(export.achIntName, &szIntName[0]);
     289                            if (export.achName == '\0')
     290                                sprintf(&szName[0], "Ordinal%04ld", export.ulOrdinal);
    284291                            else
    285                             {   /* ordinal only */
    286                                 char szFn[50];
    287 
    288                                 sprintf(&szFn[0], "Ordinal%04ld", export.ulOrdinal);
    289                                 fprintf(phLog, "%s: %08ld %s\n", pszFilename, export.ulOrdinal, &szFn[0]);
    290                                 if (export.ulOrdinal != 0xffffffffUL)
    291                                     fOk = dbInsertUpdateFunction(sDll, &szFn[0], export.ulOrdinal, pOptions->fIgnoreOrdinals);
    292                                 else
    293                                     fprintf(phLog, "%s: error - invalid ordinal value!\n", pszFilename);
    294                             }
     292                                strcpy(&szName[0], &export.achName[0]);
     293
     294                            fprintf(phLog, "%s: %08ld %-30s %s\n",
     295                                    pszFilename, export.ulOrdinal, &szName[0], &szIntName[0]);
     296
     297                            fOk = dbInsertUpdateFunction(sDll,
     298                                                         &szName[0],
     299                                                         &szIntName[0],
     300                                                         export.ulOrdinal,
     301                                                         pOptions->fIgnoreOrdinals && export.ulOrdinal != 0xffffffffUL);
     302                            if (fOk)
     303                                cFunctions++;
    295304                        }
    296305
     
    330339}
    331340
     341
     342/**
     343 * Demangles stdcall functions.
     344 * @param       pszMangledName  Mangled name
     345 * @param       pszDemangled    Pointer to buffer which will hold the demangled name upon return.
     346 */
     347static void demangle(const char *pszMangledName, char *pszDemangled)
     348{
     349    int iEnd;
     350    /* check for @ */
     351    iEnd = strlen(pszMangledName);
     352    if (iEnd-- > 3 && *pszMangledName == '_')
     353    {
     354        while ((pszMangledName[iEnd] >= '0' && pszMangledName[iEnd] <= '9') && iEnd > 0)
     355            iEnd--;
     356        if (pszMangledName[iEnd] == '@')
     357        {
     358            *pszDemangled = '\0';
     359            strncat(pszDemangled, pszMangledName+1, iEnd - 1);
     360            return;
     361        }
     362    }
     363
     364    /* not stdcall */
     365    strcpy(pszDemangled, pszMangledName);
     366}
     367
Note: See TracChangeset for help on using the changeset viewer.