Changeset 1844 for trunk/src


Ignore:
Timestamp:
Nov 26, 1999, 1:05:20 AM (26 years ago)
Author:
sandervl
Message:

Allow executable api exports

Location:
trunk/src/kernel32
Files:
9 edited

Legend:

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

    r1811 r1844  
    1 /* $Id: oslibdos.cpp,v 1.9 1999-11-22 20:35:50 sandervl Exp $ */
     1/* $Id: oslibdos.cpp,v 1.10 1999-11-26 00:05:18 sandervl Exp $ */
    22
    33/*
     
    4747  if(size != cb) {
    4848        dprintf(("ERROR: OSLibDosAliasMem: size != cb (%x!=%x)!!!!!!!!", size, cb));
    49         return 5;
     49        //ignore this and continue return 5;
     50        attr = fl; //just use original protection flags (NOT CORRECT)
    5051  }
    5152  attr &= (PAG_READ|PAG_WRITE|PAG_EXECUTE|PAG_GUARD|PAG_DEFAULT);
  • trunk/src/kernel32/windlllx.cpp

    r1423 r1844  
    1 /* $Id: windlllx.cpp,v 1.4 1999-10-23 23:02:17 sandervl Exp $ */
     1/* $Id: windlllx.cpp,v 1.5 1999-11-26 00:05:19 sandervl Exp $ */
    22
    33/*
     
    114114//******************************************************************************
    115115//******************************************************************************
    116 ULONG Win32LxDll::getApi(char *name)
    117 {
    118   APIRET      rc;
    119   ULONG       apiaddr;
    120 
    121   rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr);
    122   if(rc) 
    123   {
    124         if(rc == ERROR_INVALID_HANDLE)
    125         {//handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
    126                 char szErrName[CCHMAXPATH];
    127 
    128                 rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hinstance);
    129                 if(!rc)
    130                         rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr);
    131         }
    132         if(rc)  return(0);
    133   }
    134   return(apiaddr);
    135 }
    136 //******************************************************************************
    137 //******************************************************************************
    138 ULONG Win32LxDll::getApi(int ordinal)
    139 {
    140  APIRET      rc;
    141  ULONG       apiaddr;
    142 
    143   rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr);
    144   if(rc) {
    145         if(rc == ERROR_INVALID_HANDLE)
    146         {//handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
    147                 char szErrName[CCHMAXPATH];
    148 
    149                 rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hinstance);
    150                 if(!rc)
    151                         rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr);
    152         }
    153         if(rc)  return(0);
    154   }
    155   return(apiaddr);
    156 }
    157 //******************************************************************************
    158 //******************************************************************************
    159116BOOL Win32LxDll::isLxDll()
    160117{
  • trunk/src/kernel32/windllpe2lx.cpp

    r1325 r1844  
    1 /* $Id: windllpe2lx.cpp,v 1.3 1999-10-17 01:49:08 bird Exp $ */
     1/* $Id: windllpe2lx.cpp,v 1.4 1999-11-26 00:05:19 sandervl Exp $ */
    22
    33/*
     
    168168
    169169/**
    170  * Gets pointer to an exported procedure by procedure name.
    171  * @returns   Address of exported procedure. 0UL if not found.
    172  * @param     name  Exported procedure name.
    173  * @status    completely implemented.
    174  * @author    Sander van Leeuwen
    175  * @remark
    176  */
    177 ULONG Win32Pe2LxDll::getApi(char *name)
    178 {
    179     APIRET      rc;
    180     ULONG       ulApiAddr;
    181 
    182     rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&ulApiAddr);
    183     return rc == NO_ERROR ? ulApiAddr : 0;
    184 }
    185 
    186 
    187 /**
    188  * Gets pointer to an exported procedure by ordinal.
    189  * @returns   Pointer to an exported procedure. 0UL if not found.
    190  * @param     ordinal  Export ordinal number.
    191  * @status    completely implemented.
    192  * @author    Sander van Leeuwen
    193  * @remark    FIXME:
    194  *            This function should be implemented for both Exe and Dll images!
    195  *            It could be done similar in both peldr image and pe2lx images by
    196  *            accessing PE structures.
    197  */
    198 ULONG Win32Pe2LxDll::getApi(int ordinal)
    199 {
    200     APIRET      rc;
    201     ULONG       ulApiAddr;
    202 
    203     rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&ulApiAddr);
    204 
    205     return rc == NO_ERROR ? ulApiAddr : 0;
    206 }
    207 
    208 
    209 /**
    210170 * Simple question: -Native LX dll?
    211171 *                  -No!
  • trunk/src/kernel32/windllpeldr.cpp

    r1833 r1844  
    1 /* $Id: windllpeldr.cpp,v 1.3 1999-11-24 19:31:23 sandervl Exp $ */
     1/* $Id: windllpeldr.cpp,v 1.4 1999-11-26 00:05:19 sandervl Exp $ */
    22
    33/*
     
    8181//******************************************************************************
    8282//******************************************************************************
    83 ULONG Win32PeLdrDll::getApi(char *name)
    84 {
    85   ULONG       apiaddr, i, apilen;
    86   char       *apiname;
    87   char        tmp[4];
    88   NameExport *curexport;
    89   ULONG       ulAPIOrdinal;                      /* api requested by ordinal */
    90  
    91   apilen = strlen(name) + 1;
    92   if(apilen < 4)
    93   {
    94         *(ULONG *)tmp = 0;
    95         strcpy(tmp, name);
    96         apiname = tmp;
    97   }
    98   else  apiname = name;
    99 
    100   curexport = nameexports;
    101   for(i=0; i<nrNameExports; i++)
    102   {
    103     if(apilen == curexport->nlength &&
    104        *(ULONG *)curexport->name == *(ULONG *)name)
    105     {
    106         if(strcmp(curexport->name, name) == 0)
    107                 return(curexport->virtaddr);
    108     }
    109     curexport = (NameExport *)((ULONG)curexport->name + curexport->nlength);
    110   }
    111   return(0);
    112 }
    113 //******************************************************************************
    114 //******************************************************************************
    115 ULONG Win32PeLdrDll::getApi(int ordinal)
    116 {
    117  ULONG       apiaddr, i;
    118  OrdExport  *curexport;
    119  NameExport *nexport;
    120 
    121   curexport = ordexports;
    122   for(i=0;i<nrOrdExports;i++) {
    123         if(curexport->ordinal == ordinal)
    124                 return(curexport->virtaddr);
    125         curexport++;
    126   }
    127   //Name exports also contain an ordinal, so check this
    128   nexport = nameexports;
    129   for(i=0;i<nrNameExports;i++) {
    130         if(nexport->ordinal == ordinal)
    131                 return(nexport->virtaddr);
    132 
    133         nexport = (NameExport *)((ULONG)nexport->name + nexport->nlength);
    134   }
    135   return(0);
    136 }
    137 //******************************************************************************
    138 //******************************************************************************
    13983BOOL Win32PeLdrDll::isLxDll()
    14084{
  • trunk/src/kernel32/winfakepeldr.cpp

    r1833 r1844  
    1 /* $Id: winfakepeldr.cpp,v 1.2 1999-11-24 19:31:23 sandervl Exp $ */
     1/* $Id: winfakepeldr.cpp,v 1.3 1999-11-26 00:05:19 sandervl Exp $ */
    22
    33/*
     
    4949//******************************************************************************
    5050//******************************************************************************
     51ULONG Win32PeLdrRsrcImg::getApi(char *name)
     52{
     53   DebugInt3();
     54   return 0;
     55}
     56//******************************************************************************
     57//******************************************************************************
     58ULONG Win32PeLdrRsrcImg::getApi(int ordinal)
     59{
     60   DebugInt3();
     61   return 0;
     62}
     63//******************************************************************************
     64//******************************************************************************
  • trunk/src/kernel32/winimagelx.cpp

    r1131 r1844  
    1 /* $Id: winimagelx.cpp,v 1.3 1999-10-04 20:52:33 sandervl Exp $ */
     1/* $Id: winimagelx.cpp,v 1.4 1999-11-26 00:05:19 sandervl Exp $ */
    22
    33/*
     
    6868//******************************************************************************
    6969//******************************************************************************
     70ULONG Win32LxImage::getApi(char *name)
     71{
     72  APIRET      rc;
     73  ULONG       apiaddr;
    7074
     75  rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr);
     76  if(rc) 
     77  {
     78        if(rc == ERROR_INVALID_HANDLE)
     79        {//handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
     80                char szErrName[CCHMAXPATH];
     81
     82                rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hinstance);
     83                if(!rc)
     84                        rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr);
     85        }
     86        if(rc)  return(0);
     87  }
     88  return(apiaddr);
     89}
     90//******************************************************************************
     91//******************************************************************************
     92ULONG Win32LxImage::getApi(int ordinal)
     93{
     94 APIRET      rc;
     95 ULONG       apiaddr;
     96
     97  rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr);
     98  if(rc) {
     99        if(rc == ERROR_INVALID_HANDLE)
     100        {//handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
     101                char szErrName[CCHMAXPATH];
     102
     103                rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hinstance);
     104                if(!rc)
     105                        rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr);
     106        }
     107        if(rc)  return(0);
     108  }
     109  return(apiaddr);
     110}
     111//******************************************************************************
     112//******************************************************************************
     113
  • trunk/src/kernel32/winimagepe2lx.cpp

    r1767 r1844  
    1 /* $Id: winimagepe2lx.cpp,v 1.5 1999-11-18 08:55:06 bird Exp $ */
     1/* $Id: winimagepe2lx.cpp,v 1.6 1999-11-26 00:05:19 sandervl Exp $ */
    22
    33/*
     
    1616#define INCL_DOSERRORS          /* DOS Error values */
    1717#define INCL_DOSPROFILE         /* DosQuerySysState (Toolkit 4.5) */
     18#define INCL_DOSMODULEMGR   /* DOS Module management */
    1819
    1920#define ALIGN(a, alignment) (((a) + (alignment - 1UL)) & ~(alignment - 1UL))
     
    524525}
    525526
     527/**
     528 * Gets pointer to an exported procedure by procedure name.
     529 * @returns   Address of exported procedure. 0UL if not found.
     530 * @param     name  Exported procedure name.
     531 * @status    completely implemented.
     532 * @author    Sander van Leeuwen
     533 * @remark
     534 */
     535ULONG Win32Pe2LxImage::getApi(char *name)
     536{
     537    APIRET      rc;
     538    ULONG       ulApiAddr;
     539
     540    rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&ulApiAddr);
     541    return rc == NO_ERROR ? ulApiAddr : 0;
     542}
     543
     544
     545/**
     546 * Gets pointer to an exported procedure by ordinal.
     547 * @returns   Pointer to an exported procedure. 0UL if not found.
     548 * @param     ordinal  Export ordinal number.
     549 * @status    completely implemented.
     550 * @author    Sander van Leeuwen
     551 * @remark    FIXME:
     552 *            This function should be implemented for both Exe and Dll images!
     553 *            It could be done similar in both peldr image and pe2lx images by
     554 *            accessing PE structures.
     555 */
     556ULONG Win32Pe2LxImage::getApi(int ordinal)
     557{
     558    APIRET      rc;
     559    ULONG       ulApiAddr;
     560
     561    rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&ulApiAddr);
     562
     563    return rc == NO_ERROR ? ulApiAddr : 0;
     564}
  • trunk/src/kernel32/winimagepeldr.cpp

    r1835 r1844  
    1 /* $Id: winimagepeldr.cpp,v 1.16 1999-11-24 19:52:34 sandervl Exp $ */
     1/* $Id: winimagepeldr.cpp,v 1.17 1999-11-26 00:05:19 sandervl Exp $ */
    22
    33/*
     
    315315                tlsDir = (IMAGE_TLS_DIRECTORY *)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_TLS);
    316316                if(tlsDir) {
    317                         fout << "TLS Directory" << endl;
    318                         fout << "TLS Address of Index     " << hex((ULONG)tlsDir->AddressOfIndex) << endl;
    319                         fout << "TLS Address of Callbacks " << hex((ULONG)tlsDir->AddressOfCallBacks) << endl;
    320                         fout << "TLS SizeOfZeroFill       " << hex(tlsDir->SizeOfZeroFill) << endl;
    321                         fout << "TLS Characteristics      " << hex(tlsDir->Characteristics) << endl;
    322317                        addSection(SECTION_TLS, psh[i].PointerToRawData,
    323318                                   psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase,
     
    440435                goto failure;
    441436        }
     437        fout << "TLS Directory" << endl;
     438        fout << "TLS Address of Index     " << hex((ULONG)tlsDir->AddressOfIndex) << endl;
     439        fout << "TLS Address of Callbacks " << hex((ULONG)tlsDir->AddressOfCallBacks) << endl;
     440        fout << "TLS SizeOfZeroFill       " << hex(tlsDir->SizeOfZeroFill) << endl;
     441        fout << "TLS Characteristics      " << hex(tlsDir->Characteristics) << endl;
    442442        setTLSAddress((char *)sect->realvirtaddr);
    443443        setTLSInitSize(tlsDir->EndAddressOfRawData - tlsDir->StartAddressOfRawData);
     
    463463        commitPage((ULONG)pFixups, FALSE);
    464464   }
    465    if(fh.Characteristics & IMAGE_FILE_DLL) {
     465//   if(fh.Characteristics & IMAGE_FILE_DLL) {
    466466        if(processExports((char *)win32file) == FALSE) {
    467467                fout << "Failed to process exported apis" << endl;
    468468                goto failure;
    469469        }
    470    }
     470//   }
    471471  }
    472472
     
    14321432//******************************************************************************
    14331433//******************************************************************************
     1434ULONG Win32PeLdrImage::getApi(char *name)
     1435{
     1436  ULONG       apiaddr, i, apilen;
     1437  char       *apiname;
     1438  char        tmp[4];
     1439  NameExport *curexport;
     1440  ULONG       ulAPIOrdinal;                      /* api requested by ordinal */
     1441 
     1442  apilen = strlen(name) + 1;
     1443  if(apilen < 4)
     1444  {
     1445        *(ULONG *)tmp = 0;
     1446        strcpy(tmp, name);
     1447        apiname = tmp;
     1448  }
     1449  else  apiname = name;
     1450
     1451  curexport = nameexports;
     1452  for(i=0; i<nrNameExports; i++)
     1453  {
     1454    if(apilen == curexport->nlength &&
     1455       *(ULONG *)curexport->name == *(ULONG *)name)
     1456    {
     1457        if(strcmp(curexport->name, name) == 0)
     1458                return(curexport->virtaddr);
     1459    }
     1460    curexport = (NameExport *)((ULONG)curexport->name + curexport->nlength);
     1461  }
     1462  return(0);
     1463}
     1464//******************************************************************************
     1465//******************************************************************************
     1466ULONG Win32PeLdrImage::getApi(int ordinal)
     1467{
     1468 ULONG       apiaddr, i;
     1469 OrdExport  *curexport;
     1470 NameExport *nexport;
     1471
     1472  curexport = ordexports;
     1473  for(i=0;i<nrOrdExports;i++) {
     1474        if(curexport->ordinal == ordinal)
     1475                return(curexport->virtaddr);
     1476        curexport++;
     1477  }
     1478  //Name exports also contain an ordinal, so check this
     1479  nexport = nameexports;
     1480  for(i=0;i<nrNameExports;i++) {
     1481        if(nexport->ordinal == ordinal)
     1482                return(nexport->virtaddr);
     1483
     1484        nexport = (NameExport *)((ULONG)nexport->name + nexport->nlength);
     1485  }
     1486  return(0);
     1487}
     1488//******************************************************************************
     1489//******************************************************************************
    14341490ULONG MissingApi()
    14351491{
  • trunk/src/kernel32/wprocess.cpp

    r1811 r1844  
    1 /* $Id: wprocess.cpp,v 1.50 1999-11-22 20:35:52 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.51 1999-11-26 00:05:20 sandervl Exp $ */
    22
    33/*
     
    684684FARPROC WIN32API GetProcAddress(HMODULE hModule, LPCSTR lpszProc)
    685685{
    686  Win32DllBase *winmod;
     686 Win32ImageBase *winmod;
    687687 FARPROC   proc;
    688688 ULONG     ulAPIOrdinal;
    689689
    690   winmod = Win32DllBase::findModule((HINSTANCE)hModule);
     690  if(hModule == 0 || hModule == -1 || (WinExe && hModule == WinExe->getInstanceHandle())) {
     691        winmod = WinExe;
     692  }
     693  else  winmod = (Win32ImageBase *)Win32DllBase::findModule((HINSTANCE)hModule);
     694
    691695  if(winmod) {
    692696        ulAPIOrdinal = (ULONG)lpszProc;
Note: See TracChangeset for help on using the changeset viewer.