@@ -4,9 +4,18 @@ import go
44
55/** Provides models of commonly used functions and types in the protobuf packages. */
66module Protobuf {
7- /** Gets the name of a protobuf implementation package. */
7+ /** Gets the name of the modern protobuf top-level implementation package. */
8+ string modernProtobufPackage ( ) { result = "google.golang.org/protobuf/proto" }
9+
10+ /** Gets the name of the modern protobuf implementation's `protoiface` subpackage. */
11+ string protobufIfacePackage ( ) { result = "google.golang.org/protobuf/runtime/protoiface" }
12+
13+ /** Gets the name of the modern protobuf implementation's `protoreflect` subpackage. */
14+ string protobufReflectPackage ( ) { result = "google.golang.org/protobuf/reflect/protoreflect" }
15+
16+ /** Gets the name of a top-level protobuf implementation package. */
817 string protobufPackages ( ) {
9- result in [ "github.com/golang/protobuf/proto" , "google.golang.org/protobuf/proto" ]
18+ result in [ "github.com/golang/protobuf/proto" , modernProtobufPackage ( ) ]
1019 }
1120
1221 /** The `Marshal` and `MarshalAppend` functions in the protobuf packages. */
@@ -17,7 +26,7 @@ module Protobuf {
1726 name = [ "Marshal" , "MarshalAppend" ] and
1827 (
1928 this .hasQualifiedName ( protobufPackages ( ) , name ) or
20- this .( Method ) .hasQualifiedName ( "google.golang.org/protobuf/proto" , "MarshalOptions" , name )
29+ this .( Method ) .hasQualifiedName ( modernProtobufPackage ( ) , "MarshalOptions" , name )
2130 )
2231 }
2332
@@ -39,14 +48,11 @@ module Protobuf {
3948 }
4049
4150 private Field inputMessageField ( ) {
42- result
43- .hasQualifiedName ( "google.golang.org/protobuf/runtime/protoiface" , "MarshalInput" , "Message" )
51+ result .hasQualifiedName ( protobufIfacePackage ( ) , "MarshalInput" , "Message" )
4452 }
4553
4654 private Method marshalStateMethod ( ) {
47- result
48- .hasQualifiedName ( "google.golang.org/protobuf/runtime/protoiface" , "MarshalOptions" ,
49- "MarshalState" )
55+ result .hasQualifiedName ( protobufIfacePackage ( ) , "MarshalOptions" , "MarshalState" )
5056 }
5157
5258 /**
@@ -76,9 +82,7 @@ module Protobuf {
7682 class UnmarshalFunction extends TaintTracking:: FunctionModel , UnmarshalingFunction:: Range {
7783 UnmarshalFunction ( ) {
7884 this .hasQualifiedName ( protobufPackages ( ) , "Unmarshal" ) or
79- this
80- .( Method )
81- .hasQualifiedName ( "google.golang.org/protobuf/proto" , "UnmarshalOptions" , "Unmarshal" )
85+ this .( Method ) .hasQualifiedName ( modernProtobufPackage ( ) , "UnmarshalOptions" , "Unmarshal" )
8286 }
8387
8488 override predicate hasTaintFlow ( DataFlow:: FunctionInput inp , DataFlow:: FunctionOutput outp ) {
@@ -103,9 +107,7 @@ module Protobuf {
103107
104108 /** A protobuf `Message` type. */
105109 class MessageType extends Type {
106- MessageType ( ) {
107- this .implements ( "google.golang.org/protobuf/reflect/protoreflect" , "ProtoMessage" )
108- }
110+ MessageType ( ) { this .implements ( protobufReflectPackage ( ) , "ProtoMessage" ) }
109111 }
110112
111113 /** The `Clone` function in the protobuf packages. */
0 commit comments