Skip to content

Commit a323370

Browse files
authored
feat: decrypt encrypted net-messages in CS2 demos (#697)
* feat: decrypt encrypted net-messages in CS2 demos * chore: update protobuf messages
2 parents 75855e4 + af587b7 commit a323370

43 files changed

Lines changed: 4612 additions & 2244 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎go.mod‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/markus-wa/go-unassert v0.1.3
1010
github.com/markus-wa/gobitread v0.2.5-0.20241202000432-3c3e0bc797c6
1111
github.com/markus-wa/godispatch v1.4.1
12+
github.com/markus-wa/ice-cipher-go v0.0.0-20230901094113-348096939ba7
1213
github.com/markus-wa/quickhull-go/v2 v2.2.0
1314
github.com/oklog/ulid/v2 v2.1.1
1415
github.com/pkg/errors v0.9.1

‎go.sum‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ github.com/markus-wa/gobitread v0.2.5-0.20241202000432-3c3e0bc797c6 h1:VNn0S4GFv
2525
github.com/markus-wa/gobitread v0.2.5-0.20241202000432-3c3e0bc797c6/go.mod h1:PcWXMH4gx7o2CKslbkFkLyJB/aHW7JVRG3MRZe3PINg=
2626
github.com/markus-wa/godispatch v1.4.1 h1:Cdff5x33ShuX3sDmUbYWejk7tOuoHErFYMhUc2h7sLc=
2727
github.com/markus-wa/godispatch v1.4.1/go.mod h1:tk8L0yzLO4oAcFwM2sABMge0HRDJMdE8E7xm4gK/+xM=
28+
github.com/markus-wa/ice-cipher-go v0.0.0-20230901094113-348096939ba7 h1:aR9pvnlnBxifXBmzidpAiq2prLSGlkhE904qnk2sCz4=
29+
github.com/markus-wa/ice-cipher-go v0.0.0-20230901094113-348096939ba7/go.mod h1:JIsht5Oa9P50VnGJTvH2a6nkOqDFJbUeU1YRZYvdplw=
2830
github.com/markus-wa/quickhull-go/v2 v2.2.0 h1:rB99NLYeUHoZQ/aNRcGOGqjNBGmrOaRxdtqTnsTUPTA=
2931
github.com/markus-wa/quickhull-go/v2 v2.2.0/go.mod h1:EuLMucfr4B+62eipXm335hOs23LTnO62W7Psn3qvU2k=
3032
github.com/oklog/ulid/v2 v2.1.1 h1:suPZ4ARWLOJLegGFiZZ1dFAkqzhMjL3J1TzI+5wHz8s=

‎pkg/demoinfocs/events/events.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,15 @@ const (
598598
WarnTypeStringTableParsingFailure // Should happen only with CS2 POV demos
599599
WarnTypePacketEntitiesPanic
600600
WarnTypeUnknownProtobufMessage
601+
602+
// WarnTypeMissingNetMessageDecryptionKey occurs when encrypted net-messages are encountered and the decryption key is missing.
603+
// See ParserConfig.NetMessageDecryptionKey
604+
WarnTypeMissingNetMessageDecryptionKey
605+
606+
// WarnTypeCantReadEncryptedNetMessage occurs when an encrypted net-message can't be decrypted even though the decryption key is set.
607+
// May occur because the decryption key used is incorrect.
608+
// See ParserConfig.NetMessageDecryptionKey
609+
WarnTypeCantReadEncryptedNetMessage
601610
)
602611

603612
// WarnTypeUnknownDemoCommandMessageType occurs when a demo-command message type is unknown - contact a maintainer.

‎pkg/demoinfocs/matchinfo.go‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package demoinfocs
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/markus-wa/demoinfocs-golang/v5/pkg/demoinfocs/msg"
8+
"github.com/pkg/errors"
9+
"google.golang.org/protobuf/proto"
10+
)
11+
12+
// MatchInfoDecryptionKey extracts the net-message decryption key stored in `match730_*.dem.info`.
13+
// Pass the whole contents of `match730_*.dem.info` to this function to get the key.
14+
// See also: ParserConfig.NetMessageDecryptionKey
15+
func MatchInfoDecryptionKey(b []byte) ([]byte, error) {
16+
m := new(msg.CDataGCCStrike15V2_MatchInfo)
17+
18+
err := proto.Unmarshal(b, m)
19+
if err != nil {
20+
return nil, errors.Wrap(err, "failed to unmarshal MatchInfo message")
21+
}
22+
23+
k := []byte(strings.ToUpper(fmt.Sprintf("%016x", m.GetWatchablematchinfo().GetClDecryptdataKeyPub())))
24+
25+
return k, nil
26+
}

‎pkg/demoinfocs/msg/cs_gameevents.pb.go‎

Lines changed: 12 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)