def extract_files(ubifs, out_path, perms=False): """Extract UBIFS contents to_path/ Arguments: Obj:ubifs -- UBIFS object. Str:out_path -- Path to extract contents to. """ try: inodes = {} bad_blocks = [] walk.index(ubifs, ubifs.master_node.root_lnum, ubifs.master_node.root_offs, inodes, bad_blocks) if len(inodes) < 2: raise Exception('No inodes found') for dent in inodes[1]['dent']: extract_dents(ubifs, inodes, dent, out_path, perms) if len(bad_blocks): error( extract_files, 'Warning', 'Data may be missing or corrupted, bad blocks, LEB [%s]' % ','.join(map(str, bad_blocks))) except Exception as e: error(extract_files, 'Error', '%s' % e)
def list_files(ubifs, list_path): pathnames = list_path.split("/") pnames = [] for i in pathnames: if len(i) > 0: pnames.append(i) try: inodes = {} bad_blocks = [] walk.index(ubifs, ubifs.master_node.root_lnum, ubifs.master_node.root_offs, inodes, bad_blocks) if len(inodes) < 2: raise Exception('No inodes found') inum = find_dir(inodes, 1, pnames, 0) if inum == None: return if not 'dent' in inodes[inum]: return for dent in inodes[inum]['dent']: print_dent(ubifs, inodes, dent, longts=False) if len(bad_blocks): error( list_files, 'Warning', 'Data may be missing or corrupted, bad blocks, LEB [%s]' % ','.join(map(str, bad_blocks))) except Exception as e: error(list_files, 'Error', '%s' % e)
def list_files(ubifs, list_path): pathnames = list_path.split("/") pnames = [] for i in pathnames: if len(i) > 0: pnames.append(i) try: inodes = {} bad_blocks = [] walk.index(ubifs, ubifs.master_node.root_lnum, ubifs.master_node.root_offs, inodes, bad_blocks) if len(inodes) < 2: raise Exception('No inodes found') inum = find_dir(inodes, 1, pnames, 0) if inum == None: return if not 'dent' in inodes[inum]: return for dent in inodes[inum]['dent']: print_dent(ubifs, inodes, dent, longts=False) if len(bad_blocks): error(list_files, 'Warning', 'Data may be missing or corrupted, bad blocks, LEB [%s]' % ','.join(map(str, bad_blocks))) except Exception as e: error(list_files, 'Error', '%s' % e)
def copy_file(ubifs, filepath, destpath): pathnames = filepath.split("/") pnames = [] for i in pathnames: if len(i) > 0: pnames.append(i) filename = pnames[len(pnames)-1] del pnames[-1] inodes = {} bad_blocks = [] walk.index(ubifs, ubifs.master_node.root_lnum, ubifs.master_node.root_offs, inodes, bad_blocks) if len(inodes) < 2: return False inum = find_dir(inodes, 1, pnames, 0) if inum == None: return False if not 'dent' in inodes[inum]: return False for dent in inodes[inum]['dent']: if dent.name == filename: filedata = _process_reg_file(ubifs, inodes[dent.inum], filepath) if os.path.isdir(destpath): destpath = os.path.join(destpath, filename) with open(destpath, 'wb') as f: f.write(filedata) return True return False
def extract_files(ubifs, out_path, perms=False): """Extract UBIFS contents to_path/ Arguments: Obj:ubifs -- UBIFS object. Str:out_path -- Path to extract contents to. """ try: inodes = {} walk.index(ubifs, ubifs.master_node.root_lnum, ubifs.master_node.root_offs, inodes) for dent in inodes[1]['dent']: extract_dents(ubifs, inodes, dent, out_path, perms) except Exception, e: error(extract_files, 'Fatal', '%s' % e)
def extract_files(ubifs, out_path, perms=False): """Extract UBIFS contents to_path/ Arguments: Obj:ubifs -- UBIFS object. Str:out_path -- Path to extract contents to. """ try: inodes = {} walk.index(ubifs, ubifs.master_node.root_lnum, ubifs.master_node.root_offs, inodes) #only return if a directory cannot be extracted if not 'dent' in inodes[1].keys(): print("Couldn't read dent for %s" % out_path) return for dent in inodes[1]['dent']: extract_dents(ubifs, inodes, dent, out_path, perms) except Exception as e: error(extract_files, 'Fatal', '%s' % e)
def copy_file(ubifs, filepath, destpath): pathnames = filepath.split("/") pnames = [] for i in pathnames: if len(i) > 0: pnames.append(i) filename = pnames[len(pnames) - 1] del pnames[-1] inodes = {} bad_blocks = [] walk.index(ubifs, ubifs.master_node.root_lnum, ubifs.master_node.root_offs, inodes, bad_blocks) if len(inodes) < 2: return False inum = find_dir(inodes, 1, pnames, 0) if inum == None: return False if not 'dent' in inodes[inum]: return False for dent in inodes[inum]['dent']: if dent.name == filename: filedata = _process_reg_file(ubifs, inodes[dent.inum], filepath) if os.path.isdir(destpath): destpath = os.path.join(destpath, filename) with open(destpath, 'wb') as f: f.write(filedata) return True return False
def my_extract_files(ubifs, extract_func): try: inodes = {} bad_blocks = [] walk.index(ubifs, ubifs.master_node.root_lnum, ubifs.master_node.root_offs, inodes, bad_blocks) if len(inodes) < 2: raise Exception('No inodes found') index = 0 for dent in inodes[1]['dent']: index = IMG_UBI.extract_dents(ubifs, inodes, dent, index, "", False, extract_func) index += 1 if len(bad_blocks): error( extract_files, 'Warning', 'Data may be missing or corrupted, bad blocks, LEB [%s]' % ','.join(map(str, bad_blocks))) except Exception as e: error(extract_files, 'Error', '%s' % e)
def extract_files(ubifs, out_path, perms=False): """Extract UBIFS contents to_path/ Arguments: Obj:ubifs -- UBIFS object. Str:out_path -- Path to extract contents to. """ try: inodes = {} bad_blocks = [] walk.index(ubifs, ubifs.master_node.root_lnum, ubifs.master_node.root_offs, inodes, bad_blocks) if len(inodes) < 2: raise Exception('No inodes found') for dent in inodes[1]['dent']: extract_dents(ubifs, inodes, dent, out_path, perms) if len(bad_blocks): error(extract_files, 'Warning', 'Data may be missing or corrupted, bad blocks, LEB [%s]' % ','.join(map(str, bad_blocks))) except Exception as e: error(extract_files, 'Error', '%s' % e)