From 6626516d2b82f5535e16a16a71d77f7fbe322c8b Mon Sep 17 00:00:00 2001 From: iphydf Date: Sun, 28 Aug 2016 11:44:52 +0100 Subject: [PATCH] Hack to make scalar numeric fields packed. proto3 has this as default, but proto-lens doesn't think so. --- Makefile | 6 +++++- protos | 2 +- src/Pokemon/Envelope.hs | 8 ++++---- src/Pokemon/Location.hs | 20 ++++++++++++++++++-- test/Pokemon/EnvelopeSpec.hs | 11 +---------- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 9feb2b3..97b8085 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,9 @@ PROCS := $(shell sysctl -n hw.ncpu) endif +SCALAR_NUMERIC := fixed32|fixed64|int32|int64|uint32|uint64|float|bool + + .PHONY: run run: dist/build/pokemon/pokemon cabal run pokemon --jobs=$(PROCS) @@ -36,7 +39,8 @@ protos/src/Pokemon.proto: $(shell find protos/src/POGOProtos -name "*.proto") echo 'syntax = "proto3";' > $@ (for i in $^; do cat $$i; echo; done) \ | egrep -v '^(syntax|package|import)' \ - | sed -e 's/\.POGOProtos\.[^ ]*\.//g' \ + | sed -E -e 's/\.POGOProtos\.[^ ]+\.//g' \ + | sed -E -e 's/(repeated (${SCALAR_NUMERIC}) [a-z_]+ = [0-9]+);/\1 [packed=true];/' \ >> $@ src/encrypt.c: diff --git a/protos b/protos index e98e025..df92b09 160000 --- a/protos +++ b/protos @@ -1 +1 @@ -Subproject commit e98e025277e6d84ae3508a91f6d2f1929e6a6d3b +Subproject commit df92b09ce720e8b59d719abfe0f99635f1c87585 diff --git a/src/Pokemon/Envelope.hs b/src/Pokemon/Envelope.hs index 7727a42..10e7ab0 100644 --- a/src/Pokemon/Envelope.hs +++ b/src/Pokemon/Envelope.hs @@ -24,7 +24,7 @@ import Pokemon.Proto (AuthTicket, Request, RequestEnvelope, RequestEnvelope'AuthInfo (..), RequestEnvelope'AuthInfo'JWT (..), Signature, Unknown6, - Unknown6'Unknown2 (..), altitude, + Unknown6'Unknown2 (..), accuracy, authInfo, authTicket, deviceInfo, encryptedSignature, latitude, locationHash1, locationHash2, longitude, @@ -103,8 +103,8 @@ authenticate sHash iv now startTime (AuthTicket ticket) env = where lat = env ^. latitude lng = env ^. longitude - alt = env ^. altitude - loc = Location.fromLatLngAlt lat lng alt + acc = env ^. accuracy + loc = Location.fromLatLngAcc lat lng acc ticketSerialised = encodeMessage ticket @@ -140,7 +140,7 @@ envelope reqId sHash iv now startTime auth location reqs = & requests .~ reqs & latitude .~ Location.latitude location & longitude .~ Location.longitude location - & altitude .~ Location.altitude location + & accuracy .~ Location.accuracy location & msSinceLastLocationfix .~ 989 diff --git a/src/Pokemon/Location.hs b/src/Pokemon/Location.hs index f09aca5..1c279ff 100644 --- a/src/Pokemon/Location.hs +++ b/src/Pokemon/Location.hs @@ -34,7 +34,7 @@ instance Default Location where def = Location -- Somewhere in London { description = "London, UK" - , accuracy = 0 + , accuracy = 10 , latitude = 51.507351 , longitude = -0.127758 , altitude = 14 -- Elevation in London. @@ -42,7 +42,23 @@ instance Default Location where fromLatLngAlt :: Double -> Double -> Double -> Location -fromLatLngAlt = Location "" 0 +fromLatLngAlt lat lng alt = Location + { description = "" + , accuracy = 0 + , latitude = lat + , longitude = lng + , altitude = alt + } + + +fromLatLngAcc :: Double -> Double -> Double -> Location +fromLatLngAcc lat lng acc = Location + { description = "" + , accuracy = acc + , latitude = lat + , longitude = lng + , altitude = 0 + } -- vim:sw=2 diff --git a/test/Pokemon/EnvelopeSpec.hs b/test/Pokemon/EnvelopeSpec.hs index 56c23ae..1174598 100644 --- a/test/Pokemon/EnvelopeSpec.hs +++ b/test/Pokemon/EnvelopeSpec.hs @@ -30,17 +30,8 @@ spec = do it "does the same as the Python version" $ Envelope.generateLocation2 (Location.fromLatLngAlt 1 1 1) `shouldBe` 4239058444 - describe "decodeSignature" $ do + describe "decodeSignature" $ it "can decode signatures made by encodeSignature" $ property $ \iv sig' -> let sig = unArbitraryMessage sig' in Envelope.decodeSignature (Envelope.encodeSignature iv sig) `shouldBe` Right sig - - it "can decode purchase.req" $ - when False $ do - bytes <- BS.readFile "purchase.req" - let Right req = decodeMessage bytes - let [_, encodedReq] = Proto._RequestEnvelope'unknown6 req - let Just encodedSig = Proto._Unknown6'unknown2 encodedReq - let Right decodedSig = Envelope.decodeSignature encodedSig - putStrLn (showMessage decodedSig)