coff 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #------------------------------------------------------------------------------
  2. # $File: coff,v 1.6 2021/04/26 15:56:00 christos Exp $
  3. # coff: file(1) magic for Common Object Files not specific to known cpu types or manufactures
  4. #
  5. # COFF
  6. #
  7. # by Joerg Jenderek at Oct 2015, Feb 2021
  8. # https://en.wikipedia.org/wiki/COFF
  9. # https://de.wikipedia.org/wiki/Common_Object_File_Format
  10. # http://www.delorie.com/djgpp/doc/coff/filhdr.html
  11. # display name+variables+flags of Common Object Files Format (32bit)
  12. # Maybe used also in adi,att3b,clipper,hitachi-sh,hp,ibm6000,intel,
  13. # mips,motorola,msdos,osf1,sharc,varied.out,vax
  14. 0 name display-coff
  15. # test for unused flag bits (0x8000,0x0800,0x0400,0x0200,x0080) in f_flags
  16. >18 uleshort&0x8E80 0
  17. # skip DOCTOR.DAILY READER.NDA REDBOX.ROOT by looking for positive number of sections
  18. >>2 uleshort >0
  19. # skip ega80woa.fnt svgafix.fnt HP3FNTS1.DAT HP3FNTS2.DAT INTRO.ACT LEARN.PIF by looking for low number of sections
  20. >>>2 uleshort <4207
  21. >>>>0 clear x
  22. # f_magic - magic number
  23. # DJGPP, 80386 COFF executable, MS Windows COFF Intel 80386 object file (./intel)
  24. >>>>0 uleshort 0x014C Intel 80386
  25. # Hitachi SH big-endian COFF (./hitachi-sh)
  26. >>>>0 uleshort 0x0500 Hitachi SH big-endian
  27. # Hitachi SH little-endian COFF (./hitachi-sh)
  28. >>>>0 uleshort 0x0550 Hitachi SH little-endian
  29. # executable (RISC System/6000 V3.1) or obj module (./ibm6000)
  30. #>>>>0 uleshort 0x01DF
  31. # MS Windows COFF Intel Itanium, AMD64
  32. # https://msdn.microsoft.com/en-us/library/windows/desktop/ms680313(v=vs.85).aspx
  33. >>>>0 uleshort 0x0200 Intel ia64
  34. >>>>0 uleshort 0x8664 Intel amd64
  35. # ARM COFF (./arm)
  36. >>>>0 uleshort 0xaa64 Aarch64
  37. >>>>0 uleshort 0x01c0 ARM
  38. >>>>0 uleshort 0x01c2 ARM Thumb
  39. >>>>0 uleshort 0x01c4 ARMv7 Thumb
  40. # TODO for other COFFs
  41. #>>>>0 uleshort 0xABCD COFF_TEMPLATE
  42. >>>>0 default x
  43. >>>>>0 uleshort x type %#04x
  44. >>>>0 uleshort x COFF
  45. # F_EXEC flag bit
  46. >>>>18 leshort ^0x0002 object file
  47. !:mime application/x-coff
  48. !:ext o/obj/lib
  49. # no cof sample found
  50. #!:ext cof/o/obj/lib
  51. >>>>18 leshort &0x0002 executable
  52. #!:mime application/x-coffexec
  53. # F_RELFLG flag bit,static object
  54. >>>>18 leshort &0x0001 \b, no relocation info
  55. # F_LNNO flag bit
  56. >>>>18 leshort &0x0004 \b, no line number info
  57. # F_LSYMS flag bit
  58. >>>>18 leshort &0x0008 \b, stripped
  59. >>>>18 leshort ^0x0008 \b, not stripped
  60. # flags in other COFF versions
  61. #0x0010 F_FDPR_PROF
  62. #0x0020 F_FDPR_OPTI
  63. #0x0040 F_DSA
  64. # F_AR32WR flag bit
  65. #>>>>18 leshort &0x0100 \b, 32 bit little endian
  66. #0x1000 F_DYNLOAD
  67. #0x2000 F_SHROBJ
  68. #0x4000 F_LOADONLY
  69. # f_nscns - number of sections like: 1 2 3 4 5 7 8 9 11 12 15 16 19 20 21 22 26 30 36 40 42 56 80 89 96 124
  70. >>>>2 uleshort <2 \b, %u section
  71. >>>>2 uleshort >1 \b, %u sections
  72. # f_symptr - symbol table pointer, only for not stripped
  73. # like: 0 0x7c 0xf4 0x104 0x182 0x1c2 0x1c6 0x468 0x948 0x416e 0x149a6 0x1c9d8 0x23a68 0x35120 0x7afa0
  74. >>>>8 ulelong >0 \b, symbol offset=%#x
  75. # f_nsyms - number of symbols, only for not stripped
  76. # like: 0 2 7 9 10 11 20 35 41 63 71 80 105 146 153 158 170 208 294 572 831 1546
  77. >>>>12 ulelong >0 \b, %d symbols
  78. # f_opthdr - optional header size. An object file should have a value of 0
  79. >>>>16 uleshort >0 \b, optional header size %u
  80. # f_timdat - file time & date stamp only for little endian
  81. >>>>4 ledate >0 \b, created %s
  82. # at offset 20 can be optional header, extra bytes FILHSZ-20 because
  83. # do not rely on sizeof(FILHDR) to give the correct size for header.
  84. # or first section header
  85. # additional variables for other COFF files
  86. >>>>16 uleshort =0
  87. # first section name s_name[8] like: .text .data .debug$S .drectve .testseg
  88. >>>>>20 string x \b, 1st section name "%.8s"
  89. # >20 beshort 0407 (impure)
  90. # >20 beshort 0410 (pure)
  91. # >20 beshort 0413 (demand paged)
  92. # >20 beshort 0421 (standalone)
  93. # >22 leshort >0 - version %d
  94. # >168 string .lowmem Apple toolbox