打印xattr十六进制输出的字符串表示形式 [英] Printing string representations of xattr hex output

查看:308
本文介绍了打印xattr十六进制输出的字符串表示形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编写一个脚本来从使用xattr的OS X下载的Safari磁盘映像中提取原始下载URL,以便我可以重命名它们,但仍然可以轻松地获取其原始名称以供参考。 b
$ b

这个命令打印下载给定文件的URL的十六进制表示形式,例如:

  xattr -p com.apple.metadata:kMDItemWhereFroms * .dmg 

p>

  62 70 6C 69 73 74 30 30 A1 01 5F 10 4F 68 74 74 
70 3A 2F 2F 61 64 63 64 6F 77 6E 6C 6F 61 64 2E
61 70 70 6C 65 2E 63 6F 6D 2F 4D 61 63 5F 4F 53
5F 58 2F 6D 61 63 5F 6F 73 5F 78 5F 31 30 2E 36
2E 31 5F 62 75 69 6C 64 5F 31 30 62 35 30 34 2F
30 34 31 35 30 37 33 61 2E 64 6D 67 08 0A 00 00
00 00 00 00 01 01 00 00 00 00 00 00 00 02 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 5C

URL从第14个字节开始(如果我正确计算的话)和是NULL终止。我怎样才能格式化这个字符串,以便我得到一个字符串输出,如下所示:



http://adcdownload.apple.com/Mac_OS_X/mac_os_x_10.6.1_build_10b504/0415073a.dmg

< (不要担心,除非您登录ADC,否则此链接不起作用)



...实际上, Finder将在获取信息中显示同样的内容。我试图管xattr的输出到xxd,但我不知道如何指定偏移量,所以字符串开始在正确的地方。

解决方案

<所以,在查看由xattr -p返回的二进制数据后,我意识到它实际上是一个二进制plist ...因此数据前面的bplist。出于某种原因,我没有注意到这一点,但是鉴于此,这里有一个适当的解决方案,应该适用于从10.5到10.8的每一个OS X.



为了避免我会链接到源代码,而不是粘贴它: https://github.com/jakepetroules/wherefrom


I'm trying to write a script to extract the original download URL from disk images downloaded with Safari on OS X using xattr, so that I can rename them but still easily obtain their original names for reference.

This command prints the hex representation of the URL that the given file was downloaded from, as an example:

xattr -p com.apple.metadata:kMDItemWhereFroms *.dmg

gives

62 70 6C 69 73 74 30 30 A1 01 5F 10 4F 68 74 74
70 3A 2F 2F 61 64 63 64 6F 77 6E 6C 6F 61 64 2E
61 70 70 6C 65 2E 63 6F 6D 2F 4D 61 63 5F 4F 53
5F 58 2F 6D 61 63 5F 6F 73 5F 78 5F 31 30 2E 36
2E 31 5F 62 75 69 6C 64 5F 31 30 62 35 30 34 2F
30 34 31 35 30 37 33 61 2E 64 6D 67 08 0A 00 00
00 00 00 00 01 01 00 00 00 00 00 00 00 02 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 5C

The URL starts at the 14th byte (if I counted correctly) and is NULL terminated. How can I format this string so that I get a string output as follows:

http://adcdownload.apple.com/Mac_OS_X/mac_os_x_10.6.1_build_10b504/0415073a.dmg

(don't worry, this link doesn't work unless you're logged in to ADC)

...essentially, the same thing Finder will display in Get Info. I tried piping xattr's output to xxd but I'm not sure how to specify the offset so the string starts at the right place.

解决方案

So, after looking at the binary data returned by xattr -p, I realized that it was actually a binary plist... hence "bplist" at the front of the data. For some reason I didn't notice this before, but in light of this, here's a proper solution that should work on every OS X from 10.5 to 10.8.

To avoid duplication, I'll link to the source instead of pasting it: https://github.com/jakepetroules/wherefrom

这篇关于打印xattr十六进制输出的字符串表示形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