Changeset 5932 for trunk/src


Ignore:
Timestamp:
Jun 8, 2001, 1:04:26 PM (24 years ago)
Author:
sandervl
Message:

pe loader optimizations, WritePrivateProfileStructA added (Wine), WinExec fix

Location:
trunk/src/kernel32
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/profile.cpp

    r4756 r5932  
    1 /* $Id: profile.cpp,v 1.28 2000-12-05 13:04:48 sandervl Exp $ */
     1/* $Id: profile.cpp,v 1.29 2001-06-08 11:04:24 sandervl Exp $ */
    22
    33/*
     
    309309}
    310310
    311 
    312311/***********************************************************************
    313312 *           PROFILE_DeleteKey
     
    342341}
    343342
     343/***********************************************************************
     344 *           PROFILE_DeleteAllKeys
     345 *
     346 * Delete all keys from a profile tree.
     347 */
     348void PROFILE_DeleteAllKeys( LPCSTR section_name)
     349{
     350    PROFILESECTION **section= &CurProfile->section;
     351    while (*section)
     352    {
     353        if ((*section)->name && !strcasecmp( (*section)->name, section_name ))
     354        {
     355            PROFILEKEY **key = &(*section)->key;
     356            while (*key)
     357            {
     358                PROFILEKEY *to_del = *key;
     359                *key = to_del->next;
     360                if (to_del->name) HeapFree( GetProcessHeap(), 0, to_del->name );
     361                if (to_del->value) HeapFree( GetProcessHeap(), 0, to_del->value);
     362                HeapFree( GetProcessHeap(), 0, to_del );
     363                CurProfile->changed =TRUE;
     364            }
     365        }
     366        section = &(*section)->next;
     367    }
     368}
    344369
    345370/***********************************************************************
     
    13881413              LPCSTR, filename)
    13891414{
    1390   char *p =(char*)string;
    1391 
    1392   dprintf(("Kernel32:Profile:fixme WritePrivateProfileSection32A empty stub\n"));
    1393   return FALSE;
     1415    BOOL ret = FALSE;
     1416    LPSTR p ;
     1417
     1418    dprintf(("WritePrivateProfileSectionA %s %s %s", section, string, filename));
     1419
     1420    EnterCriticalSection( &PROFILE_CritSect );
     1421
     1422    if (PROFILE_Open( filename )) {
     1423        if (!section && !string)
     1424            PROFILE_ReleaseFile();  /* always return FALSE in this case */
     1425        else if (!string) /* delete the named section*/
     1426            ret = PROFILE_SetString(section,NULL,NULL);
     1427        else {
     1428            PROFILE_DeleteAllKeys(section);
     1429            ret = TRUE;
     1430            while(*string) {
     1431                LPSTR buf=HEAP_strdupA( GetProcessHeap(), 0, string );
     1432                if((p=strchr( buf, '='))){
     1433                    *p='\0';
     1434                    ret = PROFILE_SetString( section, buf, p+1 );
     1435                   
     1436                }
     1437                HeapFree( GetProcessHeap(), 0, buf );
     1438                string += strlen(string)+1;
     1439            }
     1440           
     1441        }
     1442    }
     1443
     1444    LeaveCriticalSection( &PROFILE_CritSect );
     1445    return ret;
    13941446}
    13951447
  • trunk/src/kernel32/winimagepeldr.cpp

    r5915 r5932  
    1 /* $Id: winimagepeldr.cpp,v 1.85 2001-06-06 10:33:16 sandervl Exp $ */
     1/* $Id: winimagepeldr.cpp,v 1.86 2001-06-08 11:04:25 sandervl Exp $ */
    22
    33/*
     
    13841384    }
    13851385  }
    1386  
     1386
    13871387  return(TRUE);
    13881388}
     
    13911391void Win32PeLdrImage::AddNameExport(ULONG virtaddr, char *apiname, ULONG ordinal, BOOL fAbsoluteAddress)
    13921392{
    1393  ULONG nsize;
     1393    ULONG nsize;
     1394    int iApiNameLength = strlen(apiname);
    13941395
    13951396    if(nameexports == NULL) {
    1396         nameExportSize= 4096;
     1397        // think of a maximum of bytes per export name,
     1398        // verify if this is true for MFC-DLLs, etc.
     1399        nameExportSize = nrNameExports * (sizeof(NameExport) + 32);
     1400
    13971401        nameexports   = (NameExport *)malloc(nameExportSize);
    13981402        curnameexport = nameexports;
    13991403    }
    14001404    nsize = (ULONG)curnameexport - (ULONG)nameexports;
    1401     if(nsize + sizeof(NameExport) + strlen(apiname) > nameExportSize) {
     1405    if(nsize + sizeof(NameExport) + iApiNameLength > nameExportSize) {
    14021406        nameExportSize += 4096;
    14031407        char *tmp = (char *)nameexports;
     
    14131417    curnameexport->ordinal  = ordinal;
    14141418    *(ULONG *)curnameexport->name = 0;
    1415     strcpy(curnameexport->name, apiname);
    1416 
    1417     curnameexport->nlength = strlen(apiname) + 1;
     1419
     1420    curnameexport->nlength = iApiNameLength + 1;
     1421    memcpy(curnameexport->name, apiname,  curnameexport->nlength);
     1422
    14181423    if(curnameexport->nlength < sizeof(curnameexport->name))
    14191424        curnameexport->nlength = sizeof(curnameexport->name);
     
    14421447BOOL Win32PeLdrImage::AddForwarder(ULONG virtaddr, char *apiname, ULONG ordinal)
    14431448{
    1444  char         *forward = (char *)(realBaseAddress + (virtaddr - oh.ImageBase));
    1445  char         *forwarddll, *forwardapi;
    1446  Win32DllBase *WinDll;
    1447  DWORD         exportaddr;
    1448  int           forwardord;
    1449 
    1450     forwarddll = strdup(forward);
     1449    char         *forward = (char *)(realBaseAddress + (virtaddr - oh.ImageBase));
     1450    char         *forwarddll, *forwardapi;
     1451    Win32DllBase *WinDll;
     1452    DWORD         exportaddr;
     1453    int           forwardord;
     1454    int           iForwardDllLength = strlen(forward);
     1455    int           iForwardApiLength;
     1456
     1457    if(iForwardDllLength == 0)
     1458        return FALSE;
     1459
     1460    forwarddll = (char*)alloca(iForwardDllLength);
    14511461    if(forwarddll == NULL) {
     1462        DebugInt3();
    14521463        return FALSE;
    14531464    }
     1465    memcpy(forwarddll, forward, iForwardDllLength + 1);
     1466
    14541467    forwardapi = strchr(forwarddll, '.');
    14551468    if(forwardapi == NULL) {
    1456         goto fail;
     1469        return FALSE;
    14571470    }
    14581471    *forwardapi++ = 0;
    1459     if(strlen(forwarddll) == 0 || strlen(forwardapi) == 0) {
    1460         goto fail;
     1472    iForwardApiLength = strlen(forwardapi);
     1473    if(iForwardApiLength == 0) {
     1474        return FALSE;
    14611475    }
    14621476    WinDll = Win32DllBase::findModule(forwarddll);
     
    14651479        if(WinDll == NULL) {
    14661480            dprintf((LOG, "ERROR: couldn't find forwarder %s.%s", forwarddll, forwardapi));
    1467             goto fail;
     1481            return FALSE;
    14681482        }
    14691483    }
     
    14731487        forwardord = atoi(forwardapi);
    14741488    }
    1475     if(forwardord != 0 || (strlen(forwardapi) == 1 && *forwardapi == '0')) {
    1476         exportaddr = WinDll->getApi(forwardord);
    1477     }
    1478     else  exportaddr = WinDll->getApi(forwardapi);
     1489    if(forwardord != 0 || (iForwardApiLength == 1 && *forwardapi == '0')) {
     1490         exportaddr = WinDll->getApi(forwardord);
     1491    }
     1492    else exportaddr = WinDll->getApi(forwardapi);
    14791493
    14801494    if(apiname) {
     
    14841498    else {
    14851499        dprintf((LOG, "address 0x%x @%d (0x%08x) forwarder %s.%s", virtaddr - oh.ImageBase, ordinal, virtaddr, forwarddll, forwardapi));
    1486          AddOrdExport(exportaddr, ordinal, TRUE);
    1487     }
    1488     free(forwarddll);
     1500        AddOrdExport(exportaddr, ordinal, TRUE);
     1501    }
    14891502    return TRUE;
    1490 
    1491 fail:
    1492   free(forwarddll);
    1493   return FALSE;
    14941503}
    14951504//******************************************************************************
     
    15861595    return WinDll;
    15871596}
     1597
    15881598//******************************************************************************
    15891599/** All initial processing of imports is done here
     
    15961606BOOL Win32PeLdrImage::processImports(char *win32file)
    15971607{
    1598  PIMAGE_IMPORT_DESCRIPTOR pID;
    1599  IMAGE_SECTION_HEADER     shID;
    1600  IMAGE_SECTION_HEADER     shExtra = {0};
    1601  PIMAGE_OPTIONAL_HEADER   pOH;
    1602  int    i,j, nrPages;
    1603  BOOL   fBorland = 0;
    1604  int    cModules;
    1605  char  *pszModules;
    1606  char  *pszCurModule;
    1607  char  *pszTmp;
    1608  ULONG *pulImport;
    1609  ULONG  ulCurFixup;
    1610  int    Size;
    1611  Win32DllBase    *WinDll;
    1612  Win32ImageBase  *WinImage = NULL;
    1613  Section *section;
    1614 
    1615 /* "algorithm:"
    1616  *      1) get module names and store them
    1617  *          a) check dwRVAModuleName is within .idata seg - if not find section
    1618  *      2) iterate thru functions of each module
    1619  *          a) check OriginalFirstThunk is not 0 and that it points to a RVA.
    1620  *          b) if not a) borland-styled PE-file - ARG!!!
    1621  *              check FirstThunk
    1622  *          c) check OriginalFirstThunk/FirstThunk ok RVAs and find right section
    1623  *          d) store ordinal/name import
    1624  *      3) finished
    1625  */
    1626 
    1627    /* 1) get module names */
    1628    pID = (PIMAGE_IMPORT_DESCRIPTOR)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_IMPORT);
    1629    if (pID == NULL)
     1608    PIMAGE_IMPORT_DESCRIPTOR pID;
     1609    IMAGE_SECTION_HEADER     shID;
     1610    IMAGE_SECTION_HEADER     shExtra = {0};
     1611    PIMAGE_OPTIONAL_HEADER   pOH;
     1612    int    i,j, nrPages;
     1613    BOOL   fBorland = 0;
     1614    int    cModules;
     1615    char  *pszModules;
     1616    char  *pszCurModule;
     1617    char  *pszTmp;
     1618    ULONG *pulImport;
     1619    ULONG  ulCurFixup;
     1620    int    Size;
     1621    Win32DllBase    *WinDll;
     1622    Win32ImageBase  *WinImage = NULL;
     1623    Section *section;
     1624
     1625    /* "algorithm:"
     1626     *      1) get module names and store them
     1627     *          a) check dwRVAModuleName is within .idata seg - if not find section
     1628     *      2) iterate thru functions of each module
     1629     *          a) check OriginalFirstThunk is not 0 and that it points to a RVA.
     1630     *          b) if not a) borland-styled PE-file - ARG!!!
     1631     *              check FirstThunk
     1632     *          c) check OriginalFirstThunk/FirstThunk ok RVAs and find right section
     1633     *          d) store ordinal/name import
     1634     *      3) finished
     1635     */
     1636
     1637    /* 1) get module names */
     1638    pID = (PIMAGE_IMPORT_DESCRIPTOR)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_IMPORT);
     1639    if (pID == NULL)
    16301640        return TRUE;
    1631    if (!GetSectionHdrByImageDir(win32file, IMAGE_DIRECTORY_ENTRY_IMPORT, &shID))
     1641    if (!GetSectionHdrByImageDir(win32file, IMAGE_DIRECTORY_ENTRY_IMPORT, &shID))
    16321642        return TRUE;
    16331643
    1634    //calc size of module list
    1635    i = Size = cModules = 0;
    1636    while (pID[i].Name != 0)
    1637    {
    1638     //test RVA inside ID-Section
    1639     if (pID[i].Name >= shID.VirtualAddress && pID[i].Name < shID.VirtualAddress + max(shID.Misc.VirtualSize, shID.SizeOfRawData)) {
    1640         pszTmp = (char*)(pID[i].Name + (ULONG)win32file);
    1641     }
    1642     else {
    1643         //is the "Extra"-section already found or do we have to find it?
    1644         if (pID[i].Name < shExtra.VirtualAddress || pID[i].Name >= shExtra.VirtualAddress + max(shExtra.Misc.VirtualSize, shExtra.SizeOfRawData)) {
    1645             if (!GetSectionHdrByRVA(win32file, &shExtra, pID[i].Name))
    1646                  return FALSE;
    1647         }
    1648         pszTmp = (char*)(pID[i].Name + (ULONG)win32file);
    1649     }
    1650     Size += strlen(pszTmp) + 1;
    1651     i++;
    1652     cModules++;
    1653   }
    1654 
    1655   pszModules = (char*)malloc(Size);
    1656   assert(pszModules != NULL);
    1657   j = 0;
    1658   for (i = 0; i < cModules; i++)
    1659   {
    1660     //test RVA inside ID-Section
    1661     if (pID[i].Name >= shID.VirtualAddress && pID[i].Name < shID.VirtualAddress + max(shID.Misc.VirtualSize, shID.SizeOfRawData)) {
    1662         pszTmp = (char*)(pID[i].Name + (ULONG)win32file);
    1663     }
    1664     else {
    1665         fBorland = TRUE;
    1666         //is the "Extra"-section already found or do we have to find it?
    1667         if (pID[i].Name < shExtra.VirtualAddress || pID[i].Name >= shExtra.VirtualAddress + max(shExtra.Misc.VirtualSize, shExtra.SizeOfRawData))
     1644    //calc size of module list
     1645    i = Size = cModules = 0;
     1646    while (pID[i].Name != 0)
     1647    {
     1648        //test RVA inside ID-Section
     1649        if (pID[i].Name >= shID.VirtualAddress && pID[i].Name < shID.VirtualAddress + max(shID.Misc.VirtualSize, shID.SizeOfRawData)) {
     1650            pszTmp = (char*)(pID[i].Name + (ULONG)win32file);
     1651        }
     1652        else {
     1653            //is the "Extra"-section already found or do we have to find it?
     1654            if (pID[i].Name < shExtra.VirtualAddress || pID[i].Name >= shExtra.VirtualAddress + max(shExtra.Misc.VirtualSize, shExtra.SizeOfRawData)) {
     1655                if (!GetSectionHdrByRVA(win32file, &shExtra, pID[i].Name))
     1656                    return FALSE;
     1657            }
     1658            pszTmp = (char*)(pID[i].Name + (ULONG)win32file);
     1659        }
     1660        Size += strlen(pszTmp) + 1;
     1661        i++;
     1662        cModules++;
     1663    }
     1664
     1665    pszModules = (char*)alloca(Size);
     1666    if(pszModules == NULL) {
     1667        DebugInt3();
     1668        return FALSE;
     1669    }
     1670    j = 0;
     1671    for (i = 0; i < cModules; i++)
     1672    {
     1673        //test RVA inside ID-Section
     1674        if (pID[i].Name >= shID.VirtualAddress && pID[i].Name < shID.VirtualAddress + max(shID.Misc.VirtualSize, shID.SizeOfRawData)) {
     1675            pszTmp = (char*)(pID[i].Name + (ULONG)win32file);
     1676        }
     1677        else {
     1678            fBorland = TRUE;
     1679            //is the "Extra"-section already found or do we have to find it?
     1680            if (pID[i].Name < shExtra.VirtualAddress || pID[i].Name >= shExtra.VirtualAddress + max(shExtra.Misc.VirtualSize, shExtra.SizeOfRawData))
     1681            {
     1682                if (GetSectionHdrByRVA(win32file, &shExtra, pID[i].Name)) {
     1683                    return FALSE;
     1684                }
     1685            }
     1686            pszTmp = (char*)(pID[i].Name + (ULONG)win32file);
     1687        }
     1688
     1689        int iTmpLength = strlen(pszTmp) + 1;
     1690        memcpy(pszModules+j, pszTmp, iTmpLength);
     1691        j += iTmpLength;
     1692    }
     1693    if (fBorland)
     1694        dprintf((LOG, "Borland-styled PE-File." ));
     1695
     1696    //Store modules
     1697    dprintf((LOG, "%d imported Modules: ", cModules ));
     1698
     1699    /* 2) functions */
     1700    pszCurModule = pszModules;
     1701    pOH = (PIMAGE_OPTIONAL_HEADER)OPTHEADEROFF(win32file);
     1702    for (i = 0; i < cModules; i++)
     1703    {
     1704        dprintf((LOG, "Module %s", pszCurModule ));
     1705        if(pID[i].ForwarderChain) {
     1706            dprintf((LOG, "ForwarderChain: %x", pID[i].ForwarderChain));
     1707        }
     1708        //  a) check that OriginalFirstThunk not is 0 and look for Borland-styled PE
     1709        if (i == 0)
    16681710        {
    1669             if (GetSectionHdrByRVA(win32file, &shExtra, pID[i].Name)) {
    1670                 free(pszModules);
    1671                 return FALSE;
    1672             }
    1673         }
    1674         pszTmp = (char*)(pID[i].Name + (ULONG)win32file);
    1675     }
    1676 
    1677     strcpy(pszModules+j, pszTmp);
    1678     j += strlen(pszTmp) + 1;
    1679   }
    1680   if (fBorland)
    1681     dprintf((LOG, "Borland-styled PE-File." ));
    1682 
    1683   //Store modules
    1684   dprintf((LOG, "%d imported Modules: ", cModules ));
    1685 
    1686   /* 2) functions */
    1687   pszCurModule = pszModules;
    1688   pOH = (PIMAGE_OPTIONAL_HEADER)OPTHEADEROFF(win32file);
    1689   for (i = 0; i < cModules; i++)
    1690   {
    1691     dprintf((LOG, "Module %s", pszCurModule ));
    1692     if(pID[i].ForwarderChain) {
    1693         dprintf((LOG, "ForwarderChain: %x", pID[i].ForwarderChain));
    1694     }
    1695     //  a) check that OriginalFirstThunk not is 0 and look for Borland-styled PE
    1696     if (i == 0)
    1697     {
    1698         //heavy borland-style test - assume array of thunks is within that style does not change
    1699         if((ULONG)pID[i].u.OriginalFirstThunk == 0 ||
    1700            (ULONG)pID[i].u.OriginalFirstThunk < shID.VirtualAddress ||
    1701            (ULONG)pID[i].u.OriginalFirstThunk >= shID.VirtualAddress + max(shID.Misc.VirtualSize, shID.SizeOfRawData) ||
    1702            (ULONG)pID[i].u.OriginalFirstThunk >= pOH->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress &&
    1703            (ULONG)pID[i].u.OriginalFirstThunk < sizeof(*pID)*cModules + pOH->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress)
     1711            //heavy borland-style test - assume array of thunks is within that style does not change
     1712            if((ULONG)pID[i].u.OriginalFirstThunk == 0 ||
     1713               (ULONG)pID[i].u.OriginalFirstThunk < shID.VirtualAddress ||
     1714               (ULONG)pID[i].u.OriginalFirstThunk >= shID.VirtualAddress + max(shID.Misc.VirtualSize, shID.SizeOfRawData) ||
     1715               (ULONG)pID[i].u.OriginalFirstThunk >= pOH->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress &&
     1716               (ULONG)pID[i].u.OriginalFirstThunk < sizeof(*pID)*cModules + pOH->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress)
     1717            {
     1718                fBorland = TRUE;
     1719            }
     1720        }
     1721        //light borland-style test
     1722        if (pID[i].u.OriginalFirstThunk == 0 || fBorland) {
     1723             pulImport = (ULONG*)pID[i].FirstThunk;
     1724        }
     1725        else pulImport = (ULONG*)pID[i].u.OriginalFirstThunk;
     1726
     1727        //  b) check if RVA ok
     1728        if (!(pulImport > 0 && (ULONG)pulImport < pOH->SizeOfImage)) {
     1729            dprintf((LOG, "Invalid RVA %x", pulImport ));
     1730            break;
     1731        }
     1732        // check section
     1733        if ((ULONG)pulImport < shExtra.VirtualAddress || (ULONG)pulImport >= shExtra.VirtualAddress + max(shExtra.Misc.VirtualSize, shExtra.SizeOfRawData))
    17041734        {
    1705             fBorland = TRUE;
    1706         }
    1707     }
    1708     //light borland-style test
    1709     if (pID[i].u.OriginalFirstThunk == 0 || fBorland) {
    1710             pulImport = (ULONG*)pID[i].FirstThunk;
    1711     }
    1712     else    pulImport = (ULONG*)pID[i].u.OriginalFirstThunk;
    1713 
    1714     //  b) check if RVA ok
    1715     if (!(pulImport > 0 && (ULONG)pulImport < pOH->SizeOfImage)) {
    1716         dprintf((LOG, "Invalid RVA %x", pulImport ));
    1717         break;
    1718     }
    1719     // check section
    1720     if ((ULONG)pulImport < shExtra.VirtualAddress || (ULONG)pulImport >= shExtra.VirtualAddress + max(shExtra.Misc.VirtualSize, shExtra.SizeOfRawData))
    1721     {
    1722         if (!GetSectionHdrByRVA(win32file, &shExtra, (ULONG)pulImport))
    1723         {
    1724             dprintf((LOG, "warning: could not find section for Thunk RVA %x", pulImport ));
    1725             break;
    1726         }
    1727     }
    1728 
    1729     //SvL: Load dll if needed
    1730     dprintf((LOG, "**********************************************************************" ));
    1731     dprintf((LOG, "************** Import Module %s ", pszCurModule ));
    1732     dprintf((LOG, "**********************************************************************" ));
    1733     WinDll = Win32DllBase::findModule(pszCurModule);
    1734 
    1735     if(WinDll == NULL)
    1736     {  //not found, so load it
    1737         if (WinExe != NULL && WinExe->matchModName(pszCurModule)) {
    1738              WinImage = (Win32ImageBase *)WinExe;
     1735            if (!GetSectionHdrByRVA(win32file, &shExtra, (ULONG)pulImport))
     1736            {
     1737                dprintf((LOG, "warning: could not find section for Thunk RVA %x", pulImport ));
     1738                break;
     1739            }
     1740        }
     1741
     1742        //Load dll if needed
     1743        dprintf((LOG, "**********************************************************************" ));
     1744        dprintf((LOG, "************** Import Module %s ", pszCurModule ));
     1745        dprintf((LOG, "**********************************************************************" ));
     1746        WinDll = Win32DllBase::findModule(pszCurModule);
     1747
     1748        if(WinDll == NULL)
     1749        {  //not found, so load it
     1750            if (WinExe != NULL && WinExe->matchModName(pszCurModule)) {
     1751                WinImage = (Win32ImageBase *)WinExe;
     1752            }
     1753            else {
     1754                WinDll = loadDll(pszCurModule);
     1755                if(WinDll == NULL) {
     1756                    return FALSE;
     1757                }
     1758            }
    17391759        }
    17401760        else {
    1741              WinDll = loadDll(pszCurModule);
    1742              if(WinDll == NULL) {
    1743                  return FALSE;
    1744              }
    1745         }
    1746     }
    1747     else {
    1748         WinDll->AddRef();
    1749         dprintf((LOG, "Already found ", pszCurModule));
    1750     }
    1751     if(WinDll != NULL) {
    1752         //add the dll we just loaded to dependency list for this image
    1753         addDependency(WinDll);
    1754 
    1755         //Make sure the dependency list is correct (already done
    1756         //in the ctor of Win32DllBase, but for LX dlls the parent is
    1757         //then set to NULL; so change it here again
    1758         WinDll->setUnloadOrder(this);
    1759         WinImage = (Win32ImageBase *)WinDll;
    1760     }
    1761     else
    1762     if(WinImage == NULL) {
    1763         dprintf((LOG, "Unable to load dll %s", pszCurModule ));
    1764         return FALSE;
    1765     }
    1766 
    1767     pulImport  = (PULONG)((ULONG)pulImport + (ULONG)win32file);
    1768     j          = 0;
    1769     ulCurFixup = (ULONG)pID[i].FirstThunk + (ULONG)win32file;
    1770 
    1771     section    = findSectionByOS2Addr(ulCurFixup);
    1772     if(section == NULL) {
    1773         dprintf((LOG, "Unable to find section for %x", ulCurFixup ));
    1774         return FALSE;
    1775     }
    1776     //SvL: Read page from disk
    1777     commitPage(ulCurFixup & ~0xfff, FALSE, SINGLE_PAGE);
    1778     //SvL: Enable write access
    1779     DosSetMem((PVOID)(ulCurFixup & ~0xfff), PAGE_SIZE, PAG_READ|PAG_WRITE);
    1780     nrPages    = 1;
    1781 
    1782     while (pulImport[j] != 0) {
    1783         if (pulImport[j] & IMAGE_ORDINAL_FLAG) { //ordinal
    1784             dprintf((LOG, "0x%08x Imported function %s @%d", ulCurFixup , pszCurModule, (pulImport[j] & ~IMAGE_ORDINAL_FLAG) ));
    1785             StoreImportByOrd(WinImage, pulImport[j] & ~IMAGE_ORDINAL_FLAG, ulCurFixup);
    1786         }
    1787         else {  //name
    1788             //check
    1789             if (pulImport[j] < shExtra.VirtualAddress || pulImport[j] >= shExtra.VirtualAddress + max(shExtra.Misc.VirtualSize, shExtra.SizeOfRawData)) {
    1790                 if (!GetSectionHdrByRVA(win32file, &shExtra, pulImport[j]))
     1761            WinDll->AddRef();
     1762            dprintf((LOG, "Already found ", pszCurModule));
     1763        }
     1764        if(WinDll != NULL) {
     1765            //add the dll we just loaded to dependency list for this image
     1766            addDependency(WinDll);
     1767
     1768            //Make sure the dependency list is correct (already done
     1769            //in the ctor of Win32DllBase, but for LX dlls the parent is
     1770            //then set to NULL; so change it here again
     1771            WinDll->setUnloadOrder(this);
     1772            WinImage = (Win32ImageBase *)WinDll;
     1773        }
     1774        else
     1775        if(WinImage == NULL) {
     1776            dprintf((LOG, "Unable to load dll %s", pszCurModule ));
     1777            return FALSE;
     1778        }
     1779
     1780        pulImport  = (PULONG)((ULONG)pulImport + (ULONG)win32file);
     1781        j          = 0;
     1782        ulCurFixup = (ULONG)pID[i].FirstThunk + (ULONG)win32file;
     1783
     1784        section    = findSectionByOS2Addr(ulCurFixup);
     1785        if(section == NULL) {
     1786            dprintf((LOG, "Unable to find section for %x", ulCurFixup ));
     1787            return FALSE;
     1788        }
     1789        //Read page from disk
     1790        commitPage(ulCurFixup & ~0xfff, FALSE, SINGLE_PAGE);
     1791        //Enable write access
     1792        DosSetMem((PVOID)(ulCurFixup & ~0xfff), PAGE_SIZE, PAG_READ|PAG_WRITE);
     1793        nrPages    = 1;
     1794
     1795        while (pulImport[j] != 0) {
     1796            if (pulImport[j] & IMAGE_ORDINAL_FLAG) { //ordinal
     1797                dprintf((LOG, "0x%08x Imported function %s @%d", ulCurFixup , pszCurModule, (pulImport[j] & ~IMAGE_ORDINAL_FLAG) ));
     1798                StoreImportByOrd(WinImage, pulImport[j] & ~IMAGE_ORDINAL_FLAG, ulCurFixup);
     1799            }
     1800            else {  //name
     1801                //check
     1802                if (pulImport[j] < shExtra.VirtualAddress || pulImport[j] >= shExtra.VirtualAddress + max(shExtra.Misc.VirtualSize, shExtra.SizeOfRawData))
    17911803                {
    1792                     dprintf((LOG, "warning: could not find section for Import Name RVA ", pulImport[j] ));
    1793                     break;
    1794                 }
    1795             }
    1796             //KSO - Aug 6 1998 1:15am:this eases comparing...
    1797             char *pszFunctionName = (char*)(pulImport[j] + (ULONG)win32file + 2);
    1798             dprintf((LOG, "0x%08x Imported function %s (0x%08x)", ulCurFixup,  pszFunctionName, WinImage->getApi(pszFunctionName)));
    1799             StoreImportByName(WinImage, pszFunctionName, ulCurFixup);
    1800         }
    1801         ulCurFixup += sizeof(IMAGE_THUNK_DATA);
    1802         j++;
    1803         if((ulCurFixup & 0xfff) == 0) {
    1804             commitPage(ulCurFixup & ~0xfff, FALSE, SINGLE_PAGE);
    1805             DosSetMem((PVOID)(ulCurFixup & ~0xfff), PAGE_SIZE, PAG_READ|PAG_WRITE);
    1806             nrPages++;
    1807         }
    1808     }
    1809     //SvL: And restore original protection flags
    1810     ulCurFixup = (ULONG)pID[i].FirstThunk + pOH->ImageBase;
    1811     DosSetMem((PVOID)(ulCurFixup & ~0xfff), PAGE_SIZE*nrPages, section->pageflags);
    1812 
    1813     dprintf((LOG, "**********************************************************************" ));
    1814     dprintf((LOG, "************** End Import Module %s ", pszCurModule ));
    1815     dprintf((LOG, "**********************************************************************" ));
    1816 
    1817     pszCurModule += strlen(pszCurModule) + 1;
    1818   }//for (i = 0; i < cModules; i++)
    1819 
    1820   free(pszModules);
    1821   return TRUE;
     1804                    if (!GetSectionHdrByRVA(win32file, &shExtra, pulImport[j]))
     1805                    {
     1806                        dprintf((LOG, "warning: could not find section for Import Name RVA ", pulImport[j] ));
     1807                        break;
     1808                    }
     1809                }
     1810                //KSO - Aug 6 1998 1:15am:this eases comparing...
     1811                char *pszFunctionName = (char*)(pulImport[j] + (ULONG)win32file + 2);
     1812                dprintf((LOG, "0x%08x Imported function %s (0x%08x)", ulCurFixup,  pszFunctionName, WinImage->getApi(pszFunctionName)));
     1813                StoreImportByName(WinImage, pszFunctionName, ulCurFixup);
     1814            }
     1815            ulCurFixup += sizeof(IMAGE_THUNK_DATA);
     1816            j++;
     1817            if((ulCurFixup & 0xfff) == 0) {
     1818                commitPage(ulCurFixup & ~0xfff, FALSE, SINGLE_PAGE);
     1819                DosSetMem((PVOID)(ulCurFixup & ~0xfff), PAGE_SIZE, PAG_READ|PAG_WRITE);
     1820                nrPages++;
     1821            }
     1822        }
     1823        //SvL: And restore original protection flags
     1824        ulCurFixup = (ULONG)pID[i].FirstThunk + pOH->ImageBase;
     1825        DosSetMem((PVOID)(ulCurFixup & ~0xfff), PAGE_SIZE*nrPages, section->pageflags);
     1826
     1827        dprintf((LOG, "**********************************************************************" ));
     1828        dprintf((LOG, "************** End Import Module %s ", pszCurModule ));
     1829        dprintf((LOG, "**********************************************************************" ));
     1830
     1831        pszCurModule += strlen(pszCurModule) + 1;
     1832    }//for (i = 0; i < cModules; i++)
     1833    return TRUE;
    18221834}
    18231835//******************************************************************************
     
    18981910   * with the linear search.
    18991911   */
    1900  
     1912
    19011913  // start in the middle of the tree
    19021914  i = nrOrdExportsRegistered >> 1;
    19031915  int iStep = i;
    1904  
     1916
    19051917  for(;;)
    19061918  {
    19071919    int iThisExport = curexport[i].ordinal;
    1908    
     1920
    19091921    iStep >>= 1;                    // next step will be narrower
    19101922
     
    19601972        }
    19611973      }
    1962      
     1974
    19631975      // not found yet.
    19641976      break;
  • trunk/src/kernel32/wprocess.cpp

    r5666 r5932  
    1 /* $Id: wprocess.cpp,v 1.120 2001-05-07 10:07:40 phaller Exp $ */
     1/* $Id: wprocess.cpp,v 1.121 2001-06-08 11:04:26 sandervl Exp $ */
    22
    33/*
     
    16961696   
    16971697    DWORD Characteristics, SubSystem;
    1698     if(Win32ImageBase::isPEImage(exename, &Characteristics, &SubSystem)) {
    1699         dprintf(("CreateProcess: not a PE executable!!"));
    1700         SetLastError(ERROR_BAD_EXE_FORMAT);
    1701         return FALSE;
    1702     }
    1703 
    1704     char *lpszPE;
    1705     if(SubSystem == IMAGE_SUBSYSTEM_WINDOWS_CUI) {
    1706          lpszPE = "PEC.EXE";
    1707     }
    1708     else lpszPE = "PE.EXE";
    1709 
    1710     //SvL: Allright. Before we call O32_CreateProcess, we must take care of
    1711     //     lpCurrentDirectory ourselves. (Open32 ignores it!)
    1712     if(lpCurrentDirectory) {
    1713         char *newcmdline;
    1714 
    1715         newcmdline = (char *)malloc(strlen(lpCurrentDirectory) + strlen(cmdline) + 32);
    1716         sprintf(newcmdline, "%s /OPT:[CURDIR=%s] %s", lpszPE, lpCurrentDirectory, cmdline);
    1717         free(cmdline);
    1718         cmdline = newcmdline;
    1719     }
    1720     else {
    1721         char *newcmdline;
    1722 
    1723         newcmdline = (char *)malloc(strlen(cmdline) + 16);
    1724         sprintf(newcmdline, "%s %s", lpszPE, cmdline);
    1725         free(cmdline);
    1726         cmdline = newcmdline;
    1727     }
    1728     rc = O32_CreateProcess(lpszPE, (LPCSTR)cmdline,lpProcessAttributes,
    1729                          lpThreadAttributes, bInheritHandles, dwCreationFlags,
    1730                          lpEnvironment, lpCurrentDirectory, lpStartupInfo,
    1731                          lpProcessInfo);
     1698    if(Win32ImageBase::isPEImage(exename, &Characteristics, &SubSystem) == 0) {
     1699        char *lpszPE;
     1700        if(SubSystem == IMAGE_SUBSYSTEM_WINDOWS_CUI) {
     1701             lpszPE = "PEC.EXE";
     1702        }
     1703        else lpszPE = "PE.EXE";
     1704   
     1705        //SvL: Allright. Before we call O32_CreateProcess, we must take care of
     1706        //     lpCurrentDirectory ourselves. (Open32 ignores it!)
     1707        if(lpCurrentDirectory) {
     1708            char *newcmdline;
     1709   
     1710            newcmdline = (char *)malloc(strlen(lpCurrentDirectory) + strlen(cmdline) + 32);
     1711            sprintf(newcmdline, "%s /OPT:[CURDIR=%s] %s", lpszPE, lpCurrentDirectory, cmdline);
     1712            free(cmdline);
     1713            cmdline = newcmdline;
     1714        }
     1715        else {
     1716            char *newcmdline;
     1717
     1718            newcmdline = (char *)malloc(strlen(cmdline) + 16);
     1719            sprintf(newcmdline, "%s %s", lpszPE, cmdline);
     1720            free(cmdline);
     1721            cmdline = newcmdline;
     1722        }
     1723        rc = O32_CreateProcess(lpszPE, (LPCSTR)cmdline,lpProcessAttributes,
     1724                               lpThreadAttributes, bInheritHandles, dwCreationFlags,
     1725                               lpEnvironment, lpCurrentDirectory, lpStartupInfo,
     1726                               lpProcessInfo);
     1727    }
     1728    else {//16 bits windows app
     1729        rc = O32_CreateProcess(NULL, (LPCSTR)cmdline,lpProcessAttributes,
     1730                               lpThreadAttributes, bInheritHandles, dwCreationFlags,
     1731                               lpEnvironment, lpCurrentDirectory, lpStartupInfo,
     1732                               lpProcessInfo);
     1733    }
    17321734    if(rc == TRUE)
    17331735    {
     
    17951797 PROCESS_INFORMATION procinfo;
    17961798 DWORD               rc;
     1799 HINSTANCE           hInstance;
    17971800
    17981801    dprintf(("KERNEL32: WinExec %s\n", lpCmdLine));
     
    18011804                      &startinfo, &procinfo) == FALSE)
    18021805    {
    1803         return 0;
     1806        hInstance = (HINSTANCE)GetLastError();
     1807        if(hInstance >= 32) {
     1808            hInstance = 11;
     1809        }
     1810        dprintf(("KERNEL32: WinExec failed with rc %d", hInstance));
     1811        return hInstance;
    18041812    }
    18051813    //block until the launched app waits for input (or a timeout of 15 seconds)
     
    18091817        dprintf(("WinExec: WaitForInputIdle %x returned %x", procinfo.hProcess, rc));
    18101818    }
    1811     return procinfo.hProcess; //correct?
     1819    CloseHandle(procinfo.hThread);
     1820    CloseHandle(procinfo.hProcess);
     1821    return 33;
    18121822}
    18131823//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.