Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

Commit

Permalink
Merge branch 'unstable'
Browse files Browse the repository at this point in the history
  • Loading branch information
TBulbaDB committed Sep 1, 2016
2 parents 345a753 + f5982b4 commit cf845ca
Show file tree
Hide file tree
Showing 39 changed files with 13,342 additions and 321 deletions.
12 changes: 9 additions & 3 deletions PoGoMITM.Base/Config/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Configuration;
using System.IO;
using System.Linq;
using log4net;
using PoGoMITM.Base.Dumpers;

namespace PoGoMITM.Base.Config
Expand All @@ -11,9 +12,10 @@ public static class AppConfig
{
private static readonly int _bindPort;
private static readonly int _webServerPort;
private static readonly bool _dumpRaw;
private static readonly bool _dumpProcessed;

public static ILog Logger { get; set; }

public static string ProxyIp { get; private set; }
public static int ProxyPort => _bindPort;
public static int WebServerPort => _webServerPort;
Expand All @@ -24,7 +26,11 @@ public static class AppConfig
public static string TempFolder { get; private set; }
public static List<IDataDumper> DataDumpers { get; private set; }

public static bool DumpRaw => _dumpRaw;
public static double InitialLatitude { get; set; }
public static double InitialLongitude { get; set; }

public static bool DumpRaw { get; }

public static bool DumpProcessed => _dumpProcessed;

public static HashSet<string> HostsToDump { get; private set; }
Expand Down Expand Up @@ -61,7 +67,7 @@ static AppConfig()
TempFolder = Path.Combine(Environment.CurrentDirectory, TempFolder);
}

_dumpRaw = true;
DumpRaw = true;

var dumpProcessed = ConfigurationManager.AppSettings["DumpProcessed"] ?? "true";
bool.TryParse(dumpProcessed, out _dumpProcessed);
Expand Down
2 changes: 1 addition & 1 deletion PoGoMITM.Base/Dumpers/PrettyFileDataDumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task Dump<T>(T context)
var requestList = "";
if (context is RequestContext)
{
foreach (var request in (context as RequestContext).RequestEnvelope.Requests)
foreach (var request in (context as RequestContext).RequestData.RequestEnvelope.Requests)
{
requestList += (requestList == "" ? "" : ", ") + request.RequestType.ToString();
}
Expand Down
18 changes: 15 additions & 3 deletions PoGoMITM.Base/Logging/Log4NetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public static IAppender ConsoleAppender(Level threshold)

public static IAppender FileAppender(Level threshhold)
{
var appender=new FileAppender();
var appender = new FileAppender();
appender.Name = "FileAppender";
appender.AppendToFile = true;
appender.Encoding=Encoding.UTF8;
appender.Encoding = Encoding.UTF8;
appender.ImmediateFlush = true;
appender.File = GenerateLogFileName();
appender.Threshold = threshhold;
Expand All @@ -67,7 +67,19 @@ private static string GenerateLogFileName()

public static void LogException(this ILog logger, Exception ex)
{
logger.Error($"[{ex.GetType().Name}] {ex.Message}");
logger.Error($"[{ex.GetType().Name}] {ex.Message}\r\n{ex.StackTrace}");
if (ex.InnerException != null)
{
logger.LogException(ex.InnerException);
}
var aggregateException = ex as AggregateException;
if (aggregateException != null)
{
foreach (var ex1 in aggregateException.InnerExceptions)
{
logger.LogException(ex1);
}
}
}
}
}
12 changes: 12 additions & 0 deletions PoGoMITM.Base/Models/IModifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Threading.Tasks;

namespace PoGoMITM.Base.Models
{
public interface IModifierPlugin
{
bool Enabled { get; }
bool ModifyRequest(RequestContext requestContext);
bool ModifyResponse(RequestContext requestContext);
void ResetState();
}
}
9 changes: 9 additions & 0 deletions PoGoMITM.Base/Models/IRequestPacker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;

namespace PoGoMITM.Base.Models
{
public interface IRequestPacker
{
byte[] GenerateRequestBody(RequestData requestData);
}
}
5 changes: 3 additions & 2 deletions PoGoMITM.Base/Models/IRequestParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PoGoMITM.Base.Models
{
public interface IRequestParser
public interface IProtoParser
{
Task ParseRequest(RequestContext requestContext);
void ParseRequest(RequestContext requestContext, RequestData requestData);
void ParseResponse(RequestContext requestContext, ResponseData responseData);
object SignatureEncryption { get; set; }
}
}
10 changes: 10 additions & 0 deletions PoGoMITM.Base/Models/IResponseModifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Threading.Tasks;

namespace PoGoMITM.Base.Models
{
public interface IResponseModifier
{
bool Enabled { get; }
bool ModifyResponse(RequestContext requestContext);
}
}
9 changes: 9 additions & 0 deletions PoGoMITM.Base/Models/IResponsePacker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;

namespace PoGoMITM.Base.Models
{
public interface IResponsePacker
{
byte[] GenerateResponseBody(ResponseData responseData);
}
}
19 changes: 0 additions & 19 deletions PoGoMITM.Base/Models/MessageBlock.cs

This file was deleted.

134 changes: 134 additions & 0 deletions PoGoMITM.Base/Models/POGOProtosRequestPacker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Google.Protobuf;
using Google.Protobuf.Collections;
using PoGoMITM.Base.Utils.Crypt;
using POGOProtos.Networking.Envelopes;
using POGOProtos.Networking.Platform;
using POGOProtos.Networking.Platform.Requests;
using POGOProtos.Networking.Requests;

