Skip to content
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

Merged
merged 3 commits into from
Oct 24, 2023
Merged

Encode and decode remote XPC messages #290

merged 3 commits into from
Oct 24, 2023

Conversation

dmissmann
Copy link
Collaborator

@dmissmann dmissmann commented Oct 19, 2023

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

@dmissmann dmissmann marked this pull request as ready for review October 20, 2023 08:50
Copy link
Owner

@danielpaulus danielpaulus left a 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.

return err
}

var flags uint32
Copy link
Owner

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
Copy link
Owner

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.

Copy link
Collaborator Author

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.

if buf[0] == 0 {
s := b.String()
toSkip := calcPadding(len(s) + 1)
io.CopyN(io.Discard, r, toSkip)
Copy link
Owner

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

func decodeUint64(r io.Reader) (uint64, error) {
var i uint64
err := binary.Read(r, binary.LittleEndian, &i)
if err != nil {
Copy link
Owner

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

t xpcType
l uint32
}{stringType, uint32(len(s) + 1)}
binary.Write(w, binary.LittleEndian, header)
Copy link
Owner

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

Not all types and flags are implemented yet.
It works only with maps and not custom struct types
@dmissmann dmissmann merged commit 232e3a6 into main Oct 24, 2023
2 checks passed
@dmissmann dmissmann deleted the dm-xpc-codec branch October 24, 2023 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants