Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unicode decode errors #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions autoit_ripper/autoit_unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def read_string(
stream: ByteStream,
decryptor: Union[EA05Decryptor, EA06Decryptor],
keys: Tuple[int, int],
) -> str:
) -> Optional[str]:
length = stream.u32() ^ keys[0]
enc_key = length + keys[1]

Expand All @@ -61,7 +61,10 @@ def read_string(
else:
encoding = "utf-8"

return decryptor.decrypt(stream.get_bytes(length), enc_key).decode(encoding)
try:
return decryptor.decrypt(stream.get_bytes(length), enc_key).decode(encoding)
except UnicodeDecodeError:
return None


def parse_au3_header(
Expand All @@ -74,10 +77,12 @@ def parse_au3_header(
log.debug("FILE magic mismatch")
# Asssume that this is the end of the embedded data
return
yield

au3_ResSubType = read_string(stream, decryptor, decryptor.au3_ResSubType)
au3_ResName = read_string(stream, decryptor, decryptor.au3_ResName)
if not au3_ResSubType or not au3_ResName:
log.error("Unicode decode error when decoding type and name")
return
log.debug("Found a new autoit string: %s", au3_ResSubType)
log.debug("Found a new path: %s", au3_ResName)

Expand Down Expand Up @@ -109,14 +114,12 @@ def parse_au3_header(
else:
log.error("CRC data mismatch")
return
yield

if au3_ResIsCompressed == 1:
dec = decompress(ByteStream(dec_data))
if not dec:
log.error("Error while trying to decompress data")
return
yield
dec_data = dec

if au3_ResSubType == ">>>AUTOIT SCRIPT<<<":
Expand Down