Busy Java Developer’s Guide to JVM Bytecode – Ted Neward
Podobno każdy programista Javy wie/powinien wiedzieć (niepotrzebne skreślić), co to jest CAFEBABE…
Przyznam, że spotkałem się z tym terminem jedynie w książce Java Puzzlers.
Kiedy jednak poszukałem trochę w Internecie, dowiedziałem się ciekawej historii od Jamesa Goslinga:
As far as I know, I’m the guilty party on this one. I was totally unaware of the NeXT connection. The small number of interesting HEX words is probably the source of the match. As for the derivation of the use of CAFEBABE in Java, it’s somewhat circuitous:
We used to go to lunch at a place called St Michael’s Alley. According to local legend, in the deep dark past, the Grateful Dead used to perform there before they made it big. It was a pretty funky place that was definitely a Grateful Dead Kinda Place. When Jerry died, they even put up a little Buddhist-esque shrine. When we used to go there, we referred to the place as Cafe Dead.
Somewhere along the line it was noticed that this was a HEX number. I was re-vamping some file format code and needed a couple of magic numbers: one for the persistent object file, and one for classes. I used CAFEDEAD for the object file format, and in grepping for 4 character hex words that fit after CAFE (it seemed to be a good theme) I hit on BABE and decided to use it.
At that time, it didn’t seem terribly important or destined to go anywhere but the trash-can of history. So CAFEBABE became the class file format, and CAFEDEAD was the persistent object format. But the persistent object facility went away, and along with it went the use of CAFEDEAD – it was eventually replaced by RMI.
Rzeczywiście:
barista@javaczyherbata.pl$ xxd -p Barista.class cafebabe00000034000d0a0003000a07000b07000c0100063c696e69743e 010003282956010004436f646501000f4c696e654e756d6265725461626c 6501000a536f7572636546696c6501000c426172697374612e6a6176610c 00040005010007426172697374610100106a6176612f6c616e672f4f626a 656374002100020003000000000001000100040005000100060000001d00 010001000000052ab70001b1000000010007000000060001000000010001 0008000000020009
Okazuje się, że takich „magic number” jest w świecie IT więcej:
- 0x8BADF00D – ate bad food; is used by Apple in iOS crash reports, when an application takes too long to launch, terminate, or respond to system events
- 0x1BADB002 – 1 bad boot; Multiboot header magic number
- 0x1CEB00DA – ice buddha; was used as the origin for the binary file parser IceBuddha
- 0xB105F00D – BIOS food; is the value of the low bytes of last four registers on ARM PrimeCell compatible components (the component_id registers), used to identify correct behaviour of a memory-mapped component
- 0xB16B00B5 – big boobs; was required by Microsoft’s Hyper-V hypervisor to be used by Linux guests as their „guest signature”
- 0x0DEFACED – defaced; Actually, it was initially changed to decimal and then replaced entirely
- 0xBAADF00D – bad food; is used by Microsoft’s LocalAlloc(LMEM_FIXED) to indicate uninitialised allocated heap memory when the debug heap is used
- 0xCAFED00D – cafe dude; is used by Java as a magic number for their pack200 compression
- 0xDEADBABE – Dead Babe; is used by IBM Jikes RVM as a sanity check of the stack of the primary thread
- 0xDEADC0DE – dead code; is used as a marker in OpenWrt firmware to signify the beginning of the to-be created jffs2 filesystem at the end of the static firmware
- 0xDEADD00D – dead dude; is used by Android in the Dalvik virtual machine to indicate a VM abort
- face:b00c – facebook; used in the IPv6 address of www.v6.facebook.com
- 0xFEE1DEAD – feel dead; is used as a magic number in the Linux reboot system call
Więcej na Hexspeak.
Pretekstem do tematu o 0xCAFEBABE jest bardzo ciekawa prezentacja Teda Newarda z tegorocznej konferencji 33rd Degree.