- Timestamp:
- Jun 5, 2001, 9:36:28 PM (24 years ago)
- Location:
- trunk/src/kernel32
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/winimagepeldr.cpp
r5909 r5910 1 /* $Id: winimagepeldr.cpp,v 1.8 1 2001-06-05 16:44:46phaller Exp $ */1 /* $Id: winimagepeldr.cpp,v 1.82 2001-06-05 19:36:28 phaller Exp $ */ 2 2 3 3 /* … … 111 111 imageVirtBase(-1), realBaseAddress(0), imageVirtEnd(0), 112 112 nrNameExports(0), nrOrdExports(0), nameexports(NULL), ordexports(NULL), 113 memmap(NULL), pFixups(NULL), dwFixupSize(0), curnameexport(NULL), curordexport(NULL) 113 memmap(NULL), pFixups(NULL), dwFixupSize(0), curnameexport(NULL), curordexport(NULL), 114 nrOrdExportsRegistered(0) 114 115 { 115 116 HFILE dllfile; … … 1383 1384 } 1384 1385 } 1386 1385 1387 return(TRUE); 1386 1388 } … … 1434 1436 curordexport->ordinal = ordinal; 1435 1437 curordexport++; 1438 nrOrdExportsRegistered++; 1436 1439 } 1437 1440 //****************************************************************************** … … 1882 1885 ULONG Win32PeLdrImage::getApi(int ordinal) 1883 1886 { 1884 ULONG apiaddr, i; 1885 OrdExport *curexport; 1886 NameExport *nexport; 1887 1888 curexport = ordexports; 1887 ULONG apiaddr, i; 1888 OrdExport *curexport; 1889 NameExport *nexport; 1890 register int iDiff; 1891 1892 curexport = ordexports; 1889 1893 1890 #if 1 1891 /* accelerated resolving of ordinal exports 1892 * is based on the assumption the ordinal export 1893 * table is always sorted ascending. 1894 * 1895 * When the step size is too small, we continue 1896 * with the linear search. 1897 */ 1898 1899 // start in the middle of the tree 1900 i = nrOrdExports >> 1; 1901 int iStep = i; 1902 1903 for(;;) 1894 i = 0; 1895 if (nrOrdExportsRegistered > 1000) 1904 1896 { 1905 int iThisExport = curexport[i].ordinal; 1906 1907 iStep >>= 1; // next step will be narrower 1908 1909 if (iThisExport < ordinal) 1910 i += iStep; // move farther down the list 1911 else 1912 if (iThisExport == ordinal) // found the export? 1913 return curexport[i].virtaddr; 1914 else 1915 i -= iStep; // move farther up the list 1916 1917 // if we're in the direct neighbourhood search linearly 1918 if (iStep <= 1) 1919 { 1920 // decide if we're to search backward or forward 1921 if (ordinal > curexport[i].ordinal) 1922 { 1923 // As a certain number of exports are 0 at the end 1924 // of the array, this case will hit fairly often. 1925 // the last comparison will send the loop off into the 1926 // wrong direction! 1927 if (curexport[i].ordinal == 0) 1928 { 1929 // start over with plain dump search 1930 for(i = 0; i < nrOrdExports; i++) 1931 { 1932 if(curexport[i].ordinal == ordinal) 1933 return(curexport[i].virtaddr); 1934 } 1935 break; // not found yet! 1936 } 1937 1938 for (;i<nrOrdExports;i++) // scan forward 1939 { 1940 iThisExport = curexport[i].ordinal; 1941 if(iThisExport == ordinal) 1942 return(curexport[i].virtaddr); 1943 else 1944 if (iThisExport > ordinal) 1945 { 1946 // Oops, cannot find the ordinal in the sorted list 1947 break; 1948 } 1949 } 1897 for(i=0;i<nrOrdExportsRegistered;i+=1000) { 1898 iDiff = curexport[i].ordinal - ordinal; 1899 if(iDiff > 0) { 1900 if(i) i -= 1000; 1901 break; 1950 1902 } 1951 1903 else 1952 { 1953 for (;i>=0;i--) // scan backward 1954 { 1955 iThisExport = curexport[i].ordinal; 1956 if(curexport[i].ordinal == ordinal) 1957 return(curexport[i].virtaddr); 1958 else 1959 if (iThisExport < ordinal) 1960 // Oops, cannot find the ordinal in the sorted list 1961 break; 1962 } 1904 if(iDiff == 0) 1905 return(curexport[i].virtaddr); 1906 } 1907 if (i > nrOrdExportsRegistered) i -= 1000; 1908 } 1909 1910 if (nrOrdExportsRegistered > 100) 1911 { 1912 for(i;i<nrOrdExportsRegistered;i+=100) { 1913 iDiff = curexport[i].ordinal - ordinal; 1914 if(iDiff > 0) { 1915 if(i) i -= 100; 1916 break; 1963 1917 } 1964 1965 // not found yet. 1966 break; 1967 } 1918 else 1919 if(iDiff == 0) 1920 return(curexport[i].virtaddr); 1921 } 1922 if (i > nrOrdExportsRegistered) i -= 100; 1968 1923 } 1969 #endif 1924 1925 if (nrOrdExportsRegistered > 10) 1926 { 1927 for(i;i<nrOrdExportsRegistered;i+=10) { 1928 iDiff = curexport[i].ordinal - ordinal; 1929 if(iDiff > 0) { 1930 if(i) i -= 10; 1931 break; 1932 } 1933 else 1934 if(iDiff == 0) 1935 return(curexport[i].virtaddr); 1936 } 1937 if (i > nrOrdExportsRegistered) i -= 10; 1938 } 1970 1939 1971 1972 #if 0 1973 i = 0; 1974 if(nrOrdExports > 1000) { 1975 for(i=0;i<nrOrdExports;i+=1000) { 1976 if(curexport[i].ordinal == ordinal) 1977 return(curexport[i].virtaddr); 1978 else 1979 if(ordinal < curexport[i].ordinal) { 1980 if(i) i -= 1000; 1981 break; 1982 } 1983 } 1984 if(i >= nrOrdExports) i -= 1000; 1985 } 1986 1987 if(nrOrdExports > 100) { 1988 for(i;i<nrOrdExports;i+=100) { 1989 if(curexport[i].ordinal == ordinal) 1990 return(curexport[i].virtaddr); 1991 else 1992 if(ordinal < curexport[i].ordinal) { 1993 if(i) i -= 100; 1994 break; 1995 } 1996 } 1997 if(i >= nrOrdExports) i -= 100; 1998 } 1999 2000 if(nrOrdExports > 10) { 2001 for(i;i<nrOrdExports;i+=10) { 2002 if(curexport[i].ordinal == ordinal) 2003 return(curexport[i].virtaddr); 2004 else 2005 if(ordinal < curexport[i].ordinal) { 2006 if(i) i -= 10; 2007 break; 2008 } 2009 } 2010 if(i >= nrOrdExports) i -= 10; 2011 } 2012 #endif 2013 2014 #if 0 2015 for(i;i<nrOrdExports;i++) { 2016 if(curexport[i].ordinal == ordinal) 2017 return(curexport[i].virtaddr); 2018 } 2019 #endif 2020 2021 //Name exports also contain an ordinal, so check this 2022 nexport = nameexports; 2023 for(i=0;i<nrNameExports;i++) { 2024 if(nexport->ordinal == ordinal) 2025 return(nexport->virtaddr); 2026 2027 nexport = (NameExport *)((ULONG)nexport->name + nexport->nlength); 2028 } 2029 return(0); 1940 for(i;i<nrOrdExportsRegistered;i++) { 1941 if(curexport[i].ordinal == ordinal) 1942 return(curexport[i].virtaddr); 1943 } 1944 1945 //Name exports also contain an ordinal, so check this 1946 nexport = nameexports; 1947 for(i=0;i<nrNameExports;i++) { 1948 if(nexport->ordinal == ordinal) 1949 return(nexport->virtaddr); 1950 1951 nexport = (NameExport *)((ULONG)nexport->name + nexport->nlength); 1952 } 1953 return(0); 2030 1954 } 2031 1955 //****************************************************************************** -
trunk/src/kernel32/winimagepeldr.h
r5862 r5910 1 /* $Id: winimagepeldr.h,v 1.1 3 2001-06-01 08:22:34 sandervlExp $ */1 /* $Id: winimagepeldr.h,v 1.14 2001-06-05 19:36:28 phaller Exp $ */ 2 2 3 3 /* … … 131 131 ULONG nrNameExports, nameExportSize; 132 132 ULONG nrOrdExports; 133 ULONG nrOrdExportsRegistered; 133 134 NameExport *nameexports, *curnameexport; 134 135 OrdExport *ordexports, *curordexport;
Note:
See TracChangeset
for help on using the changeset viewer.