Hexspeak&leetspeak

在看一些开源项目的时候,经常会遇到一些奇怪的 magic numbers,比如 0xdeedbeef,它们经常出现,但是有什么含义呢?

wiki 上对 Hexspeak 的解释如下:

Hexspeak, like leetspeak, is a novelty form of variant English spelling using the hexadecimal digits. Created by programmers as memorable magic numbers, hexspeak words can serve as a clear and unique identifier with which to mark memory or data.

简而言之,hexspeak,就是一种程序员发明的,用 16 进制数来表达的一种变体的英文拼写。

翻译规则

16 进制的书写由0123456789ABCDEF15 个字符来完成,仅仅使用ABCDEF几个字母就已经可以拼写出很多单词了。剩余的0123456789可以将它们转化成对应的字母,比如:

  • 0可以当作字母O
  • 1可以当作字母L或者I
  • 5可以当作字母S,
  • 7可以当作字母T,
  • 12可以当作字母R,
  • 6或者9可以当作字母G或者g,
  • 5可以当作字母S,
  • 248则可使用谐音,如toforate

通过这种方式就可以表达出更多含义了。

常见的 magic numbers

许多计算机处理器、操作系统和调试器都会使用幻数,尤其是将其作为调试值。下面是 wiki 中收录的一些常见幻数:

Code Description
0x0000000FF1CE (“office”) is used as the last part of product codes (GUID) for Microsoft Office components (visible in registry under the HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall registry key).
0x00BAB10C (“über (ooba) block”) is used as the magic number for the ZFS uberblock.
0x1BADB002 (“1 bad boot”[1]) Multiboot header magic number.[2]
0x4B1D (“forbid”) was a password in some calibration consoles for developers to peer deeper into control registers outside the normal calibration memory range.[citation needed]
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.[3]
0xABADBABE (“a bad babe”) was/is used by Microsoft’s Windows 7 to trigger a debugger break-point, probably when a USB device is attached[4]
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”.[5] One proposal suggested changing it to 0x0DEFACED (“defaced”).[6] But in actuality, it was initially changed to decimal and then replaced entirely.[7]
0x0B00B135 (“boobies”) was likewise required by Microsoft’s Hyper-V hypervisor to be used by a user of XEN as their user id.[8] It was removed on January 22, 2010.[9]
0xBAAAAAAD (“baaaaaad”) is used by Apple’s iOS exception report to indicate that the log is a stackshot of the entire system, not a crash report.[10]
0xBAADF00D (“bad food”) is used by Microsoft’s LocalAlloc(LMEM_FIXED) to indicate uninitialised allocated heap memory when the debug heap is used.[11]
0xBAD22222 (“bad too repeatedly”) is used by Apple’s iOS exception log to indicate that a VoIP application has been terminated by iOS because it resumed too frequently.[10]
0xBADDCAFE (“bad cafe”) is used by Libumem to indicate uninitialized memory area.
0xCAFEB0BA (“cafe boba”) is used by datp as canned return value for QKit MFCC keyword detection for Host GUI development since his colleague likes coffee (and maybe boba, too).
0xB0BABABE (“boba babe”) is used by pton as Host GUI Ack to QKit MFCC keyword detection response.
0xBEEFBABE (“beef babe”) is used by the 1997 video game Frogger to detect a stack buffer overflow.
0xB000 0xDEAD (“boo dead”) was displayed by PA-RISC based HP 3000 and HP 9000 computers upon encountering a “system halt” (aka “low level halt”).[12]
0xC00010FF (“cool off”) is used by Apple in iOS crash reports, when application was killed in response to a thermal event.[3]
C15C:0D06:F00D (“cisco dog food”) used in the IPv6 address of www.cisco.com on World IPv6 Day. “Dog food” refers to Cisco eating its own dog food with IPv6.
0xCAFEBABE (“cafe babe”) is used by Plan 9’s libc as a poison value for memory pools.[13] It is also used by Mach-O to identify Universal object files, and by the Java programming language to identify Java bytecode class files. It was originally created by NeXTSTEP developers as a reference to the baristas at Peet’s Coffee & Tea.[14]
0xCAFED00D (“cafe dude”) is used by Java as a magic number for their pack200 compression.[15]
0xCEFAEDFE (“face feed”) is used by Mach-O to identify flat (single architecture) object files. In little endian this reads FEEDFACE, “Feed Face”.
0x0D15EA5E (“zero disease”) is a flag that indicates regular boot on the Nintendo GameCube and Wii consoles.[16][17]
0xDABBAD00 (“dabba doo”) is the name of a blog on computer security.[18]
0xDEAD2BAD (“dead too bad”) was used to mark allocated areas of memory that had not yet been initialised on Sequent Dynix/ptx systems.
0xDEADBAAD (“dead bad”) is used by the Android libc abort() function when native heap corruption is detected.
0xDEADBABE (“dead babe”) is used by IBM Jikes RVM as a sanity check of the stack of the primary thread.[19]
0xDEADBEAF (“dead beaf”) is part of the signature code of Jazz Jackrabbit 2 tileset files.[20] Level files have less room for their signatures and use 0xBABE (“babe”) instead.[21] It is also the header of campaign gamesaves used in the Halo game series.
deadbeef-dead-beef-dead-beef00000075 (“dead beef”) is the GUID assigned to hung/dead virtual machines in Citrix XenServer.
0xDEADBEEF (“dead beef”) is frequently used to indicate a software crash or deadlock in embedded systems. 0xDEADBEEF was originally used to mark newly allocated areas of memory that had not yet been initialized—when scanning a memory dump, it is easy to see the 0xDEADBEEF. It is used by IBM RS/6000 systems, Mac OS on 32-bit PowerPC processors, and the Commodore Amiga as a magic debug value. On Sun MicrosystemsSolaris, it marks freed kernel memory. The DEC Alpha SRM console has a background process that traps memory errors, identified by PS as “BeefEater waiting on 0xdeadbeef”.[22]
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.
0xDEADDEAD (“dead dead”) is the bug check (STOP) code displayed when invoking a Blue Screen of Death either by telling the kernel via the attached debugger, or by using a special keystroke combination.[23] This is usually seen by driver developers, as it is used to get a memory dump on Windows NT based systems. An alternative to 0xDEADDEAD is the bug check code 0x000000E2,[24] as they are both called MANUALLY_INITIATED_CRASH as seen on the Microsoft Developer Network.
0xDEADD00D (“dead dude”) is used by Android in the Dalvik virtual machine to indicate a VM abort.
0xDEADFA11 (“dead fall” or “dead fail”) is used by Apple in iOS crash reports, when the user force quits an application.[3]
0xDEAD10CC (“dead lock”) is used by Apple in iOS crash reports, when an application holds on to a system resource while running in the background.[