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 some bytes/str conversion issue #36

Open
wants to merge 3 commits 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
20 changes: 10 additions & 10 deletions chainbreaker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,14 @@ def _get_int(self, base_addr, pcol):
# Get 4 character code from the keychain buffer
def _get_four_char_code(self, base_addr, pcol):
if pcol <= 0:
return ''
return b''
else:
return _FOUR_CHAR_CODE(self.kc_buffer[base_addr + pcol:base_addr + pcol + 4]).Value

# Get a lv from the keychain buffer
def _get_lv(self, base_addr, pcol):
if pcol <= 0:
return ''
return b''

str_length = _INT(self.kc_buffer[base_addr + pcol:base_addr + pcol + 4]).Value
# 4byte arrangement
Expand All @@ -362,7 +362,7 @@ def _get_lv(self, base_addr, pcol):
data = _LV(self.kc_buffer[base_addr + pcol + 4:base_addr + pcol + 4 + real_str_len], real_str_len).Value
except struct.error:
self.logger.debug('LV string length is too long.')
return ''
return b''

return data

Expand All @@ -372,7 +372,7 @@ def _private_key_decryption(self, encryptedblob, iv):
plain = Chainbreaker._kcdecrypt(self.db_key, Chainbreaker.MAGIC_CMS_IV, encryptedblob)

if len(plain) == 0:
return '', ''
return b'', b''

# reverse the plaintext before decrypting again
plain = bytes(reversed(plain))
Expand All @@ -398,7 +398,7 @@ def _find_wrapping_key(self, master):
plain = Chainbreaker._kcdecrypt(master, self.dbblob.IV, ciphertext)

if len(plain) < Chainbreaker.KEYLEN:
return ''
return b''

dbkey = plain[:Chainbreaker.KEYLEN]

Expand All @@ -410,10 +410,10 @@ def _find_wrapping_key(self, master):
def dump_keychain_password_hash(self):
cyphertext = hexlify(self.kc_buffer[self.base_addr
+ self.dbblob.StartCryptoBlob:self.base_addr
+ self.dbblob.TotalLength])
+ self.dbblob.TotalLength]).decode()

iv = hexlify(self.dbblob.IV)
salt = hexlify(self.dbblob.Salt)
iv = hexlify(self.dbblob.IV).decode()
salt = hexlify(self.dbblob.Salt).decode()

return self.KeychainPasswordHash(salt, iv, cyphertext)

Expand Down Expand Up @@ -959,7 +959,7 @@ def exportable(self):

@property
def file_name(self):
return "".join(str(x) for x in self.PrintName if type(x) is int)
return self.PrintName.decode(errors='ignore')

@property
def file_ext(self):
Expand Down Expand Up @@ -1011,7 +1011,7 @@ def exportable(self):

@property
def file_name(self):
return "".join(str(x) for x in self.PrintName if type(x) is int)
return self.PrintName.decode(errors='ignore')

@property
def file_ext(self):
Expand Down