public void StartHook() { this.processHandle = MemoryManager.OpenProcessHandle; this.OriginalBytes = new byte[cOptions.NumBytesToCopy]; for (int i = 0; i < cOptions.NumBytesToCopy; i++) { this.OriginalBytes[i] = MemoryManager.ReadByte(cOptions.PacketSendFunction + i); } byte[] numArray = (byte[])this._ListenFunction.Clone(); this.offset_MyFunc = InjectHelper.AllocateMemory(this.processHandle, (int)numArray.Length + cOptions.NumBytesToCopy + 5 + 2); this.offset_data_addr = InjectHelper.AllocateMemory(this.processHandle, 4); this.offset_data_size = InjectHelper.AllocateMemory(this.processHandle, 4); this.offset_flag = InjectHelper.AllocateMemory(this.processHandle, 4); MemoryManager.WriteBytes(this.offset_data_addr, new byte[4]); MemoryManager.WriteBytes(this.offset_data_size, new byte[4]); MemoryManager.WriteBytes(this.offset_flag, new byte[4]); byte[] bytes = BitConverter.GetBytes(this.offset_data_addr); byte[] bytes1 = BitConverter.GetBytes(this.offset_data_size); byte[] numArray1 = BitConverter.GetBytes(this.offset_flag); numArray[5] = bytes[0]; numArray[6] = bytes[1]; numArray[7] = bytes[2]; numArray[8] = bytes[3]; numArray[14] = bytes1[0]; numArray[15] = bytes1[1]; numArray[16] = bytes1[2]; numArray[17] = bytes1[3]; numArray[20] = numArray1[0]; numArray[21] = numArray1[1]; numArray[22] = numArray1[2]; numArray[23] = numArray1[3]; numArray[29] = numArray1[0]; numArray[30] = numArray1[1]; numArray[31] = numArray1[2]; numArray[32] = numArray1[3]; MemoryManager.WriteBytes(this.offset_MyFunc, numArray); MemoryManager.WriteBytes(this.offset_MyFunc + (int)numArray.Length, this.OriginalBytes); byte[] bytes2 = BitConverter.GetBytes(cOptions.PacketSendFunction + cOptions.NumBytesToCopy); byte[] numArray2 = new byte[] { 184, bytes2[0], bytes2[1], bytes2[2], bytes2[3], 255, 224 }; MemoryManager.WriteBytes(this.offset_MyFunc + (int)numArray.Length + (int)this.OriginalBytes.Length, numArray2); byte[] bytes3 = BitConverter.GetBytes(this.offset_MyFunc); byte[] numArray3 = new byte[cOptions.NumBytesToCopy]; numArray3[0] = 184; numArray3[1] = bytes3[0]; numArray3[2] = bytes3[1]; numArray3[3] = bytes3[2]; numArray3[4] = bytes3[3]; numArray3[5] = 255; numArray3[6] = 224; for (int j = 7; j < cOptions.NumBytesToCopy; j++) { numArray3[j] = 144; } MemoryManager.WriteBytes(cOptions.PacketSendFunction, numArray3); }
private void LoadSendPacketOpcode(IntPtr processHandle) { this._sendPacketOpcodeAddress = InjectHelper.AllocateMemory(processHandle, (int)this._sendPacketOpcode.Length); MemoryManager.WriteBytes(this._sendPacketOpcodeAddress, this._sendPacketOpcode); byte[] bytes = BitConverter.GetBytes(cOptions.PacketSendFunction); byte[] numArray = BitConverter.GetBytes(cOptions.BaseAddress); MemoryManager.WriteBytes(this._sendPacketOpcodeAddress + 2, bytes); MemoryManager.WriteBytes(this._sendPacketOpcodeAddress + 8, numArray); this._packetAddressLocation = this._sendPacketOpcodeAddress + 16; this._packetSizeAddress = this._sendPacketOpcodeAddress + 21; }
public void SendPacket(byte[] packetData) { IntPtr openProcessHandle = MemoryManager.OpenProcessHandle; int num = InjectHelper.AllocateMemory(openProcessHandle, (int)packetData.Length); MemoryManager.WriteBytes(num, packetData); byte[] bytes = BitConverter.GetBytes(num); if (this._sendPacketOpcodeAddress == 0) { this.LoadSendPacketOpcode(openProcessHandle); } MemoryManager.WriteBytes(this._packetAddressLocation, bytes); MemoryManager.WriteBytes(this._packetSizeAddress, BitConverter.GetBytes((int)packetData.Length)); IntPtr intPtr = InjectHelper.CreateRemoteThread(openProcessHandle, this._sendPacketOpcodeAddress); WinApi.WaitForSingleObject(intPtr, 100); WinApi.CloseHandle(intPtr); InjectHelper.FreeMemory(openProcessHandle, num, (int)packetData.Length); InjectHelper.FreeMemory(openProcessHandle, this._sendPacketOpcodeAddress, (int)this._sendPacketOpcode.Length); }