Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
  2. 00000000 04 03 02 01 00 00 00 00 00 00 00 04 46 36 36 30 ............F660
  3. 00000010 01 02 03 04 00 00 00 00 00 02 37 AB 00 00 36 79 ..........7«..6y
  4. 00000020 00 01 00 00 97 10 5B C9 6E 6F 53 12 00 00 00 00 ....—.[ÉnoS.....
  5. 00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  6. 00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 ................
  7. 00000050 00 00 16 B8 00 00 17 00 78 DA ED 3D 5B 77 DB 38 ...¸....xÚí=[wÛ8
  8. 00000060 73 EF FD 15 69 DA 3E 75 D7 E6 4D F4 E5 7C DB 53 sïý.iÚ>u×æMôå|ÛS
  9. 00000070 99 94 1D 9D 95 14 46 94 AD AF FB E2 03 53 B0 CC ™”..•.F”.¯ûâ.S°Ì
  10. 00000080 13 1A 64 49 CA 97 FD F5 05 A8 1B 05 02 20 48 C9 ..dIÊ—ýõ.¨... HÉ
  11. 00000090 B2 94 D2 49 6C 47 33 04 06 83 B9 01 1C 60 FE 61 ²”ÒIlG3..ƒ¹..`þa
  12. 000000A0 5F FD D7 BF FC 63 F4 10 7C 41 E0 19 FE F1 D5 BE _ý׿ücô.|Aà.þñÕ¾
  13. 000000B0 BA 02 09 FC FA 65 18 BE 5A E1 0C A5 7F 7C 55 BF º..üúe.¾Zá.¥.|U¿
  14. 000000C0 62 04 FC DF 2F 83 F0 8F AF 0A F9 8F DD 5F 20 77 b.üß/ƒð.¯.ù.Ý_ w
  15. 000000D0 AF BB E8 31 FC FA E5 05 04 18 A4 E2 3F 9A A2 64 ¯»è1üúå...¤â?š¢d
  16. 000000E0 FF 94 EC 67 DB 30 F0 67 F8 CB 50 8C 6B F2 F3 EB ÿ”ìgÛ0ðgøËPŒkòóë
  17. 000000F0 29 7E FC 14 37 46 7E E0 4E 37 BA 1E B7 07 76 BE )~ü.7F~àN7º.·.v¾
  18. 00000100 63 8D DF F1 9D 0F 5F 07 F8 B7 45 D7 DD 1B FB 64 c.ßñ.._.ø·E×Ý.ûd
  19. 00000110 6C AB 59 EB 2B 1C D2 DC E8 3D 5A E2 18 05 A8 65 l«Yë+.ÒÜè=Zâ..¨e
  20. 00000120 5B 20 F2 FC F4 7D 81 41 3D 3F 8A FD E9 14 C6 1D [ òüô}.A=?Šýé.Æ.
  21. 00000130 04 1E 02 B8 81 B2 18 C0 92 34 B5 9C 34 4D 48 9A ...¸.².À’4µœ4MHš
  22.  
  23. import sys
  24. import binascii
  25. import struct
  26. import zlib
  27.  
  28. if (len(sys.argv) < 1):
  29. print 'usage: check_config.py config_file'
  30.  
  31. cf = open(sys.argv[1], 'rb')
  32. h = cf.read(0x4c)
  33.  
  34. #--------------------
  35. # read the header
  36. if (h[0:4] != 'x04x03x02x01'):
  37. print 'Invalid magic'
  38. sys.exit(-1)
  39.  
  40. if (h[0x10:0x14] != 'x01x02x03x04'):
  41. print 'Invalid magic'
  42. sys.exit(-1)
  43.  
  44. h2 = h[0x10:]
  45. hcrc_calc = binascii.crc32(h2[0:0x18])&0xffffffff
  46. hcrc_store = struct.unpack('!L', h2[0x18:0x1c])[0]
  47. print 'calc: %x - stored: %x'%(hcrc_calc, hcrc_store)
  48. if (hcrc_calc != hcrc_store):
  49. print 'Invalid header CRC'
  50. sys.exit(-2)
  51.  
  52. block_buffer_size = struct.unpack('!L', h2[0x10:0x14])[0]
  53. # used to allocate memory for temp buffers
  54. print 'block buffer size: %x'%(block_buffer_size)
  55.  
  56. #--------------------
  57. # read the blocks
  58. fout = open('%s.xml'%(sys.argv[1]), 'wb')
  59. cumulate_crc = 0
  60. while (True):
  61. bheader = cf.read(0x0c)
  62. if (len(bheader) == 0):
  63. break
  64. block_size = struct.unpack('!L', bheader[0x04:0x08])[0]
  65. print 'block size: %x'%(block_size)
  66.  
  67. # read the whole block to previously allocated buffer
  68. # Possible heap based buffer overflow, because the size was not checked in
  69. # the dbcCfgFileDecry function!
  70. block = cf.read(block_size)
  71. cumulate_crc = binascii.crc32(block, cumulate_crc)&0xffffffff
  72. decompressed = zlib.decompress(block)
  73. fout.write(decompressed)
  74.  
  75. stored_cumulate_crc = struct.unpack('!L', h2[0x14:0x18])[0]
  76. print 'cumulate crc: calc: %x - stored: %x'%(cumulate_crc, stored_cumulate_crc)
  77. if (cumulate_crc != stored_cumulate_crc):
  78. print 'Invalid cumulate CRC'
  79. sys.exit(-3)
  80.  
  81. cf.close()
  82. fout.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement