//SearchToken生成 public string SearchToken(string word) { byte[] wordArray = Encoding.UTF8.GetBytes(word); byte[] tokenArray = HmacHash.Sign(k1, wordArray); string token = tool.ByteToHex(tokenArray); history.Add(token); return(token); }
public override void Write() { byte[] port = BitConverter.GetBytes((ushort)Payload.Where.Port); byte[] address = new byte[16]; byte addressType = 3; if (Payload.Where.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { Buffer.BlockCopy(Payload.Where.Address.GetAddressBytes(), 0, address, 0, 4); addressType = 1; } else { Buffer.BlockCopy(Payload.Where.Address.GetAddressBytes(), 0, address, 0, 16); addressType = 2; } HmacHash hmacHash = new HmacHash(RsaStore.WherePacketHmac); hmacHash.Process(address, 16); hmacHash.Process(BitConverter.GetBytes(addressType), 1); hmacHash.Process(port, 2); hmacHash.Process(Haiku); hmacHash.Process(Payload.PanamaKey, 32); hmacHash.Process(PiDigits, 108); hmacHash.Finish(BitConverter.GetBytes(Payload.XorMagic), 1); ByteBuffer payload = new ByteBuffer(); payload.WriteUInt32(Payload.Adler32); payload.WriteUInt8(addressType); payload.WriteBytes(address, 16); payload.WriteUInt16(Payload.Where.Port); payload.WriteString(Haiku); payload.WriteBytes(Payload.PanamaKey, 32); payload.WriteBytes(PiDigits, 108); payload.WriteUInt8(Payload.XorMagic); payload.WriteBytes(hmacHash.Digest); _worldPacket.WriteUInt64(Key); _worldPacket.WriteUInt32(Serial); _worldPacket.WriteBytes(Crypt.Encrypt(payload.GetData()), 256); _worldPacket.WriteUInt8(Con); }
public override void RequestData() { Log.outDebug(LogFilter.Warden, "Request data"); // If all checks were done, fill the todo list again if (_memChecksTodo.Empty()) { _memChecksTodo.AddRange(Global.WardenCheckMgr.MemChecksIdPool); } if (_otherChecksTodo.Empty()) { _otherChecksTodo.AddRange(Global.WardenCheckMgr.OtherChecksIdPool); } _serverTicks = GameTime.GetGameTimeMS(); ushort id; WardenCheckType type; WardenCheck wd; _currentChecks.Clear(); // Build check request for (uint i = 0; i < WorldConfig.GetUIntValue(WorldCfg.WardenNumMemChecks); ++i) { // If todo list is done break loop (will be filled on next Update() run) if (_memChecksTodo.Empty()) { break; } // Get check id from the end and remove it from todo id = _memChecksTodo.Last(); _memChecksTodo.Remove(id); // Add the id to the list sent in this cycle _currentChecks.Add(id); } ByteBuffer buffer = new ByteBuffer(); buffer.WriteUInt8((byte)WardenOpcodes.Smsg_CheatChecksRequest); for (uint i = 0; i < WorldConfig.GetUIntValue(WorldCfg.WardenNumOtherChecks); ++i) { // If todo list is done break loop (will be filled on next Update() run) if (_otherChecksTodo.Empty()) { break; } // Get check id from the end and remove it from todo id = _otherChecksTodo.Last(); _otherChecksTodo.Remove(id); // Add the id to the list sent in this cycle _currentChecks.Add(id); wd = Global.WardenCheckMgr.GetWardenDataById(id); switch (wd.Type) { case WardenCheckType.MPQ: case WardenCheckType.LuaStr: case WardenCheckType.Driver: buffer.WriteUInt8((byte)wd.Str.GetByteCount()); buffer.WriteString(wd.Str); break; default: break; } } byte xorByte = _inputKey[0]; // Add TIMING_CHECK buffer.WriteUInt8(0x00); buffer.WriteUInt8((byte)((int)WardenCheckType.Timing ^ xorByte)); byte index = 1; foreach (var checkId in _currentChecks) { wd = Global.WardenCheckMgr.GetWardenDataById(checkId); type = wd.Type; buffer.WriteUInt8((byte)((int)type ^ xorByte)); switch (type) { case WardenCheckType.Memory: { buffer.WriteUInt8(0x00); buffer.WriteUInt32(wd.Address); buffer.WriteUInt8(wd.Length); break; } case WardenCheckType.PageA: case WardenCheckType.PageB: { buffer.WriteBytes(wd.Data.ToByteArray()); buffer.WriteUInt32(wd.Address); buffer.WriteUInt8(wd.Length); break; } case WardenCheckType.MPQ: case WardenCheckType.LuaStr: { buffer.WriteUInt8(index++); break; } case WardenCheckType.Driver: { buffer.WriteBytes(wd.Data.ToByteArray()); buffer.WriteUInt8(index++); break; } case WardenCheckType.Module: { uint seed = RandomHelper.Rand32(); buffer.WriteUInt32(seed); HmacHash hmac = new HmacHash(BitConverter.GetBytes(seed)); hmac.Finish(wd.Str); buffer.WriteBytes(hmac.Digest); break; } /*case PROC_CHECK: * { * buff.append(wd.i.AsByteArray(0, false).get(), wd.i.GetNumBytes()); * buff << uint8(index++); * buff << uint8(index++); * buff << uint32(wd.Address); * buff << uint8(wd.Length); * break; * }*/ default: break; // Should never happen } } buffer.WriteUInt8(xorByte); WardenDataServer packet = new WardenDataServer(); packet.Data = EncryptData(buffer.GetData()); _session.SendPacket(packet); _dataSent = true; string stream = "Sent check id's: "; foreach (var checkId in _currentChecks) { stream += checkId + " "; } Log.outDebug(LogFilter.Warden, stream); }