diff --git a/.gitattributes b/.gitattributes index bdb0cab..7351b55 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,17 +1,17 @@ -# Auto detect text files and perform LF normalization -* text=auto - -# Custom for Visual Studio -*.cs diff=csharp - -# Standard to msysgit -*.doc diff=astextplain -*.DOC diff=astextplain -*.docx diff=astextplain -*.DOCX diff=astextplain -*.dot diff=astextplain -*.DOT diff=astextplain -*.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore index 10d4dc7..ebed997 100644 --- a/.gitignore +++ b/.gitignore @@ -1,256 +1,258 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# User-specific files -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ - -# Visual Studio 2015 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# DNX -project.lock.json -project.fragment.lock.json -artifacts/ - -*_i.c -*_p.c -*_i.h -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding add-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config -# NuGet v3's project.json files produces more ignoreable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.pfx -*.publishsettings -node_modules/ -orleans.codegen.cs - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -*.mdf -*.ldf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# JetBrains Rider -.idea/ -*.sln.iml - -# CodeRush -.cr/ \ No newline at end of file +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ +*.cache +obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache \ No newline at end of file diff --git a/Extensions/HttpClientExtensions.cs b/Extensions/HttpClientExtensions.cs index df21cf7..0db3d61 100644 --- a/Extensions/HttpClientExtensions.cs +++ b/Extensions/HttpClientExtensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Diagnostics; using System.Net.Http; using System.Threading.Tasks; @@ -105,4 +105,4 @@ public static async Task PostProto(this System.Net.H return decodedResponse; } } -} +} \ No newline at end of file diff --git a/Helpers/Crypt.cs b/Helpers/Crypt.cs index 7e70b3d..83b310c 100644 --- a/Helpers/Crypt.cs +++ b/Helpers/Crypt.cs @@ -1,69 +1,69 @@ -using System; -using System.Runtime.InteropServices; -using System.Security.Cryptography; - -namespace PokemonGo.RocketAPI.Helpers -{ - public class Crypt - { - private EncryptDelegate encryptNative; - - public Crypt() - { - if (encryptNative == null) - encryptNative = (EncryptDelegate)LoadFunction(@"Resources\encrypt.dll", "encrypt"); - } - - [DllImport("Kernel32.dll")] - private static extern IntPtr LoadLibrary(string path); - - [DllImport("Kernel32.dll")] - private static extern IntPtr GetProcAddress(IntPtr hModule, string procName); - - [DllImport("kernel32.dll", EntryPoint = "RtlFillMemory", SetLastError = false)] - private static extern void FillMemory(IntPtr destination, uint length, byte fill); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private unsafe delegate int EncryptDelegate(IntPtr arr, int length, IntPtr iv, int ivsize, IntPtr output, out int outputSize); - - private Delegate LoadFunction(string dllPath, string functionName) - { - var hModule = LoadLibrary(dllPath); - var functionAddress = GetProcAddress(hModule, functionName); - return Marshal.GetDelegateForFunctionPointer(functionAddress, typeof(T)); - } - - private byte[] GetURandom(int size) - { - var rng = new RNGCryptoServiceProvider(); - var buffer = new byte[size]; - rng.GetBytes(buffer); - return buffer; - } - - public byte[] Encrypt(byte[] bytes) - { - var outputLength = 32 + bytes.Length + (256 - (bytes.Length % 256)); - var ptr = Marshal.AllocHGlobal(outputLength); - var ptrOutput = Marshal.AllocHGlobal(outputLength); - FillMemory(ptr, (uint)outputLength, 0); - FillMemory(ptrOutput, (uint)outputLength, 0); - Marshal.Copy(bytes, 0, ptr, bytes.Length); - - var iv = GetURandom(32); - var iv_ptr = Marshal.AllocHGlobal(iv.Length); - Marshal.Copy(iv, 0, iv_ptr, iv.Length); - - try - { - var outputSize = outputLength; - encryptNative(ptr, bytes.Length, iv_ptr, iv.Length, ptrOutput, out outputSize); - } - catch { } - - var output = new byte[outputLength]; - Marshal.Copy(ptrOutput, output, 0, outputLength); - return output; - } - } -} +using System; +using System.Runtime.InteropServices; +using System.Security.Cryptography; + +namespace PokemonGo.RocketAPI.Helpers +{ + public class Crypt + { + private EncryptDelegate encryptNative; + + public Crypt() + { + if (encryptNative == null) + encryptNative = (EncryptDelegate)LoadFunction(@"Resources\encrypt.dll", "encrypt"); + } + + [DllImport("Kernel32.dll")] + private static extern IntPtr LoadLibrary(string path); + + [DllImport("Kernel32.dll")] + private static extern IntPtr GetProcAddress(IntPtr hModule, string procName); + + [DllImport("kernel32.dll", EntryPoint = "RtlFillMemory", SetLastError = false)] + private static extern void FillMemory(IntPtr destination, uint length, byte fill); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private unsafe delegate int EncryptDelegate(IntPtr arr, int length, IntPtr iv, int ivsize, IntPtr output, out int outputSize); + + private Delegate LoadFunction(string dllPath, string functionName) + { + var hModule = LoadLibrary(dllPath); + var functionAddress = GetProcAddress(hModule, functionName); + return Marshal.GetDelegateForFunctionPointer(functionAddress, typeof(T)); + } + + private byte[] GetURandom(int size) + { + var rng = new RNGCryptoServiceProvider(); + var buffer = new byte[size]; + rng.GetBytes(buffer); + return buffer; + } + + public byte[] Encrypt(byte[] bytes) + { + var outputLength = 32 + bytes.Length + (256 - (bytes.Length % 256)); + var ptr = Marshal.AllocHGlobal(outputLength); + var ptrOutput = Marshal.AllocHGlobal(outputLength); + FillMemory(ptr, (uint)outputLength, 0); + FillMemory(ptrOutput, (uint)outputLength, 0); + Marshal.Copy(bytes, 0, ptr, bytes.Length); + + var iv = GetURandom(32); + var iv_ptr = Marshal.AllocHGlobal(iv.Length); + Marshal.Copy(iv, 0, iv_ptr, iv.Length); + + try + { + var outputSize = outputLength; + encryptNative(ptr, bytes.Length, iv_ptr, iv.Length, ptrOutput, out outputSize); + } + catch { } + + var output = new byte[outputLength]; + Marshal.Copy(ptrOutput, output, 0, outputLength); + return output; + } + } +} diff --git a/Helpers/RandomHelper.cs b/Helpers/RandomHelper.cs index 2999507..f56ee02 100644 --- a/Helpers/RandomHelper.cs +++ b/Helpers/RandomHelper.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace PokemonGo.RocketAPI.Helpers { @@ -15,4 +15,4 @@ public static long GetLongRandom(long min, long max) return Math.Abs(longRand%(max - min)) + min; } } -} +} \ No newline at end of file diff --git a/Helpers/RequestBuilder.cs b/Helpers/RequestBuilder.cs index b521cdc..38d780b 100644 --- a/Helpers/RequestBuilder.cs +++ b/Helpers/RequestBuilder.cs @@ -1,221 +1,529 @@ -using Google.Protobuf; -using PokemonGo.RocketAPI.Enums; -using POGOProtos.Networking; -using POGOProtos.Networking.Envelopes; -using POGOProtos.Networking.Requests; -using System; -using System.Runtime.InteropServices; -using System.Diagnostics; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using PokemonGo.RocketAPI.Extensions; - -namespace PokemonGo.RocketAPI.Helpers -{ - public class RequestBuilder - { - private readonly string _authToken; - private readonly AuthType _authType; - private readonly double _latitude; - private readonly double _longitude; - private readonly double _altitude; - private readonly AuthTicket _authTicket; - static private readonly Stopwatch _internalWatch = new Stopwatch(); - private readonly ISettings settings; - - public RequestBuilder(string authToken, AuthType authType, double latitude, double longitude, double altitude, ISettings settings, AuthTicket authTicket = null) - { - _authToken = authToken; - _authType = authType; - _latitude = latitude; - _longitude = longitude; - _altitude = altitude; - this.settings = settings; - _authTicket = authTicket; - if (!_internalWatch.IsRunning) - _internalWatch.Start(); - } - - private Unknown6 GenerateSignature(IEnumerable requests) - { - var sig = new POGOProtos.Networking.Signature(); - sig.TimestampSinceStart = (ulong)_internalWatch.ElapsedMilliseconds; - sig.Timestamp = (ulong)DateTime.UtcNow.ToUnixTime(); - sig.SensorInfo = new POGOProtos.Networking.Signature.Types.SensorInfo() - { - AccelNormalizedZ = GenRandom(9.8), - AccelNormalizedX = GenRandom(0.02), - AccelNormalizedY = GenRandom(0.3), - TimestampSnapshot = (ulong)_internalWatch.ElapsedMilliseconds - 230, - MagnetometerX = GenRandom(0.12271042913198471), - MagnetometerY = GenRandom(-0.015570580959320068), - MagnetometerZ = GenRandom(0.010850906372070313), - AngleNormalizedX = GenRandom(17.950439453125), - AngleNormalizedY = GenRandom(-23.36273193359375), - AngleNormalizedZ = GenRandom(-48.8250732421875), - AccelRawX = GenRandom(-0.0120010357350111), - AccelRawY = GenRandom(-0.04214850440621376), - AccelRawZ = GenRandom(0.94571763277053833), - GyroscopeRawX = GenRandom(7.62939453125e-005), - GyroscopeRawY = GenRandom(-0.00054931640625), - GyroscopeRawZ = GenRandom(0.0024566650390625), - AccelerometerAxes = 3 - }; - sig.DeviceInfo = new POGOProtos.Networking.Signature.Types.DeviceInfo() - { - DeviceId = settings.DeviceId, - AndroidBoardName = settings.AndroidBoardName, - AndroidBootloader = settings.AndroidBootloader, - DeviceBrand = settings.DeviceBrand, - DeviceModel = settings.DeviceModel, - DeviceModelIdentifier = settings.DeviceModelIdentifier, - DeviceModelBoot = settings.DeviceModelBoot, - HardwareManufacturer = settings.HardwareManufacturer, - HardwareModel = settings.HardwareModel, - FirmwareBrand = settings.FirmwareBrand, - FirmwareTags = settings.FirmwareTags, - FirmwareType = settings.FirmwareType, - FirmwareFingerprint = settings.FirmwareFingerprint - }; - sig.LocationFix.Add(new POGOProtos.Networking.Signature.Types.LocationFix() - { - Provider = "network", - - //Unk4 = 120, - Latitude = (float)_latitude, - Longitude = (float)_longitude, - Altitude = (float)_altitude, - TimestampSinceStart = (ulong)_internalWatch.ElapsedMilliseconds - 200, - Floor = 3, - LocationType = 1 - }); - - //Compute 10 - var x = new System.Data.HashFunction.xxHash(32, 0x1B845238); - var firstHash = BitConverter.ToUInt32(x.ComputeHash(_authTicket.ToByteArray()), 0); - x = new System.Data.HashFunction.xxHash(32, firstHash); - var locationBytes = BitConverter.GetBytes(_latitude).Reverse() - .Concat(BitConverter.GetBytes(_longitude).Reverse()) - .Concat(BitConverter.GetBytes(_altitude).Reverse()).ToArray(); - sig.LocationHash1 = BitConverter.ToUInt32(x.ComputeHash(locationBytes), 0); - //Compute 20 - x = new System.Data.HashFunction.xxHash(32, 0x1B845238); - sig.LocationHash2 = BitConverter.ToUInt32(x.ComputeHash(locationBytes), 0); - //Compute 24 - x = new System.Data.HashFunction.xxHash(64, 0x1B845238); - var seed = BitConverter.ToUInt64(x.ComputeHash(_authTicket.ToByteArray()), 0); - x = new System.Data.HashFunction.xxHash(64, seed); - foreach (var req in requests) - sig.RequestHash.Add(BitConverter.ToUInt64(x.ComputeHash(req.ToByteArray()), 0)); - - //static for now - sig.Unk22 = ByteString.CopyFrom(new byte[16] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }); - - - Unknown6 val = new Unknown6(); - val.RequestType = 6; - val.Unknown2 = new Unknown6.Types.Unknown2(); - val.Unknown2.EncryptedSignature = ByteString.CopyFrom(Encrypt(sig.ToByteArray())); - return val; - } - private byte[] Encrypt(byte[] bytes) - { - var outputLength = 32 + bytes.Length + (256 - (bytes.Length % 256)); - var ptr = Marshal.AllocHGlobal(outputLength); - var ptrOutput = Marshal.AllocHGlobal(outputLength); - FillMemory(ptr, (uint)outputLength, 0); - FillMemory(ptrOutput, (uint)outputLength, 0); - Marshal.Copy(bytes, 0, ptr, bytes.Length); - try - { - int outputSize = outputLength; - EncryptNative(ptr, bytes.Length, new byte[32], 32, ptrOutput, out outputSize); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - var output = new byte[outputLength]; - Marshal.Copy(ptrOutput, output, 0, outputLength); - Marshal.FreeHGlobal(ptr); - Marshal.FreeHGlobal(ptrOutput); - return output; - } - - [DllImport("Resources/encrypt.dll", EntryPoint = "encrypt", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] - static extern private void EncryptNative(IntPtr arr, int length, byte[] iv, int ivsize, IntPtr output, out int outputSize); - [DllImport("kernel32.dll", EntryPoint = "RtlFillMemory", SetLastError = false)] - static extern void FillMemory(IntPtr destination, uint length, byte fill); - - public RequestEnvelope GetRequestEnvelope(params Request[] customRequests) - { - var e = new RequestEnvelope - { - StatusCode = 2, //1 - - RequestId = 1469378659230941192, //3 - Requests = { customRequests }, //4 - - //Unknown6 = , //6 - Latitude = _latitude, //7 - Longitude = _longitude, //8 - Altitude = _altitude, //9 - AuthTicket = _authTicket, //11 - MsSinceLastLocationfix = 989 //12 - }; - e.Unknown6.Add(GenerateSignature(customRequests)); - return e; - } - - public RequestEnvelope GetInitialRequestEnvelope(params Request[] customRequests) - { - var e = new RequestEnvelope - { - StatusCode = 2, //1 - - RequestId = 1469378659230941192, //3 - Requests = { customRequests }, //4 - - //Unknown6 = , //6 - Latitude = _latitude, //7 - Longitude = _longitude, //8 - Altitude = _altitude, //9 - AuthInfo = new POGOProtos.Networking.Envelopes.RequestEnvelope.Types.AuthInfo - { - Provider = _authType == AuthType.Google ? "google" : "ptc", - Token = new POGOProtos.Networking.Envelopes.RequestEnvelope.Types.AuthInfo.Types.JWT - { - Contents = _authToken, - Unknown2 = 14 - } - }, //10 - MsSinceLastLocationfix = 989 //12 - }; - return e; - } - - - - public RequestEnvelope GetRequestEnvelope(RequestType type, IMessage message) - { - return GetRequestEnvelope(new Request() - { - RequestType = type, - RequestMessage = message.ToByteString() - }); - - } - - private static readonly Random RandomDevice = new Random(); - - public static double GenRandom(double num) - { - var randomFactor = 0.3f; - var randomMin = (num * (1 - randomFactor)); - var randomMax = (num * (1 + randomFactor)); - var randomizedDelay = RandomDevice.NextDouble() * (randomMax - randomMin) + randomMin; ; - return randomizedDelay;; - } - } -} \ No newline at end of file +using Google.Protobuf; +using PokemonGo.RocketAPI.Enums; +using POGOProtos.Networking; +using POGOProtos.Networking.Envelopes; +using POGOProtos.Networking.Requests; +using POGOProtos.Networking.Platform; +using System; +using System.Net; +using System.Threading; +using System.Threading.Tasks; +using System.Runtime.InteropServices; +using System.Diagnostics; +using System.Collections.Generic; +using System.Linq; +using PokemonGo.RocketAPI.Extensions; +using POGOProtos.Networking.Platform.Requests; + +namespace PokemonGo.RocketAPI.Helpers +{ + public class RequestBuilder + { + private static readonly Stopwatch _internalWatch = new Stopwatch(); + + public static double currentSpeed { get; set; } + private readonly string _authToken; + private readonly AuthType _authType; + private readonly double _latitude; + private readonly double _longitude; + private readonly double _accuracy = (float)Math.Round(GenRandom(50, 100), 3); + private readonly double _altitude; + private readonly double _currentSpeed; + private readonly AuthTicket _authTicket; + private int _startTime; + private ulong _nextRequestId; + private readonly ISettings settings; + private ISettings DeviceBrand { get; } + + private ByteString SessionHash + { + get { return settings.SessionHash; } + set { settings.SessionHash = value; } + } + + public void GenerateNewHash() + { + var hashBytes = new byte[16]; + RandomDevice.NextBytes(hashBytes); + SessionHash = ByteString.CopyFrom(hashBytes); + } + public RequestBuilder(string authToken, AuthType authType, double latitude, double longitude, double altitude, double horizontalAccuracy, ISettings settings, AuthTicket authTicket = null) + { + _authToken = authToken; + _authType = authType; + _currentSpeed = currentSpeed; + _latitude = latitude; + _longitude = longitude; + _altitude = altitude; + _authTicket = authTicket; + _accuracy = horizontalAccuracy; + this.settings = settings; + _nextRequestId = Convert.ToUInt64(RandomDevice.NextDouble() * Math.Pow(10, 18)); + if (_startTime == 0) + _startTime = Utils.GetTime(true); + if (SessionHash == null) + { + GenerateNewHash(); + } + } + + private RequestEnvelope.Types.PlatformRequest GenerateSignature(IEnumerable requests) + { + var ticketBytes = _authTicket.ToByteArray(); + var sig = new SignalAgglomUpdates() + { + EpochTimestampMs = (ulong)Utils.GetTime(true), + TimestampMsSinceStart = (ulong)(Utils.GetTime(true) - _startTime), + LocationHashByTokenSeed = (uint)Utils.GenerateLocation1(ticketBytes, _latitude, _longitude, _accuracy), + LocationHash = (uint)Utils.GenerateLocation2(_latitude, _longitude, _accuracy), + SensorUpdates = new SignalAgglomUpdates.Types.SensorUpdate() + { + GravityX = GenRandom(-0.31110161542892456, 0.1681540310382843), + GravityY = GenRandom(-0.6574847102165222, -0.07290205359458923), + GravityZ = GenRandom(-0.9943905472755432, -0.7463029026985168), + Timestamp = (ulong)(Utils.GetTime(true) - _startTime - RandomDevice.Next(100, 400)), + AccelerationX = GenRandom(-0.139084026217, 0.138112977147), + AccelerationY = GenRandom(-0.2, 0.19), + AccelerationZ = GenRandom(-0.2, 0.4), + MagneticFieldX = GenRandom(-47.149471283, 61.8397789001), + MagneticFieldY = GenRandom(-47.149471283, 61.8397789001), + MagneticFieldZ = GenRandom(-47.149471283, 5), + AttitudePitch = GenRandom(0.0729667818829, 0.0729667818829), + AttitudeYaw = GenRandom(-2.788630499244109, 3.0586791383810468), + AttitudeRoll = GenRandom(-0.34825887123552773, 0.19347580173737935), + RotationRateX = GenRandom(-0.9703824520111084, 0.8556089401245117), + RotationRateY = GenRandom(-1.7470258474349976, 1.4218578338623047), + RotationRateZ = GenRandom(-0.9681901931762695, 0.8396636843681335), + Status = 3 + }, + DeviceInfo = new SignalAgglomUpdates.Types.DeviceInfo() + { + DeviceId = settings.DeviceId, + AndroidBoardName = settings.AndroidBoardName, + AndroidBootloader = settings.AndroidBootloader, + DeviceBrand = settings.DeviceBrand, + DeviceModel = settings.DeviceModel, + DeviceModelIdentifier = settings.DeviceModelIdentifier, + DeviceCommsModel = settings.DeviceModelBoot, + HardwareManufacturer = settings.HardwareManufacturer, + HardwareModel = settings.HardwareModel, + FirmwareBrand = settings.FirmwareBrand, + FirmwareTags = settings.FirmwareTags, + FirmwareType = settings.FirmwareType, + FirmwareFingerprint = settings.FirmwareFingerprint + } + }; + if (settings.DeviceBrand == "APPLE") + sig.LocationUpdates.Add(new SignalAgglomUpdates.Types.LocationUpdate() + { + Name = "fused", + TimestampMs = (Utils.GetTime(true) - _startTime - RandomDevice.Next(100, 300)), + Latitude = (float)_latitude, + Longitude = (float)_longitude, + Altitude = (-(float)_altitude) - 13, + DeviceSpeed = (float)_currentSpeed, + DeviceCourse = -1, + HorizontalAccuracy = (float)_accuracy, + VerticalAccuracy = RandomDevice.Next(2, 5), + ProviderStatus = 3, + Floor = 0, + LocationType = 1 + }); + else + sig.LocationUpdates.Add(new SignalAgglomUpdates.Types.LocationUpdate() + { + Name = "fused", + TimestampMs = (Utils.GetTime(true) - _startTime - RandomDevice.Next(100, 300)), + Latitude = (float)_latitude, + Longitude = (float)_longitude, + Altitude = (-(float)_altitude) - 13, + HorizontalAccuracy = (float)_accuracy, + VerticalAccuracy = RandomDevice.Next(2, 5), + ProviderStatus = 3, + Floor = 0, + LocationType = 1 + }); + + //Compute 10 + var x = new System.Data.HashFunction.xxHash(32, 0x1B845238); + var firstHash = BitConverter.ToUInt32(x.ComputeHash(_authTicket.ToByteArray()), 0); + x = new System.Data.HashFunction.xxHash(32, firstHash); + var locationBytes = BitConverter.GetBytes(_latitude).Reverse() + .Concat(BitConverter.GetBytes(_longitude).Reverse()) + .Concat(BitConverter.GetBytes(_accuracy).Reverse()).ToArray(); + sig.LocationHashByTokenSeed = BitConverter.ToUInt32(x.ComputeHash(locationBytes), 0); + //Compute 20 + x = new System.Data.HashFunction.xxHash(32, 0x1B845238); + sig.LocationHash = BitConverter.ToUInt32(x.ComputeHash(locationBytes), 0); + //Compute 24 + x = new System.Data.HashFunction.xxHash(64, 0x1B845238); + var seed = BitConverter.ToUInt64(x.ComputeHash(_authTicket.ToByteArray()), 0); + x = new System.Data.HashFunction.xxHash(64, seed); + foreach (var req in requests) + sig.RequestHashes.Add(BitConverter.ToUInt64(x.ComputeHash(req.ToByteArray()), 0)); + + sig.Field22 = SessionHash; + //static for now + sig.Field25 = 7363665268261373700; + + + + + RequestEnvelope.Types.PlatformRequest val = new RequestEnvelope.Types.PlatformRequest(); + val.Type = PlatformRequestType.SendEncryptedSignature; + SendEncryptedSignatureRequest sigRequest = new SendEncryptedSignatureRequest(); + sigRequest.EncryptedSignature = ByteString.CopyFrom(Encrypt(sig.ToByteArray())); + val.RequestMessage = sigRequest.ToByteString(); + return val; + + } + private byte[] Encrypt(byte[] bytes) + { + var outputLength = 32 + bytes.Length + (256 - (bytes.Length % 256)); + var ptr = Marshal.AllocHGlobal(outputLength); + var ptrOutput = Marshal.AllocHGlobal(outputLength); + FillMemory(ptr, (uint)outputLength, 0); + FillMemory(ptrOutput, (uint)outputLength, 0); + Marshal.Copy(bytes, 0, ptr, bytes.Length); + try + { + int outputSize = outputLength; + EncryptNative(ptr, bytes.Length, new byte[32], 32, ptrOutput, out outputSize); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + var output = new byte[outputLength]; + Marshal.Copy(ptrOutput, output, 0, outputLength); + Marshal.FreeHGlobal(ptr); + Marshal.FreeHGlobal(ptrOutput); + return output; + } + + [DllImport("Resources/encrypt.dll", EntryPoint = "encrypt", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] + static extern private void EncryptNative(IntPtr arr, int length, byte[] iv, int ivsize, IntPtr output, out int outputSize); + [DllImport("kernel32.dll", EntryPoint = "RtlFillMemory", SetLastError = false)] + static extern void FillMemory(IntPtr destination, uint length, byte fill); + + public RequestEnvelope GetRequestEnvelope(params Request[] customRequests) + { + var e = new RequestEnvelope + { + StatusCode = 2, //1 + + RequestId = _nextRequestId++, //3 + Requests = { customRequests }, //4 + + //Unknown6 = , //6 + Latitude = _latitude, //7 + Longitude = _longitude, //8 + Accuracy = _accuracy, //9 + AuthTicket = _authTicket, //11 + MsSinceLastLocationfix = RandomDevice.Next(800, 1900) //12 + }; + e.PlatformRequests.Add(GenerateSignature(customRequests)); + return e; + } + + + public RequestEnvelope GetInitialRequestEnvelope(params Request[] customRequests) + { + var e = new RequestEnvelope + { + StatusCode = 2, //1 + + RequestId = _nextRequestId++, //3 + Requests = { customRequests }, //4 + + //Unknown6 = , //6 + Latitude = _latitude, //7 + Longitude = _longitude, //8 + Accuracy = _accuracy, //9 + AuthInfo = new POGOProtos.Networking.Envelopes.RequestEnvelope.Types.AuthInfo + { + Provider = _authType == AuthType.Google ? "google" : "ptc", + Token = new POGOProtos.Networking.Envelopes.RequestEnvelope.Types.AuthInfo.Types.JWT + { + Contents = _authToken, + Unknown2 = 59 + } + }, //10 + MsSinceLastLocationfix = RandomDevice.Next(1200, 1900) //12 + }; + return e; + } + + + + public RequestEnvelope GetRequestEnvelope(RequestType type, IMessage message) + { + return GetRequestEnvelope(new Request() + { + RequestType = type, + RequestMessage = message.ToByteString() + }); + + } + + private static readonly Random RandomDevice = new Random(); + + public static double GenRandom(double num) + { + var randomFactor = 0.3f; + var randomMin = (num * (1 - randomFactor)); + var randomMax = (num * (1 + randomFactor)); + var randomizedDelay = RandomDevice.NextDouble() * (randomMax - randomMin) + randomMin; ; + return randomizedDelay;; + } + + public static double GenRandom(double min, double max) + { + return RandomDevice.NextDouble() * (max - min) + min; + } + } +======= +using Google.Protobuf; +using PokemonGo.RocketAPI.Enums; +using POGOProtos.Networking; +using POGOProtos.Networking.Envelopes; +using POGOProtos.Networking.Requests; +using System; +using System.Net; +using System.Threading; +using System.Threading.Tasks; +using System.Runtime.InteropServices; +using System.Diagnostics; +using System.Collections.Generic; +using System.Linq; +using PokemonGo.RocketAPI.Extensions; + +namespace PokemonGo.RocketAPI.Helpers +{ + public class RequestBuilder + { + public static double currentSpeed { get; set; } + private readonly string _authToken; + private readonly AuthType _authType; + private readonly double _latitude; + private readonly double _longitude; + private readonly double _accuracy = (float)Math.Round(GenRandom(50, 250), 7); + private readonly double _altitude; + private readonly double _currentSpeed; + private readonly AuthTicket _authTicket; + private int _startTime; + private ulong _nextRequestId; + private readonly ISettings settings; + + public RequestBuilder(string authToken, AuthType authType, double latitude, double longitude, double altitude, double horizontalAccuracy, ISettings settings, AuthTicket authTicket = null) + { + _authToken = authToken; + _authType = authType; + _currentSpeed = currentSpeed; + _latitude = latitude; + _longitude = longitude; + _altitude = altitude; + _authTicket = authTicket; + _accuracy = horizontalAccuracy; + this.settings = settings; + _nextRequestId = Convert.ToUInt64(RandomDevice.NextDouble() * Math.Pow(10, 18)); + if (_startTime == 0) + _startTime = Utils.GetTime(true); + } + + private Unknown6 GenerateSignature(IEnumerable requests) + { + var ticketBytes = _authTicket.ToByteArray(); + var sig = new Signature() + { + Timestamp = (ulong)Utils.GetTime(true), + TimestampSinceStart = (ulong)(Utils.GetTime(true) - _startTime), + LocationHash1 = Utils.GenerateLocation1(ticketBytes, _latitude, _longitude, _altitude), + LocationHash2 = Utils.GenerateLocation2(_latitude, _longitude, _altitude), + SensorInfo = new Signature.Types.SensorInfo() + { + AccelNormalizedX = GenRandom(-0.31110161542892456, 0.1681540310382843), + AccelNormalizedY = GenRandom(-0.6574847102165222, -0.07290205359458923), + AccelNormalizedZ = GenRandom(-0.9943905472755432, -0.7463029026985168), + TimestampSnapshot = (ulong)(Utils.GetTime(true) - _startTime - RandomDevice.Next(100, 400)), + MagnetometerX = GenRandom(-0.139084026217, 0.138112977147), + MagnetometerY = GenRandom(-0.2, 0.19), + MagnetometerZ = GenRandom(-0.2, 0.4), + AngleNormalizedX = GenRandom(-47.149471283, 61.8397789001), + AngleNormalizedY = GenRandom(-47.149471283, 61.8397789001), + AngleNormalizedZ = GenRandom(-47.149471283, 5), + AccelRawX = GenRandom(0.0729667818829, 0.0729667818829), + AccelRawY = GenRandom(-2.788630499244109, 3.0586791383810468), + AccelRawZ = GenRandom(-0.34825887123552773, 0.19347580173737935), + GyroscopeRawX = GenRandom(-0.9703824520111084, 0.8556089401245117), + GyroscopeRawY = GenRandom(-1.7470258474349976, 1.4218578338623047), + GyroscopeRawZ = GenRandom(-0.9681901931762695, 0.8396636843681335), + AccelerometerAxes = 3 + }, + DeviceInfo = new Signature.Types.DeviceInfo() + { + DeviceId = settings.DeviceId, + AndroidBoardName = settings.AndroidBoardName, + AndroidBootloader = settings.AndroidBootloader, + DeviceBrand = settings.DeviceBrand, + DeviceModel = settings.DeviceModel, + DeviceModelIdentifier = settings.DeviceModelIdentifier, + DeviceModelBoot = settings.DeviceModelBoot, + HardwareManufacturer = settings.HardwareManufacturer, + HardwareModel = settings.HardwareModel, + FirmwareBrand = settings.FirmwareBrand, + FirmwareTags = settings.FirmwareTags, + FirmwareType = settings.FirmwareType, + FirmwareFingerprint = settings.FirmwareFingerprint + } + }; + sig.LocationFix.Add(new POGOProtos.Networking.Envelopes.Signature.Types.LocationFix() + { + Provider = "fused", + TimestampSnapshot = (ulong)(Utils.GetTime(true) - _startTime - RandomDevice.Next(100, 300)), + Latitude = (float)_latitude, + Longitude = (float)_longitude, + Altitude = (float)_altitude, + Speed = (float)_currentSpeed, + Course = -1, + HorizontalAccuracy = (float)_accuracy, + VerticalAccuracy = RandomDevice.Next(2, 5), + ProviderStatus = 3, + Floor = 0, + LocationType = 1 + }); + + //Compute 10 + var x = new System.Data.HashFunction.xxHash(32, 0x1B845238); + var firstHash = BitConverter.ToUInt32(x.ComputeHash(_authTicket.ToByteArray()), 0); + x = new System.Data.HashFunction.xxHash(32, firstHash); + var locationBytes = BitConverter.GetBytes(_latitude).Reverse() + .Concat(BitConverter.GetBytes(_longitude).Reverse()) + .Concat(BitConverter.GetBytes(_accuracy).Reverse()).ToArray(); + sig.LocationHash1 = BitConverter.ToUInt32(x.ComputeHash(locationBytes), 0); + //Compute 20 + x = new System.Data.HashFunction.xxHash(32, 0x1B845238); + sig.LocationHash2 = BitConverter.ToUInt32(x.ComputeHash(locationBytes), 0); + //Compute 24 + x = new System.Data.HashFunction.xxHash(64, 0x1B845238); + var seed = BitConverter.ToUInt64(x.ComputeHash(_authTicket.ToByteArray()), 0); + x = new System.Data.HashFunction.xxHash(64, seed); + foreach (var req in requests) + sig.RequestHash.Add(BitConverter.ToUInt64(x.ComputeHash(req.ToByteArray()), 0)); + + //static for now + sig.SessionHash = ByteString.CopyFrom(new byte[16] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }); + sig.Unknown25 = 7363665268261373700; + + Unknown6 val = new Unknown6(); + val.RequestType = 6; + val.Unknown2 = new Unknown6.Types.Unknown2(); + val.Unknown2.EncryptedSignature = ByteString.CopyFrom(Encrypt(sig.ToByteArray())); + return val; + } + private byte[] Encrypt(byte[] bytes) + { + var outputLength = 32 + bytes.Length + (256 - (bytes.Length % 256)); + var ptr = Marshal.AllocHGlobal(outputLength); + var ptrOutput = Marshal.AllocHGlobal(outputLength); + FillMemory(ptr, (uint)outputLength, 0); + FillMemory(ptrOutput, (uint)outputLength, 0); + Marshal.Copy(bytes, 0, ptr, bytes.Length); + try + { + int outputSize = outputLength; + EncryptNative(ptr, bytes.Length, new byte[32], 32, ptrOutput, out outputSize); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + var output = new byte[outputLength]; + Marshal.Copy(ptrOutput, output, 0, outputLength); + Marshal.FreeHGlobal(ptr); + Marshal.FreeHGlobal(ptrOutput); + return output; + } + + [DllImport("Resources/encrypt.dll", EntryPoint = "encrypt", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] + static extern private void EncryptNative(IntPtr arr, int length, byte[] iv, int ivsize, IntPtr output, out int outputSize); + [DllImport("kernel32.dll", EntryPoint = "RtlFillMemory", SetLastError = false)] + static extern void FillMemory(IntPtr destination, uint length, byte fill); + + public RequestEnvelope GetRequestEnvelope(params Request[] customRequests) + { + var e = new RequestEnvelope + { + StatusCode = 2, //1 + + RequestId = _nextRequestId++, //3 + Requests = { customRequests }, //4 + + //Unknown6 = , //6 + Latitude = _latitude, //7 + Longitude = _longitude, //8 + Accuracy = _accuracy, //9 + AuthTicket = _authTicket, //11 + MsSinceLastLocationfix = 989 //12 + }; + e.Unknown6.Add(GenerateSignature(customRequests)); + return e; + } + + + public RequestEnvelope GetInitialRequestEnvelope(params Request[] customRequests) + { + var e = new RequestEnvelope + { + StatusCode = 2, //1 + + RequestId = _nextRequestId++, //3 + Requests = { customRequests }, //4 + + //Unknown6 = , //6 + Latitude = _latitude, //7 + Longitude = _longitude, //8 + Accuracy = _accuracy, //9 + AuthInfo = new POGOProtos.Networking.Envelopes.RequestEnvelope.Types.AuthInfo + { + Provider = _authType == AuthType.Google ? "google" : "ptc", + Token = new POGOProtos.Networking.Envelopes.RequestEnvelope.Types.AuthInfo.Types.JWT + { + Contents = _authToken, + Unknown2 = 14 + } + }, //10 + MsSinceLastLocationfix = 989 //12 + }; + return e; + } + + + + public RequestEnvelope GetRequestEnvelope(RequestType type, IMessage message) + { + return GetRequestEnvelope(new Request() + { + RequestType = type, + RequestMessage = message.ToByteString() + }); + + } + + private static readonly Random RandomDevice = new Random(); + + public static double GenRandom(double num) + { + var randomFactor = 0.3f; + var randomMin = (num * (1 - randomFactor)); + var randomMax = (num * (1 + randomFactor)); + var randomizedDelay = RandomDevice.NextDouble() * (randomMax - randomMin) + randomMin; ; + return randomizedDelay; ; + } + + public static double GenRandom(double min, double max) + { + return RandomDevice.NextDouble() * (max - min) + min; + } + } +} diff --git a/Helpers/Utils.cs b/Helpers/Utils.cs index e882740..f2965c6 100644 --- a/Helpers/Utils.cs +++ b/Helpers/Utils.cs @@ -1,18 +1,63 @@ -using System; - -namespace PokemonGo.RocketAPI.Helpers -{ - public class Utils - { - public static ulong FloatAsUlong(double value) - { - var bytes = BitConverter.GetBytes(value); - return BitConverter.ToUInt64(bytes, 0); - } - - public static DateTime FromUnixTimeUtc(long time) - { - return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(time); - } - } +using System; +using System.Collections.Generic; +using System.Data.HashFunction; +using System.Linq; + +namespace PokemonGo.RocketAPI.Helpers +{ + public class Utils + { + public static ulong FloatAsUlong(double value) + { + var bytes = BitConverter.GetBytes(value); + return BitConverter.ToUInt64(bytes, 0); + } + + public static DateTime FromUnixTimeUtc(long time) + { + return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(time); + } + + public static int GetTime(bool ms = false) + { + TimeSpan timeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1)); + + if (ms) + return (int)Math.Round(timeSpan.TotalMilliseconds); + else + return (int)Math.Round(timeSpan.TotalSeconds); + } + + public static uint GenerateLocation1(byte[] authTicket, double lat, double lng, double alt) + { + var seed = BitConverter.ToUInt32(new xxHash(32, 0x1B845238).ComputeHash(authTicket), 0); + var xxh32 = new xxHash(32, seed); + + var locationBytes = new List(); + locationBytes.AddRange(BitConverter.GetBytes(lat).Reverse()); + locationBytes.AddRange(BitConverter.GetBytes(lng).Reverse()); + locationBytes.AddRange(BitConverter.GetBytes(alt).Reverse()); + + return BitConverter.ToUInt32(xxh32.ComputeHash(locationBytes.ToArray()), 0); + } + + public static uint GenerateLocation2(double lat, double lng, double alt) + { + var xxh32 = new xxHash(32, 0x1B845238); + + var locationBytes = new List(); + locationBytes.AddRange(BitConverter.GetBytes(lat).Reverse()); + locationBytes.AddRange(BitConverter.GetBytes(lng).Reverse()); + locationBytes.AddRange(BitConverter.GetBytes(alt).Reverse()); + + return BitConverter.ToUInt32(xxh32.ComputeHash(locationBytes.ToArray()), 0); + } + + public static ulong GenerateRequestHash(byte[] authTicket, byte[] request) + { + var seed = BitConverter.ToUInt64(new xxHash(64, 0x1B845238).ComputeHash(authTicket), 0); + var xxh64 = new xxHash(64, seed); + return BitConverter.ToUInt64(xxh64.ComputeHash(request), 0); + } + } } \ No newline at end of file diff --git a/ISettings.cs b/ISettings.cs index f00bbc0..a0cc7ae 100644 --- a/ISettings.cs +++ b/ISettings.cs @@ -1,4 +1,5 @@ -using PokemonGo.RocketAPI.Enums; +using Google.Protobuf; +using PokemonGo.RocketAPI.Enums; namespace PokemonGo.RocketAPI { @@ -26,6 +27,7 @@ public interface ISettings string FirmwareTags { get; set; } string FirmwareType { get; set; } string FirmwareFingerprint { get; set; } + ByteString SessionHash { get; set; } bool UseProxy { get; set; } bool UseProxyAuthentication { get; set; } string UseProxyHost { get; set; } diff --git a/PokemonGo.RocketAPI.csproj b/PokemonGo.RocketAPI.csproj index 49a50ba..2c8da4e 100644 --- a/PokemonGo.RocketAPI.csproj +++ b/PokemonGo.RocketAPI.csproj @@ -1,166 +1,173 @@ - - - - - Debug - AnyCPU - {05D2DA44-1B8E-4CF7-94ED-4D52451CD095} - Library - Properties - PokemonGo.RocketAPI - PokemonGo.Rocket.API - v4.5.2 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - true - bin\x86\Debug\ - DEBUG;TRACE - full - x86 - prompt - MinimumRecommendedRules.ruleset - - - bin\x86\Release\ - TRACE - true - pdbonly - x86 - prompt - MinimumRecommendedRules.ruleset - - - - $(SolutionDir)\packages\C5.2.4.5947.17249\lib\net45\C5.dll - True - - - $(SolutionDir)\packages\Google.Protobuf.3.0.0-beta4\lib\net45\Google.Protobuf.dll - True - - - ..\..\packages\GPSOAuthSharp.0.0.5\lib\GPSOAuthSharp.dll - True - - - $(SolutionDir)\packages\EnterpriseLibrary.TransientFaultHandling.6.0.1304.0\lib\portable-net45+win+wp8\Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.dll - True - - - $(SolutionDir)\packages\EnterpriseLibrary.TransientFaultHandling.Data.6.0.1304.1\lib\NET45\Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.Data.dll - True - - - $(SolutionDir)\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - True - - - $(SolutionDir)\packages\S2Geometry.1.0.1\lib\portable-net45+wp8+win8\S2Geometry.dll - True - - - - - - ..\..\packages\System.Data.HashFunction.Core.1.8.2.2\lib\net45\System.Data.HashFunction.Core.dll - True - - - ..\..\packages\System.Data.HashFunction.Interfaces.1.0.0.2\lib\net45\System.Data.HashFunction.Interfaces.dll - True - - - ..\..\packages\System.Data.HashFunction.xxHash.1.8.2.2\lib\net45\System.Data.HashFunction.xxHash.dll - True - - - $(SolutionDir)\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll - True - - - $(SolutionDir)\packages\VarintBitConverter.1.0.0.0\lib\Net40\System.VarintBitConverter.dll - True - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {a03a7bb2-4f0b-467b-84b2-9a76e6aae6fb} - POGOProtos - - - + + + + + Debug + AnyCPU + {05D2DA44-1B8E-4CF7-94ED-4D52451CD095} + Library + Properties + PokemonGo.RocketAPI + PokemonGo.Rocket.API + v4.5.2 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + + + + $(SolutionDir)\packages\C5.2.4.5947.17249\lib\net45\C5.dll + True + + + ..\packages\Google.Protobuf.3.0.0\lib\net45\Google.Protobuf.dll + True + + + ..\..\packages\GPSOAuthSharp.0.0.5\lib\GPSOAuthSharp.dll + True + + + $(SolutionDir)\packages\EnterpriseLibrary.TransientFaultHandling.6.0.1304.0\lib\portable-net45+win+wp8\Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.dll + True + + + $(SolutionDir)\packages\EnterpriseLibrary.TransientFaultHandling.Data.6.0.1304.1\lib\NET45\Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.Data.dll + True + + + $(SolutionDir)\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + True + + + ..\packages\S2Geometry.1.0.3\lib\portable-net45+wp8+win8\S2Geometry.dll + True + + + + + + + ..\..\packages\System.Data.HashFunction.Core.1.8.2.2\lib\net45\System.Data.HashFunction.Core.dll + True + + + ..\..\packages\System.Data.HashFunction.Interfaces.1.0.0.2\lib\net45\System.Data.HashFunction.Interfaces.dll + True + + + ..\..\packages\System.Data.HashFunction.xxHash.1.8.2.2\lib\net45\System.Data.HashFunction.xxHash.dll + True + + + + $(SolutionDir)\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + True + + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.0.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + True + + + $(SolutionDir)\packages\VarintBitConverter.1.0.0.0\lib\Net40\System.VarintBitConverter.dll + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {a03a7bb2-4f0b-467b-84b2-9a76e6aae6fb} + POGOProtos + + + + --> \ No newline at end of file diff --git a/Rpc/BaseRpc.cs b/Rpc/BaseRpc.cs index bfe5cd0..ce26b4d 100644 --- a/Rpc/BaseRpc.cs +++ b/Rpc/BaseRpc.cs @@ -15,7 +15,7 @@ namespace PokemonGo.RocketAPI.Rpc public class BaseRpc { protected Client _client; - protected RequestBuilder RequestBuilder => new RequestBuilder(_client.AuthToken, _client.AuthType, _client.CurrentLatitude, _client.CurrentLongitude, _client.CurrentAltitude, _client.Settings, _client.AuthTicket); + protected RequestBuilder RequestBuilder => new RequestBuilder(_client.AuthToken, _client.AuthType, _client.CurrentLatitude, _client.CurrentLongitude, _client.CurrentAltitude, 5.0, _client.Settings, _client.AuthTicket); protected string ApiUrl => $"https://{_client.ApiUrl}/rpc"; protected BaseRpc(Client client) { @@ -61,15 +61,16 @@ protected async Task> PostProtoPayload(requestEnvelope, typeof(T1), typeof(T2), typeof(T3), typeof(T4)); return new Tuple(responses[0] as T1, responses[1] as T2, responses[2] as T3, responses[3] as T4); } - protected async Task> PostProtoPayload(RequestEnvelope requestEnvelope) where TRequest : IMessage + protected async Task> PostProtoPayload(RequestEnvelope requestEnvelope) where TRequest : IMessage where T1 : class, IMessage, new() where T2 : class, IMessage, new() where T3 : class, IMessage, new() where T4 : class, IMessage, new() where T5 : class, IMessage, new() + where T6 : class, IMessage, new() { - var responses = await PostProtoPayload(requestEnvelope, typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5)); - return new Tuple(responses[0] as T1, responses[1] as T2, responses[2] as T3, responses[3] as T4, responses[3] as T5); + var responses = await PostProtoPayload(requestEnvelope, typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6)); + return new Tuple(responses[0] as T1, responses[1] as T2, responses[2] as T3, responses[3] as T4, responses[3] as T5, responses[3] as T6); } protected async Task PostProtoPayload(RequestEnvelope requestEnvelope, params Type[] responseTypes) where TRequest : IMessage diff --git a/Rpc/Download.cs b/Rpc/Download.cs index 77d079a..23749bd 100644 --- a/Rpc/Download.cs +++ b/Rpc/Download.cs @@ -31,15 +31,15 @@ public async Task GetItemTemplates() return await PostProtoPayload(RequestType.DownloadItemTemplates, new DownloadItemTemplatesMessage()); } - public async Task GetRemoteConfigVersion(uint appVersion, string deviceManufacturer, string deviceModel, string locale, Platform platform) + public async Task GetRemoteConfigVersion(Platform platform, uint appVersion, string deviceManufacturer, string deviceModel, string locale) { return await PostProtoPayload(RequestType.DownloadRemoteConfigVersion, new DownloadRemoteConfigVersionMessage() { - AppVersion = appVersion, + Platform = platform, DeviceManufacturer = deviceManufacturer, DeviceModel = deviceModel, Locale = locale, - Platform = platform + AppVersion = appVersion }); } @@ -47,11 +47,11 @@ public async Task GetAssetDigest(uint appVersion, string { return await PostProtoPayload(RequestType.GetAssetDigest, new GetAssetDigestMessage() { - AppVersion = appVersion, + Platform = platform, DeviceManufacturer = deviceManufacturer, DeviceModel = deviceModel, Locale = locale, - Platform = platform + AppVersion = appVersion }); } diff --git a/Rpc/Login.cs b/Rpc/Login.cs index b188ca3..04ee0b1 100644 --- a/Rpc/Login.cs +++ b/Rpc/Login.cs @@ -49,16 +49,7 @@ private async Task SetServer() #region Standard intial request messages in right Order var getPlayerMessage = new GetPlayerMessage(); - var getHatchedEggsMessage = new GetHatchedEggsMessage(); - var getInventoryMessage = new GetInventoryMessage - { - LastTimestampMs = DateTime.UtcNow.ToUnixTime() - }; - var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage(); - var downloadSettingsMessage = new DownloadSettingsMessage - { - Hash = "2788184af4004004d6ab0740f7632983332106f6" - }; + var checkChallengeMessage = new CheckChallengeMessage(); #endregion @@ -69,20 +60,8 @@ private async Task SetServer() RequestMessage = getPlayerMessage.ToByteString() }, new Request { - RequestType = RequestType.GetHatchedEggs, - RequestMessage = getHatchedEggsMessage.ToByteString() - }, new Request - { - RequestType = RequestType.GetInventory, - RequestMessage = getInventoryMessage.ToByteString() - }, new Request - { - RequestType = RequestType.CheckAwardedBadges, - RequestMessage = checkAwardedBadgesMessage.ToByteString() - }, new Request - { - RequestType = RequestType.DownloadSettings, - RequestMessage = downloadSettingsMessage.ToByteString() + RequestType = RequestType.CheckChallenge, + RequestMessage = checkChallengeMessage.ToByteString() }); diff --git a/Rpc/Map.cs b/Rpc/Map.cs index 99b4a3d..1506420 100644 --- a/Rpc/Map.cs +++ b/Rpc/Map.cs @@ -9,6 +9,7 @@ using POGOProtos.Networking.Requests; using POGOProtos.Networking.Requests.Messages; using POGOProtos.Networking.Responses; +using POGOProtos.Networking.Envelopes; namespace PokemonGo.RocketAPI.Rpc { @@ -18,7 +19,7 @@ public Map(Client client) : base(client) { } - public async Task> GetMapObjects() + public async Task> GetMapObjects() { #region Messages @@ -29,6 +30,7 @@ public async Task(request); + return await PostProtoPayload(request); } public async Task GetIncensePokemons() diff --git a/Rpc/Misc.cs b/Rpc/Misc.cs index 5f48874..83ca32d 100644 --- a/Rpc/Misc.cs +++ b/Rpc/Misc.cs @@ -1,56 +1,60 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using POGOProtos.Networking.Requests; -using POGOProtos.Networking.Requests.Messages; -using POGOProtos.Networking.Responses; - -namespace PokemonGo.RocketAPI.Rpc -{ - public class Misc : BaseRpc - { - public Misc(Client client) : base(client) - { - } - - - public async Task ClaimCodename(string codename) - { - return - await - PostProtoPayload(RequestType.ClaimCodename, - new ClaimCodenameMessage() - { - Codename = codename - }); - } - - public async Task CheckCodenameAvailable(string codename) - { - return - await - PostProtoPayload(RequestType.CheckCodenameAvailable, - new CheckCodenameAvailableMessage() - { - Codename = codename - }); - } - - public async Task GetSuggestedCodenames() - { - return await PostProtoPayload(RequestType.GetSuggestedCodenames, new GetSuggestedCodenamesMessage()); - } - - public async Task SendEcho() - { - return await PostProtoPayload(RequestType.Echo, new EchoMessage()); - } - - public async Task MarkTutorialComplete() - { - return await PostProtoPayload(RequestType.MarkTutorialComplete, new MarkTutorialCompleteMessage()); - } - } +using System.Threading.Tasks; +using POGOProtos.Networking.Requests; +using POGOProtos.Networking.Requests.Messages; +using POGOProtos.Networking.Responses; +using Google.Protobuf.Collections; +using POGOProtos.Enums; + + +namespace PokemonGo.RocketAPI.Rpc +{ + public class Misc : BaseRpc + { + public Misc(Client client) : base(client) + { + } + + + public async Task ClaimCodename(string codename) + { + return + await + PostProtoPayload(RequestType.ClaimCodename, + new ClaimCodenameMessage() + { + Codename = codename + }); + } + + public async Task CheckCodenameAvailable(string codename) + { + return + await + PostProtoPayload(RequestType.CheckCodenameAvailable, + new CheckCodenameAvailableMessage() + { + Codename = codename + }); + } + + public async Task GetSuggestedCodenames() + { + return await PostProtoPayload(RequestType.GetSuggestedCodenames, new GetSuggestedCodenamesMessage()); + } + + public async Task SendEcho() + { + return await PostProtoPayload(RequestType.Echo, new EchoMessage()); + } + + public async Task MarkTutorialComplete(RepeatedField toComplete) + { + return await PostProtoPayload(RequestType.MarkTutorialComplete, new MarkTutorialCompleteMessage() + { + SendMarketingEmails = false, + SendPushNotifications = false, + TutorialsCompleted = { toComplete } + }); + } + } } \ No newline at end of file diff --git a/packages.config b/packages.config index 6f08b67..510acdd 100644 --- a/packages.config +++ b/packages.config @@ -3,15 +3,47 @@ - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file