Skip to content

Commit

Permalink
Hack to make scalar numeric fields packed.
Browse files Browse the repository at this point in the history
proto3 has this as default, but proto-lens doesn't think so.
  • Loading branch information
iphydf committed Aug 28, 2016
1 parent 383d17d commit 6626516
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
6 changes: 5 additions & 1 deletion Makefile
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions src/Pokemon/Envelope.hs
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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


Expand Down
20 changes: 18 additions & 2 deletions src/Pokemon/Location.hs
Expand Up @@ -34,15 +34,31 @@ 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.
}


fromLatLngAlt :: Double -> Double -> Double -> Location
fromLatLngAlt = Location "<code>" 0
fromLatLngAlt lat lng alt = Location
{ description = "<code>"
, accuracy = 0
, latitude = lat
, longitude = lng
, altitude = alt
}


fromLatLngAcc :: Double -> Double -> Double -> Location
fromLatLngAcc lat lng acc = Location
{ description = "<code>"
, accuracy = acc
, latitude = lat
, longitude = lng
, altitude = 0
}


-- vim:sw=2
11 changes: 1 addition & 10 deletions test/Pokemon/EnvelopeSpec.hs
Expand Up @@ -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)

0 comments on commit 6626516

Please sign in to comment.