mirror of
https://github.com/gutosie/neoboot.git
synced 2026-01-01 04:59:40 +01:00
More adaptation for Novaler4k Pro
** apply aggressive autopep8 on all files ** add condition for novaler4kpro in extract.py ** add receiver icon for novaler4kpro ** fix mounting internal storage for novaler4k pro ** other minor fixes
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,3 @@
|
||||
#!/usr/bin/python
|
||||
import re
|
||||
from ubi.volume import get_volumes
|
||||
from ubi.block import sort, get_blocks_in_list, extract_blocks
|
||||
@@ -16,7 +15,7 @@ class ubi:
|
||||
self._blocks = extract_blocks(self)
|
||||
self._block_count = len(self.blocks)
|
||||
if self._block_count <= 0:
|
||||
raise Exception('No blocks found.')
|
||||
raise Exception("No blocks found.")
|
||||
layout_list, data_list, int_vol_list, unknown_list = sort.by_type(
|
||||
self.blocks)
|
||||
self._layout_blocks_list = layout_list
|
||||
@@ -28,7 +27,8 @@ class ubi:
|
||||
self._leb_size = self.file.block_size - arbitrary_block.ec_hdr.data_offset
|
||||
layout_pairs = layout.group_pairs(self.blocks, self.layout_blocks_list)
|
||||
layout_infos = layout.associate_blocks(
|
||||
self.blocks, layout_pairs, self.first_peb_num)
|
||||
self.blocks, layout_pairs, self.first_peb_num
|
||||
)
|
||||
self._images = []
|
||||
for i in range(0, len(layout_infos)):
|
||||
self._images.append(image(self.blocks, layout_infos[i]))
|
||||
@@ -96,14 +96,14 @@ class ubi:
|
||||
|
||||
blocks = property(_get_blocks)
|
||||
|
||||
def display(self, tab=''):
|
||||
def display(self, tab=""):
|
||||
display.ubi(self, tab)
|
||||
|
||||
|
||||
def get_peb_size(path):
|
||||
file_offset = 0
|
||||
offsets = []
|
||||
f = open(path, 'rb')
|
||||
f = open(path, "rb")
|
||||
f.seek(0, 2)
|
||||
file_size = f.tell() + 1
|
||||
f.seek(0)
|
||||
@@ -125,7 +125,7 @@ def get_peb_size(path):
|
||||
for i in range(0, len(offsets)):
|
||||
try:
|
||||
diff = offsets[i] - offsets[i - 1]
|
||||
except:
|
||||
except BaseException:
|
||||
diff = offsets[i]
|
||||
|
||||
if diff not in occurances:
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#!/usr/bin/python
|
||||
import re
|
||||
from ubi import display
|
||||
from ubi.defines import *
|
||||
@@ -18,7 +17,11 @@ class description(object):
|
||||
self.ec_hdr = extract_ec_hdr(block_buf[0:UBI_EC_HDR_SZ])
|
||||
if not self.ec_hdr.errors:
|
||||
self.vid_hdr = extract_vid_hdr(
|
||||
block_buf[self.ec_hdr.vid_hdr_offset:self.ec_hdr.vid_hdr_offset + UBI_VID_HDR_SZ])
|
||||
block_buf[
|
||||
self.ec_hdr.vid_hdr_offset: self.ec_hdr.vid_hdr_offset
|
||||
+ UBI_VID_HDR_SZ
|
||||
]
|
||||
)
|
||||
self.is_internal_vol = self.vid_hdr.vol_id >= UBI_INTERNAL_VOL_START
|
||||
if self.vid_hdr.vol_id >= UBI_INTERNAL_VOL_START:
|
||||
self.vtbl_recs = extract_vtbl_rec(
|
||||
@@ -29,9 +32,9 @@ class description(object):
|
||||
return
|
||||
|
||||
def __repr__(self):
|
||||
return 'Block: PEB# %s: LEB# %s' % (self.peb_num, self.leb_num)
|
||||
return "Block: PEB# %s: LEB# %s" % (self.peb_num, self.leb_num)
|
||||
|
||||
def display(self, tab=''):
|
||||
def display(self, tab=""):
|
||||
display.block(self, tab)
|
||||
|
||||
|
||||
@@ -45,7 +48,10 @@ def extract_blocks(ubi):
|
||||
ubi.file.seek(ubi.file.start_offset)
|
||||
peb_count = 0
|
||||
cur_offset = 0
|
||||
for i in range(ubi.file.start_offset, ubi.file.end_offset, ubi.file.block_size):
|
||||
for i in range(
|
||||
ubi.file.start_offset,
|
||||
ubi.file.end_offset,
|
||||
ubi.file.block_size):
|
||||
buf = ubi.file.read(ubi.file.block_size)
|
||||
if buf.startswith(UBI_EC_HDR_MAGIC):
|
||||
blk = description(buf)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#!/usr/bin/python
|
||||
from ubi.block import sort
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#!/usr/bin/python
|
||||
def list_by_list(blist, slist):
|
||||
slist_blocks = []
|
||||
for block in blist:
|
||||
@@ -24,11 +23,11 @@ def by_range(blocks, block_range):
|
||||
|
||||
def by_leb(blocks):
|
||||
slist_len = len(blocks)
|
||||
slist = ['x'] * slist_len
|
||||
slist = ["x"] * slist_len
|
||||
for block in blocks:
|
||||
if blocks[block].leb_num >= slist_len:
|
||||
add_elements = blocks[block].leb_num - slist_len + 1
|
||||
slist += ['x'] * add_elements
|
||||
slist += ["x"] * add_elements
|
||||
slist_len = len(slist)
|
||||
slist[blocks[block].leb_num] = block
|
||||
|
||||
@@ -78,7 +77,4 @@ def by_type(blocks, slist=None):
|
||||
else:
|
||||
unknown.append(i)
|
||||
|
||||
return (layout,
|
||||
data,
|
||||
int_vol,
|
||||
unknown)
|
||||
return (layout, data, int_vol, unknown)
|
||||
|
||||
@@ -1,63 +1,64 @@
|
||||
#!/usr/bin/python
|
||||
import struct
|
||||
|
||||
UBI_CRC32_INIT = 4294967295
|
||||
UBI_MAX_VOLUMES = 128
|
||||
UBI_INTERNAL_VOL_START = 2147479551
|
||||
UBI_EC_HDR_MAGIC = 'UBI#'
|
||||
EC_HDR_FORMAT = '>4sB3sQIII32sI'
|
||||
EC_HDR_FIELDS = ['magic',
|
||||
'version',
|
||||
'padding',
|
||||
'ec',
|
||||
'vid_hdr_offset',
|
||||
'data_offset',
|
||||
'image_seq',
|
||||
'padding2',
|
||||
'hdr_crc']
|
||||
UBI_EC_HDR_MAGIC = "UBI#"
|
||||
EC_HDR_FORMAT = ">4sB3sQIII32sI"
|
||||
EC_HDR_FIELDS = [
|
||||
"magic",
|
||||
"version",
|
||||
"padding",
|
||||
"ec",
|
||||
"vid_hdr_offset",
|
||||
"data_offset",
|
||||
"image_seq",
|
||||
"padding2",
|
||||
"hdr_crc",
|
||||
]
|
||||
UBI_EC_HDR_SZ = struct.calcsize(EC_HDR_FORMAT)
|
||||
UBI_VID_HDR_MAGIC = 'UBI!'
|
||||
VID_HDR_FORMAT = '>4sBBBBII4sIIII4sQ12sI'
|
||||
VID_HDR_FIELDS = ['magic',
|
||||
'version',
|
||||
'vol_type',
|
||||
'copy_flag',
|
||||
'compat',
|
||||
'vol_id',
|
||||
'lnum',
|
||||
'padding',
|
||||
'data_size',
|
||||
'used_ebs',
|
||||
'data_pad',
|
||||
'data_crc',
|
||||
'padding2',
|
||||
'sqnum',
|
||||
'padding3',
|
||||
'hdr_crc']
|
||||
UBI_VID_HDR_MAGIC = "UBI!"
|
||||
VID_HDR_FORMAT = ">4sBBBBII4sIIII4sQ12sI"
|
||||
VID_HDR_FIELDS = [
|
||||
"magic",
|
||||
"version",
|
||||
"vol_type",
|
||||
"copy_flag",
|
||||
"compat",
|
||||
"vol_id",
|
||||
"lnum",
|
||||
"padding",
|
||||
"data_size",
|
||||
"used_ebs",
|
||||
"data_pad",
|
||||
"data_crc",
|
||||
"padding2",
|
||||
"sqnum",
|
||||
"padding3",
|
||||
"hdr_crc",
|
||||
]
|
||||
UBI_VID_HDR_SZ = struct.calcsize(VID_HDR_FORMAT)
|
||||
VTBL_REC_FORMAT = '>IIIBBH128sB23sI'
|
||||
VTBL_REC_FIELDS = ['reserved_pebs',
|
||||
'alignment',
|
||||
'data_pad',
|
||||
'vol_type',
|
||||
'upd_marker',
|
||||
'name_len',
|
||||
'name',
|
||||
'flags',
|
||||
'padding',
|
||||
'crc']
|
||||
VTBL_REC_FORMAT = ">IIIBBH128sB23sI"
|
||||
VTBL_REC_FIELDS = [
|
||||
"reserved_pebs",
|
||||
"alignment",
|
||||
"data_pad",
|
||||
"vol_type",
|
||||
"upd_marker",
|
||||
"name_len",
|
||||
"name",
|
||||
"flags",
|
||||
"padding",
|
||||
"crc",
|
||||
]
|
||||
UBI_VTBL_REC_SZ = struct.calcsize(VTBL_REC_FORMAT)
|
||||
UBI_VID_DYNAMIC = 1
|
||||
UBI_VID_STATIC = 2
|
||||
PRINT_VOL_TYPE_LIST = [0, 'dynamic', 'static']
|
||||
PRINT_VOL_TYPE_LIST = [0, "dynamic", "static"]
|
||||
UBI_VTBL_AUTORESIZE_FLG = 1
|
||||
UBI_COMPAT_DELETE = 1
|
||||
UBI_COMPAT_RO = 2
|
||||
UBI_COMPAT_PRESERVE = 4
|
||||
UBI_COMPAT_REJECT = 5
|
||||
PRINT_COMPAT_LIST = [0,
|
||||
'Delete',
|
||||
'Read Only',
|
||||
0,
|
||||
'Preserve',
|
||||
'Reject']
|
||||
PRINT_COMPAT_LIST = [0, "Delete", "Read Only", 0, "Preserve", "Reject"]
|
||||
FILE_CHUNK_SZ = 5242880
|
||||
|
||||
@@ -1,111 +1,111 @@
|
||||
#!/usr/bin/python
|
||||
from ubi.defines import PRINT_COMPAT_LIST, PRINT_VOL_TYPE_LIST, UBI_VTBL_AUTORESIZE_FLG
|
||||
|
||||
|
||||
def ubi(ubi, tab=''):
|
||||
print(('%sUBI File' % tab))
|
||||
print(('%s---------------------' % tab))
|
||||
print(('\t%sMin I/O: %s' % (tab, ubi.min_io_size)))
|
||||
print(('\t%sLEB Size: %s' % (tab, ubi.leb_size)))
|
||||
print(('\t%sPEB Size: %s' % (tab, ubi.peb_size)))
|
||||
print(('\t%sTotal Block Count: %s' % (tab, ubi.block_count)))
|
||||
print(('\t%sData Block Count: %s' % (tab, len(ubi.data_blocks_list))))
|
||||
print(('\t%sLayout Block Count: %s' % (tab, len(ubi.layout_blocks_list))))
|
||||
print(('\t%sInternal Volume Block Count: %s' %
|
||||
def ubi(ubi, tab=""):
|
||||
print(("%sUBI File" % tab))
|
||||
print(("%s---------------------" % tab))
|
||||
print(("\t%sMin I/O: %s" % (tab, ubi.min_io_size)))
|
||||
print(("\t%sLEB Size: %s" % (tab, ubi.leb_size)))
|
||||
print(("\t%sPEB Size: %s" % (tab, ubi.peb_size)))
|
||||
print(("\t%sTotal Block Count: %s" % (tab, ubi.block_count)))
|
||||
print(("\t%sData Block Count: %s" % (tab, len(ubi.data_blocks_list))))
|
||||
print(("\t%sLayout Block Count: %s" % (tab, len(ubi.layout_blocks_list))))
|
||||
print(("\t%sInternal Volume Block Count: %s" %
|
||||
(tab, len(ubi.int_vol_blocks_list))))
|
||||
print(('\t%sUnknown Block Count: %s' % (tab, len(ubi.unknown_blocks_list))))
|
||||
print(('\t%sFirst UBI PEB Number: %s' % (tab, ubi.first_peb_num)))
|
||||
print(("\t%sUnknown Block Count: %s" %
|
||||
(tab, len(ubi.unknown_blocks_list))))
|
||||
print(("\t%sFirst UBI PEB Number: %s" % (tab, ubi.first_peb_num)))
|
||||
|
||||
|
||||
def image(image, tab=''):
|
||||
print(('%s%s' % (tab, image)))
|
||||
print(('%s---------------------' % tab))
|
||||
print(('\t%sImage Sequence Num: %s' % (tab, image.image_seq)))
|
||||
def image(image, tab=""):
|
||||
print(("%s%s" % (tab, image)))
|
||||
print(("%s---------------------" % tab))
|
||||
print(("\t%sImage Sequence Num: %s" % (tab, image.image_seq)))
|
||||
for volume in image.volumes:
|
||||
print(('\t%sVolume Name:%s' % (tab, volume)))
|
||||
print(("\t%sVolume Name:%s" % (tab, volume)))
|
||||
|
||||
print(('\t%sPEB Range: %s - %s' %
|
||||
(tab, image.peb_range[0], image.peb_range[1])))
|
||||
print(("\t%sPEB Range: %s - %s" %
|
||||
(tab, image.peb_range[0], image.peb_range[1])))
|
||||
|
||||
|
||||
def volume(volume, tab=''):
|
||||
print(('%s%s' % (tab, volume)))
|
||||
print(('%s---------------------' % tab))
|
||||
print(('\t%sVol ID: %s' % (tab, volume.vol_id)))
|
||||
print(('\t%sName: %s' % (tab, volume.name)))
|
||||
print(('\t%sBlock Count: %s' % (tab, volume.block_count)))
|
||||
print('\n')
|
||||
print(('\t%sVolume Record' % tab))
|
||||
print(('\t%s---------------------' % tab))
|
||||
vol_rec(volume.vol_rec, '\t\t%s' % tab)
|
||||
print('\n')
|
||||
def volume(volume, tab=""):
|
||||
print(("%s%s" % (tab, volume)))
|
||||
print(("%s---------------------" % tab))
|
||||
print(("\t%sVol ID: %s" % (tab, volume.vol_id)))
|
||||
print(("\t%sName: %s" % (tab, volume.name)))
|
||||
print(("\t%sBlock Count: %s" % (tab, volume.block_count)))
|
||||
print("\n")
|
||||
print(("\t%sVolume Record" % tab))
|
||||
print(("\t%s---------------------" % tab))
|
||||
vol_rec(volume.vol_rec, "\t\t%s" % tab)
|
||||
print("\n")
|
||||
|
||||
|
||||
def block(block, tab='\t'):
|
||||
print(('%s%s' % (tab, block)))
|
||||
print(('%s---------------------' % tab))
|
||||
print(('\t%sFile Offset: %s' % (tab, block.file_offset)))
|
||||
print(('\t%sPEB #: %s' % (tab, block.peb_num)))
|
||||
print(('\t%sLEB #: %s' % (tab, block.leb_num)))
|
||||
print(('\t%sBlock Size: %s' % (tab, block.size)))
|
||||
print(('\t%sInternal Volume: %s' % (tab, block.is_internal_vol)))
|
||||
print(('\t%sIs Volume Table: %s' % (tab, block.is_vtbl)))
|
||||
print(('\t%sIs Valid: %s' % (tab, block.is_valid)))
|
||||
def block(block, tab="\t"):
|
||||
print(("%s%s" % (tab, block)))
|
||||
print(("%s---------------------" % tab))
|
||||
print(("\t%sFile Offset: %s" % (tab, block.file_offset)))
|
||||
print(("\t%sPEB #: %s" % (tab, block.peb_num)))
|
||||
print(("\t%sLEB #: %s" % (tab, block.leb_num)))
|
||||
print(("\t%sBlock Size: %s" % (tab, block.size)))
|
||||
print(("\t%sInternal Volume: %s" % (tab, block.is_internal_vol)))
|
||||
print(("\t%sIs Volume Table: %s" % (tab, block.is_vtbl)))
|
||||
print(("\t%sIs Valid: %s" % (tab, block.is_valid)))
|
||||
if not block.ec_hdr.errors:
|
||||
print('\n')
|
||||
print(('\t%sErase Count Header' % tab))
|
||||
print(('\t%s---------------------' % tab))
|
||||
ec_hdr(block.ec_hdr, '\t\t%s' % tab)
|
||||
print("\n")
|
||||
print(("\t%sErase Count Header" % tab))
|
||||
print(("\t%s---------------------" % tab))
|
||||
ec_hdr(block.ec_hdr, "\t\t%s" % tab)
|
||||
if block.vid_hdr and not block.vid_hdr.errors:
|
||||
print('\n')
|
||||
print(('\t%sVID Header Header' % tab))
|
||||
print(('\t%s---------------------' % tab))
|
||||
vid_hdr(block.vid_hdr, '\t\t%s' % tab)
|
||||
print("\n")
|
||||
print(("\t%sVID Header Header" % tab))
|
||||
print(("\t%s---------------------" % tab))
|
||||
vid_hdr(block.vid_hdr, "\t\t%s" % tab)
|
||||
if block.vtbl_recs:
|
||||
print('\n')
|
||||
print(('\t%sVolume Records' % tab))
|
||||
print(('\t%s---------------------' % tab))
|
||||
print("\n")
|
||||
print(("\t%sVolume Records" % tab))
|
||||
print(("\t%s---------------------" % tab))
|
||||
for vol in block.vtbl_recs:
|
||||
vol_rec(vol, '\t\t%s' % tab)
|
||||
vol_rec(vol, "\t\t%s" % tab)
|
||||
|
||||
print('\n')
|
||||
print("\n")
|
||||
|
||||
|
||||
def ec_hdr(ec_hdr, tab=''):
|
||||
def ec_hdr(ec_hdr, tab=""):
|
||||
for key, value in ec_hdr:
|
||||
if key == 'errors':
|
||||
value = ','.join(value)
|
||||
print(('%s%s: %r' % (tab, key, value)))
|
||||
if key == "errors":
|
||||
value = ",".join(value)
|
||||
print(("%s%s: %r" % (tab, key, value)))
|
||||
|
||||
|
||||
def vid_hdr(vid_hdr, tab=''):
|
||||
def vid_hdr(vid_hdr, tab=""):
|
||||
for key, value in vid_hdr:
|
||||
if key == 'errors':
|
||||
value = ','.join(value)
|
||||
elif key == 'compat':
|
||||
if key == "errors":
|
||||
value = ",".join(value)
|
||||
elif key == "compat":
|
||||
if value in PRINT_COMPAT_LIST:
|
||||
value = PRINT_COMPAT_LIST[value]
|
||||
else:
|
||||
value = -1
|
||||
elif key == 'vol_type':
|
||||
elif key == "vol_type":
|
||||
if value < len(PRINT_VOL_TYPE_LIST):
|
||||
value = PRINT_VOL_TYPE_LIST[value]
|
||||
else:
|
||||
value = -1
|
||||
print(('%s%s: %s' % (tab, key, value)))
|
||||
print(("%s%s: %s" % (tab, key, value)))
|
||||
|
||||
|
||||
def vol_rec(vol_rec, tab=''):
|
||||
def vol_rec(vol_rec, tab=""):
|
||||
for key, value in vol_rec:
|
||||
if key == 'errors':
|
||||
value = ','.join(value)
|
||||
elif key == 'vol_type':
|
||||
if key == "errors":
|
||||
value = ",".join(value)
|
||||
elif key == "vol_type":
|
||||
if value < len(PRINT_VOL_TYPE_LIST):
|
||||
value = PRINT_VOL_TYPE_LIST[value]
|
||||
else:
|
||||
value = -1
|
||||
elif key == 'flags' and value == UBI_VTBL_AUTORESIZE_FLG:
|
||||
value = 'autoresize'
|
||||
elif key == 'name':
|
||||
value = value.strip('\x00')
|
||||
print(('%s%s: %s' % (tab, key, value)))
|
||||
elif key == "flags" and value == UBI_VTBL_AUTORESIZE_FLG:
|
||||
value = "autoresize"
|
||||
elif key == "name":
|
||||
value = value.strip("\x00")
|
||||
print(("%s%s: %s" % (tab, key, value)))
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#!/usr/bin/python
|
||||
import struct
|
||||
from ubi.defines import *
|
||||
from ubi.headers import errors
|
||||
@@ -12,14 +11,14 @@ class ec_hdr(object):
|
||||
for key in fields:
|
||||
setattr(self, key, fields[key])
|
||||
|
||||
setattr(self, 'errors', [])
|
||||
setattr(self, "errors", [])
|
||||
|
||||
def __repr__(self):
|
||||
return 'Error Count Header'
|
||||
return "Error Count Header"
|
||||
|
||||
def __iter__(self):
|
||||
for key in dir(self):
|
||||
if not key.startswith('_'):
|
||||
if not key.startswith("_"):
|
||||
yield (key, getattr(self, key))
|
||||
|
||||
|
||||
@@ -31,15 +30,15 @@ class vid_hdr(object):
|
||||
for key in fields:
|
||||
setattr(self, key, fields[key])
|
||||
|
||||
setattr(self, 'errors', [])
|
||||
setattr(self, "errors", [])
|
||||
|
||||
def __iter__(self):
|
||||
for key in dir(self):
|
||||
if not key.startswith('_'):
|
||||
if not key.startswith("_"):
|
||||
yield (key, getattr(self, key))
|
||||
|
||||
def __repr__(self):
|
||||
return 'VID Header'
|
||||
return "VID Header"
|
||||
|
||||
|
||||
class vtbl_rec(object):
|
||||
@@ -50,15 +49,15 @@ class vtbl_rec(object):
|
||||
for key in fields:
|
||||
setattr(self, key, fields[key])
|
||||
|
||||
setattr(self, 'errors', [])
|
||||
setattr(self, 'rec_index', -1)
|
||||
setattr(self, "errors", [])
|
||||
setattr(self, "rec_index", -1)
|
||||
|
||||
def __repr__(self):
|
||||
return 'Volume Table Record: %s' % getattr(self, 'name')
|
||||
return "Volume Table Record: %s" % getattr(self, "name")
|
||||
|
||||
def __iter__(self):
|
||||
for key in dir(self):
|
||||
if not key.startswith('_'):
|
||||
if not key.startswith("_"):
|
||||
yield (key, getattr(self, key))
|
||||
|
||||
|
||||
@@ -79,10 +78,10 @@ def extract_vid_hdr(buf):
|
||||
def extract_vtbl_rec(buf):
|
||||
data_buf = buf
|
||||
vtbl_recs = []
|
||||
vtbl_rec_ret = ''
|
||||
vtbl_rec_ret = ""
|
||||
for i in range(0, UBI_MAX_VOLUMES):
|
||||
offset = i * UBI_VTBL_REC_SZ
|
||||
vtbl_rec_buf = data_buf[offset:offset + UBI_VTBL_REC_SZ]
|
||||
vtbl_rec_buf = data_buf[offset: offset + UBI_VTBL_REC_SZ]
|
||||
if len(vtbl_rec_buf) == UBI_VTBL_REC_SZ:
|
||||
vtbl_rec_ret = vtbl_rec(vtbl_rec_buf)
|
||||
errors.vtbl_rec(vtbl_rec_ret, vtbl_rec_buf)
|
||||
|
||||
@@ -1,29 +1,28 @@
|
||||
#!/usr/bin/python
|
||||
from zlib import crc32
|
||||
from ubi.defines import *
|
||||
|
||||
|
||||
def ec_hdr(ec_hdr, buf):
|
||||
if ec_hdr.hdr_crc != ~crc32(buf[:-4]) & 4294967295:
|
||||
ec_hdr.errors.append('crc')
|
||||
ec_hdr.errors.append("crc")
|
||||
return ec_hdr
|
||||
|
||||
|
||||
def vid_hdr(vid_hdr, buf):
|
||||
vid_hdr.errors = []
|
||||
if vid_hdr.hdr_crc != ~crc32(buf[:-4]) & 4294967295:
|
||||
vid_hdr.errors.append('crc')
|
||||
vid_hdr.errors.append("crc")
|
||||
return vid_hdr
|
||||
|
||||
|
||||
def vtbl_rec(vtbl_rec, buf):
|
||||
likely_vtbl = True
|
||||
if vtbl_rec.name_len != len(vtbl_rec.name.strip('\x00')):
|
||||
if vtbl_rec.name_len != len(vtbl_rec.name.strip("\x00")):
|
||||
likely_vtbl = False
|
||||
elif vtbl_rec.vol_type not in (1, 2):
|
||||
likely_vtbl = False
|
||||
if vtbl_rec.crc != ~crc32(buf[:-4]) & 4294967295:
|
||||
vtbl_rec.errors.append('crc')
|
||||
vtbl_rec.errors.append("crc")
|
||||
if not likely_vtbl:
|
||||
vtbl_rec.errors = ['False']
|
||||
vtbl_rec.errors = ["False"]
|
||||
return vtbl_rec
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#!/usr/bin/python
|
||||
from ubi import display
|
||||
from ubi.volume import get_volumes
|
||||
from ubi.block import get_blocks_in_list
|
||||
@@ -15,10 +14,12 @@ class description(object):
|
||||
self._volumes = get_volumes(blocks, layout_info)
|
||||
|
||||
def __repr__(self):
|
||||
return 'Image: %s' % self.image_seq
|
||||
return "Image: %s" % self.image_seq
|
||||
|
||||
def get_blocks(self, blocks):
|
||||
return get_blocks_in_list(blocks, list(range(self._start_peb, self._end_peb + 1)))
|
||||
return get_blocks_in_list(
|
||||
blocks, list(range(self._start_peb, self._end_peb + 1))
|
||||
)
|
||||
|
||||
def _get_peb_range(self):
|
||||
return [self._start_peb, self._end_peb]
|
||||
@@ -35,5 +36,5 @@ class description(object):
|
||||
|
||||
volumes = property(_get_volumes)
|
||||
|
||||
def display(self, tab=''):
|
||||
def display(self, tab=""):
|
||||
display.image(self, tab)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#!/usr/bin/python
|
||||
from ubi import display
|
||||
from ubi.block import sort, get_blocks_in_list
|
||||
|
||||
@@ -12,7 +11,7 @@ class description(object):
|
||||
self._block_list = block_list
|
||||
|
||||
def __repr__(self):
|
||||
return 'Volume: %s' % self.name
|
||||
return "Volume: %s" % self.name
|
||||
|
||||
def _get_name(self):
|
||||
return self._name
|
||||
@@ -42,15 +41,15 @@ class description(object):
|
||||
def get_blocks(self, blocks):
|
||||
return get_blocks_in_list(blocks, self._block_list)
|
||||
|
||||
def display(self, tab=''):
|
||||
def display(self, tab=""):
|
||||
display.volume(self, tab)
|
||||
|
||||
def reader(self, ubi):
|
||||
last_leb = 0
|
||||
for block in sort.by_leb(self.get_blocks(ubi.blocks)):
|
||||
if block == 'x':
|
||||
if block == "x":
|
||||
last_leb += 1
|
||||
yield '\xff' * ubi.leb_size
|
||||
yield "\xff" * ubi.leb_size
|
||||
else:
|
||||
last_leb += 1
|
||||
yield ubi.file.read_block_data(ubi.blocks[block])
|
||||
@@ -60,10 +59,11 @@ def get_volumes(blocks, layout_info):
|
||||
volumes = {}
|
||||
vol_blocks_lists = sort.by_vol_id(blocks, layout_info[2])
|
||||
for vol_rec in blocks[layout_info[0]].vtbl_recs:
|
||||
vol_name = vol_rec.name.strip('\x00')
|
||||
vol_name = vol_rec.name.strip("\x00")
|
||||
if vol_rec.rec_index not in vol_blocks_lists:
|
||||
vol_blocks_lists[vol_rec.rec_index] = []
|
||||
volumes[vol_name] = description(
|
||||
vol_rec.rec_index, vol_rec, vol_blocks_lists[vol_rec.rec_index])
|
||||
vol_rec.rec_index, vol_rec, vol_blocks_lists[vol_rec.rec_index]
|
||||
)
|
||||
|
||||
return volumes
|
||||
|
||||
@@ -1,38 +1,58 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import os
|
||||
import sys
|
||||
# import argparse_neo
|
||||
|
||||
try:
|
||||
import argparse
|
||||
except:
|
||||
except BaseException:
|
||||
import argparse_neo
|
||||
from ubi import ubi, get_peb_size
|
||||
from ubifs import ubifs
|
||||
from ubi_io import ubi_file, leb_virtual_file
|
||||
from ui.common import extract_files, output_dir
|
||||
if __name__ == '__main__':
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.system(
|
||||
'echo "\n[NeoBoot] Zip file unzipped.\nInstallation in progress, please wait ..."')
|
||||
description = 'Extract contents of UBI image.'
|
||||
usage = 'ubi_extract_files.py [options] filepath'
|
||||
# parser = argparse_neo.ArgumentParser(usage=usage, description=description)
|
||||
'echo "\n[NeoBoot] Zip file unzipped.\nInstallation in progress, please wait ..."'
|
||||
)
|
||||
description = "Extract contents of UBI image."
|
||||
usage = "ubi_extract_files.py [options] filepath"
|
||||
try:
|
||||
parser = argparse.ArgumentParser(usage=usage, description=description)
|
||||
except:
|
||||
except BaseException:
|
||||
parser = argparse_neo.ArgumentParser(
|
||||
usage=usage, description=description)
|
||||
parser.add_argument('-l', '--log-file', dest='logpath',
|
||||
help='Log output to file output/LOGPATH. (default: ubifs_output.log)')
|
||||
parser.add_argument('-k', '--keep-permissions', action='store_true', dest='permissions',
|
||||
help='Maintain file permissions, requires running as root. (default: False)')
|
||||
parser.add_argument('-q', '--quiet', action='store_true', dest='quiet',
|
||||
help='Suppress warnings and non-fatal errors. (default: False)')
|
||||
parser.add_argument('-p', '--peb-size', type=int,
|
||||
dest='block_size', help='Specify PEB size.')
|
||||
parser.add_argument('-o', '--output-dir', dest='output_path',
|
||||
help='Specify output directory path.')
|
||||
parser.add_argument('filepath', help='File to extract contents of.')
|
||||
parser.add_argument(
|
||||
"-l",
|
||||
"--log-file",
|
||||
dest="logpath",
|
||||
help="Log output to file output/LOGPATH. (default: ubifs_output.log)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-k",
|
||||
"--keep-permissions",
|
||||
action="store_true",
|
||||
dest="permissions",
|
||||
help="Maintain file permissions, requires running as root. (default: False)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-q",
|
||||
"--quiet",
|
||||
action="store_true",
|
||||
dest="quiet",
|
||||
help="Suppress warnings and non-fatal errors. (default: False)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-p",
|
||||
"--peb-size",
|
||||
type=int,
|
||||
dest="block_size",
|
||||
help="Specify PEB size.")
|
||||
parser.add_argument(
|
||||
"-o",
|
||||
"--output-dir",
|
||||
dest="output_path",
|
||||
help="Specify output directory path.")
|
||||
parser.add_argument("filepath", help="File to extract contents of.")
|
||||
if len(sys.argv) == 1:
|
||||
parser.print_help()
|
||||
sys.exit()
|
||||
@@ -69,13 +89,16 @@ if __name__ == '__main__':
|
||||
os.makedirs(vol_out_path)
|
||||
elif os.listdir(vol_out_path):
|
||||
parser.error(
|
||||
'Volume output directory is not empty. %s' % vol_out_path)
|
||||
"Volume output directory is not empty. %s" %
|
||||
vol_out_path)
|
||||
ufsfile = leb_virtual_file(uubi, image.volumes[volume])
|
||||
uubifs = ubifs(ufsfile)
|
||||
uubifs.log.log_file = log_file
|
||||
uubifs.log.log_to_file = log_to_file
|
||||
uubifs.log.quiet = quiet
|
||||
print("Wait almost over ...\nLoading the image to: %s" % vol_out_path)
|
||||
print(
|
||||
"Wait almost over ...\nLoading the image to: %s" %
|
||||
vol_out_path)
|
||||
extract_files(uubifs, vol_out_path, perms)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#!/usr/bin/python
|
||||
from ubi.block import sort
|
||||
|
||||
|
||||
class ubi_file(object):
|
||||
|
||||
def __init__(self, path, block_size, start_offset=0, end_offset=None):
|
||||
self._fhandle = open(path, 'rb')
|
||||
self._fhandle = open(path, "rb")
|
||||
self._start_offset = start_offset
|
||||
if end_offset:
|
||||
self._end_offset = end_offset
|
||||
@@ -14,7 +13,7 @@ class ubi_file(object):
|
||||
self._end_offset = self.tell()
|
||||
self._block_size = block_size
|
||||
if start_offset >= self._end_offset:
|
||||
raise Exception('Start offset larger than file size!')
|
||||
raise Exception("Start offset larger than file size!")
|
||||
self._fhandle.seek(self._start_offset)
|
||||
|
||||
def _set_start(self, i):
|
||||
@@ -69,7 +68,8 @@ class ubi_file(object):
|
||||
def read_block_data(self, block):
|
||||
self.seek(block.file_offset + block.ec_hdr.data_offset)
|
||||
buf = self._fhandle.read(
|
||||
block.size - block.ec_hdr.data_offset - block.vid_hdr.data_pad)
|
||||
block.size - block.ec_hdr.data_offset - block.vid_hdr.data_pad
|
||||
)
|
||||
return buf
|
||||
|
||||
|
||||
@@ -82,22 +82,22 @@ class leb_virtual_file:
|
||||
self._seek = 0
|
||||
self.leb_data_size = len(self._blocks) * self._ubi.leb_size
|
||||
self._last_leb = -1
|
||||
self._last_buf = ''
|
||||
self._last_buf = ""
|
||||
|
||||
def read(self, i):
|
||||
buf = ''
|
||||
buf = ""
|
||||
leb = int(self.tell() / self._ubi.leb_size)
|
||||
offset = self.tell() % self._ubi.leb_size
|
||||
if leb == self._last_leb:
|
||||
self.seek(self.tell() + i)
|
||||
return self._last_buf[offset:offset + i]
|
||||
return self._last_buf[offset: offset + i]
|
||||
else:
|
||||
buf = self._ubi.file.read_block_data(
|
||||
self._ubi.blocks[self._blocks[leb]])
|
||||
self._last_buf = buf
|
||||
self._last_leb = leb
|
||||
self.seek(self.tell() + i)
|
||||
return buf[offset:offset + i]
|
||||
return buf[offset: offset + i]
|
||||
|
||||
def reset(self):
|
||||
self.seek(0)
|
||||
@@ -113,7 +113,7 @@ class leb_virtual_file:
|
||||
for block in self._blocks:
|
||||
while 0 != self._ubi.blocks[block].leb_num - last_leb:
|
||||
last_leb += 1
|
||||
yield '\xff' * self._ubi.leb_size
|
||||
yield "\xff" * self._ubi.leb_size
|
||||
|
||||
last_leb += 1
|
||||
yield self._ubi.file.read_block_data(self._ubi.blocks[block])
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#!/usr/bin/python
|
||||
import re
|
||||
import struct
|
||||
from ubifs.defines import *
|
||||
@@ -50,7 +49,7 @@ class ubifs:
|
||||
|
||||
|
||||
def get_leb_size(path):
|
||||
f = open(path, 'rb')
|
||||
f = open(path, "rb")
|
||||
f.seek(0, 2)
|
||||
file_size = f.tell() + 1
|
||||
f.seek(0)
|
||||
@@ -59,7 +58,7 @@ def get_leb_size(path):
|
||||
buf = f.read(FILE_CHUNK_SZ)
|
||||
for m in re.finditer(UBIFS_NODE_MAGIC, buf):
|
||||
start = m.start()
|
||||
chdr = nodes.common_hdr(buf[start:start + UBIFS_COMMON_HDR_SZ])
|
||||
chdr = nodes.common_hdr(buf[start: start + UBIFS_COMMON_HDR_SZ])
|
||||
if chdr and chdr.node_type == UBIFS_SB_NODE:
|
||||
sb_start = start + UBIFS_COMMON_HDR_SZ
|
||||
sb_end = sb_start + UBIFS_SB_NODE_SZ
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/python
|
||||
import struct
|
||||
UBIFS_NODE_MAGIC = '1\x18\x10\x06'
|
||||
|
||||
UBIFS_NODE_MAGIC = "1\x18\x10\x06"
|
||||
UBIFS_CRC32_INIT = 4294967295
|
||||
UBIFS_MIN_COMPR_LEN = 128
|
||||
UBIFS_MIN_COMPRESS_DIFF = 64
|
||||
@@ -10,7 +10,7 @@ UBIFS_MAX_NLEN = 255
|
||||
UBIFS_MAX_JHEADS = 1
|
||||
UBIFS_BLOCK_SIZE = 4096
|
||||
UBIFS_BLOCK_SHIFT = 12
|
||||
UBIFS_PADDING_BYTE = '\xce'
|
||||
UBIFS_PADDING_BYTE = "\xce"
|
||||
UBIFS_MAX_KEY_LEN = 16
|
||||
UBIFS_SK_LEN = 8
|
||||
UBIFS_MIN_FANOUT = 3
|
||||
@@ -37,7 +37,7 @@ UBIFS_ITYPE_SOCK = 6
|
||||
UBIFS_ITYPES_CNT = 7
|
||||
UBIFS_KEY_HASH_R5 = 0
|
||||
UBIFS_KEY_HASH_TEST = 1
|
||||
PRINT_UBIFS_KEY_HASH = ['r5', 'test']
|
||||
PRINT_UBIFS_KEY_HASH = ["r5", "test"]
|
||||
UBIFS_SIMPLE_KEY_FMT = 0
|
||||
UBIFS_S_KEY_BLOCK_BITS = 29
|
||||
UBIFS_S_KEY_BLOCK_MASK = 536870911
|
||||
@@ -64,7 +64,7 @@ UBIFS_COMPR_NONE = 0
|
||||
UBIFS_COMPR_LZO = 1
|
||||
UBIFS_COMPR_ZLIB = 2
|
||||
UBIFS_COMPR_TYPES_CNT = 3
|
||||
PRINT_UBIFS_COMPR = ['none', 'lzo', 'zlib']
|
||||
PRINT_UBIFS_COMPR = ["none", "lzo", "zlib"]
|
||||
UBIFS_INO_NODE = 0
|
||||
UBIFS_DATA_NODE = 1
|
||||
UBIFS_DENT_NODE = 2
|
||||
@@ -86,136 +86,133 @@ UBIFS_IN_NODE_GROUP = 1
|
||||
UBIFS_LAST_OF_NODE_GROUP = 2
|
||||
UBIFS_FLG_BIGLPT = 2
|
||||
UBIFS_FLG_SPACE_FIXUP = 4
|
||||
UBIFS_COMMON_HDR_FORMAT = '<IIQIBB2s'
|
||||
UBIFS_COMMON_HDR_FIELDS = ['magic',
|
||||
'crc',
|
||||
'sqnum',
|
||||
'len',
|
||||
'node_type',
|
||||
'group_type',
|
||||
'padding']
|
||||
UBIFS_COMMON_HDR_FORMAT = "<IIQIBB2s"
|
||||
UBIFS_COMMON_HDR_FIELDS = [
|
||||
"magic",
|
||||
"crc",
|
||||
"sqnum",
|
||||
"len",
|
||||
"node_type",
|
||||
"group_type",
|
||||
"padding",
|
||||
]
|
||||
UBIFS_COMMON_HDR_SZ = struct.calcsize(UBIFS_COMMON_HDR_FORMAT)
|
||||
UBIFS_KEY_OFFSET = UBIFS_COMMON_HDR_SZ
|
||||
UBIFS_DEV_DESC_FORMAT = '<IQ'
|
||||
UBIFS_DEV_DESC_FIELDS = ['new', 'huge']
|
||||
UBIFS_DEV_DESC_FORMAT = "<IQ"
|
||||
UBIFS_DEV_DESC_FIELDS = ["new", "huge"]
|
||||
UBIFS_DEV_DESC_SZ = struct.calcsize(UBIFS_DEV_DESC_FORMAT)
|
||||
UBIFS_INO_NODE_FORMAT = '<%ssQQQQQIIIIIIIIIII4sIH26s' % UBIFS_MAX_KEY_LEN
|
||||
UBIFS_INO_NODE_FIELDS = ['key',
|
||||
'creat_sqnum',
|
||||
'size',
|
||||
'atime_sec',
|
||||
'ctime_sec',
|
||||
'mtime_sec',
|
||||
'atime_nsec',
|
||||
'ctime_nsec',
|
||||
'mtime_nsec',
|
||||
'nlink',
|
||||
'uid',
|
||||
'gid',
|
||||
'mode',
|
||||
'flags',
|
||||
'data_len',
|
||||
'xattr_cnt',
|
||||
'xattr_size',
|
||||
'padding1',
|
||||
'xattr_names',
|
||||
'compr_type',
|
||||
'padding2']
|
||||
UBIFS_INO_NODE_FORMAT = "<%ssQQQQQIIIIIIIIIII4sIH26s" % UBIFS_MAX_KEY_LEN
|
||||
UBIFS_INO_NODE_FIELDS = [
|
||||
"key",
|
||||
"creat_sqnum",
|
||||
"size",
|
||||
"atime_sec",
|
||||
"ctime_sec",
|
||||
"mtime_sec",
|
||||
"atime_nsec",
|
||||
"ctime_nsec",
|
||||
"mtime_nsec",
|
||||
"nlink",
|
||||
"uid",
|
||||
"gid",
|
||||
"mode",
|
||||
"flags",
|
||||
"data_len",
|
||||
"xattr_cnt",
|
||||
"xattr_size",
|
||||
"padding1",
|
||||
"xattr_names",
|
||||
"compr_type",
|
||||
"padding2",
|
||||
]
|
||||
UBIFS_INO_NODE_SZ = struct.calcsize(UBIFS_INO_NODE_FORMAT)
|
||||
UBIFS_DENT_NODE_FORMAT = '<%ssQBBH4s' % UBIFS_MAX_KEY_LEN
|
||||
UBIFS_DENT_NODE_FIELDS = ['key',
|
||||
'inum',
|
||||
'padding1',
|
||||
'type',
|
||||
'nlen',
|
||||
'padding2']
|
||||
UBIFS_DENT_NODE_FORMAT = "<%ssQBBH4s" % UBIFS_MAX_KEY_LEN
|
||||
UBIFS_DENT_NODE_FIELDS = [
|
||||
"key",
|
||||
"inum",
|
||||
"padding1",
|
||||
"type",
|
||||
"nlen",
|
||||
"padding2"]
|
||||
UBIFS_DENT_NODE_SZ = struct.calcsize(UBIFS_DENT_NODE_FORMAT)
|
||||
UBIFS_DATA_NODE_FORMAT = '<%ssIH2s' % UBIFS_MAX_KEY_LEN
|
||||
UBIFS_DATA_NODE_FIELDS = ['key',
|
||||
'size',
|
||||
'compr_type',
|
||||
'padding']
|
||||
UBIFS_DATA_NODE_FORMAT = "<%ssIH2s" % UBIFS_MAX_KEY_LEN
|
||||
UBIFS_DATA_NODE_FIELDS = ["key", "size", "compr_type", "padding"]
|
||||
UBIFS_DATA_NODE_SZ = struct.calcsize(UBIFS_DATA_NODE_FORMAT)
|
||||
UBIFS_TRUN_NODE_FORMAT = '<I12sQQ'
|
||||
UBIFS_TRUN_NODE_FIELDS = ['inum',
|
||||
'padding',
|
||||
'old_size',
|
||||
'new_size']
|
||||
UBIFS_TRUN_NODE_FORMAT = "<I12sQQ"
|
||||
UBIFS_TRUN_NODE_FIELDS = ["inum", "padding", "old_size", "new_size"]
|
||||
UBIFS_TRUN_NODE_SZ = struct.calcsize(UBIFS_TRUN_NODE_FORMAT)
|
||||
UBIFS_PAD_NODE_FORMAT = '<I'
|
||||
UBIFS_PAD_NODE_FIELDS = ['pad_len']
|
||||
UBIFS_PAD_NODE_FORMAT = "<I"
|
||||
UBIFS_PAD_NODE_FIELDS = ["pad_len"]
|
||||
UBIFS_PAD_NODE_SZ = struct.calcsize(UBIFS_PAD_NODE_FORMAT)
|
||||
UBIFS_SB_NODE_FORMAT = '<2sBBIIIIIQIIIIIIIH2sIIQI16sI3968s'
|
||||
UBIFS_SB_NODE_FIELDS = ['padding',
|
||||
'key_hash',
|
||||
'key_fmt',
|
||||
'flags',
|
||||
'min_io_size',
|
||||
'leb_size',
|
||||
'leb_cnt',
|
||||
'max_leb_cnt',
|
||||
'max_bud_bytes',
|
||||
'log_lebs',
|
||||
'lpt_lebs',
|
||||
'orph_lebs',
|
||||
'jhead_cnt',
|
||||
'fanout',
|
||||
'lsave_cnt',
|
||||
'fmt_version',
|
||||
'default_compr',
|
||||
'padding1',
|
||||
'rp_uid',
|
||||
'rp_gid',
|
||||
'rp_size',
|
||||
'time_gran',
|
||||
'uuid',
|
||||
'ro_compat_version',
|
||||
'padding2']
|
||||
UBIFS_SB_NODE_FORMAT = "<2sBBIIIIIQIIIIIIIH2sIIQI16sI3968s"
|
||||
UBIFS_SB_NODE_FIELDS = [
|
||||
"padding",
|
||||
"key_hash",
|
||||
"key_fmt",
|
||||
"flags",
|
||||
"min_io_size",
|
||||
"leb_size",
|
||||
"leb_cnt",
|
||||
"max_leb_cnt",
|
||||
"max_bud_bytes",
|
||||
"log_lebs",
|
||||
"lpt_lebs",
|
||||
"orph_lebs",
|
||||
"jhead_cnt",
|
||||
"fanout",
|
||||
"lsave_cnt",
|
||||
"fmt_version",
|
||||
"default_compr",
|
||||
"padding1",
|
||||
"rp_uid",
|
||||
"rp_gid",
|
||||
"rp_size",
|
||||
"time_gran",
|
||||
"uuid",
|
||||
"ro_compat_version",
|
||||
"padding2",
|
||||
]
|
||||
UBIFS_SB_NODE_SZ = struct.calcsize(UBIFS_SB_NODE_FORMAT)
|
||||
UBIFS_MST_NODE_FORMAT = '<QQIIIIIIIIQQQQQQIIIIIIIIIIII344s'
|
||||
UBIFS_MST_NODE_FIELDS = ['highest_inum',
|
||||
'cmt_no',
|
||||
'flags',
|
||||
'log_lnum',
|
||||
'root_lnum',
|
||||
'root_offs',
|
||||
'root_len',
|
||||
'gc_lnum',
|
||||
'ihead_lnum',
|
||||
'ihead_offs',
|
||||
'index_size',
|
||||
'total_free',
|
||||
'total_dirty',
|
||||
'total_used',
|
||||
'total_dead',
|
||||
'total_dark',
|
||||
'lpt_lnum',
|
||||
'lpt_offs',
|
||||
'nhead_lnum',
|
||||
'nhead_offs',
|
||||
'ltab_lnum',
|
||||
'ltab_offs',
|
||||
'lsave_lnum',
|
||||
'lsave_offs',
|
||||
'lscan_lnum',
|
||||
'empty_lebs',
|
||||
'idx_lebs',
|
||||
'leb_cnt',
|
||||
'padding']
|
||||
UBIFS_MST_NODE_FORMAT = "<QQIIIIIIIIQQQQQQIIIIIIIIIIII344s"
|
||||
UBIFS_MST_NODE_FIELDS = [
|
||||
"highest_inum",
|
||||
"cmt_no",
|
||||
"flags",
|
||||
"log_lnum",
|
||||
"root_lnum",
|
||||
"root_offs",
|
||||
"root_len",
|
||||
"gc_lnum",
|
||||
"ihead_lnum",
|
||||
"ihead_offs",
|
||||
"index_size",
|
||||
"total_free",
|
||||
"total_dirty",
|
||||
"total_used",
|
||||
"total_dead",
|
||||
"total_dark",
|
||||
"lpt_lnum",
|
||||
"lpt_offs",
|
||||
"nhead_lnum",
|
||||
"nhead_offs",
|
||||
"ltab_lnum",
|
||||
"ltab_offs",
|
||||
"lsave_lnum",
|
||||
"lsave_offs",
|
||||
"lscan_lnum",
|
||||
"empty_lebs",
|
||||
"idx_lebs",
|
||||
"leb_cnt",
|
||||
"padding",
|
||||
]
|
||||
UBIFS_MST_NODE_SZ = struct.calcsize(UBIFS_MST_NODE_FORMAT)
|
||||
UBIFS_REF_NODE_FORMAT = '<III28s'
|
||||
UBIFS_REF_NODE_FIELDS = ['lnum',
|
||||
'offs',
|
||||
'jhead',
|
||||
'padding']
|
||||
UBIFS_REF_NODE_FORMAT = "<III28s"
|
||||
UBIFS_REF_NODE_FIELDS = ["lnum", "offs", "jhead", "padding"]
|
||||
UBIFS_REF_NODE_SZ = struct.calcsize(UBIFS_REF_NODE_FORMAT)
|
||||
UBIFS_BRANCH_FORMAT = '<III%ss' % UBIFS_SK_LEN
|
||||
UBIFS_BRANCH_FIELDS = ['lnum',
|
||||
'offs',
|
||||
'len',
|
||||
'key']
|
||||
UBIFS_BRANCH_FORMAT = "<III%ss" % UBIFS_SK_LEN
|
||||
UBIFS_BRANCH_FIELDS = ["lnum", "offs", "len", "key"]
|
||||
UBIFS_BRANCH_SZ = struct.calcsize(UBIFS_BRANCH_FORMAT)
|
||||
UBIFS_IDX_NODE_FORMAT = '<HH'
|
||||
UBIFS_IDX_NODE_FIELDS = ['child_cnt', 'level']
|
||||
UBIFS_IDX_NODE_FORMAT = "<HH"
|
||||
UBIFS_IDX_NODE_FIELDS = ["child_cnt", "level"]
|
||||
UBIFS_IDX_NODE_SZ = struct.calcsize(UBIFS_IDX_NODE_FORMAT)
|
||||
FILE_CHUNK_SZ = 5242880
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#!/usr/bin/python
|
||||
import os
|
||||
import sys
|
||||
import ui
|
||||
@@ -8,18 +7,18 @@ class log:
|
||||
|
||||
def __init__(self):
|
||||
self.log_to_file = False
|
||||
self.log_file = 'ubifs_output.log'
|
||||
self.log_file = "ubifs_output.log"
|
||||
self.exit_on_except = False
|
||||
self.quiet = False
|
||||
|
||||
def _out(self, s):
|
||||
if not self.quiet:
|
||||
if self.log_to_file:
|
||||
with open(os.path.join(ui.common.output_dir, self.log_file), 'a') as f:
|
||||
f.write('%s\n' % s)
|
||||
with open(os.path.join(ui.common.output_dir, self.log_file), "a") as f:
|
||||
f.write("%s\n" % s)
|
||||
f.close()
|
||||
else:
|
||||
print(('%s' % s))
|
||||
print(("%s" % s))
|
||||
if self.exit_on_except:
|
||||
sys.exit()
|
||||
|
||||
@@ -27,8 +26,8 @@ class log:
|
||||
self._out(s)
|
||||
|
||||
def write_node(self, n):
|
||||
buf = '%s\n' % n
|
||||
buf = "%s\n" % n
|
||||
for key, value in n:
|
||||
buf += '\t%s: %s\n' % (key, value)
|
||||
buf += "\t%s: %s\n" % (key, value)
|
||||
|
||||
self._out(buf)
|
||||
|
||||
@@ -1,46 +1,34 @@
|
||||
#!/usr/bin/python
|
||||
# import lzo
|
||||
import struct
|
||||
import zlib
|
||||
from ubifs.defines import *
|
||||
ino_types = ['file',
|
||||
'dir',
|
||||
'lnk',
|
||||
'blk',
|
||||
'chr',
|
||||
'fifo',
|
||||
'sock']
|
||||
node_types = ['ino',
|
||||
'data',
|
||||
'dent',
|
||||
'xent',
|
||||
'trun',
|
||||
'pad',
|
||||
'sb',
|
||||
'mst',
|
||||
'ref',
|
||||
'idx',
|
||||
'cs',
|
||||
'orph']
|
||||
key_types = ['ino',
|
||||
'data',
|
||||
'dent',
|
||||
'xent']
|
||||
|
||||
ino_types = ["file", "dir", "lnk", "blk", "chr", "fifo", "sock"]
|
||||
node_types = [
|
||||
"ino",
|
||||
"data",
|
||||
"dent",
|
||||
"xent",
|
||||
"trun",
|
||||
"pad",
|
||||
"sb",
|
||||
"mst",
|
||||
"ref",
|
||||
"idx",
|
||||
"cs",
|
||||
"orph",
|
||||
]
|
||||
key_types = ["ino", "data", "dent", "xent"]
|
||||
|
||||
|
||||
def parse_key(key):
|
||||
hkey, lkey = struct.unpack('<II', key[0:UBIFS_SK_LEN])
|
||||
hkey, lkey = struct.unpack("<II", key[0:UBIFS_SK_LEN])
|
||||
ino_num = hkey & UBIFS_S_KEY_HASH_MASK
|
||||
key_type = lkey >> UBIFS_S_KEY_BLOCK_BITS
|
||||
khash = lkey
|
||||
return {'type': key_type,
|
||||
'ino_num': ino_num,
|
||||
'khash': khash}
|
||||
return {"type": key_type, "ino_num": ino_num, "khash": khash}
|
||||
|
||||
|
||||
def decompress(ctype, unc_len, data):
|
||||
# if ctype == UBIFS_COMPR_LZO:
|
||||
# return lzo.decompress(''.join(('\xf0', struct.pack('>I', unc_len), data)))
|
||||
if ctype == UBIFS_COMPR_ZLIB:
|
||||
return zlib.decompress(data, -11)
|
||||
else:
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#!/usr/bin/python
|
||||
import struct
|
||||
from ubifs.defines import *
|
||||
from ubifs.misc import parse_key
|
||||
@@ -8,18 +7,18 @@ class common_hdr(object):
|
||||
|
||||
def __init__(self, buf):
|
||||
fields = dict(list(zip(UBIFS_COMMON_HDR_FIELDS,
|
||||
struct.unpack(UBIFS_COMMON_HDR_FORMAT, buf))))
|
||||
struct.unpack(UBIFS_COMMON_HDR_FORMAT, buf))))
|
||||
for key in fields:
|
||||
setattr(self, key, fields[key])
|
||||
|
||||
setattr(self, 'errors', [])
|
||||
setattr(self, "errors", [])
|
||||
|
||||
def __repr__(self):
|
||||
return 'UBIFS Common Header'
|
||||
return "UBIFS Common Header"
|
||||
|
||||
def __iter__(self):
|
||||
for key in dir(self):
|
||||
if not key.startswith('_'):
|
||||
if not key.startswith("_"):
|
||||
yield (key, getattr(self, key))
|
||||
|
||||
|
||||
@@ -27,16 +26,17 @@ class sb_node(object):
|
||||
|
||||
def __init__(self, buf):
|
||||
fields = dict(
|
||||
list(zip(UBIFS_SB_NODE_FIELDS, struct.unpack(UBIFS_SB_NODE_FORMAT, buf))))
|
||||
list(zip(UBIFS_SB_NODE_FIELDS, struct.unpack(UBIFS_SB_NODE_FORMAT, buf)))
|
||||
)
|
||||
for key in fields:
|
||||
setattr(self, key, fields[key])
|
||||
|
||||
def __repr__(self):
|
||||
return 'UBIFS Super Block Node'
|
||||
return "UBIFS Super Block Node"
|
||||
|
||||
def __iter__(self):
|
||||
for key in dir(self):
|
||||
if not key.startswith('_'):
|
||||
if not key.startswith("_"):
|
||||
yield (key, getattr(self, key))
|
||||
|
||||
|
||||
@@ -44,16 +44,17 @@ class mst_node(object):
|
||||
|
||||
def __init__(self, buf):
|
||||
fields = dict(
|
||||
list(zip(UBIFS_MST_NODE_FIELDS, struct.unpack(UBIFS_MST_NODE_FORMAT, buf))))
|
||||
list(zip(UBIFS_MST_NODE_FIELDS, struct.unpack(UBIFS_MST_NODE_FORMAT, buf)))
|
||||
)
|
||||
for key in fields:
|
||||
setattr(self, key, fields[key])
|
||||
|
||||
def __repr__(self):
|
||||
return 'UBIFS Master Block Node'
|
||||
return "UBIFS Master Block Node"
|
||||
|
||||
def __iter__(self):
|
||||
for key in dir(self):
|
||||
if not key.startswith('_'):
|
||||
if not key.startswith("_"):
|
||||
yield (key, getattr(self, key))
|
||||
|
||||
|
||||
@@ -61,21 +62,24 @@ class dent_node(object):
|
||||
|
||||
def __init__(self, buf):
|
||||
fields = dict(
|
||||
list(zip(UBIFS_DENT_NODE_FIELDS, struct.unpack(UBIFS_DENT_NODE_FORMAT, buf))))
|
||||
list(
|
||||
zip(UBIFS_DENT_NODE_FIELDS, struct.unpack(UBIFS_DENT_NODE_FORMAT, buf))
|
||||
)
|
||||
)
|
||||
for key in fields:
|
||||
if key == 'key':
|
||||
if key == "key":
|
||||
setattr(self, key, parse_key(fields[key]))
|
||||
else:
|
||||
setattr(self, key, fields[key])
|
||||
|
||||
setattr(self, 'name', '')
|
||||
setattr(self, "name", "")
|
||||
|
||||
def __repr__(self):
|
||||
return 'UBIFS Directory Entry Node'
|
||||
return "UBIFS Directory Entry Node"
|
||||
|
||||
def __iter__(self):
|
||||
for key in dir(self):
|
||||
if not key.startswith('_'):
|
||||
if not key.startswith("_"):
|
||||
yield (key, getattr(self, key))
|
||||
|
||||
|
||||
@@ -83,22 +87,25 @@ class data_node(object):
|
||||
|
||||
def __init__(self, buf):
|
||||
fields = dict(
|
||||
list(zip(UBIFS_DATA_NODE_FIELDS, struct.unpack(UBIFS_DATA_NODE_FORMAT, buf))))
|
||||
list(
|
||||
zip(UBIFS_DATA_NODE_FIELDS, struct.unpack(UBIFS_DATA_NODE_FORMAT, buf))
|
||||
)
|
||||
)
|
||||
for key in fields:
|
||||
if key == 'key':
|
||||
if key == "key":
|
||||
setattr(self, key, parse_key(fields[key]))
|
||||
else:
|
||||
setattr(self, key, fields[key])
|
||||
|
||||
setattr(self, 'offset', 0)
|
||||
setattr(self, 'compr_len', 0)
|
||||
setattr(self, "offset", 0)
|
||||
setattr(self, "compr_len", 0)
|
||||
|
||||
def __repr__(self):
|
||||
return 'UBIFS Data Node'
|
||||
return "UBIFS Data Node"
|
||||
|
||||
def __iter__(self):
|
||||
for key in dir(self):
|
||||
if not key.startswith('_'):
|
||||
if not key.startswith("_"):
|
||||
yield (key, getattr(self, key))
|
||||
|
||||
|
||||
@@ -106,18 +113,19 @@ class idx_node(object):
|
||||
|
||||
def __init__(self, buf):
|
||||
fields = dict(
|
||||
list(zip(UBIFS_IDX_NODE_FIELDS, struct.unpack(UBIFS_IDX_NODE_FORMAT, buf))))
|
||||
list(zip(UBIFS_IDX_NODE_FIELDS, struct.unpack(UBIFS_IDX_NODE_FORMAT, buf)))
|
||||
)
|
||||
for key in fields:
|
||||
setattr(self, key, fields[key])
|
||||
|
||||
setattr(self, 'branches', [])
|
||||
setattr(self, "branches", [])
|
||||
|
||||
def __repr__(self):
|
||||
return 'UBIFS Index Node'
|
||||
return "UBIFS Index Node"
|
||||
|
||||
def __iter__(self):
|
||||
for key in dir(self):
|
||||
if not key.startswith('_'):
|
||||
if not key.startswith("_"):
|
||||
yield (key, getattr(self, key))
|
||||
|
||||
|
||||
@@ -125,21 +133,22 @@ class ino_node(object):
|
||||
|
||||
def __init__(self, buf):
|
||||
fields = dict(
|
||||
list(zip(UBIFS_INO_NODE_FIELDS, struct.unpack(UBIFS_INO_NODE_FORMAT, buf))))
|
||||
list(zip(UBIFS_INO_NODE_FIELDS, struct.unpack(UBIFS_INO_NODE_FORMAT, buf)))
|
||||
)
|
||||
for key in fields:
|
||||
if key == 'key':
|
||||
if key == "key":
|
||||
setattr(self, key, parse_key(fields[key]))
|
||||
else:
|
||||
setattr(self, key, fields[key])
|
||||
|
||||
setattr(self, 'data', '')
|
||||
setattr(self, "data", "")
|
||||
|
||||
def __repr__(self):
|
||||
return 'UBIFS Ino Node'
|
||||
return "UBIFS Ino Node"
|
||||
|
||||
def __iter__(self):
|
||||
for key in dir(self):
|
||||
if not key.startswith('_'):
|
||||
if not key.startswith("_"):
|
||||
yield (key, getattr(self, key))
|
||||
|
||||
|
||||
@@ -147,14 +156,15 @@ class branch(object):
|
||||
|
||||
def __init__(self, buf):
|
||||
fields = dict(
|
||||
list(zip(UBIFS_BRANCH_FIELDS, struct.unpack(UBIFS_BRANCH_FORMAT, buf))))
|
||||
list(zip(UBIFS_BRANCH_FIELDS, struct.unpack(UBIFS_BRANCH_FORMAT, buf)))
|
||||
)
|
||||
for key in fields:
|
||||
setattr(self, key, fields[key])
|
||||
|
||||
def __repr__(self):
|
||||
return 'UBIFS Branch'
|
||||
return "UBIFS Branch"
|
||||
|
||||
def __iter__(self):
|
||||
for key in dir(self):
|
||||
if not key.startswith('_'):
|
||||
if not key.startswith("_"):
|
||||
yield (key, getattr(self, key))
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#!/usr/bin/python
|
||||
from ubifs import nodes
|
||||
from ubifs.defines import *
|
||||
|
||||
@@ -28,7 +27,7 @@ def sb_node(ubifs, offset=0):
|
||||
def dent_node(ubifs, lnum, offset=0):
|
||||
ubifs.file.seek(ubifs.leb_size * lnum + offset)
|
||||
den = nodes.dent_node(ubifs.file.read(UBIFS_DENT_NODE_SZ))
|
||||
den.name = '%s' % ubifs.file.read(den.nlen)
|
||||
den.name = "%s" % ubifs.file.read(den.nlen)
|
||||
return den
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#!/usr/bin/python
|
||||
import os
|
||||
import struct
|
||||
from ubifs.defines import *
|
||||
from ubifs.misc import decompress
|
||||
|
||||
|
||||
def dents(ubifs, inodes, dent_node, path='', perms=False):
|
||||
def dents(ubifs, inodes, dent_node, path="", perms=False):
|
||||
inode = inodes[dent_node.inum]
|
||||
dent_path = os.path.join(path, dent_node.name)
|
||||
if dent_node.type == UBIFS_ITYPE_DIR:
|
||||
@@ -15,41 +14,42 @@ def dents(ubifs, inodes, dent_node, path='', perms=False):
|
||||
if perms:
|
||||
set_file_perms(dent_path, inode)
|
||||
except Exception as e:
|
||||
ubifs.log.write('DIR Fail: %s' % e)
|
||||
ubifs.log.write("DIR Fail: %s" % e)
|
||||
|
||||
if 'dent' in inode:
|
||||
for dnode in inode['dent']:
|
||||
if "dent" in inode:
|
||||
for dnode in inode["dent"]:
|
||||
dents(ubifs, inodes, dnode, dent_path, perms)
|
||||
|
||||
elif dent_node.type == UBIFS_ITYPE_REG:
|
||||
try:
|
||||
if inode['ino'].nlink > 1:
|
||||
if 'hlink' not in inode:
|
||||
inode['hlink'] = dent_path
|
||||
if inode["ino"].nlink > 1:
|
||||
if "hlink" not in inode:
|
||||
inode["hlink"] = dent_path
|
||||
buf = process_reg_file(ubifs, inode, dent_path)
|
||||
write_reg_file(dent_path, buf)
|
||||
else:
|
||||
os.link(inode['hlink'], dent_path)
|
||||
os.link(inode["hlink"], dent_path)
|
||||
else:
|
||||
buf = process_reg_file(ubifs, inode, dent_path)
|
||||
write_reg_file(dent_path, buf)
|
||||
if perms:
|
||||
set_file_perms(dent_path, inode)
|
||||
except Exception as e:
|
||||
ubifs.log.write('FILE Fail: %s' % e)
|
||||
ubifs.log.write("FILE Fail: %s" % e)
|
||||
|
||||
elif dent_node.type == UBIFS_ITYPE_LNK:
|
||||
try:
|
||||
os.symlink('%s' % inode['ino'].data, dent_path)
|
||||
os.symlink("%s" % inode["ino"].data, dent_path)
|
||||
except Exception as e:
|
||||
ubifs.log.write('SYMLINK Fail: %s : %s' %
|
||||
(inode['ino'].data, dent_path))
|
||||
ubifs.log.write(
|
||||
"SYMLINK Fail: %s : %s" %
|
||||
(inode["ino"].data, dent_path))
|
||||
|
||||
elif dent_node.type in [UBIFS_ITYPE_BLK, UBIFS_ITYPE_CHR]:
|
||||
try:
|
||||
dev = struct.unpack('<II', inode['ino'].data)[0]
|
||||
dev = struct.unpack("<II", inode["ino"].data)[0]
|
||||
if perms:
|
||||
os.mknod(dent_path, inode['ino'].mode, dev)
|
||||
os.mknod(dent_path, inode["ino"].mode, dev)
|
||||
if perms:
|
||||
set_file_perms(path, inode)
|
||||
else:
|
||||
@@ -57,60 +57,60 @@ def dents(ubifs, inodes, dent_node, path='', perms=False):
|
||||
if perms:
|
||||
set_file_perms(dent_path, inode)
|
||||
except Exception as e:
|
||||
ubifs.log.write('DEV Fail: %s : %s' % (dent_path, e))
|
||||
ubifs.log.write("DEV Fail: %s : %s" % (dent_path, e))
|
||||
|
||||
elif dent_node.type == UBIFS_ITYPE_FIFO:
|
||||
try:
|
||||
os.mkfifo(dent_path, inode['ino'].mode)
|
||||
os.mkfifo(dent_path, inode["ino"].mode)
|
||||
if perms:
|
||||
set_file_perms(dent_path, inode)
|
||||
except Exception as e:
|
||||
ubifs.log.write('FIFO Fail: %s : %s' % (dent_path, e))
|
||||
ubifs.log.write("FIFO Fail: %s : %s" % (dent_path, e))
|
||||
|
||||
elif dent_node.type == UBIFS_ITYPE_SOCK:
|
||||
try:
|
||||
write_reg_file(dent_path, '')
|
||||
write_reg_file(dent_path, "")
|
||||
if perms:
|
||||
set_file_perms(dent_path, inode)
|
||||
except Exception as e:
|
||||
ubifs.log.write('SOCK Fail: %s' % dent_path)
|
||||
ubifs.log.write("SOCK Fail: %s" % dent_path)
|
||||
|
||||
|
||||
def set_file_perms(path, inode):
|
||||
try:
|
||||
os.chmod(path, inode['ino'].mode)
|
||||
os.chown(path, inode['ino'].uid, inode['ino'].gid)
|
||||
except:
|
||||
raise Exception('Failed File Permissions: %s' % path)
|
||||
os.chmod(path, inode["ino"].mode)
|
||||
os.chown(path, inode["ino"].uid, inode["ino"].gid)
|
||||
except BaseException:
|
||||
raise Exception("Failed File Permissions: %s" % path)
|
||||
|
||||
|
||||
def write_reg_file(path, data):
|
||||
with open(path, 'wb') as f:
|
||||
with open(path, "wb") as f:
|
||||
f.write(data)
|
||||
|
||||
|
||||
def process_reg_file(ubifs, inode, path):
|
||||
try:
|
||||
buf = ''
|
||||
if 'data' in inode:
|
||||
buf = ""
|
||||
if "data" in inode:
|
||||
compr_type = 0
|
||||
sorted_data = sorted(inode['data'], key=lambda x: x.key['khash'])
|
||||
last_khash = sorted_data[0].key['khash'] - 1
|
||||
sorted_data = sorted(inode["data"], key=lambda x: x.key["khash"])
|
||||
last_khash = sorted_data[0].key["khash"] - 1
|
||||
for data in sorted_data:
|
||||
if data.key['khash'] - last_khash != 1:
|
||||
while 1 != data.key['khash'] - last_khash:
|
||||
buf += '\x00' * UBIFS_BLOCK_SIZE
|
||||
if data.key["khash"] - last_khash != 1:
|
||||
while 1 != data.key["khash"] - last_khash:
|
||||
buf += "\x00" * UBIFS_BLOCK_SIZE
|
||||
last_khash += 1
|
||||
|
||||
compr_type = data.compr_type
|
||||
ubifs.file.seek(data.offset)
|
||||
d = ubifs.file.read(data.compr_len)
|
||||
buf += decompress(compr_type, data.size, d)
|
||||
last_khash = data.key['khash']
|
||||
last_khash = data.key["khash"]
|
||||
|
||||
except Exception as e:
|
||||
raise Exception('inode num:%s :%s' % (inode['ino'].key['ino_num'], e))
|
||||
raise Exception("inode num:%s :%s" % (inode["ino"].key["ino_num"], e))
|
||||
|
||||
if inode['ino'].size > len(buf):
|
||||
buf += '\x00' * (inode['ino'].size - len(buf))
|
||||
if inode["ino"].size > len(buf):
|
||||
buf += "\x00" * (inode["ino"].size - len(buf))
|
||||
return buf
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#!/usr/bin/python
|
||||
from ubifs import extract
|
||||
from ubifs.defines import *
|
||||
|
||||
@@ -12,24 +11,28 @@ def index(ubifs, lnum, offset, inodes={}):
|
||||
|
||||
elif chdr.node_type == UBIFS_INO_NODE:
|
||||
inon = extract.ino_node(ubifs, lnum, offset + UBIFS_COMMON_HDR_SZ)
|
||||
ino_num = inon.key['ino_num']
|
||||
ino_num = inon.key["ino_num"]
|
||||
if ino_num not in inodes:
|
||||
inodes[ino_num] = {}
|
||||
inodes[ino_num]['ino'] = inon
|
||||
inodes[ino_num]["ino"] = inon
|
||||
elif chdr.node_type == UBIFS_DATA_NODE:
|
||||
datn = extract.data_node(
|
||||
ubifs, lnum, offset + UBIFS_COMMON_HDR_SZ, chdr.len)
|
||||
ino_num = datn.key['ino_num']
|
||||
ubifs,
|
||||
lnum,
|
||||
offset +
|
||||
UBIFS_COMMON_HDR_SZ,
|
||||
chdr.len)
|
||||
ino_num = datn.key["ino_num"]
|
||||
if ino_num not in inodes:
|
||||
inodes[ino_num] = {}
|
||||
if 'data' not in inodes[ino_num]:
|
||||
inodes[ino_num]['data'] = []
|
||||
inodes[ino_num]['data'].append(datn)
|
||||
if "data" not in inodes[ino_num]:
|
||||
inodes[ino_num]["data"] = []
|
||||
inodes[ino_num]["data"].append(datn)
|
||||
elif chdr.node_type == UBIFS_DENT_NODE:
|
||||
dn = extract.dent_node(ubifs, lnum, offset + UBIFS_COMMON_HDR_SZ)
|
||||
ino_num = dn.key['ino_num']
|
||||
ino_num = dn.key["ino_num"]
|
||||
if ino_num not in inodes:
|
||||
inodes[ino_num] = {}
|
||||
if 'dent' not in inodes[ino_num]:
|
||||
inodes[ino_num]['dent'] = []
|
||||
inodes[ino_num]['dent'].append(dn)
|
||||
if "dent" not in inodes[ino_num]:
|
||||
inodes[ino_num]["dent"] = []
|
||||
inodes[ino_num]["dent"].append(dn)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#!/usr/bin/python
|
||||
import os
|
||||
from ubi_io import leb_virtual_file
|
||||
from ubifs import ubifs, walk, output
|
||||
from ubifs.defines import PRINT_UBIFS_KEY_HASH, PRINT_UBIFS_COMPR
|
||||
from ubi.defines import PRINT_VOL_TYPE_LIST, UBI_VTBL_AUTORESIZE_FLG
|
||||
output_dir = os.path.join(os.path.dirname(
|
||||
os.path.dirname(os.path.realpath(__file__))), 'output')
|
||||
|
||||
output_dir = os.path.join(
|
||||
os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "output"
|
||||
)
|
||||
|
||||
|
||||
def extract_files(ubifs, out_path, perms=False):
|
||||
@@ -13,34 +14,37 @@ def extract_files(ubifs, out_path, perms=False):
|
||||
inodes = {}
|
||||
walk.index(ubifs, ubifs.master_node.root_lnum,
|
||||
ubifs.master_node.root_offs, inodes)
|
||||
for dent in inodes[1]['dent']:
|
||||
for dent in inodes[1]["dent"]:
|
||||
output.dents(ubifs, inodes, dent, out_path, perms)
|
||||
|
||||
except Exception as e:
|
||||
import traceback
|
||||
ubifs.log.write('%s' % e)
|
||||
|
||||
ubifs.log.write("%s" % e)
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
def get_ubi_params(ubi):
|
||||
ubi_flags = {'min_io_size': '-m',
|
||||
'max_bud_bytes': '-j',
|
||||
'leb_size': '-e',
|
||||
'default_compr': '-x',
|
||||
'sub_page_size': '-s',
|
||||
'fanout': '-f',
|
||||
'key_hash': '-k',
|
||||
'orph_lebs': '-p',
|
||||
'log_lebs': '-l',
|
||||
'max_leb_cnt': '-c',
|
||||
'peb_size': '-p',
|
||||
'sub_page_size': '-s',
|
||||
'vid_hdr_offset': '-O',
|
||||
'version': '-x',
|
||||
'image_seq': '-Q',
|
||||
'alignment': '-a',
|
||||
'vol_id': '-n',
|
||||
'name': '-N'}
|
||||
ubi_flags = {
|
||||
"min_io_size": "-m",
|
||||
"max_bud_bytes": "-j",
|
||||
"leb_size": "-e",
|
||||
"default_compr": "-x",
|
||||
"sub_page_size": "-s",
|
||||
"fanout": "-f",
|
||||
"key_hash": "-k",
|
||||
"orph_lebs": "-p",
|
||||
"log_lebs": "-l",
|
||||
"max_leb_cnt": "-c",
|
||||
"peb_size": "-p",
|
||||
"sub_page_size": "-s",
|
||||
"vid_hdr_offset": "-O",
|
||||
"version": "-x",
|
||||
"image_seq": "-Q",
|
||||
"alignment": "-a",
|
||||
"vol_id": "-n",
|
||||
"name": "-N",
|
||||
}
|
||||
ubi_params = {}
|
||||
ubi_args = {}
|
||||
ini_params = {}
|
||||
@@ -52,41 +56,55 @@ def get_ubi_params(ubi):
|
||||
for volume in image.volumes:
|
||||
ubi_args[img_seq][volume] = {}
|
||||
ini_params[img_seq][volume] = {}
|
||||
ini_params[img_seq][volume]['vol_type'] = PRINT_VOL_TYPE_LIST[image.volumes[volume].vol_rec.vol_type]
|
||||
ini_params[img_seq][volume]["vol_type"] = PRINT_VOL_TYPE_LIST[
|
||||
image.volumes[volume].vol_rec.vol_type
|
||||
]
|
||||
if image.volumes[volume].vol_rec.flags == UBI_VTBL_AUTORESIZE_FLG:
|
||||
ini_params[img_seq][volume]['vol_flags'] = 'autoresize'
|
||||
ini_params[img_seq][volume]["vol_flags"] = "autoresize"
|
||||
else:
|
||||
ini_params[img_seq][volume]['vol_flags'] = image.volumes[volume].vol_rec.flags
|
||||
ini_params[img_seq][volume]['vol_id'] = image.volumes[volume].vol_id
|
||||
ini_params[img_seq][volume]['vol_name'] = image.volumes[volume].name.rstrip(
|
||||
'\x00')
|
||||
ini_params[img_seq][volume]['vol_alignment'] = image.volumes[volume].vol_rec.alignment
|
||||
ini_params[img_seq][volume]['vol_size'] = image.volumes[volume].vol_rec.reserved_pebs * ubi.leb_size
|
||||
ini_params[img_seq][volume]["vol_flags"] = image.volumes[
|
||||
volume
|
||||
].vol_rec.flags
|
||||
ini_params[img_seq][volume]["vol_id"] = image.volumes[volume].vol_id
|
||||
ini_params[img_seq][volume]["vol_name"] = image.volumes[volume].name.rstrip(
|
||||
"\x00")
|
||||
ini_params[img_seq][volume]["vol_alignment"] = image.volumes[
|
||||
volume
|
||||
].vol_rec.alignment
|
||||
ini_params[img_seq][volume]["vol_size"] = (
|
||||
image.volumes[volume].vol_rec.reserved_pebs * ubi.leb_size
|
||||
)
|
||||
ufsfile = leb_virtual_file(ubi, image.volumes[volume])
|
||||
uubifs = ubifs(ufsfile)
|
||||
for key, value in uubifs.superblock_node:
|
||||
if key == 'key_hash':
|
||||
if key == "key_hash":
|
||||
value = PRINT_UBIFS_KEY_HASH[value]
|
||||
elif key == 'default_compr':
|
||||
elif key == "default_compr":
|
||||
value = PRINT_UBIFS_COMPR[value]
|
||||
if key in ubi_flags:
|
||||
ubi_args[img_seq][volume][key] = value
|
||||
|
||||
for key, value in image.volumes[volume].vol_rec:
|
||||
if key == 'name':
|
||||
value = value.rstrip('\x00')
|
||||
if key == "name":
|
||||
value = value.rstrip("\x00")
|
||||
if key in ubi_flags:
|
||||
ubi_args[img_seq][volume][key] = value
|
||||
|
||||
ubi_args[img_seq][volume]['version'] = image.version
|
||||
ubi_args[img_seq][volume]['vid_hdr_offset'] = image.vid_hdr_offset
|
||||
ubi_args[img_seq][volume]['sub_page_size'] = ubi_args[img_seq][volume]['vid_hdr_offset']
|
||||
ubi_args[img_seq][volume]['sub_page_size'] = ubi_args[img_seq][volume]['vid_hdr_offset']
|
||||
ubi_args[img_seq][volume]['image_seq'] = image.image_seq
|
||||
ubi_args[img_seq][volume]['peb_size'] = ubi.peb_size
|
||||
ubi_args[img_seq][volume]['vol_id'] = image.volumes[volume].vol_id
|
||||
ubi_params[img_seq][volume] = {'flags': ubi_flags,
|
||||
'args': ubi_args[img_seq][volume],
|
||||
'ini': ini_params[img_seq][volume]}
|
||||
ubi_args[img_seq][volume]["version"] = image.version
|
||||
ubi_args[img_seq][volume]["vid_hdr_offset"] = image.vid_hdr_offset
|
||||
ubi_args[img_seq][volume]["sub_page_size"] = ubi_args[img_seq][volume][
|
||||
"vid_hdr_offset"
|
||||
]
|
||||
ubi_args[img_seq][volume]["sub_page_size"] = ubi_args[img_seq][volume][
|
||||
"vid_hdr_offset"
|
||||
]
|
||||
ubi_args[img_seq][volume]["image_seq"] = image.image_seq
|
||||
ubi_args[img_seq][volume]["peb_size"] = ubi.peb_size
|
||||
ubi_args[img_seq][volume]["vol_id"] = image.volumes[volume].vol_id
|
||||
ubi_params[img_seq][volume] = {
|
||||
"flags": ubi_flags,
|
||||
"args": ubi_args[img_seq][volume],
|
||||
"ini": ini_params[img_seq][volume],
|
||||
}
|
||||
|
||||
return ubi_params
|
||||
|
||||
Reference in New Issue
Block a user