Created
August 2, 2021 19:37
-
-
Save sysopfb/ccb44855314fbde6a926475dafb861da to your computer and use it in GitHub Desktop.
Black Matter blob decoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python2 just because | |
# Samples: | |
# 22d7d67c3af10b1a37f277ebabe2d1eb4fd25afbd6437d4377400e148bcc08d6 | |
# c6e2ef30a86baa670590bd21acf5b91822117e0cbe6060060bc5fe0182dace99 | |
import pefile | |
import struct | |
import sys | |
def LCG(seed, lastseed): | |
newseed = lastseed * 0x8088405 | |
newseed &= 0xffffffff | |
newseed += 1 | |
ret_val = newseed * seed | |
ret_val = (ret_val>>32) & 0xffffffff | |
return((newseed,ret_val)) | |
pe = pefile.PE(sys.argv[1]) | |
blob = None | |
seed = 0 | |
for s in pe.sections: | |
if '.data' in s.Name: | |
blob = s.get_data() | |
elif '.rsrc' in s.Name: | |
seed = struct.unpack_from('<I', s.get_data())[0] | |
decoded = [] | |
if blob != None and seed != 0: | |
l = struct.unpack_from('<I', blob)[0] | |
while l != 0 and l > 0 and l < len(blob): | |
blob = blob[4:] | |
out = "" | |
lastseed = seed | |
for i in range(l/4): | |
v = LCG(seed,lastseed) | |
lastseed = v[0] | |
ttemp = struct.unpack_from('<I', blob[i*4:])[0] | |
ttemp ^= v[1] | |
out += struct.pack('<I', ttemp) | |
print(''.join(out.split('\x00'))) | |
decoded.append(out) | |
blob = blob[l:] | |
l = struct.unpack_from('<I', blob)[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Decoded example: