public WardenMaiev() { WardenModule = Array.Empty <byte>(); ModuleName = ""; ModuleKey = Array.Empty <byte>(); ModuleData = Array.Empty <byte>(); ModuleSize = 0; CheckIDs = new byte[8]; Script = null; delegateCache = new Dictionary <string, Delegate>(); dwModuleSize = 0; dwLibraryCount = 0; SendPacketD = null; CheckModuleD = null; ModuleLoadD = null; AllocateMemD = null; FreeMemoryD = null; SetRC4DataD = null; GetRC4DataD = null; GenerateRC4Keys = null; UnloadModule = null; PacketHandler = null; Tick = null; m_Mod = 0; m_ModMem = 0; InitPointer = 0; init = null; myFuncList = IntPtr.Zero; myFunctionList = default; pFuncList = 0; ppFuncList = 0; myWardenList = default; pWardenList = 0; m_RC4 = 0; m_PKT = Array.Empty <byte>(); }
private bool InitModule(ref byte[] Data) { int A; int B; int C; var bCode = new byte[16]; MemoryStream ms = new(Data); BinaryReader br = new(ms); Marshal.Copy(Data, 0, new IntPtr(m_Mod), Data.Length); br.BaseStream.Position = 0x18L; C = br.ReadInt32(); B = 1 - C; br.BaseStream.Position = 0x14L; if (B > br.ReadInt32()) { return(false); } br.BaseStream.Position = 0x10L; A = br.ReadInt32(); br.BaseStream.Position = A + (B * 4); A = br.ReadInt32() + m_Mod; InitPointer = A; Console.WriteLine("Initialize Function is mapped at 0x{0:X}", InitPointer); SendPacketD = SendPacket; CheckModuleD = CheckModule; ModuleLoadD = ModuleLoad; AllocateMemD = AllocateMem; FreeMemoryD = FreeMemory; SetRC4DataD = SetRC4Data; GetRC4DataD = GetRC4Data; myFunctionList = new FuncList { fpSendPacket = Marshal.GetFunctionPointerForDelegate(SendPacketD).ToInt32(), fpCheckModule = Marshal.GetFunctionPointerForDelegate(CheckModuleD).ToInt32(), fpLoadModule = Marshal.GetFunctionPointerForDelegate(ModuleLoadD).ToInt32(), fpAllocateMemory = Marshal.GetFunctionPointerForDelegate(AllocateMemD).ToInt32(), fpReleaseMemory = Marshal.GetFunctionPointerForDelegate(FreeMemoryD).ToInt32(), fpSetRC4Data = Marshal.GetFunctionPointerForDelegate(SetRC4DataD).ToInt32(), fpGetRC4Data = Marshal.GetFunctionPointerForDelegate(GetRC4DataD).ToInt32() }; Console.WriteLine("Imports: "); Console.WriteLine(" SendPacket: 0x{0:X}", myFunctionList.fpSendPacket); Console.WriteLine(" CheckModule: 0x{0:X}", myFunctionList.fpCheckModule); Console.WriteLine(" LoadModule: 0x{0:X}", myFunctionList.fpLoadModule); Console.WriteLine(" AllocateMemory: 0x{0:X}", myFunctionList.fpAllocateMemory); Console.WriteLine(" ReleaseMemory: 0x{0:X}", myFunctionList.fpReleaseMemory); Console.WriteLine(" SetRC4Data: 0x{0:X}", myFunctionList.fpSetRC4Data); Console.WriteLine(" GetRC4Data: 0x{0:X}", myFunctionList.fpGetRC4Data); // http://forum.valhallalegends.com/index.php?topic=17758.0 myFuncList = new IntPtr(malloc(0x1C)); Marshal.StructureToPtr(myFunctionList, myFuncList, false); pFuncList = myFuncList.ToInt32(); int localVarPtr() { object argobj = pFuncList; var ret = VarPtr(ref argobj); return(ret); } ppFuncList = localVarPtr(); Console.WriteLine("Initializing module"); init = (InitializeModule)Marshal.GetDelegateForFunctionPointer(new IntPtr(InitPointer), typeof(InitializeModule)); m_ModMem = init.Invoke(ppFuncList); pWardenList = Marshal.ReadInt32(new IntPtr(m_ModMem)); myWardenList = (WardenFuncList)Marshal.PtrToStructure(new IntPtr(pWardenList), typeof(WardenFuncList)); Console.WriteLine("Exports:"); Console.WriteLine(" GenerateRC4Keys: 0x{0:X}", myWardenList.fpGenerateRC4Keys); Console.WriteLine(" Unload: 0x{0:X}", myWardenList.fpUnload); Console.WriteLine(" PacketHandler: 0x{0:X}", myWardenList.fpPacketHandler); Console.WriteLine(" Tick: 0x{0:X}", myWardenList.fpTick); GenerateRC4Keys = (GenerateRC4KeysDelegate)Marshal.GetDelegateForFunctionPointer(new IntPtr(myWardenList.fpGenerateRC4Keys), typeof(GenerateRC4KeysDelegate)); UnloadModule = (UnloadModuleDelegate)Marshal.GetDelegateForFunctionPointer(new IntPtr(myWardenList.fpUnload), typeof(UnloadModuleDelegate)); PacketHandler = (PacketHandlerDelegate)Marshal.GetDelegateForFunctionPointer(new IntPtr(myWardenList.fpPacketHandler), typeof(PacketHandlerDelegate)); Tick = (TickDelegate)Marshal.GetDelegateForFunctionPointer(new IntPtr(myWardenList.fpTick), typeof(TickDelegate)); ms.Close(); ms.Dispose(); ms = null; br = null; return(true); }