Changeset 9617 for trunk/src/kernel32/winimagepeldr.cpp
- Timestamp:
- Jan 5, 2003, 1:31:26 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/winimagepeldr.cpp
r9537 r9617 1 /* $Id: winimagepeldr.cpp,v 1.10 2 2002-12-20 11:39:42sandervl Exp $ */1 /* $Id: winimagepeldr.cpp,v 1.103 2003-01-05 12:31:25 sandervl Exp $ */ 2 2 3 3 /* … … 44 44 #include <win32api.h> 45 45 #include <heapcode.h> 46 #include <custombuild.h> 46 47 #include "winimagebase.h" 47 48 #include "winimagepeldr.h" … … 1372 1373 } 1373 1374 //****************************************************************************** 1375 //Install a hook that gets called when the exports have been processed 1376 //****************************************************************************** 1377 static ODINPROC_DLLLOAD pfnDllLoad = NULL; 1378 //****************************************************************************** 1379 BOOL WIN32API ODIN_SetDllLoadCallback(ODINPROC_DLLLOAD pfnMyDllLoad) 1380 { 1381 pfnDllLoad = pfnMyDllLoad; 1382 return TRUE; 1383 } 1384 //****************************************************************************** 1374 1385 //****************************************************************************** 1375 1386 BOOL Win32PeLdrImage::processExports(char *win32file) … … 1437 1448 } 1438 1449 } 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); 1439 1456 } 1440 1457 … … 1915 1932 //****************************************************************************** 1916 1933 //****************************************************************************** 1917 ULONG Win32PeLdrImage::getApi(char *name)1934 NameExport *Win32PeLdrImage::findApi(char *name) 1918 1935 { 1919 1936 ULONG apiaddr, i, apilen; … … 1940 1957 { 1941 1958 if(strcmp(curexport->name, apiname) == 0) 1942 return (curexport->virtaddr);1959 return curexport; 1943 1960 } 1944 1961 curexport = (NameExport *)((ULONG)curexport->name + curexport->nlength); 1945 1962 } 1946 return(0); 1947 } 1948 //****************************************************************************** 1949 //****************************************************************************** 1950 ULONG Win32PeLdrImage::getApi(int ordinal) 1963 return NULL; 1964 } 1965 //****************************************************************************** 1966 //****************************************************************************** 1967 ULONG 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 //****************************************************************************** 1980 ULONG 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 //****************************************************************************** 1995 OrdExport *Win32PeLdrImage::findApi(int ordinal) 1951 1996 { 1952 1997 ULONG apiaddr, i; 1953 1998 OrdExport *curexport; 1954 NameExport *nexport;1955 1999 1956 2000 curexport = ordexports; … … 1978 2022 else 1979 2023 if (iThisExport == ordinal) // found the export? 1980 return curexport[i].virtaddr;2024 return &curexport[i]; 1981 2025 else 1982 2026 i -= min(iStep, (iThisExport-ordinal)); // move farther up the list … … 2003 2047 iThisExport = curexport[i].ordinal; 2004 2048 if(iThisExport == ordinal) 2005 return (curexport[i].virtaddr);2049 return &curexport[i]; 2006 2050 else 2007 2051 if (iThisExport > ordinal) … … 2018 2062 iThisExport = curexport[i].ordinal; 2019 2063 if(curexport[i].ordinal == ordinal) 2020 return (curexport[i].virtaddr);2064 return &curexport[i]; 2021 2065 else 2022 2066 if (iThisExport < ordinal) … … 2030 2074 } 2031 2075 } 2076 return NULL; 2077 } 2078 //****************************************************************************** 2079 //****************************************************************************** 2080 ULONG Win32PeLdrImage::getApi(int ordinal) 2081 { 2082 OrdExport *curexport; 2083 NameExport *nexport; 2084 2085 curexport = findApi(ordinal); 2086 if(curexport) { 2087 return curexport->virtaddr; 2088 } 2032 2089 2033 2090 //Name exports also contain an ordinal, so check this 2034 2091 nexport = nameexports; 2035 for(i =0;i<nrNameExports;i++) {2092 for(int i=0;i<nrNameExports;i++) { 2036 2093 if(nexport->ordinal == ordinal) 2037 2094 return(nexport->virtaddr); … … 2040 2097 } 2041 2098 return(0); 2099 } 2100 //****************************************************************************** 2101 //Override an ordinal export 2102 //****************************************************************************** 2103 ULONG 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; 2042 2130 } 2043 2131 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.