Code:
public static uint GetProcAddressEx(int hProc, uint hModule, string lpProcName)
{
uint procAddress = 0;
byte[] pDosHd = ReadRemoteMemory(hProc, hModule, 0x40);
if (pDosHd != null && BitConverter.ToUInt16(pDosHd, 0) == 0x5A4D)
{
uint e_lfanew = BitConverter.ToUInt32(pDosHd, 0x3C);
if (e_lfanew > 0)
{
byte[] pNtHd = ReadRemoteMemory(hProc, hModule + e_lfanew, 0x108);
if (pNtHd != null && BitConverter.ToUInt32(pNtHd, 0) == 0x4550)
{
uint expDirPtr = BitConverter.ToUInt32(pNtHd, 0x78);
if ( expDirPtr != 0)
{
byte[] pExpDir = ReadRemoteMemory(hProc, hModule + expDirPtr, 0x28);
uint pEat = BitConverter.ToUInt32(pExpDir, 0x1C);
uint pOrd = BitConverter.ToUInt32(pExpDir, 0x24);
uint ordbase = BitConverter.ToUInt32(pExpDir, 0x10);
int index = SearchExports(hProc, hModule, pExpDir, lpProcName);
if (pEat > 0 && pOrd > 0 && index > -1)
{
byte[] bOrd = ReadRemoteMemory(hProc, (uint)(hModule + pOrd + (index << 1)), 0x2);
int ord = (int)(bOrd == null ? -1 : BitConverter.ToUInt16(bOrd, 0));
if (ord != -1)
{
byte[] addr = ReadRemoteMemory(hProc, (uint)(hModule + pEat + ((ord - (ordbase - 1)) << 2)), 0x4);
if (addr != null)
procAddress = hModule + BitConverter.ToUInt32(addr, 0);
}
}
}
}
}
}
return procAddress;
}
private static int SearchExports(int hProcess, uint hModule, byte[] exports, string name)
{
uint cntExports = BitConverter.ToUInt32(exports, 0x18);
uint ptrNameTable = BitConverter.ToUInt32(exports, 0x20);
int rva = -1;
if (cntExports > 0 && ptrNameTable > 0)
{
byte[] rawPtrs = ReadRemoteMemory(hProcess, hModule + ptrNameTable, cntExports << 2);
if (rawPtrs != null && rawPtrs.Length >= 4)
{
uint[] namePtrs = new uint[cntExports];
for (int i = 0; i < namePtrs.Length; i++)
namePtrs[i] = BitConverter.ToUInt32(rawPtrs, i << 2);
int start = 0, end = namePtrs.Length - 1, middle = 0;
string curvalue = string.Empty;
while (start <= end && rva == -1)
{
middle = start + ((end - start) / 2);
curvalue = StringFromPTR(hProcess, hModule + namePtrs[middle]);
if (curvalue.Equals(name))
rva = middle;
else if (curvalue.CompareTo(name) < 0)
start = middle - 1;
else
end = middle + 1;
}
}
}
return rva;
} BEJELLY!