tplink 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #------------------------------------------------------------------------------
  2. # $File: tplink,v 1.8 2023/05/15 16:41:02 christos Exp $
  3. # tplink: File magic for openwrt firmware files
  4. # URL: https://wiki.openwrt.org/doc/techref/header
  5. # Reference: https://git.openwrt.org/?p=openwrt.git;a=blob;f=tools/firmware-utils/src/mktplinkfw.c
  6. # http://mark0.net/download/triddefs_xml.7z/defs/b/bin-tplink-v1.trid.xml
  7. # Note: called "TP-Link router firmware (v1)" by TrID
  8. # From: Joerg Jenderek
  9. # check for valid header version 1 or 2
  10. 0 ulelong <3
  11. >0 ulelong !0
  12. # test for header padding with nulls
  13. >>0x100 long 0
  14. # skip Norton Commander Cleanup Utility NCCLEAN.INI by looking for valid vendor name
  15. >>>4 ubelong >0x1F000000
  16. # skip user.dbt by looking for positive hardware id
  17. >>>>0x40 ubeshort >0
  18. # skip cversions.1.db cversions.2.db cversions.3.db inside
  19. # c:\ProgramData\Microsoft\Windows\Caches
  20. # with invalid vendor names \240\0\0\0 \140\0\0\0 \040\0\0\0
  21. >>>>>5 short !0
  22. >>>>>>0 use firmware-tplink
  23. 0 name firmware-tplink
  24. >0 ubyte x firmware
  25. !:mime application/x-tplink-bin
  26. # like: TL-WR1043ND-V1-FW0.0.3-stripped.bin gluon-ffrefugee-0.9.2-tp-link-archer-c5-v1-sysupgrade.bin
  27. !:ext bin
  28. # hardware id like 10430001 07410001 09410004 09410006
  29. >0x40 ubeshort x %x
  30. >0x42 ubeshort x v%x
  31. # hardware revision like 1
  32. >0x44 ubelong !1 (revision %u)
  33. # vendor_name[24] like OpenWrt or TP-LINK Technologies
  34. >4 string x %.24s
  35. # fw_version[36] like r49389 or ver. 1.0
  36. >0x1c string x %.36s
  37. # header version 1 or 2
  38. >0 ubyte !1 V%X
  39. # ver_hi.ver_mid.ver_lo
  40. >0x98 long !0 \b, version
  41. >>0x98 ubeshort x %u
  42. >>0x9A ubeshort x \b.%u
  43. >>0x9C ubeshort x \b.%u
  44. # region code 0~universal 1~US
  45. >0x48 ubelong x
  46. #>>0x48 ubelong 0 (universal)
  47. >>0x48 ubelong 1 (US)
  48. >>0x48 ubelong >1 (region %u)
  49. # total length of the firmware. not always true
  50. >0x7C ubelong x \b, %u bytes or less
  51. # unknown 1
  52. >0x48 ubelong !0 \b, UNKNOWN1 %#x
  53. # md5sum1[16]
  54. #>0x4c ubequad x \b, MD5 %llx
  55. #>>0x54 ubequad x \b%llx
  56. # unknown 2
  57. >0x5c ubelong !0 \b, UNKNOWN2 %#x
  58. # md5sum2[16]
  59. #>0x60 ubequad !0 \b, 2nd MD5 %llx
  60. #>>0x68 ubequad x \b%llx
  61. # unknown 3
  62. >0x70 ubelong !0 \b, UNKNOWN3 %#x
  63. # kernel load address
  64. #>0x74 ubelong x \b, %#x load
  65. # kernel entry point
  66. #>0x78 ubelong x \b, %#x entry
  67. # kernel data offset. 200h means direct after header
  68. >0x80 ubelong x \b, at %#x
  69. # kernel data length and 1 space
  70. >0x84 ubelong x %u bytes
  71. # look for kernel type (gzip compressed vmlinux.bin by ./compress)
  72. >(0x80.L) indirect x
  73. # root file system data offset
  74. # WRONG in 5.35 with above indirect expression
  75. >0x88 ubelong x \b, at %#x
  76. # rootfs data length and 1 space
  77. >0x8C ubelong x %u bytes
  78. # in 5.32 only true for offset ~< FILE_BYTES_MAX=9 MB defined in ../../src/file.h
  79. >(0x88.L) indirect x
  80. # 'qshs' for wr940nv1_en_3_13_7_up(111228).bin
  81. #>(0x88.L) string x \b, file system '%.4s'
  82. #>(0x88.L) ubequad x \b, file system %#llx
  83. # bootloader data offset
  84. >0x90 ubelong !0 \b, at %#x
  85. # bootloader data length only reasonable if bootloader offset not null
  86. >>0x94 ubelong !0 %u bytes
  87. # pad[354] should be 354 null bytes.
  88. #>0x9E ubequad !0 \b, padding %#llx
  89. # But at 0x120 18 non null bytes in examples like
  90. # wr940nv4_eu_3_16_9_up_boot(160620).bin
  91. # wr940nv6_us_3_18_1_up_boot(171030).bin
  92. #>0x120 ubequad !0 \b, other padding %#llx