go-plist icon indicating copy to clipboard operation
go-plist copied to clipboard

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

Open stephane-archer opened this issue 1 year ago • 2 comments

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

stephane-archer avatar Nov 27 '23 22:11 stephane-archer

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

DHowett avatar Dec 01 '23 07:12 DHowett

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?

stephane-archer avatar Dec 02 '23 10:12 stephane-archer