-
-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Encode and decode remote XPC messages #290
Conversation
3cd9dbe
to
1eb9bcf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job! I just got some minor nitpicks, the code looks really awesome though.
ios/xpc/encoding.go
Outdated
return err | ||
} | ||
|
||
var flags uint32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#nitpick
might be bit easier to read this way
flags:=alwaysSetFlag
if len(body) != 0 {
flags |= dataFlag
}
} | ||
|
||
wrapper := struct { | ||
magic uint32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you have two structs defined at the top and one inline, I think it would be better to all define them at the top for easier reading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I move the anonymous structs to the top as they are used only here for the encoding part (you'll find them in more places here btw 😉 ), the ones at the top are used in multiple places.
ios/xpc/encoding.go
Outdated
if buf[0] == 0 { | ||
s := b.String() | ||
toSkip := calcPadding(len(s) + 1) | ||
io.CopyN(io.Discard, r, toSkip) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_,err := io.CopyN(io.Discard, r, toSkip)
return s, err
ios/xpc/encoding.go
Outdated
func decodeUint64(r io.Reader) (uint64, error) { | ||
var i uint64 | ||
err := binary.Read(r, binary.LittleEndian, &i) | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return i, err
would also work
ios/xpc/encoding.go
Outdated
t xpcType | ||
l uint32 | ||
}{stringType, uint32(len(s) + 1)} | ||
binary.Write(w, binary.LittleEndian, header) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forgot to handle the err
1eb9bcf
to
c2a043d
Compare
Not all types and flags are implemented yet. It works only with maps and not custom struct types
f959069
to
ad57e48
Compare
This is a preparation for iOS 17 support. Some new services write RemoteXPC messages over a HTTP2 connection.
The actual work of deciphering those messages was done by somebody else, please check this blog post from Duo.com