From ca4cc1a4eca22982b32819194000b5fc2089274f Mon Sep 17 00:00:00 2001 From: Jason Pruitt Date: Thu, 25 Mar 2021 21:11:48 -0700 Subject: [PATCH] Updated ubifs/defines.py with latest node fields --- ubireader/ubifs/defines.py | 266 ++++++++++++++++++++++--------------- ubireader/ubifs/display.py | 22 +++ 2 files changed, 184 insertions(+), 104 deletions(-) diff --git a/ubireader/ubifs/defines.py b/ubireader/ubifs/defines.py index bb423b0..1520706 100644 --- a/ubireader/ubifs/defines.py +++ b/ubireader/ubifs/defines.py @@ -156,31 +156,38 @@ UBIFS_FL_MASK = 0x0000001F # Compression alogrithms. -UBIFS_COMPR_NONE = 0 # No compression -UBIFS_COMPR_LZO = 1 # LZO compression -UBIFS_COMPR_ZLIB = 2 # ZLIB compression -UBIFS_COMPR_TYPES_CNT = 3 # Count of supported compression types -PRINT_UBIFS_COMPR = ['none','lzo','zlib'] +UBIFS_COMPR_NONE = 0 # No compression +UBIFS_COMPR_LZO = 1 # LZO compression +UBIFS_COMPR_ZLIB = 2 # ZLIB compression +UBIFS_COMPR_ZSTD = 3 # ZSTD compression +UBIFS_COMPR_TYPES_CNT = 4 # Count of supported compression types +PRINT_UBIFS_COMPR = ['none','lzo','zlib', 'zstd'] # UBIFS node types -UBIFS_INO_NODE = 0 # Inode node -UBIFS_DATA_NODE = 1 # Data node -UBIFS_DENT_NODE = 2 # Directory entry node -UBIFS_XENT_NODE = 3 # Extended attribute node -UBIFS_TRUN_NODE = 4 # Truncation node -UBIFS_PAD_NODE = 5 # Padding node -UBIFS_SB_NODE = 6 # Superblock node -UBIFS_MST_NODE = 7 # Master node -UBIFS_REF_NODE = 8 # LEB reference node -UBIFS_IDX_NODE = 9 # Index node -UBIFS_CS_NODE = 10 # Commit start node -UBIFS_ORPH_NODE = 11 # Orphan node -UBIFS_NODE_TYPES_CNT = 12 # Count of supported node types +UBIFS_INO_NODE = 0 # Inode node +UBIFS_DATA_NODE = 1 # Data node +UBIFS_DENT_NODE = 2 # Directory entry node +UBIFS_XENT_NODE = 3 # Extended attribute node +UBIFS_TRUN_NODE = 4 # Truncation node +UBIFS_PAD_NODE = 5 # Padding node +UBIFS_SB_NODE = 6 # Superblock node +UBIFS_MST_NODE = 7 # Master node +UBIFS_REF_NODE = 8 # LEB reference node +UBIFS_IDX_NODE = 9 # Index node +UBIFS_CS_NODE = 10 # Commit start node +UBIFS_ORPH_NODE = 11 # Orphan node +UBIFS_AUTH_NODE = 12 # Authentication node +UBIFS_SIG_NODE = 13 # Signature node +UBIFS_NODE_TYPES_CNT = 14 # Count of supported node types # Master node flags -UBIFS_MST_DIRTY = 1 # Rebooted uncleanly -UBIFS_MST_NO_ORPHS = 2 # No orphans present -UBIFS_MST_RCVRY = 4 # Written by recovery +UBIFS_MST_DIRTY = 1 # Rebooted uncleanly +UBIFS_MST_NO_ORPHS = 2 # No orphans present +UBIFS_MST_RCVRY = 4 # Written by recovery +PRINT_UBIFS_MST = [[UBIFS_MST_DIRTY, 'Dirty'], + [UBIFS_MST_NO_ORPHS, 'No orphans'], + [UBIFS_MST_RCVRY, 'Recovery write'], + ] # Node group type UBIFS_NO_NODE_GROUP = 0 # This node is not part of a group @@ -188,21 +195,30 @@ UBIFS_LAST_OF_NODE_GROUP = 2 # This node is the last in a group # Superblock flags -UBIFS_FLG_BIGLPT = 2 # if 'big' LPT model is used if set. -UBIFS_FLG_SPACE_FIXUP = 4 # first-mount 'fixup' of free space within - +UBIFS_FLG_BIGLPT = 2 # If 'big' LPT model is used if set. +UBIFS_FLG_SPACE_FIXUP = 4 # First-mount 'fixup' of free space within. +UBIFS_FLG_DOUBLE_HASH = 8 # Store 32bit cookie for 64bit support. +UBIFS_FLG_ENCRYPTION = 16 # If filesystem contains encrypted files. +UBIFS_FLG_AUTHENTICATION = 32 # If contains hashes for authentication. +PRINT_UBIFS_FLGS = [[UBIFS_FLG_BIGLPT, 'Big LPT'], + [UBIFS_FLG_SPACE_FIXUP, 'Space fixup'], + [UBIFS_FLG_DOUBLE_HASH, 'Double hash'], + [UBIFS_FLG_ENCRYPTION, 'Encryption'], + [UBIFS_FLG_AUTHENTICATION,'Authentication'], + ] # Struct defines # Common header node UBIFS_COMMON_HDR_FORMAT = '. ############################################################# +from ubireader.ubifs.defines import PRINT_UBIFS_FLGS, PRINT_UBIFS_MST def ubifs(ubifs, tab=''): buf = '%sUBIFS Image\n' % (tab) @@ -51,6 +52,17 @@ def sb_node(node, tab=''): buf += '%s%s: %s\n' % (tab, key, ','.join(value)) elif key == 'uuid': buf += '%s%s: %r\n' % (tab, key, value) + elif key == 'flags': + flags = '' + for flag in PRINT_UBIFS_FLGS: + if value & flag[0]: + flags += '%s, ' % flag[1] + + if flags.endswith(', '): + flags = flags[0:-2] + + buf += '%s%s: %s\n' % (tab, key, flags) + else: buf += '%s%s: %r\n' % (tab, key, value) return buf @@ -66,6 +78,16 @@ def mst_node(node, tab=''): continue elif key == 'errors': buf += '%s%s: %s\n' % (tab, key, ','.join(value)) + elif key == 'flags': + flags = '' + for flag in PRINT_UBIFS_MST: + if value & flag[0]: + flags += '%s, ' % flag[1] + + if flags.endswith(', '): + flags = flags[0:-2] + + buf += '%s%s: %s\n' % (tab, key, flags) else: buf += '%s%s: %r\n' % (tab, key, value) return buf