Changeset 9617 for trunk/src


Ignore:
Timestamp:
Jan 5, 2003, 1:31:26 PM (23 years ago)
Author:
sandervl
Message:

added dll load hook and function to override named or ordinal exports

Location:
trunk/src/kernel32
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/KERNEL32.DEF

    r9537 r9617  
    1 ; $Id: KERNEL32.DEF,v 1.147 2002-12-20 11:39:40 sandervl Exp $
     1; $Id: KERNEL32.DEF,v 1.148 2003-01-05 12:31:22 sandervl Exp $
    22
    33;Basis is Windows95 KERNEL32
     
    12101210    OSLibDosDevIOCtl                                              @2026 NONAME
    12111211
     1212; custom dll hook installer
     1213    _ODIN_SetDllLoadCallback@4                                    @2100 NONAME
     1214; override export
     1215    _ODIN_SetProcAddress@12                                       @2101 NONAME
     1216
    12121217    GetDisplayCodepage                                            @3000 NONAME
    12131218    GetWindowsCodepage                                            @3001 NONAME
  • trunk/src/kernel32/kernel32dbg.def

    r9537 r9617  
    1 ; $Id: kernel32dbg.def,v 1.22 2002-12-20 11:39:41 sandervl Exp $
     1; $Id: kernel32dbg.def,v 1.23 2003-01-05 12:31:23 sandervl Exp $
    22
    33;Basis is Windows95 KERNEL32
     
    12101210    OSLibDosDevIOCtl                                              @2026 NONAME
    12111211
     1212; custom dll hook installer
     1213    _ODIN_SetDllLoadCallback@4                                    @2100 NONAME
     1214; override export
     1215    _ODIN_SetProcAddress@12                                       @2101 NONAME
     1216
    12121217    GetDisplayCodepage                                            @3000 NONAME
    12131218    GetWindowsCodepage                                            @3001 NONAME
  • trunk/src/kernel32/oslibdebug.h

    r8504 r9617  
    1 /* $Id: oslibdebug.h,v 1.2 2002-05-28 09:53:34 sandervl Exp $ */
     1/* $Id: oslibdebug.h,v 1.3 2003-01-05 12:31:23 sandervl Exp $ */
    22
    33/*
     
    1313#define __OSLIBDEBUG_H__
    1414
     15#ifdef __cplusplus
     16extern "C" {
     17#endif
     18
    1519#ifndef PAGE_SIZE
    1620#define PAGE_SIZE 4096
     
    2327VOID OSLibDebugReadMemory(LPCVOID lpBaseAddress,LPVOID lpBuffer, DWORD cbRead, LPDWORD lpNumberOfBytesRead);
    2428BOOL OSLibAddWin32Event(LPDEBUG_EVENT lpde);
     29
     30#ifdef __cplusplus
     31}
     32#endif
     33
    2534#endif //__OSLIBDEBUG_H__
  • trunk/src/kernel32/oslibdos.h

    r9530 r9617  
    1 /* $Id: oslibdos.h,v 1.49 2002-12-19 12:55:27 sandervl Exp $ */
     1/* $Id: oslibdos.h,v 1.50 2003-01-05 12:31:24 sandervl Exp $ */
    22
    33/*
     
    1313#define __OSLIBDOS_H__
    1414
     15#ifdef __cplusplus
     16extern "C" {
     17#endif
    1518
    1619#ifdef OS2_INCLUDED
     
    358361DWORD OSLibDosGetNumPhysDrives();
    359362
     363#ifdef __cplusplus
     364}
     365#endif
     366
    360367#endif //__OSLIBDOS_H__
    361368
  • trunk/src/kernel32/oslibexcept.h

    r4224 r9617  
    1 /* $Id: oslibexcept.h,v 1.2 2000-09-08 18:07:50 sandervl Exp $ */
     1/* $Id: oslibexcept.h,v 1.3 2003-01-05 12:31:24 sandervl Exp $ */
    22/*
    33 * Exception handler util. procedures
     
    88#ifndef __OSLIBEXCEPT_H__
    99#define __OSLIBEXCEPT_H__
     10
     11#ifdef __cplusplus
     12extern "C" {
     13#endif
    1014
    1115//******************************************************************************
     
    1822                                     PCONTEXTRECORD pContextRec, PVOID p);
    1923
     24#ifdef __cplusplus
     25}
    2026#endif
     27
     28#endif
  • trunk/src/kernel32/osliblvm.h

    r9304 r9617  
    1 /* $Id: osliblvm.h,v 1.4 2002-09-27 14:35:56 sandervl Exp $ */
     1/* $Id: osliblvm.h,v 1.5 2003-01-05 12:31:24 sandervl Exp $ */
    22/*
    33 * OS/2 LVM (Logical Volume Management) functions
     
    1010#ifndef __OSLIBLVM_H__
    1111#define __OSLIBLVM_H__
     12
     13#ifdef __cplusplus
     14extern "C" {
     15#endif
    1216
    1317#include <win\winioctl.h>
     
    345349BOOL   OSLibLVMGetDiskGeometry(DWORD dwDiskNr, PDISK_GEOMETRY pGeom);
    346350
     351#ifdef __cplusplus
     352}
     353#endif
     354
    347355#endif //__OSLIBLVM_H__
  • trunk/src/kernel32/oslibmem.h

    r8882 r9617  
    1 /* $Id: oslibmem.h,v 1.2 2002-07-16 08:16:48 sandervl Exp $ */
     1/* $Id: oslibmem.h,v 1.3 2003-01-05 12:31:24 sandervl Exp $ */
    22/*
    33 * OS/2 Memory management procedures
     
    88#ifndef __OSLIBMEM_H__
    99#define __OSLIBMISC_H__
     10
     11#ifdef __cplusplus
     12extern "C" {
     13#endif
    1014
    1115#ifndef __OS2_H__
     
    5054PVOID OSLibDosFindMemBase(LPVOID lpMemAddr);
    5155
     56#ifdef __cplusplus
     57}
     58#endif
    5259
    5360#endif
  • trunk/src/kernel32/oslibmisc.h

    r9582 r9617  
    1 /* $Id: oslibmisc.h,v 1.10 2003-01-02 11:50:46 sandervl Exp $ */
     1/* $Id: oslibmisc.h,v 1.11 2003-01-05 12:31:24 sandervl Exp $ */
    22/*
    33 * Misc util. procedures
     
    1313char *OSLibGetDllName(ULONG hModule);
    1414BOOL  OSLibGetDllName(ULONG hModule, char *name, int length);
     15
     16#ifdef __cplusplus
     17extern "C" {
     18#endif
    1519
    1620char *OSLibStripPath(char *path);
     
    9094ULONG OSLibQueryCountry();
    9195
     96#ifdef __cplusplus
     97}
    9298#endif
     99
     100#endif
  • trunk/src/kernel32/oslibtime.h

    r8775 r9617  
    1 /* $Id: oslibtime.h,v 1.1 2002-06-26 07:14:18 sandervl Exp $ */
     1/* $Id: oslibtime.h,v 1.2 2003-01-05 12:31:24 sandervl Exp $ */
    22/*
    33 * OS/2 time procedures
     
    1111#define __OSLIBTIME_H__
    1212
     13#ifdef __cplusplus
     14extern "C" {
     15#endif
     16
    1317ULONG OSLibDosGetTickCount();
    1418
     19#ifdef __cplusplus
     20}
     21#endif
     22
    1523#endif //__OSLIBTIME_H__
  • trunk/src/kernel32/windllbase.cpp

    r9533 r9617  
    1 /* $Id: windllbase.cpp,v 1.31 2002-12-20 10:38:57 sandervl Exp $ */
     1/* $Id: windllbase.cpp,v 1.32 2003-01-05 12:31:25 sandervl Exp $ */
    22
    33/*
  • trunk/src/kernel32/winimagebase.cpp

    r8327 r9617  
    1 /* $Id: winimagebase.cpp,v 1.35 2002-04-29 17:05:30 sandervl Exp $ */
     1/* $Id: winimagebase.cpp,v 1.36 2003-01-05 12:31:25 sandervl Exp $ */
    22
    33/*
     
    151151  //dummy
    152152  return 0;
     153}
     154//******************************************************************************
     155//******************************************************************************
     156ULONG Win32ImageBase::setApi(char *name, ULONG pfnNewProc)
     157{
     158    return -1; //only implemented for PE modules
     159}
     160//******************************************************************************
     161//******************************************************************************
     162ULONG Win32ImageBase::setApi(int ordinal, ULONG pfnNewProc)
     163{
     164    return -1; //only implemented for PE modules
    153165}
    154166//******************************************************************************
  • trunk/src/kernel32/winimagebase.h

    r9537 r9617  
    1 /* $Id: winimagebase.h,v 1.22 2002-12-20 11:39:41 sandervl Exp $ */
     1/* $Id: winimagebase.h,v 1.23 2003-01-05 12:31:25 sandervl Exp $ */
    22
    33/*
     
    113113virtual ULONG getApi(int ordinal) = 0;
    114114
     115virtual ULONG setApi(char *name, ULONG pfnNewProc);
     116virtual ULONG setApi(int ordinal, ULONG pfnNewProc);
     117
    115118virtual ULONG getImageSize();
    116119
  • trunk/src/kernel32/winimagepeldr.cpp

    r9537 r9617  
    1 /* $Id: winimagepeldr.cpp,v 1.102 2002-12-20 11:39:42 sandervl Exp $ */
     1/* $Id: winimagepeldr.cpp,v 1.103 2003-01-05 12:31:25 sandervl Exp $ */
    22
    33/*
     
    4444#include <win32api.h>
    4545#include <heapcode.h>
     46#include <custombuild.h>
    4647#include "winimagebase.h"
    4748#include "winimagepeldr.h"
     
    13721373}
    13731374//******************************************************************************
     1375//Install a hook that gets called when the exports have been processed
     1376//******************************************************************************
     1377static ODINPROC_DLLLOAD pfnDllLoad = NULL;
     1378//******************************************************************************
     1379BOOL WIN32API ODIN_SetDllLoadCallback(ODINPROC_DLLLOAD pfnMyDllLoad)
     1380{
     1381    pfnDllLoad = pfnMyDllLoad;
     1382    return TRUE;
     1383}
     1384//******************************************************************************
    13741385//******************************************************************************
    13751386BOOL Win32PeLdrImage::processExports(char *win32file)
     
    14371448        }
    14381449    }
     1450  }
     1451
     1452  //Call the dll load hook; must be done here so noone has the opportunity
     1453  //to use this dll (get exports)
     1454  if(pfnDllLoad) {
     1455      pfnDllLoad(hinstance);
    14391456  }
    14401457
     
    19151932//******************************************************************************
    19161933//******************************************************************************
    1917 ULONG Win32PeLdrImage::getApi(char *name)
     1934NameExport *Win32PeLdrImage::findApi(char *name)
    19181935{
    19191936  ULONG       apiaddr, i, apilen;
     
    19401957        {
    19411958            if(strcmp(curexport->name, apiname) == 0)
    1942                 return(curexport->virtaddr);
     1959                return curexport;
    19431960        }
    19441961        curexport = (NameExport *)((ULONG)curexport->name + curexport->nlength);
    19451962    }
    1946     return(0);
    1947 }
    1948 //******************************************************************************
    1949 //******************************************************************************
    1950 ULONG Win32PeLdrImage::getApi(int ordinal)
     1963    return NULL;
     1964}
     1965//******************************************************************************
     1966//******************************************************************************
     1967ULONG Win32PeLdrImage::getApi(char *name)
     1968{
     1969    NameExport *curexport;
     1970
     1971    curexport = findApi(name);
     1972    if(curexport) {
     1973        return(curexport->virtaddr);
     1974    }
     1975    return 0;
     1976}
     1977//******************************************************************************
     1978//Override a name export
     1979//******************************************************************************
     1980ULONG Win32PeLdrImage::setApi(char *name, ULONG pfnNewProc)
     1981{
     1982    NameExport *curexport;
     1983
     1984    curexport = findApi(name);
     1985    if(curexport) {
     1986        ULONG pfnOldProc = curexport->virtaddr;
     1987
     1988        curexport->virtaddr = pfnNewProc;
     1989        return pfnOldProc;
     1990    }
     1991    return -1;
     1992}
     1993//******************************************************************************
     1994//******************************************************************************
     1995OrdExport *Win32PeLdrImage::findApi(int ordinal)
    19511996{
    19521997 ULONG       apiaddr, i;
    19531998 OrdExport  *curexport;
    1954  NameExport *nexport;
    19551999
    19562000    curexport = ordexports;
     
    19782022    else
    19792023      if (iThisExport == ordinal)   // found the export?
    1980         return curexport[i].virtaddr;
     2024        return &curexport[i];
    19812025      else
    19822026        i -= min(iStep, (iThisExport-ordinal));                 // move farther up the list
     
    20032047          iThisExport = curexport[i].ordinal;
    20042048          if(iThisExport == ordinal)
    2005             return(curexport[i].virtaddr);
     2049            return &curexport[i];
    20062050          else
    20072051            if (iThisExport > ordinal)
     
    20182062          iThisExport = curexport[i].ordinal;
    20192063          if(curexport[i].ordinal == ordinal)
    2020             return(curexport[i].virtaddr);
     2064            return &curexport[i];
    20212065          else
    20222066            if (iThisExport < ordinal)
     
    20302074    }
    20312075  }
     2076  return NULL;
     2077}
     2078//******************************************************************************
     2079//******************************************************************************
     2080ULONG Win32PeLdrImage::getApi(int ordinal)
     2081{
     2082    OrdExport  *curexport;
     2083    NameExport *nexport;
     2084
     2085    curexport = findApi(ordinal);
     2086    if(curexport) {
     2087        return curexport->virtaddr;
     2088    }
    20322089
    20332090    //Name exports also contain an ordinal, so check this
    20342091    nexport = nameexports;
    2035     for(i=0;i<nrNameExports;i++) {
     2092    for(int i=0;i<nrNameExports;i++) {
    20362093        if(nexport->ordinal == ordinal)
    20372094            return(nexport->virtaddr);
     
    20402097    }
    20412098    return(0);
     2099}
     2100//******************************************************************************
     2101//Override an ordinal export
     2102//******************************************************************************
     2103ULONG Win32PeLdrImage::setApi(int ordinal, ULONG pfnNewProc)
     2104{
     2105    OrdExport  *curexport;
     2106    NameExport *nexport;
     2107
     2108    curexport = findApi(ordinal);
     2109    if(curexport) {
     2110        ULONG pfnOldProc = curexport->virtaddr;
     2111
     2112        curexport->virtaddr = pfnNewProc;
     2113        return pfnOldProc;
     2114    }
     2115
     2116    //Name exports also contain an ordinal, so check this
     2117    nexport = nameexports;
     2118    for(int i=0;i<nrNameExports;i++)
     2119    {
     2120        if(nexport->ordinal == ordinal) {
     2121            ULONG pfnOldProc = nexport->virtaddr;
     2122
     2123            nexport->virtaddr = pfnNewProc;
     2124            return pfnOldProc;
     2125        }
     2126
     2127        nexport = (NameExport *)((ULONG)nexport->name + nexport->nlength);
     2128    }
     2129    return -1;
    20422130}
    20432131//******************************************************************************
  • trunk/src/kernel32/winimagepeldr.h

    r9537 r9617  
    1 /* $Id: winimagepeldr.h,v 1.18 2002-12-20 11:39:43 sandervl Exp $ */
     1/* $Id: winimagepeldr.h,v 1.19 2003-01-05 12:31:26 sandervl Exp $ */
    22
    33/*
     
    8787    virtual ULONG getApi(char *name);
    8888    virtual ULONG getApi(int ordinal);
     89    virtual ULONG setApi(char *name, ULONG pfnNewProc);
     90    virtual ULONG setApi(int ordinal, ULONG pfnNewProc);
    8991
    9092    virtual ULONG getImageSize();
     
    111113     Section *findSectionByOS2Addr(ULONG addr);
    112114     Section *findPreviousSectionByOS2Addr(ULONG addr);
     115
     116   OrdExport *findApi(int ordinal);
     117  NameExport *findApi(char *name);
    113118
    114119        BOOL  setMemFlags();
  • trunk/src/kernel32/wprocess.cpp

    r9540 r9617  
    1 /* $Id: wprocess.cpp,v 1.168 2002-12-20 12:40:44 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.169 2003-01-05 12:31:26 sandervl Exp $ */
    22
    33/*
     
    22862286}
    22872287//******************************************************************************
     2288// ODIN_SetProcAddress: Override a dll export
     2289//
     2290// Parameters:
     2291//      HMODULE hModule         Module handle
     2292//      LPCSTR  lpszProc        Export name or ordinal
     2293//      FARPROC pfnNewProc      New export function address
     2294//
     2295// Returns: Success -> old address of export
     2296//          Failure -> -1
     2297//
     2298//******************************************************************************
     2299FARPROC WIN32API ODIN_SetProcAddress(HMODULE hModule, LPCSTR lpszProc,
     2300                                     FARPROC pfnNewProc)
     2301{
     2302 Win32ImageBase *winmod;
     2303 FARPROC   proc;
     2304 ULONG     ulAPIOrdinal;
     2305
     2306  if(hModule == 0 || hModule == -1 || (WinExe && hModule == WinExe->getInstanceHandle())) {
     2307        winmod = WinExe;
     2308  }
     2309  else  winmod = (Win32ImageBase *)Win32DllBase::findModule((HINSTANCE)hModule);
     2310
     2311  if(winmod) {
     2312        ulAPIOrdinal = (ULONG)lpszProc;
     2313        if (ulAPIOrdinal <= 0x0000FFFF) {
     2314                proc = (FARPROC)winmod->setApi((int)ulAPIOrdinal, (ULONG)pfnNewProc);
     2315        }
     2316        else    proc = (FARPROC)winmod->setApi((char *)lpszProc, (ULONG)pfnNewProc);
     2317        if(proc == 0) {
     2318#ifdef DEBUG
     2319                if(ulAPIOrdinal <= 0x0000FFFF) {
     2320                        dprintf(("ODIN_SetProcAddress %x %x not found!", hModule, ulAPIOrdinal));
     2321                }
     2322                else    dprintf(("ODIN_SetProcAddress %x %s not found!", hModule, lpszProc));
     2323#endif
     2324                SetLastError(ERROR_PROC_NOT_FOUND);
     2325        }
     2326        if(HIWORD(lpszProc))
     2327                dprintf(("KERNEL32:  ODIN_SetProcAddress %s from %X returned %X\n", lpszProc, hModule, proc));
     2328        else    dprintf(("KERNEL32:  ODIN_SetProcAddress %x from %X returned %X\n", lpszProc, hModule, proc));
     2329
     2330        SetLastError(ERROR_SUCCESS);
     2331        return proc;
     2332  }
     2333  SetLastError(ERROR_INVALID_HANDLE);
     2334  return (FARPROC)-1;
     2335}
     2336//******************************************************************************
    22882337//Retrieve the version
    22892338//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.