I dug around my old code and this came up, hope you can use it :)
Code:
static void findAddresses(string clientLocation, string iniLocation)
{
byte[] ba;
using (FileStream br = File.OpenRead(clientLocation))
{
ba = new byte[br.Length]; //br.Length
br.Read(ba, 0, (int)br.Length); //br.Length
}
List<char> clist = new List<char>();
foreach (byte b in ba)
clist.Add((char)b);
char[] ca = clist.ToArray();
string client = new string(ca);
IniFile iniFile = new IniFile(iniLocation);
findPacketFunctionAddress(client, iniFile);
}
private static void findPacketFunctionAddress(string client, IniFile iniFile)
{
int realBaseAddress = 0;
int sendPacketAddress = 0;
Regex rx = new Regex(findPacketFunctionExpression);
foreach (Match mx in rx.Matches(client))
{
int call_pos = mx.Index + 0x40007B;
//realBaseAddress
Capture c1 = mx.Groups[1];
byte[] bb = new byte[c1.Value.Length];
int theOffset = 0;
int multiplier = 0x100;
for (int i = 0; i < c1.Value.Length; i++)
{
theOffset += (byte)c1.Value[i] * (int)Math.Pow(multiplier, i);
}
realBaseAddress = theOffset;
Debug.WriteLine("realBaseAddress: 0x{0:X}", theOffset);
iniFile.IniWriteValue("Addresses", "GRaddr", "0x" + theOffset.ToString("X"));
//sendPacketAddress
c1 = mx.Groups[2];
bb = new byte[c1.Value.Length];
theOffset = 0;
multiplier = 0x100;
for (int i = 0; i < c1.Value.Length; i++)
{
theOffset += (byte)c1.Value[i] * (int)Math.Pow(multiplier, i);
}
theOffset += call_pos + 7;
sendPacketAddress = theOffset;
Debug.WriteLine("sendPacketAddress: 0x{0:X}", theOffset);
iniFile.IniWriteValue("Addresses", "aSendPacketCall", "0x" + theOffset.ToString("X"));
}
Console.WriteLine("realBaseAddress: 0x{0:X}", realBaseAddress);
Console.WriteLine("sendPacketAddress: 0x{0:X}", sendPacketAddress);
}
private static string findPacketFunctionExpression =
@"\x6A\x21" + // push 21h
@"\xE8.{4}" + // call sub740780 // Call Procedure
@"\x8B\xF0" + // mov esi, eax
@"\x83\xC4\x04" + // add esp, 4 // Add
@"\x85\xF6" + // test esi, esi // Logical Compare
@"\x74.{1}" + // jz short loc5D9D9C // Jump if Zero (ZF=1)
@"\x8A\x44\x24\x18" + // mov al, [esp+4+moveType]
@"\x66\x8B\x4C\x24\x10" + // mov cx, [esp+4+ukShort]
@"\x66\xC7\x06\x00\x00" + // mov word ptr [esi], 0
@"\x88\x46\x1E" + // mov [esi+1Eh], al
@"\x8B\x44\x24\x08" + // mov eax, [esp+4+XYZpointer1]
@"\x66\x89\x4E\x1A" + // mov [esi+1Ah], cx
@"\xD9\x44\x24\x14" + // fld [esp+4+moveSpeed] // Load Real
@"\x8B\x10" + // mov edx, [eax]
@"\x89\x56\x02" + // mov [esi+2], edx
@"\x8B\x48\x04" + // mov ecx, [eax+4]
@"\xD8\x0D.{4}" + // fmul ds:flt8BDB08 // Multiply Real
@"\x89\x4E\x06" + // mov [esi+6], ecx
@"\x8B\x50\x08" + // mov edx, [eax+8]
@"\x8B\x44\x24\x0C" + // mov eax, [esp+4+XYZpointer2]
@"\x89\x56\x0A" + // mov [esi+0Ah], edx
@"\xD8\x05.{4}" + // fadd ds:flt8AE894 // Add Real
@"\x8B\x08" + // mov ecx, [eax]
@"\x89\x4E\x0E" + // mov [esi+0Eh], ecx
@"\x8B\x50\x04" + // mov edx, [eax+4]
@"\x89\x56\x12" + // mov [esi+12h], edx
@"\x8B\x40\x08" + // mov eax, [eax+8]
@"\x89\x46\x16" + // mov [esi+16h], eax
@"\xE8.{4}" + // call ftol // Call Procedure
@"\x66\x8B\x4C\x24\x1C" + // mov cx, [esp+4+moveCounter]
@"\x66\x89\x46\x1C" + // mov [esi+1Ch], ax
@"\x66\x89\x4E\x1F" + // mov [esi+1Fh], cx
@"\x8B\x15(.{4})" + // mov edx, dword98657C
@"\x6A\x21" + // push 21h // Size
@"\x56" + // push esi // Src
@"\x8B\x4A\x20" + // mov ecx, [edx+20h]
@"\xE8(.{4})" + // call SendPacket // Call Procedure
@"\x56" + // push esi
@"\xE8.{4}" + // call sub740790 // Call Procedure
@"\x83\xC4\x04" + // add esp, 4 // Add
@"\x5E" + // pop esi
@"\xC3"; // retn // Return Near from Procedure