analyze.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # Analyze errors
  2. import os
  3. import pefile
  4. import zipfile
  5. def addCustomComments(installer):
  6. if installer.md5 == "32aad22244ee0c8e7dcd3f86dea9e347": # NPFG10.EXE
  7. installer.addComment("This one has '../' in one of it's filenames, it is resolved by escaping the '../' with '\\.\\./'")
  8. elif installer.md5 == "a91a9034e99da6917ed6ea4ae1017474": # b65full.exe
  9. installer.addComment("Corrupt, missing data, see "
  10. "c3d819097d06d110f1b01111a89b095c for valid "
  11. "data.")
  12. elif installer.md5 in ["70a6bbf41b7e9de48e711dbc26eac88b", # dap43.exe
  13. "f463a1d47ac919160fc450d322c6c63e", # dap4.exe
  14. "7d093e7e91b17b0b6ca427c91202c839"]: # dap3908.exe
  15. installer.addComment("0x18 mismatch, there is OP 0x00 right after 0x18")
  16. elif installer.md5 in ["5516bfdc0346f475300f83ebc6c76547", # lw3drv.exe
  17. "3be4f8d1fc6ede81d954b6914530dd2b", # lw3w2k.exe
  18. "1588bc310e9a71389f1069af159203ee", # lw3wme.exe
  19. "073c6e77547bcda5ce7b5ebe96f3eb01"]:# SBL51.EXE
  20. installer.addComment("0x18 mismatch")
  21. elif installer.md5 in ["7c763e4af5aca8cc2fabcc846b788692", # DSiegeUpdate1_09_2-1_1_1460.exe
  22. "acccf3d47143f0cf2b6b893765586eb6", # Dsiegeupdate1.0-1.11.1462_english.exe
  23. "3465e2b1eec01cc26b898c4ef3ef090e"]: # dsupdate1.1-1.11.1462_eng.exe
  24. installer.addComment("0x18 mismatch, 0x18 00 08 ..")
  25. #elif installer.md5 in ["2b4e75b6c5b1ae0fd9243d0cf8db45e5" # psp700ev.exe
  26. # "215506a69c9677e9b01bd5c43314ee5f"]: # RD2_onlinedemo_03_10.exe
  27. # installer.addComment("False positive, this is a InstallShield installer")
  28. elif installer.md5 in ["dbbf3189c879ad7673d5971e457effeb", # DPPopUpStopper.exe
  29. "ae59de2259f3a109a6d66eb037da2335", # ICQ2000B.EXE
  30. "60aef2e657c05cfff2bfbc75d6385f3d"]: # DontPanc.exe
  31. installer.addComment("This installer reads the overlay header 3 bytes to early")
  32. #elif installer.md5 in ["a44f7489825a35b8ea49857d2d832ce6", # thmpls450_s.exe
  33. # "cf8e337b9c331cdfbe490a023b184a9f", # icq99b.exe
  34. # "058f7c9124cd32463e8dfebe4eb115c7"]: # icq2000a.exe
  35. # installer.addComment("FIXME Weird extra chars in unknown_22")
  36. elif installer.md5 in ["3379f7b191a5f9ad9dee9d49acf99e23", # upgrade.exe
  37. "3319738353934531293f8b7e1c103a85"]: # upgrade.exe
  38. installer.addComment("Interesting one, this has no 0x00 files, only 0x12, online installer?")
  39. elif installer.md5 == "28b29549010d0980d1cd1d0ad86f8dbe": # battlefield2demo.exe
  40. installer.addComment("False positive, InstallShield Wizard?")
  41. elif installer.md5 in ["32a6454ef70526f8d80be1069749bfde", # sumofree.exe (overlay: 0x00012200)
  42. "3dd7c98df5e6a5e528d446f4ebce46c8", # RD210.EXE (overlay: 0x00012C00)
  43. "3c50c1616008c582c7ea3c34fef90d91"]: # empireearth2_mpdemo_en.exe (overlay: 0x0001F800)
  44. installer.addComment("False positive? Raw files appended at overlay with probably a Wise installer")
  45. elif installer.md5 in ["7c420b5be50635f3a2f73cf8e5c490c5", # spf.exe
  46. "99c37f56b1a030ed4b04e0b2cb611051", # spf.exe
  47. "c087ee0bbd1baf2a6e04151b76fc1216"]: # spf.exe
  48. installer.addComment("False positive")
  49. def addPeComments(installer):
  50. pe = None
  51. try:
  52. pe = pefile.PE(installer.realpath, fast_load=True)
  53. except pefile.PEFormatError as err:
  54. installer.addComment(f"This not a PE file: {err}")
  55. return True
  56. # find the magic string in any PE section and note the offset after read
  57. magicoffset = 0
  58. sectionName = ""
  59. with open(installer.realpath, "rb") as fp:
  60. for section in pe.sections:
  61. if section.Name[:5] == b'.WISE':
  62. installer.addComment("PE .WISE section found.")
  63. # Read each section into mem and search for the magic string
  64. for section in pe.sections:
  65. fp.seek(section.VirtualAddress, 0)
  66. sectiondata = fp.read(section.SizeOfRawData)
  67. if b"Initializing Wise Installation Wizard..." in sectiondata:
  68. magicoffset = fp.tell()
  69. sectionName = section.Name
  70. break
  71. if magicoffset != 0:
  72. installer.addComment(f"'Initializing Wise Installation Wizard...' found in the PE {sectionName} section.")
  73. pe.close()
  74. return True
  75. overlay = pe.get_overlay_data_start_offset()
  76. if overlay:
  77. filesize = os.path.getsize(installer.realpath)
  78. delta = filesize - overlay
  79. if delta < 4096:
  80. installer.addComment(f"Very small overlay size of {delta} bytes")
  81. pe.close()
  82. return True
  83. else:
  84. installer.addComment(f"No overlay data")
  85. pe.close()
  86. return True
  87. with open(installer.realpath, "rb") as fp:
  88. fp.seek(overlay, 0)
  89. if fp.read(13) == b'InstallShield':
  90. installer.addComment("False positive, 'InstallShield' found at overlay.")
  91. pe.close()
  92. return True
  93. pe.close()
  94. return False
  95. def falsePositivePkCheck(installer):
  96. try:
  97. zfp = zipfile.ZipFile(installer.realpath, 'r')
  98. zfp.close()
  99. except zipfile.BadZipFile:
  100. installer.isPk = False
  101. installer.addComment("False positive PK, check the overlay header")
  102. return True
  103. return False