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

plist.Marshal("aaa", plist.BinaryFormat) is not return the expected value #81

Open
stephane-archer opened this issue Nov 27, 2023 · 2 comments

Comments

@stephane-archer
Copy link

stephane-archer commented Nov 27, 2023

Hi, I'm trying to encode a string to a binary Plist but I don't find the expected result.
How can I make Plist return the right result?

For example the string "Iphone 11 Pro" gets transformed with your package in "bplist00^Iphone 11 Pro" but I expect to get "bplist00]iPhone 11 Pro".
I'm not sure what the "]" and "^" characters represent.

Also the string "aaa" gets transformed with your package in "bplist00Taaa" but I expect to get "bplist00Saaa".
once again I'm not sure what "S" and "T" represent

@DHowett
Copy link
Owner

DHowett commented Dec 1, 2023

Hey, thanks for reaching out!

Where are you getting your expected (or "correct") bplist encodings?

The ^, ], S and T are the lucky representations of the binary plist tag that means "ASCII string" with an embedded length.

In this case...

^        0x5E           An ASCII string of 0xE (14) characters
]        0x5D           An ASCII string of 0xD (13) characters
S        0x53           An ASCII string of 0x3  (3) characters
T        0x54           An ASCII string of 0x4  (4) characters

This library emits strings in the most compact encoding possible, similar to Apple's CoreFoundation library.

For what it's worth, I have tested the case with "aaa", and I am getting bplist00Saaa like you are expecting.

func TestBplist_String_aaa(t *testing.T) {
	var buf bytes.Buffer
	encoder := NewBinaryEncoder(&buf)
	encoder.Encode("aaa")
	fmt.Printf("%02x\n", buf.Bytes())
}
=== RUN   TestBplist_String_aaa
62706c69737430305361616108000000000000010100000000000000010000000000000000000000000000000c
--- PASS: TestBplist_String_aaa (0.00s)

If you convert the leading part of that byte string to ASCII:

 b p l i s t 0 0 S a a a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
62706c69737430305361616108000000000000010100000000000000010000000000000000000000000000000c

@stephane-archer
Copy link
Author

Thank you for your answer.
These letters make more sense to me now thanks to you and hexadecimal

I was adding "Finder tags" using "Mac Finder" then I was using "xattr -l" to see the value added and tried to "reverse engineer" what was going on
But adding the same value returned by "xattr -l" is not adding the tag so it doesn't seem to be a reliable tool.

At the end of your answer, I can see a lot of data after the "aaa" What is it?

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

No branches or pull requests

2 participants