Changeset 5912 for trunk/src/kernel32/winimagepeldr.cpp
- Timestamp:
- Jun 5, 2001, 11:38:42 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/winimagepeldr.cpp
r5910 r5912 1 /* $Id: winimagepeldr.cpp,v 1.8 2 2001-06-05 19:36:28 phallerExp $ */1 /* $Id: winimagepeldr.cpp,v 1.83 2001-06-05 21:38:42 sandervl 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), 114 nrOrdExportsRegistered(0) 113 memmap(NULL), pFixups(NULL), dwFixupSize(0), curnameexport(NULL), curordexport(NULL) 115 114 { 116 115 HFILE dllfile; … … 1384 1383 } 1385 1384 } 1386 1387 1385 return(TRUE); 1388 1386 } … … 1436 1434 curordexport->ordinal = ordinal; 1437 1435 curordexport++; 1438 nrOrdExportsRegistered++;1439 1436 } 1440 1437 //****************************************************************************** … … 1885 1882 ULONG Win32PeLdrImage::getApi(int ordinal) 1886 1883 { 1887 ULONG apiaddr, i; 1888 OrdExport *curexport; 1889 NameExport *nexport; 1890 register int iDiff; 1891 1892 curexport = ordexports; 1884 ULONG apiaddr, i; 1885 OrdExport *curexport; 1886 NameExport *nexport; 1887 1888 curexport = ordexports; 1889 1890 /* accelerated resolving of ordinal exports 1891 * is based on the assumption the ordinal export 1892 * table is always sorted ascending. 1893 * 1894 * When the step size is too small, we continue 1895 * with the linear search. 1896 */ 1893 1897 1894 i = 0; 1895 if (nrOrdExportsRegistered > 1000) 1898 // start in the middle of the tree 1899 i = nrOrdExports >> 1; 1900 int iStep = i; 1901 1902 for(;;) 1896 1903 { 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; 1904 int iThisExport = curexport[i].ordinal; 1905 1906 iStep >>= 1; // next step will be narrower 1907 1908 if (iThisExport < ordinal) 1909 i += min(iStep, (ordinal-iThisExport)); // move farther down the list 1910 else 1911 if (iThisExport == ordinal) // found the export? 1912 return curexport[i].virtaddr; 1913 else 1914 i -= min(iStep, (iThisExport-ordinal)); // move farther up the list 1915 1916 // if we're in the direct neighbourhood search linearly 1917 if (iStep <= 1) 1918 { 1919 // decide if we're to search backward or forward 1920 if (ordinal > curexport[i].ordinal) 1921 { 1922 // As a certain number of exports are 0 at the end 1923 // of the array, this case will hit fairly often. 1924 // the last comparison will send the loop off into the 1925 // wrong direction! 1926 if (curexport[i].ordinal == 0) 1927 { 1928 // start over with plain dump search 1929 for(i = 0; i < nrOrdExports; i++) 1930 { 1931 if(curexport[i].ordinal == ordinal) 1932 return(curexport[i].virtaddr); 1933 } 1934 break; // not found yet! 1935 } 1936 1937 for (;i<nrOrdExports;i++) // scan forward 1938 { 1939 iThisExport = curexport[i].ordinal; 1940 if(iThisExport == ordinal) 1941 return(curexport[i].virtaddr); 1942 else 1943 if (iThisExport > ordinal) 1944 { 1945 // Oops, cannot find the ordinal in the sorted list 1946 break; 1947 } 1948 } 1902 1949 } 1903 1950 else 1904 if(iDiff == 0) 1905 return(curexport[i].virtaddr); 1906 } 1907 if (i > nrOrdExportsRegistered) i -= 1000; 1951 { 1952 for (;i>=0;i--) // scan backward 1953 { 1954 iThisExport = curexport[i].ordinal; 1955 if(curexport[i].ordinal == ordinal) 1956 return(curexport[i].virtaddr); 1957 else 1958 if (iThisExport < ordinal) 1959 // Oops, cannot find the ordinal in the sorted list 1960 break; 1961 } 1962 } 1963 1964 // not found yet. 1965 break; 1966 } 1908 1967 } 1909 1968 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; 1917 } 1918 else 1919 if(iDiff == 0) 1920 return(curexport[i].virtaddr); 1921 } 1922 if (i > nrOrdExportsRegistered) i -= 100; 1923 } 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 } 1939 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); 1969 //Name exports also contain an ordinal, so check this 1970 nexport = nameexports; 1971 for(i=0;i<nrNameExports;i++) { 1972 if(nexport->ordinal == ordinal) 1973 return(nexport->virtaddr); 1974 1975 nexport = (NameExport *)((ULONG)nexport->name + nexport->nlength); 1976 } 1977 return(0); 1954 1978 } 1955 1979 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.