Skip to content

Commit

Permalink
fixes plist read bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ydkhatri committed Mar 20, 2019
1 parent 2b7e7ed commit f46cd7d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
19 changes: 9 additions & 10 deletions plugins/_demo_plugin.py
Expand Up @@ -99,17 +99,16 @@ def Plugin_Start_Standalone(input_files_list, output_params):
for input_path in input_files_list:
log.debug("Input file passed was: " + input_path)
## Process the input file here ##
with open (input_path, 'rb') as fp:
if input_path.endswith('SystemVersion.plist'):
plist = biplist.readPlist(fp)
try:
osx_version = plist.get('ProductVersion')
except Exception:
log.error("Error finding this key within the given pList file.")

WriteMe(osx_version, output_params, input_path)
if input_path.endswith('SystemVersion.plist'):
success, plist, error = CommonFunctions.ReadPlist(input_path)
if success:
osx_version = plist.get('ProductVersion', None)
if osx_version == None:
log.error('Could not find ProductVersion in plist!')
else:
WriteMe(osx_version, output_params, input_path)
else:
log.error('Input file "{}" is not a plist'.format(input_path))
log.error('Input file "{}" is not a valid plist. Error opening file was: {}'.format(input_path, error))

if __name__ == '__main__':
print ("This plugin is a part of a framework and does not run independently on its own!")
8 changes: 4 additions & 4 deletions plugins/helpers/macinfo.py
Expand Up @@ -427,14 +427,14 @@ def ReadPlist(self, path):
# Perhaps this is manually edited or incorrectly formatted by a non-Apple utility
# that has left whitespaces at the start of file before <?xml tag
f.seek(0)
data = f.read()
data = data.lstrip(" \r\n\t")
data = f.read().decode('utf8')
data = data.lstrip(" \r\n\t").encode('utf8')
plist = biplist.readPlistFromString(data)
return (True, plist, '')
except biplist.InvalidPlistException as ex:
error = 'Could not read plist: ' + path + " Error was : " + str(ex)
except Exception as ex:
error = 'Could not read plist: ' + path + " Error was : " + str(ex)
except IOError as ex:
error = 'IOError while reading plist: ' + path + " Error was : " + str(ex)
else:
error = 'Failed to open file'
except Exception as ex:
Expand Down

0 comments on commit f46cd7d

Please sign in to comment.