當前位置: 首頁>>代碼示例>>Python>>正文


Python biplist.NotBinaryPlistException方法代碼示例

本文整理匯總了Python中biplist.NotBinaryPlistException方法的典型用法代碼示例。如果您正苦於以下問題:Python biplist.NotBinaryPlistException方法的具體用法?Python biplist.NotBinaryPlistException怎麽用?Python biplist.NotBinaryPlistException使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在biplist的用法示例。


在下文中一共展示了biplist.NotBinaryPlistException方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: GetTopLevel

# 需要導入模塊: import biplist [as 別名]
# 或者: from biplist import NotBinaryPlistException [as 別名]
def GetTopLevel(self, file_object):
    """Returns the deserialized content of a plist as a dictionary object.

    Args:
      file_object (dfvfs.FileIO): a file-like object to parse.

    Returns:
      dict[str, object]: contents of the plist.

    Raises:
      UnableToParseFile: when the file cannot be parsed.
    """
    try:
      top_level_object = biplist.readPlist(file_object)

    except (biplist.InvalidPlistException,
            biplist.NotBinaryPlistException) as exception:
      raise errors.UnableToParseFile(
          'Unable to parse plist with error: {0!s}'.format(exception))

    return top_level_object 
開發者ID:log2timeline,項目名稱:plaso,代碼行數:23,代碼來源:plist.py

示例2: Read

# 需要導入模塊: import biplist [as 別名]
# 或者: from biplist import NotBinaryPlistException [as 別名]
def Read(self, file_object):
    """Reads a plist from a file-like object.

    Args:
      file_object (dfvfs.FileIO): a file-like object containing plist data.

    Raises:
      IOError: if the plist file-like object cannot be read.
      OSError: if the plist file-like object cannot be read.
    """
    try:
      self.root_key = biplist.readPlist(file_object)

    except (
        biplist.NotBinaryPlistException,
        biplist.InvalidPlistException) as exception:
      raise IOError(exception) 
開發者ID:log2timeline,項目名稱:plaso,代碼行數:19,代碼來源:plist.py

示例3: view

# 需要導入模塊: import biplist [as 別名]
# 或者: from biplist import NotBinaryPlistException [as 別名]
def view(self):
        current_app.logger.debug(request.data)

        try:
            plist_data = biplist.readPlistFromString(request.data)
        except biplist.NotBinaryPlistException:
            abort(400, 'The request body does not contain a plist as expected')
        except biplist.InvalidPlistException:
            abort(400, 'The request body does not contain a valid plist')

        for kvr in self.kv_routes:
            if kvr['key'] not in plist_data:
                continue

            if plist_data[kvr['key']] == kvr['value']:
                return kvr['handler'](plist_data)

        abort(404, 'No matching plist route') 
開發者ID:cmdmnt,項目名稱:commandment,代碼行數:20,代碼來源:routers.py

示例4: write_plist_to_file

# 需要導入模塊: import biplist [as 別名]
# 或者: from biplist import NotBinaryPlistException [as 別名]
def write_plist_to_file(deserialised_plist, output_path):
    #Using plistLib to write plist
    out_file = None
    try:
        print('Writing out .. ' + output_path)
        out_file = open(output_path, 'wb')
        try:
            plistlib.dump(deserialised_plist, out_file, fmt=plistlib.FMT_BINARY)
            out_file.close()
            return True
        except (TypeError, OverflowError, OSError) as ex:
            out_file.close()
            print('Had an exception (error)')
            traceback.print_exc()
    except OSError as ex:
        print('Error opening file for writing: Error={} Path={}'.format(output_path, str(ex)))
    # Try using biplist
    try:
        print('Writing out (using biplist) .. ' + output_path)
        biplist.writePlist(deserialised_plist, output_path)
        return True
    except (biplist.InvalidPlistException, biplist.NotBinaryPlistException, OSError) as ex:
        print('Had an exception (error)')
        traceback.print_exc() 
開發者ID:ydkhatri,項目名稱:mac_apt,代碼行數:26,代碼來源:deserializer.py

示例5: main

# 需要導入模塊: import biplist [as 別名]
# 或者: from biplist import NotBinaryPlistException [as 別名]
def main(plist):
    print("[+] Opening {} file".format(plist))
    try:
        plist_data = biplist.readPlist(plist)
    except (biplist.InvalidPlistException,
            biplist.NotBinaryPlistException) as e:
        print("[-] Invalid PLIST file - unable to be opened by biplist")
        sys.exit(2)

    print("[+] Printing Info.plist Device "
          "and User Information to Console\n")
    for k in plist_data:
        if k != 'Applications' and k != 'iTunes Files':
            print("{:<25s} - {}".format(k, plist_data[k])) 
開發者ID:PacktPublishing,項目名稱:Python-Digital-Forensics-Cookbook,代碼行數:16,代碼來源:plist_parser.py

示例6: _DictFromSubprocess

# 需要導入模塊: import biplist [as 別名]
# 或者: from biplist import NotBinaryPlistException [as 別名]
def _DictFromSubprocess(command):
  """Returns a dict based upon a subprocess call with a -plist argument.

  Args:
    command(list(str)): the command to be executed as a list.
  Returns:
    dict: dictionary from command output.
  Raises:
    MacDiskError: if the command failed to run.
  """

  try:
    task = subprocess.Popen(
        command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  except OSError as e:
    raise MacDiskError('Could not execute: {0:s}'.format(e.strerror))
  (stdout, stderr) = task.communicate()

  if task.returncode != 0:
    raise MacDiskError(
        'Error running command: {0:s}, stderr: {1:s}' .format(
            ' '.join(command), stderr))

  try:
    return biplist.readPlistFromString(stdout)
  except (biplist.InvalidPlistException, biplist.NotBinaryPlistException):
    raise MacDiskError(
        'Error creating plist from output: {0:s}'.format(stdout)) 
開發者ID:google,項目名稱:GiftStick,代碼行數:30,代碼來源:macdisk.py

示例7: _ReadPasswordPolicyData

# 需要導入模塊: import biplist [as 別名]
# 或者: from biplist import NotBinaryPlistException [as 別名]
def _ReadPasswordPolicyData(self, password_policy_data, target_user):
        try:
            plist2 = biplist.readPlistFromString(password_policy_data[0])
            target_user.failed_login_count = plist2.get('failedLoginCount', 0)
            target_user.failed_login_timestamp = plist2.get('failedLoginTimestamp', None)
            target_user.last_login_timestamp = plist2.get('lastLoginTimestamp', None)
            target_user.password_last_set_time = plist2.get('passwordLastSetTime', None)
        except (biplist.InvalidPlistException, biplist.NotBinaryPlistException):
            log.exception('Error reading password_policy_data embedded plist') 
開發者ID:ydkhatri,項目名稱:mac_apt,代碼行數:11,代碼來源:macinfo.py

示例8: _ReadAccountPolicyData

# 需要導入模塊: import biplist [as 別名]
# 或者: from biplist import NotBinaryPlistException [as 別名]
def _ReadAccountPolicyData(self, account_policy_data, target_user):
        try:
            plist2 = biplist.readPlistFromString(account_policy_data[0])
            target_user.creation_time = CommonFunctions.ReadUnixTime(plist2.get('creationTime', None))
            target_user.failed_login_count = plist2.get('failedLoginCount', 0)
            target_user.failed_login_timestamp = CommonFunctions.ReadUnixTime(plist2.get('failedLoginTimestamp', None))
            target_user.password_last_set_time = CommonFunctions.ReadUnixTime(plist2.get('passwordLastSetTime', None))
        except (biplist.InvalidPlistException, biplist.NotBinaryPlistException):
            log.exception('Error reading password_policy_data embedded plist') 
開發者ID:ydkhatri,項目名稱:mac_apt,代碼行數:11,代碼來源:macinfo.py

示例9: _GetSystemInfo

# 需要導入模塊: import biplist [as 別名]
# 或者: from biplist import NotBinaryPlistException [as 別名]
def _GetSystemInfo(self):
        ''' Gets system version information'''
        try:
            log.debug("Trying to get system version from /System/Library/CoreServices/SystemVersion.plist")
            f = self.Open('/System/Library/CoreServices/SystemVersion.plist')
            if f != None:
                try:
                    plist = biplist.readPlist(f)
                    self.os_version = plist.get('ProductVersion', '')
                    self.os_build = plist.get('ProductBuildVersion', '')
                    if self.os_version != '':
                        if   self.os_version.startswith('10.10'): self.os_friendly_name = 'Yosemite'
                        elif self.os_version.startswith('10.11'): self.os_friendly_name = 'El Capitan'
                        elif self.os_version.startswith('10.12'): self.os_friendly_name = 'Sierra'
                        elif self.os_version.startswith('10.13'): self.os_friendly_name = 'High Sierra'
                        elif self.os_version.startswith('10.14'): self.os_friendly_name = 'Mojave'
                        elif self.os_version.startswith('10.15'): self.os_friendly_name = 'Catalina'
                        elif self.os_version.startswith('10.0'): self.os_friendly_name = 'Cheetah'
                        elif self.os_version.startswith('10.1'): self.os_friendly_name = 'Puma'
                        elif self.os_version.startswith('10.2'): self.os_friendly_name = 'Jaguar'
                        elif self.os_version.startswith('10.3'): self.os_friendly_name = 'Panther'
                        elif self.os_version.startswith('10.4'): self.os_friendly_name = 'Tiger'
                        elif self.os_version.startswith('10.5'): self.os_friendly_name = 'Leopard'
                        elif self.os_version.startswith('10.6'): self.os_friendly_name = 'Snow Leopard'
                        elif self.os_version.startswith('10.7'): self.os_friendly_name = 'Lion'
                        elif self.os_version.startswith('10.8'): self.os_friendly_name = 'Mountain Lion'
                        elif self.os_version.startswith('10.9'): self.os_friendly_name = 'Mavericks'
                        elif self.os_version.startswith('11.'): self.os_friendly_name = 'Big Sur'
                        else: self.os_friendly_name = 'Unknown version!'
                    log.info ('macOS version detected is: {} ({}) Build={}'.format(self.os_friendly_name, self.os_version, self.os_build))
                    f.close()
                    return True
                except (biplist.InvalidPlistException, biplist.NotBinaryPlistException) as ex:
                    log.error ("Could not get ProductVersion from plist. Is it a valid xml plist? Error=" + str(ex))
                f.close()
            else:
                log.error("Could not open plist to get system version info!")
        except:
            log.exception("Unknown error from _GetSystemInfo()")
        return False 
開發者ID:ydkhatri,項目名稱:mac_apt,代碼行數:42,代碼來源:macinfo.py

示例10: ReadPlist

# 需要導入模塊: import biplist [as 別名]
# 或者: from biplist import NotBinaryPlistException [as 別名]
def ReadPlist(self, path, deserialize=False):
        '''Safely open and read a plist; returns tuple (True/False, plist/None, "error_message")'''
        log.debug("Trying to open plist file : " + path)
        error = ''
        try:
            f = self.Open(path)
            if f != None:
                try:
                    log.debug("Trying to read plist file : " + path)
                    plist = biplist.readPlist(f)
                    if deserialize:
                        try:
                            f.seek(0)
                            plist = self.DeserializeNsKeyedPlist(f)
                            f.close()
                            return (True, plist, '')
                        except:
                            f.close()
                            error = 'Could not read deserialized plist: ' + path + " Error was : " + str(ex)  
                    else:
                        f.close()
                        return (True, plist, '')
                except biplist.InvalidPlistException as ex:
                    try:
                        # 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
                        # This is assuming XML format!
                        f.seek(0)
                        data = f.read().decode('utf8', 'ignore')
                        f.close()
                        data = data.lstrip(" \r\n\t").encode('utf8', 'backslashreplace')
                        if deserialize:
                            try:
                                temp_file = BytesIO(data)
                                plist = self.DeserializeNsKeyedPlist(temp_file)
                                temp_file.close()
                                return (True, plist, '')
                            except:
                                error = 'Could not read deserialized plist: ' + path + " Error was : " + str(ex)
                        else:
                            plist = biplist.readPlistFromString(data)                        
                            return (True, plist, '')
                    except (biplist.InvalidPlistException, biplist.NotBinaryPlistException) as ex:
                        error = 'Could not read plist: ' + path + " Error was : " + str(ex)
                except OSError as ex:
                    error = 'OSError while reading plist: ' + path + " Error was : " + str(ex)
            else:
                error = 'Failed to open file'
        except Exception as ex:
            error = 'Exception from ReadPlist, trying to open file. Exception=' + str(ex)
        return (False, None, error) 
開發者ID:ydkhatri,項目名稱:mac_apt,代碼行數:53,代碼來源:macinfo.py

示例11: _GetUserInfo

# 需要導入模塊: import biplist [as 別名]
# 或者: from biplist import NotBinaryPlistException [as 別名]
def _GetUserInfo(self):
        '''Populates user info from plists under: /private/var/db/dslocal/nodes/Default/users/'''
        #TODO - make a better plugin that gets all user & group info
        users_path  = '/private/var/db/dslocal/nodes/Default/users'
        user_plists = self.ListItemsInFolder(users_path, EntryType.FILES)
        for plist_meta in user_plists:
            if plist_meta['size'] > 0:
                try:
                    user_plist_path = users_path + '/' + plist_meta['name']
                    f = self.Open(user_plist_path)
                    if f!= None:
                        self.ExportFile(user_plist_path, 'USERS', '', False)
                        try:
                            plist = biplist.readPlist(f)
                            home_dir = self.GetArrayFirstElement(plist.get('home', ''))
                            if home_dir != '':
                                #log.info('{} :  {}'.format(plist_meta['name'], home_dir))
                                if home_dir.startswith('/var/'): home_dir = '/private' + home_dir # in mac /var is symbolic link to /private/var
                                target_user = UserInfo()
                                self.users.append(target_user)
                                target_user.UID = str(self.GetArrayFirstElement(plist.get('uid', '')))
                                target_user.GID = str(self.GetArrayFirstElement(plist.get('gid', '')))
                                target_user.UUID = self.GetArrayFirstElement(plist.get('generateduid', ''))
                                target_user.home_dir = home_dir
                                target_user.user_name = self.GetArrayFirstElement(plist.get('name', ''))
                                target_user.real_name = self.GetArrayFirstElement(plist.get('realname', ''))
                                target_user.pw_hint = self.GetArrayFirstElement(plist.get('hint', ''))
                                target_user._source = user_plist_path
                                os_version = self.GetVersionDictionary()
                                if os_version['major'] == 10 and os_version['minor'] <= 9: # Mavericks & earlier
                                    password_policy_data = plist.get('passwordpolicyoptions', None)
                                    if password_policy_data == None:
                                        log.debug('Could not find passwordpolicyoptions for user {}'.format(target_user.user_name))
                                    else:
                                        self._ReadPasswordPolicyData(password_policy_data, target_user)
                                else: # 10.10 - Yosemite & higher
                                    account_policy_data = plist.get('accountPolicyData', None)
                                    if account_policy_data == None: 
                                        pass #log.debug('Could not find accountPolicyData for user {}'.format(target_user.user_name))
                                    else:
                                        self._ReadAccountPolicyData(account_policy_data, target_user)
                            else:
                                log.error('Did not find \'home\' in ' + plist_meta['name'])
                        except (biplist.InvalidPlistException, biplist.NotBinaryPlistException):
                            log.exception("biplist failed to read plist " + user_plist_path)
                            self._CheckFileContents(f)
                        f.close()
                except (OSError, KeyError, ValueError, IndexError, TypeError):
                    log.exception ("Could not open/read plist " + user_plist_path)
        self._GetDomainUserInfo()
        self._GetDarwinFoldersInfo() # This probably does not apply to OSX < Mavericks ! 
開發者ID:ydkhatri,項目名稱:mac_apt,代碼行數:53,代碼來源:macinfo.py


注:本文中的biplist.NotBinaryPlistException方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。