namespace PoGoMITM.Base.Models
{
public class POGOProtosRequestPacker : IRequestPacker
{
public byte[] GenerateRequestBody(RequestData requestData)
{
var requestEnvelope = new RequestEnvelope(requestData.RequestEnvelope);
requestEnvelope.Requests.Clear();
foreach (var request in requestData.Requests)
{
var requestItem = new Request();
requestItem.RequestType = request.Key;
requestItem.RequestMessage = request.Value.ToByteString();
requestEnvelope.Requests.Add(requestItem);
}

var signatureRequest = GetSignatureRequest(requestData);
requestEnvelope.PlatformRequests.Clear();
foreach (var platformRequest in requestData.RequestEnvelope.PlatformRequests)
{
if (platformRequest.Type == PlatformRequestType.SendEncryptedSignature)
{
requestEnvelope.PlatformRequests.Add(signatureRequest);
}
else
{
requestEnvelope.PlatformRequests.Add(platformRequest);
}
}

return requestEnvelope.ToByteArray();
}


private RequestEnvelope.Types.PlatformRequest GetSignatureRequest(RequestData requestData)
{
var serializedTicket = requestData.RequestEnvelope.AuthTicket != null ? requestData.RequestEnvelope.AuthTicket.ToByteArray() : requestData.RequestEnvelope.AuthInfo.ToByteArray();
var firstHash = CalculateHash32(serializedTicket, 0x61656632);
var locationBytes = BitConverter.GetBytes(requestData.RequestEnvelope.Latitude).Reverse()
.Concat(BitConverter.GetBytes(requestData.RequestEnvelope.Latitude).Reverse())
.Concat(BitConverter.GetBytes(requestData.RequestEnvelope.Accuracy).Reverse()).ToArray();

requestData.DecryptedSignature.LocationHash1 = CalculateHash32(locationBytes, firstHash);
requestData.DecryptedSignature.LocationHash2 = CalculateHash32(locationBytes, 0x61656632);
var seed = xxHash64.CalculateHash(serializedTicket, serializedTicket.Length, 0x61656632);
foreach (var req in requestData.RequestEnvelope.Requests)
{
var reqBytes = req.ToByteArray();
requestData.DecryptedSignature.RequestHash.Add(xxHash64.CalculateHash(reqBytes, reqBytes.Length, seed));
//requestContext.DecryptedSignature.Unknown25 = 7363665268261373700;
}

var platformRequest = new RequestEnvelope.Types.PlatformRequest()
{
Type = PlatformRequestType.SendEncryptedSignature,
RequestMessage = new SendEncryptedSignatureRequest()
{
EncryptedSignature = ByteString.CopyFrom(Encryption.Encrypt(requestData.DecryptedSignature.ToByteArray())),
}.ToByteString(),
};
return platformRequest;
}

private uint CalculateHash32(byte[] bytes, uint seed)
{
var xxHash = new xxHash32();
xxHash.Init(seed);
xxHash.Update(bytes, bytes.Length);
return xxHash.Digest();
}

//_requestSeedHasher = new xxHash(64, 0x61656632);
//_locationSeedHasher = new xxHash32(32, 0x61656632);

////_unknown25Hasher = new xxHash(64, 0x88533787);
//_unknown25hash = 7363665268261374000; //BitConverter.ToInt64(_unknown25Hasher.ComputeHash(System.Text.Encoding.ASCII.GetBytes("\"b8fa9757195897aae92c53dbcf8a60fb3d86d745\"")), 0);


//private RequestEnvelope.Types.PlatformRequest GenerateEncrypterSignaturePlatformRequest(double accuracy, IEnumerable<IMessage> requests, byte[] ticketSerialized, List<Signature.Types.LocationFix> locationFixes)
//{
// var _locationSeedHasher = new xxHash32();
// var sig = new Signature();
// //sig.Timestamp = (ulong)DateTime.UtcNow.ToUnixMilliseconds();
// //sig.TimestampSinceStart = sig.Timestamp - LastLoginTime;
// // according to google, normalizing the angles means normalizing *0 to 360* degree values to -180..180


// var locationSeed = BitConverter.ToUInt32(xxHash32.CalculateHash(ticketSerialized, 32, 0x61656632).GetHashCode());

// var locationHasher = new xxHash(32, locationSeed);
// var locationBytes =
// BitConverter.GetBytes(CurrentLatitude).Reverse()
// .Concat(BitConverter.GetBytes(CurrentLongitude).Reverse())
// .Concat(BitConverter.GetBytes(accuracy).Reverse()).ToArray();

// sig.LocationHash1 = BitConverter.ToUInt32(locationHasher.ComputeHash(locationBytes), 0);

// sig.LocationHash2 = BitConverter.ToUInt32(_locationSeedHasher.ComputeHash(locationBytes), 0);

// var requestSeed = BitConverter.ToUInt64(_requestSeedHasher.ComputeHash(ticketSerialized), 0);
// var requestHasher = new xxHash(64, requestSeed);
// foreach (var req in requests)
// {
// sig.RequestHash.Add(BitConverter.ToUInt64(requestHasher.ComputeHash(req.ToByteArray()), 0));
// }

// sig.SessionHash = ByteString.CopyFrom(_sessionHash);
// sig.Unknown25 = _unknown25hash;

// var platformRequest = new RequestEnvelope.Types.PlatformRequest()
// {
// Type = POGOProtos.Networking.Platform.PlatformRequestType.SendEncryptedSignature,
// RequestMessage = new SendEncryptedSignatureRequest()
// {
// EncryptedSignature = ByteString.CopyFrom(Encrypt(sig.ToByteArray())),
// }.ToByteString(),
// };
// return platformRequest;
//}
}
}
Loading

0 comments on commit cf845ca

Please sign in to comment.