Created
December 23, 2021 00:05
-
-
Save ryancdotorg/914f3ad05bfe0c359b79716f067eaa99 to your computer and use it in GitHub Desktop.
Decrypt firmware images for (some) EnGenius devices
This file contains hidden or 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
#!/usr/bin/env python3 | |
import sys | |
key = b'\xac\x78\x3c\x9e\xcf\x67\xb3\x59' | |
filename = sys.argv[1] | |
def decrypter(reference): | |
n = len(key) | |
def decrypt(value, offset): | |
nonlocal n, reference | |
return value ^ key[(offset-reference)%n] | |
return decrypt | |
with open(filename, 'rb') as f: | |
s = bytearray(f.read()) | |
n = s[0x87] | |
d = n + 0x88 | |
end = len(s) | |
decrypt = decrypter(s.find(key)) | |
sys.stdout.buffer.write(bytes(s[0:d])) | |
while d < end: | |
stop = min(d + 4096, end) | |
for offset in range(d, stop): | |
s[offset] = decrypt(s[offset], offset) | |
sys.stdout.buffer.write(bytes(s[d:stop])) | |
d = stop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment