1327e51cbSPeter Avalos 2327e51cbSPeter Avalos#------------------------------------------------------------------------------ 3*3b9cdfa3SAntonio Huete Jimenez# $File: freebsd,v 1.9 2022/01/19 12:44:13 christos Exp $ 4327e51cbSPeter Avalos# freebsd: file(1) magic for FreeBSD objects 5327e51cbSPeter Avalos# 6327e51cbSPeter Avalos# All new-style FreeBSD magic numbers are in host byte order (i.e., 7327e51cbSPeter Avalos# little-endian on x86). 8327e51cbSPeter Avalos# 9327e51cbSPeter Avalos# XXX - this comes from the file "freebsd" in a recent FreeBSD version of 10327e51cbSPeter Avalos# "file"; it, and the NetBSD stuff in "netbsd", appear to use different 11327e51cbSPeter Avalos# schemes for distinguishing between executable images, shared libraries, 12327e51cbSPeter Avalos# and object files. 13327e51cbSPeter Avalos# 14327e51cbSPeter Avalos# FreeBSD says: 15327e51cbSPeter Avalos# 16327e51cbSPeter Avalos# Regardless of whether it's pure, demand-paged, or none of the 17327e51cbSPeter Avalos# above: 18327e51cbSPeter Avalos# 19327e51cbSPeter Avalos# if the entry point is < 4096, then it's a shared library if 20327e51cbSPeter Avalos# the "has run-time loader information" bit is set, and is 21327e51cbSPeter Avalos# position-independent if the "is position-independent" bit 22327e51cbSPeter Avalos# is set; 23327e51cbSPeter Avalos# 24327e51cbSPeter Avalos# if the entry point is >= 4096 (or >4095, same thing), then it's 25327e51cbSPeter Avalos# an executable, and is dynamically-linked if the "has run-time 26327e51cbSPeter Avalos# loader information" bit is set. 27327e51cbSPeter Avalos# 28327e51cbSPeter Avalos# On x86, NetBSD says: 29327e51cbSPeter Avalos# 30327e51cbSPeter Avalos# If it's neither pure nor demand-paged: 31327e51cbSPeter Avalos# 32327e51cbSPeter Avalos# if it has the "has run-time loader information" bit set, it's 33327e51cbSPeter Avalos# a dynamically-linked executable; 34327e51cbSPeter Avalos# 35327e51cbSPeter Avalos# if it doesn't have that bit set, then: 36327e51cbSPeter Avalos# 37327e51cbSPeter Avalos# if it has the "is position-independent" bit set, it's 38327e51cbSPeter Avalos# position-independent; 39327e51cbSPeter Avalos# 40327e51cbSPeter Avalos# if the entry point is non-zero, it's an executable, otherwise 41327e51cbSPeter Avalos# it's an object file. 42327e51cbSPeter Avalos# 43327e51cbSPeter Avalos# If it's pure: 44327e51cbSPeter Avalos# 45327e51cbSPeter Avalos# if it has the "has run-time loader information" bit set, it's 46327e51cbSPeter Avalos# a dynamically-linked executable, otherwise it's just an 47327e51cbSPeter Avalos# executable. 48327e51cbSPeter Avalos# 49327e51cbSPeter Avalos# If it's demand-paged: 50327e51cbSPeter Avalos# 51327e51cbSPeter Avalos# if it has the "has run-time loader information" bit set, 52327e51cbSPeter Avalos# then: 53327e51cbSPeter Avalos# 54327e51cbSPeter Avalos# if the entry point is < 4096, it's a shared library; 55327e51cbSPeter Avalos# 56327e51cbSPeter Avalos# if the entry point is = 4096 or > 4096 (i.e., >= 4096), 57327e51cbSPeter Avalos# it's a dynamically-linked executable); 58327e51cbSPeter Avalos# 59327e51cbSPeter Avalos# if it doesn't have the "has run-time loader information" bit 60327e51cbSPeter Avalos# set, then it's just an executable. 61327e51cbSPeter Avalos# 62327e51cbSPeter Avalos# (On non-x86, NetBSD does much the same thing, except that it uses 63327e51cbSPeter Avalos# 8192 on 68K - except for "68k4k", which is presumably "68K with 4K 64327e51cbSPeter Avalos# pages - SPARC, and MIPS, presumably because Sun-3's and Sun-4's 65327e51cbSPeter Avalos# had 8K pages; dunno about MIPS.) 66327e51cbSPeter Avalos# 67327e51cbSPeter Avalos# I suspect the two will differ only in perverse and uninteresting cases 68327e51cbSPeter Avalos# ("shared" libraries that aren't demand-paged and whose pages probably 69327e51cbSPeter Avalos# won't actually be shared, executables with entry points <4096). 70327e51cbSPeter Avalos# 71327e51cbSPeter Avalos# I leave it to those more familiar with FreeBSD and NetBSD to figure out 72327e51cbSPeter Avalos# what the right answer is (although using ">4095", FreeBSD-style, is 73327e51cbSPeter Avalos# probably better than separately checking for "=4096" and ">4096", 74327e51cbSPeter Avalos# NetBSD-style). (The old "netbsd" file analyzed FreeBSD demand paged 75327e51cbSPeter Avalos# executables using the NetBSD technique.) 76327e51cbSPeter Avalos# 77327e51cbSPeter Avalos0 lelong&0377777777 041400407 FreeBSD/i386 78327e51cbSPeter Avalos>20 lelong <4096 79327e51cbSPeter Avalos>>3 byte&0xC0 &0x80 shared library 80327e51cbSPeter Avalos>>3 byte&0xC0 0x40 PIC object 81327e51cbSPeter Avalos>>3 byte&0xC0 0x00 object 82327e51cbSPeter Avalos>20 lelong >4095 83327e51cbSPeter Avalos>>3 byte&0x80 0x80 dynamically linked executable 84327e51cbSPeter Avalos>>3 byte&0x80 0x00 executable 85327e51cbSPeter Avalos>16 lelong >0 not stripped 86327e51cbSPeter Avalos 87327e51cbSPeter Avalos0 lelong&0377777777 041400410 FreeBSD/i386 pure 88327e51cbSPeter Avalos>20 lelong <4096 89327e51cbSPeter Avalos>>3 byte&0xC0 &0x80 shared library 90327e51cbSPeter Avalos>>3 byte&0xC0 0x40 PIC object 91327e51cbSPeter Avalos>>3 byte&0xC0 0x00 object 92327e51cbSPeter Avalos>20 lelong >4095 93327e51cbSPeter Avalos>>3 byte&0x80 0x80 dynamically linked executable 94327e51cbSPeter Avalos>>3 byte&0x80 0x00 executable 95327e51cbSPeter Avalos>16 lelong >0 not stripped 96327e51cbSPeter Avalos 97327e51cbSPeter Avalos0 lelong&0377777777 041400413 FreeBSD/i386 demand paged 98327e51cbSPeter Avalos>20 lelong <4096 99327e51cbSPeter Avalos>>3 byte&0xC0 &0x80 shared library 100327e51cbSPeter Avalos>>3 byte&0xC0 0x40 PIC object 101327e51cbSPeter Avalos>>3 byte&0xC0 0x00 object 102327e51cbSPeter Avalos>20 lelong >4095 103327e51cbSPeter Avalos>>3 byte&0x80 0x80 dynamically linked executable 104327e51cbSPeter Avalos>>3 byte&0x80 0x00 executable 105327e51cbSPeter Avalos>16 lelong >0 not stripped 106327e51cbSPeter Avalos 107327e51cbSPeter Avalos0 lelong&0377777777 041400314 FreeBSD/i386 compact demand paged 108327e51cbSPeter Avalos>20 lelong <4096 109327e51cbSPeter Avalos>>3 byte&0xC0 &0x80 shared library 110327e51cbSPeter Avalos>>3 byte&0xC0 0x40 PIC object 111327e51cbSPeter Avalos>>3 byte&0xC0 0x00 object 112327e51cbSPeter Avalos>20 lelong >4095 113327e51cbSPeter Avalos>>3 byte&0x80 0x80 dynamically linked executable 114327e51cbSPeter Avalos>>3 byte&0x80 0x00 executable 115327e51cbSPeter Avalos>16 lelong >0 not stripped 116327e51cbSPeter Avalos 117327e51cbSPeter Avalos# XXX gross hack to identify core files 118327e51cbSPeter Avalos# cores start with a struct tss; we take advantage of the following: 119327e51cbSPeter Avalos# byte 7: highest byte of the kernel stack pointer, always 0xfe 120327e51cbSPeter Avalos# 8/9: kernel (ring 0) ss value, always 0x0010 121327e51cbSPeter Avalos# 10 - 27: ring 1 and 2 ss/esp, unused, thus always 0 122327e51cbSPeter Avalos# 28: low order byte of the current PTD entry, always 0 since the 123327e51cbSPeter Avalos# PTD is page-aligned 124327e51cbSPeter Avalos# 125327e51cbSPeter Avalos7 string \357\020\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 FreeBSD/i386 a.out core file 126327e51cbSPeter Avalos>1039 string >\0 from '%s' 127327e51cbSPeter Avalos 128327e51cbSPeter Avalos# /var/run/ld.so.hints 129327e51cbSPeter Avalos# What are you laughing about? 130327e51cbSPeter Avalos0 lelong 011421044151 ld.so hints file (Little Endian 131327e51cbSPeter Avalos>4 lelong >0 \b, version %d) 13279343712SPeter Avalos>4 belong <1 \b) 133327e51cbSPeter Avalos0 belong 011421044151 ld.so hints file (Big Endian 134327e51cbSPeter Avalos>4 belong >0 \b, version %d) 13579343712SPeter Avalos>4 belong <1 \b) 136327e51cbSPeter Avalos 137327e51cbSPeter Avalos# 138327e51cbSPeter Avalos# Files generated by FreeBSD scrshot(1)/vidcontrol(1) utilities 139327e51cbSPeter Avalos# 140327e51cbSPeter Avalos0 string SCRSHOT_ scrshot(1) screenshot, 141327e51cbSPeter Avalos>8 byte x version %d, 142327e51cbSPeter Avalos>9 byte 2 %d bytes in header, 143327e51cbSPeter Avalos>>10 byte x %d chars wide by 144327e51cbSPeter Avalos>>11 byte x %d chars high 145*3b9cdfa3SAntonio Huete Jimenez 146*3b9cdfa3SAntonio Huete Jimenez# 147*3b9cdfa3SAntonio Huete Jimenez# FreeBSD kernel minidumps 148*3b9cdfa3SAntonio Huete Jimenez# 149*3b9cdfa3SAntonio Huete Jimenez0 string minidump\040FreeBSD/ FreeBSD kernel minidump 150*3b9cdfa3SAntonio Huete Jimenez# powerpc uses 32-byte magic, followed by 32-byte mmu kind, then version 151*3b9cdfa3SAntonio Huete Jimenez>17 string powerpc 152*3b9cdfa3SAntonio Huete Jimenez>>17 string >\0 for %s, 153*3b9cdfa3SAntonio Huete Jimenez>>>32 string >\0 %s, 154*3b9cdfa3SAntonio Huete Jimenez>>>>64 byte 0 big endian, 155*3b9cdfa3SAntonio Huete Jimenez>>>>>64 belong x version %d 156*3b9cdfa3SAntonio Huete Jimenez>>>>64 default x little endian, 157*3b9cdfa3SAntonio Huete Jimenez>>>>>64 lelong x version %d 158*3b9cdfa3SAntonio Huete Jimenez# all other architectures use 24-byte magic, followed by version 159*3b9cdfa3SAntonio Huete Jimenez>17 default x 160*3b9cdfa3SAntonio Huete Jimenez>>17 string >\0 for %s, 161*3b9cdfa3SAntonio Huete Jimenez>>>24 byte 0 big endian, 162*3b9cdfa3SAntonio Huete Jimenez>>>>24 belong x version %d 163*3b9cdfa3SAntonio Huete Jimenez>>>24 default x little endian, 164*3b9cdfa3SAntonio Huete Jimenez>>>>24 lelong x version %d 165