U-boot with redundant environment, fw_setenv does not update both environments - linux-kernel

why fw_setenv tool set value of variable only for one environment?
I am using uboot with redundant env (#define CONFIG_ENV_OFFSET 0xc0000, #define CONFIG_ENV_OFFSET_REDUND 0x100000 ), and I am going to set value of uboot env variable from linux. There is fw_setenv/fw_printenv tool which can do this:
# fw_printenv rootfs
rootfs=mtd6
# fw_setenv rootfs mtd7
Check that it is realy was set:
# fw_printenv rootfs
rootfs=mtd7
Seems OK, but after reboot system and entering to u-boot console, the value of rootfs variable is former. uboot read former value:
=> printenv
rootfs=mtd6
Then I have looked at the hexdump output of mtd devices where uboot envs placed.
Before setting rootfs mtd7:
# hexdump -C /dev/mtd3 | head -n 200
. . . . .
000000a0 65 6c 61 79 3d 35 00 62 61 75 64 72 61 74 65 3d |elay=5.baudrate=|
000000b0 31 31 35 32 30 30 00 72 6f 6f 74 66 73 3d 6d 74 |115200.rootfs=mt|
000000c0 64 36 00 00 ff ff ff ff ff ff ff ff ff ff ff ff |d6..............|
000000d0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
Here rootfs=mtd6, seems OK.
# hexdump -C /dev/mtd4 | head -n 200
. . . . .
00000090 6f 66 66 3b 20 62 6f 6f 74 6d 00 62 6f 6f 74 64 |off; bootm.bootd|
000000a0 65 6c 61 79 3d 35 00 62 61 75 64 72 61 74 65 3d |elay=5.baudrate=|
000000b0 31 31 35 32 30 30 00 00 00 ff ff ff ff ff ff ff |115200..........|
000000c0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
There is no rootfs variable defined in env on redundant part. Why??
After using fw_setenv rootfs mtd7
# hexdump -C /dev/mtd3 | head -n 200
000000a0 65 6c 61 79 3d 35 00 62 61 75 64 72 61 74 65 3d |elay=5.baudrate=|
000000b0 31 31 35 32 30 30 00 72 6f 6f 74 66 73 3d 6d 74 |115200.rootfs=mt|
000000c0 64 36 00 00 ff ff ff ff ff ff ff ff ff ff ff ff |d6..............|
000000d0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
The environment on mtd3 stay unchanged (rootfs=mtd6).
# hexdump -C /dev/mtd4 | head -n 200
000000a0 65 6c 61 79 3d 35 00 62 61 75 64 72 61 74 65 3d |elay=5.baudrate=|
000000b0 31 31 35 32 30 30 00 72 6f 6f 74 66 73 3d 6d 74 |115200.rootfs=mt|
000000c0 64 37 00 00 ff ff ff ff ff ff ff ff ff ff ff ff |d7..............|
000000d0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
The new rootfs variable has been wrote on mtd4.
So the content in the uboot environments is not the same. How to properly set env from linux?

I believe you may have wrong info in "Device offset" column of fw_env.config file, you may try
/dev/mtd6 0x0c0000 0x10000 0x10000 0x1
/dev/mtd7 0x1c0000 0x10000 0x10000 0x1
#MTDdevname Device offset Env. size Flash sector size Number of sectors
The last three columns' info may be different for your platform.

Related

No SMBIOS table found while emulating with QEMU?

I'm developing a minimal x86-64 OS from scratch and I am attempting to detect memory to be able to map the higher half of the virtual address space to all physical memory available.
From this link: https://www.kernel.org/doc/html/latest/x86/x86_64/mm.html, I think this is what the Linux kernel does also. Probably to be able to reach all physical addresses if the need arises at some point.
ffff888000000000 | -119.5 TB | ffffc87fffffffff | 64 TB | direct mapping of all physical memory (page_offset_base)
I want to do the same in my kernel but I need to detect the amount of physical memory installed currently on my system. I can always use the Memory Map returned by UEFI but this doesn't necessarily tell me how much memory is actually installed.
I'm emulating on QEMU and I thought of locating the SMBIOS table to do that. If I print memory from 0xf0000 to 0xfffff, I don't find the signature of the SMBIOS table:
(gdb) dump memory result.bin 0xf0000 0xfffff
user#user-System-Product-Name:~$ hexdump -C result.bin
00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
0000fd00 ff ff ff ff ff ff ff ff 2e 06 a0 1b 79 c7 82 45 |............y..E|
0000fd10 85 66 33 6a e8 f7 8f 09 08 aa 01 08 f8 02 00 f8 |.f3j............|
0000fd20 0c 00 00 19 00 00 00 00 00 00 00 00 d4 02 00 19 |................|
0000fd30 31 c0 2d 00 10 00 00 3d 00 00 00 ff 72 33 81 78 |1.-....=....r3.x|
0000fd40 10 78 e5 8c 8c 75 eb 81 78 14 3d 8a 1c 4f 75 e2 |.x...u..x.=..Ou.|
0000fd50 81 78 18 99 35 89 61 75 d9 81 78 1c 85 c3 2d d3 |.x..5.au..x...-.|
0000fd60 75 d0 83 78 24 00 75 ca 89 c3 03 58 20 75 c3 eb |u..x$.u....X u..|
0000fd70 09 b8 bf bf bf bf 89 c5 eb fe 89 c5 e9 37 02 00 |.............7..|
0000fd80 00 31 db 89 de 89 e8 66 8b 5d 30 01 d8 72 3b eb |.1.....f.]0..r;.|
0000fd90 03 40 72 36 85 c0 74 32 83 c0 07 72 2d 24 f8 8a |.#r6..t2...r-$..|
0000fda0 58 17 f6 c3 20 74 ea 8b 48 14 81 e1 ff ff ff 00 |X... t..H.......|
0000fdb0 09 c9 74 dd 01 c1 74 02 72 d7 80 78 12 03 75 06 |..t...t.r..x..u.|
0000fdc0 eb 17 85 c0 75 06 89 c8 eb ca 31 c0 89 c6 85 f6 |....u.....1.....|
0000fdd0 75 02 74 fe e9 e4 01 00 00 85 c0 74 5f 83 c0 18 |u.t........t_...|
0000fde0 39 c8 73 58 80 78 03 10 74 1b 80 78 03 12 74 32 |9.sX.x..t..x..t2|
0000fdf0 8b 18 81 e3 ff ff ff 00 01 d8 72 40 83 c0 03 72 |..........r#...r|
0000fe00 3b 24 fc eb db 83 c0 04 66 81 38 4d 5a 75 2d 0f |;$......f.8MZu-.|
0000fe10 b7 58 3c 01 c3 81 3b 50 45 00 00 75 1f 03 43 28 |.X<...;PE..u..C(|
0000fe20 eb 1f 83 c0 04 89 c3 66 81 3b 56 5a 75 0e 03 43 |.......f.;VZu..C|
0000fe30 08 83 c0 28 0f b7 5b 06 29 d8 eb 05 b8 00 00 00 |...(..[.).......|
0000fe40 00 e9 7c ff ff ff eb 60 0f 20 e0 0f ba e8 05 0f |..|....`. ......|
0000fe50 22 e0 b9 80 00 00 c0 0f 32 0f ba e8 08 0f 30 0f |".......2.....0.|
0000fe60 20 c0 0f ba e8 1f 0f 22 c0 ea 70 fe ff ff 18 00 | ......"..p.....|
0000fe70 e9 4d 01 00 00 b8 00 00 00 80 0f a2 3d 1f 00 00 |.M..........=...|
0000fe80 80 7c 21 b8 1f 00 00 80 0f a2 0f ba e0 01 73 14 |.|!...........s.|
0000fe90 b9 31 01 01 c0 0f 32 0f ba e0 00 73 07 89 d8 83 |.1....2....s....|
0000fea0 e0 3f eb 02 31 c0 eb 02 eb cb 31 d2 85 c0 74 06 |.?..1.....1...t.|
0000feb0 83 e8 20 0f ab c2 b9 00 18 00 00 31 c0 89 04 8d |.. ........1....|
0000fec0 fc ff 7f 00 e2 f7 c7 05 00 00 80 00 23 10 80 00 |............#...|
0000fed0 89 15 04 00 80 00 c7 05 00 10 80 00 23 20 80 00 |............# ..|
0000fee0 89 15 04 10 80 00 c7 05 08 10 80 00 23 30 80 00 |............#0..|
0000fef0 89 15 0c 10 80 00 c7 05 10 10 80 00 23 40 80 00 |............##..|
0000ff00 89 15 14 10 80 00 c7 05 18 10 80 00 23 50 80 00 |............#P..|
0000ff10 89 15 1c 10 80 00 b9 00 08 00 00 89 c8 48 c1 e0 |.............H..|
0000ff20 15 05 e3 00 00 00 89 04 cd f8 1f 80 00 89 14 cd |................|
0000ff30 fc 1f 80 00 e2 e5 b8 00 00 80 00 0f 22 d8 e9 05 |............"...|
0000ff40 ff ff ff fa bb 00 f0 8e db bb 7a ff 2e 66 0f 01 |..........z..f..|
0000ff50 17 66 b8 23 00 00 40 0f 22 c0 66 ea 62 ff ff ff |.f.#..#.".f.b...|
0000ff60 10 00 b8 40 06 00 00 0f 22 e0 66 b8 08 00 8e d8 |...#....".f.....|
0000ff70 8e c0 8e e0 8e e8 8e d0 eb 39 1f 00 80 ff ff ff |.........9......|
0000ff80 00 00 00 00 00 00 00 00 ff ff 00 00 00 93 cf 00 |................|
0000ff90 ff ff 00 00 00 9b cf 00 ff ff 00 00 00 9b af 00 |................|
0000ffa0 bf 42 50 eb 0a bf 41 50 eb 05 66 89 c4 eb 02 eb |.BP...AP..f.....|
0000ffb0 f9 eb 90 e9 78 fd ff ff e9 c4 fd ff ff e9 84 fe |....x...........|
0000ffc0 ff ff b8 ff ff ff ff 48 21 c6 48 21 c5 48 21 c4 |.......H!.H!.H!.|
0000ffd0 48 89 e0 ff e6 90 90 90 90 90 90 90 90 90 90 90 |H...............|
0000ffe0 eb c3 90 90 90 90 90 90 00 00 00 00 56 54 46 00 |............VTF.|
0000fff0 90 90 eb ac 90 90 90 90 90 90 90 90 90 90 90 |...............|
0000ffff
I did try to add the -smbios type=0 flag when I launch QEMU from the command line.
I was wondering how the Linux kernel, when it runs within QEMU, does to detect memory and hardware. Does it use ACPI tables instead? I think SMBIOS is much more easy to use.
Is SMBIOS reliable enough so that operating-systems that run on newer hardware can assume its presence?

"zlib: inflate error = -3 (data error)" with custom png implementation

I'm implementing a PNG encoder in VHDL for learning purposes. It works with image sizes from 1x1 to 4x4. At the image size of 5x5 there is a behaviour I can't understand:
When encoding raw data with values 0...24, the encoding works. However, when using raw data with values 255...231, it generates a broken image.
Input values 0...24:
> hexdump -C png_encoder/gen/test_img_no_compression_5x5.png
00000000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 |.PNG........IHDR|
00000010 00 00 00 05 00 00 00 05 08 00 00 00 00 a8 04 79 |...............y|
00000020 39 00 00 00 4c 49 44 41 54 78 01 00 04 00 fb ff |9...LIDATx......|
00000030 00 00 01 02 00 04 00 fb ff 03 04 00 05 00 04 00 |................|
00000040 fb ff 06 07 08 09 00 04 00 fb ff 00 0a 0b 0c 00 |................|
00000050 04 00 fb ff 0d 0e 00 0f 00 04 00 fb ff 10 11 12 |................|
00000060 13 00 04 00 fb ff 00 14 15 16 01 02 00 fd ff 17 |................|
00000070 18 0b a4 01 2d d5 1f a2 6d 00 00 00 00 49 45 4e |....-...m....IEN|
00000080 44 ae 42 60 82 |D.B`.|
00000085
> pngcheck -vv png_encoder/gen/test_img_no_compression_5x5.png
File: png_encoder/gen/test_img_no_compression_5x5.png (133 bytes)
chunk IHDR at offset 0x0000c, length 13
5 x 5 image, 8-bit grayscale, non-interlaced
chunk IDAT at offset 0x00025, length 76
zlib: deflated, 32K window, superfast compression
row filters (0 none, 1 sub, 2 up, 3 avg, 4 paeth):
0 0 0 0 0 (5 out of 5)
chunk IEND at offset 0x0007d, length 0
No errors detected in png_encoder/gen/test_img_no_compression_5x5.png (3 chunks, -432.0% compression).
Input values 255...231:
> hexdump -C png_encoder/gen/test_img_no_compression_5x5.png
00000000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 |.PNG........IHDR|
00000010 00 00 00 05 00 00 00 05 08 00 00 00 00 a8 04 79 |...............y|
00000020 39 00 00 00 4c 49 44 41 54 78 01 00 04 00 fb ff |9...LIDATx......|
00000030 00 ff fe fd 00 04 00 fb ff fc fb 00 fa 00 04 00 |................|
00000040 fb ff f9 f8 f7 f6 00 04 00 fb ff 00 f5 f4 f3 00 |................|
00000050 04 00 fb ff f2 f1 00 f0 00 04 00 fb ff ef ee ed |................|
00000060 ec 00 04 00 fb ff 00 eb ea e9 01 02 00 fd ff e8 |................|
00000070 e7 6a 21 17 bc 9a 17 87 e7 00 00 00 00 49 45 4e |.j!..........IEN|
00000080 44 ae 42 60 82 |D.B`.|
00000085
> pngcheck -vv png_encoder/gen/test_img_no_compression_5x5.png
File: png_encoder/gen/test_img_no_compression_5x5.png (133 bytes)
chunk IHDR at offset 0x0000c, length 13
5 x 5 image, 8-bit grayscale, non-interlaced
chunk IDAT at offset 0x00025, length 76
zlib: deflated, 32K window, superfast compression
row filters (0 none, 1 sub, 2 up, 3 avg, 4 paeth):
zlib: inflate error = -3 (data error)
(0 out of 5)
ERRORS DETECTED in png_encoder/gen/test_img_no_compression_5x5.png
How to interpret the error message zlib: inflate error = -3 (data error)?
I read https://www.zlib.net/zlib_how.html, but didn't find more specific information. My first guess was the row filters are incorrect, but since both files are structured the same, this is unlikely. Is there something wrong with the ADLER32 calculation in the second case (possibly some overflow)?
It was an overflow in the ADLER32 checksum calculation. Specifically, there were two 16 bit numbers added and truncated before applying the modulo with 65521. Unfortunately my ADLER32 unittest didn't catch it, yet.
However, the error message was shown several times during the implementation and I was always not sure about the cause. If anybody could elaborate the error message or explain how to get a better error message, I would be glad to hear it.

SMBIOS - Invalid structure table address?

I'm currently working on an old MS-DOS application, which uses DMI to identify the hardware. It worked fine in the past, but it seems to provide invalid data on newer systems (e.g. Skylake). As stated in the spec, we are scanning 0xF0000-0xFFFFF for the "SM" anchor string, this is still working as expected.
But now it seems that the data located at the "Structure table adress" (stored at offset 0x18h in the) are invalid (see dumps below). Tools like dmidecoe deliver correct information (however, it uses GetSystemFirmwareTable() on Windows). What I am doing wrong here?
EDIT (clarify situation)
On an older system I get expected data (dump is done in FreeDOS' debug98 utility) - following come from an IvyBridge system (3rd gen.):
-d F000:04C0
F000:04C0 5F 53 4D 5F 03 1F 02 07-77 00 00 00 00 00 00 00 _SM_....w.......
F000:04D0 5F 44 4D 49 5F E0 6E 04-10 BA 0E 00 17 00 27 00 _DMI_.n.......'.
F000:04E0 1E 66 60 68 00 F0 1F B8-90 D0 83 C0 0F 24 F0 A3 .f`h.........$..
F000:04F0 1D 03 B9 00 E0 2B C8 79-02 33 C9 89 0E 1F 03 33 .....+.y.3.....3
F000:0500 C0 66 2E 8B 1E 63 00 66-83 FB 00 74 0B 66 81 FB .f...c.f...t.f..
F000:0510 00 00 0E 00 72 02 8B C3-A3 19 03 F7 D0 A3 1B 03 ....r...........
F000:0520 66 61 1F C3 00 1E 50 68-00 F0 1F 0B DB 74 28 F7 fa....Ph.....t(.
F000:0530 C3 80 00 74 1C 2E 80 3E-24 05 00 75 43 83 F9 3E ...t...>$..uC..>
-d E000:BA10
E000:BA10 00 18 00 00 01 02 00 F0-03 7F 80 98 89 3F 01 00 .............?..
E000:BA20 00 00 03 0D 04 06 FF FF-41 6D 65 72 69 63 61 6E ........American
E000:BA30 20 4D 65 67 61 74 72 65-6E 64 73 20 49 6E 63 2E Megatrends Inc.
E000:BA40 00 42 51 37 37 52 31 31-31 00 30 37 2F 30 35 2F .BQ77R111.07/05/
E000:BA50 32 30 31 33 00 00 01 1B-01 00 01 02 03 04 00 00 2013............
E000:BA60 01 26 60 24 00 05 00 06-00 07 00 08 00 09 06 05 .&`$............
E000:BA70 06 20 00 20 00 20 00 30-30 30 30 30 31 32 36 36 . . . .000001266
E000:BA80 30 32 34 00 20 00 20 00-00 02 0F 02 00 01 02 03 024. . .........
Newer systems - in this case a Skylake based one (6th gen.) data are different. In the adress the SMI structure points to i do not get the expected data (I expcted to see the BIOS strings, but they are not there):
-d f000:05e0
F000:05E0 5F 53 4D 5F F3 1F 03 00-8C 01 00 00 00 00 00 00 _SM_............
F000:05F0 5F 44 4D 49 5F 15 CE 07-00 90 1D 87 1A 00 30 00 _DMI_.........0.
F000:0600 5F 53 4D 33 5F 4A 18 03-00 00 01 00 CE 07 00 00 _SM3_J..........
F000:0610 00 90 1D 87 00 00 00 00-00 00 00 00 00 00 00 00 ................
F000:0620 1E 66 60 68 00 F0 1F B8-00 C6 83 C0 0F 24 F0 A3 .f`h.........$..
F000:0630 8E 03 B9 00 E0 2B C8 79-02 33 C9 89 0E 90 03 33 .....+.y.3.....3
F000:0640 C0 66 2E 8B 1E 63 00 66-83 FB 00 74 0B 66 81 FB .f...c.f...t.f..
F000:0650 00 00 0E 00 72 02 8B C3-A3 8A 03 F7 D0 A3 8C 03 ....r...........
-d 871d:9000
871D:9000 76 06 D1 E9 73 08 8A 05-A4 88 44 FF 74 08 8B 05 v...s.....D.t...
871D:9010 A5 89 44 FE E2 F8 5F 5E-5D C2 04 00 55 8B EC 4C ..D..._^]...U..L
871D:9020 4C 56 57 83 7E 04 02 73-2D 83 7E 04 02 74 03 E9 LVW.~..s-.~..t..
871D:9030 18 01 8B 46 06 03 06 AC-10 8B F8 50 FF 76 06 FF ...F.......P.v..
871D:9040 16 AE 10 59 59 0B C0 7F-03 E9 FE 00 FF 76 06 57 ...YY........v.W
871D:9050 E8 9D FF E9 F4 00 8B 46-04 48 F7 2E AC 10 8B 56 .......F.H.....V
871D:9060 06 03 D0 8B FA 8B 46 04-D1 E8 F7 2E AC 10 8B 56 ......F........V
871D:9070 06 03 D0 8B F2 57 56 FF-16 AE 10 59 59 0B C0 7E .....WV....YY..~
Your SMBIOS structures are located at physical address 0x871d9000 (as seen from offset f000:0610, or offset x10 from the '_SM3_' anchor string), as Michael Petch points out.
This is a minor point but could be important depending on how your software is constructed. Keep in mind this is a SMBIOS 3.0 conforming structure (per the "_SM3_" anchor string) and that the structure table address can be on any 64-bit address. To ensure your software works in all systems, you should use the _SM3_ structure table address when present and enable your software to read any 64-bit physical address using big-real mode or other mechanism. When the _SM3_ structure is not present, then revert back to your old software flow.
As for why you are just now seeing this, is this the first time you have encountered a data structure that is above 1MB physical address?

Attempting to remove Apple's quarantine gives error "xattr: [Errno 2] No such file or directory"

I am attempting to remove quarantine from file permissions on osx; a similar starting point as this question.
However, when attempting the solution that worked there, I get:
$ xattr -d com.apple.metadata:kMDItemWhereFroms myFile.pem
xattr: [Errno 13] Permission denied: 'myFile.pem'
When I follow this up by applying sudo, I get:
$ sudo xattr -d com.apple.metadata myFile.pem
xattr: [Errno 2] No such file or directory: 'myFile.pem'
Anyone know what's going on here? My file clearly exists and I am unsure of what to try next.
Edit
Attempting to delete explicitly specified attribute still gives:
sudo xattr -d com.apple.metadata:kMDItemWhereFroms myFile.pem
xattr: [Errno 2] No such file or directory: 'myFile.pem'
In your second example you don't actually have a metadata attribute, i.e.
sudo xattr -d com.apple.metadata:kMDItemWhereFroms myFile.pem
Try listing the extended attributes first before removing them, which you can do via:
xattr -l myFile.pem
Then you should know which ones to delete/change in order to get the file unquarantined.
For example, if I do this on a .dmg file I see:
[~/Downloads]:;xattr -l yahoomessenger_3.0.2build235554.dmg
com.apple.diskimages.fsck:
00000000 6A EE 43 E7 65 3C 02 09 FC CC FD EE C5 BA 6F 0C |j.C.e<........o.|
00000010 F4 8B 4F 34 |..O4|
00000014
com.apple.diskimages.recentcksum: i:9292877 on 0B331FCB-4DC8-39B4-A12B-3A71BF73FD03 # 1341527466 - CRC32:$BA65FD8D
com.apple.metadata:kMDItemDownloadedDate:
00000000 62 70 6C 69 73 74 30 30 A1 01 33 41 B8 ED A2 37 |bplist00..3A...7|
00000010 EA AD 71 08 0A 00 00 00 00 00 00 01 01 00 00 00 |..q.............|
00000020 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 |................|
00000030 00 00 00 00 13 |.....|
00000035
com.apple.metadata:kMDItemWhereFroms:
00000000 62 70 6C 69 73 74 30 30 A1 01 5F 10 42 68 74 74 |bplist00.._.Bhtt|
00000010 70 3A 2F 2F 78 70 2E 79 69 6D 67 2E 63 6F 6D 2F |p://xp.yimg.com/|
00000020 67 6A 2F 6D 73 67 72 2F 6D 61 63 2F 79 61 68 6F |gj/msgr/mac/yaho|
00000030 6F 6D 65 73 73 65 6E 67 65 72 5F 33 2E 30 2E 32 |omessenger_3.0.2|
00000040 62 75 69 6C 64 32 33 35 35 35 34 2E 64 6D 67 08 |build235554.dmg.|
00000050 0A 00 00 00 00 00 00 01 01 00 00 00 00 00 00 00 |................|
00000060 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000070 4F |O|
00000071
com.apple.quarantine: 0002;533d6ab7;Safari;79D54B00-8D85-4DF7-BB49-AA9C69B9B6E9
So I see com.apple.quarantine and com.apple.metadata:kMDItemWhereFroms. I think just removing the quarantine attribute should do it.
And I see the edits you did, try simply doing xattr -d com.apple.quarantine /explicit/path/to/myFile.pem (i.e. pass along the exact filepath to the tool). No need to do sudo here.

Printing string representations of xattr hex output

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

Resources