-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parse the 'hash' field after 'key' in IDX:branch block #97
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,7 +160,9 @@ def __init__(self, buf): | |
setattr(self, key, fields[key]) | ||
|
||
idxs = UBIFS_IDX_NODE_SZ | ||
brs = UBIFS_BRANCH_SZ | ||
# Dynamic detection of `brs` (branch size), whether a hash is present after | ||
# the key in authenticated UBIFS. Not checking the len of the hash. | ||
brs = int((len(buf) - UBIFS_IDX_NODE_SZ) / self.child_cnt) | ||
setattr(self, 'branches', [branch(buf[idxs+(brs*i):idxs+(brs*i)+brs]) for i in range(0, self.child_cnt)]) | ||
setattr(self, 'errors', []) | ||
|
||
|
@@ -183,13 +185,16 @@ class branch(object): | |
Bin:buf -- Raw data to extract header information from. | ||
""" | ||
def __init__(self, buf): | ||
fields = dict(list(zip(UBIFS_BRANCH_FIELDS, struct.unpack(UBIFS_BRANCH_FORMAT, buf)))) | ||
fields = dict(list(zip(UBIFS_BRANCH_FIELDS, struct.unpack(UBIFS_BRANCH_FORMAT, buf[0:UBIFS_BRANCH_SZ])))) | ||
for key in fields: | ||
if key == 'key': | ||
setattr(self, key, parse_key(fields[key])) | ||
else: | ||
setattr(self, key, fields[key]) | ||
|
||
if len(buf) > (UBIFS_BRANCH_SZ): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For no reason. I forgot to remove them. (Maybe in a previous iteration, this was I'll remove those unneeded parentheses. |
||
setattr(self, 'hash', buf[UBIFS_BRANCH_SZ:]) | ||
|
||
setattr(self, 'errors', []) | ||
|
||
def __repr__(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
int
casting is hiding low-level details. Do you want to round up or round down ? It would be cleaner withmath.floor
ormath.ceil
, depending on implementation details. You can also use//
instead of/
if you want to round down.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
//
is what I was trying to achieve. In theory, if the UBIFS image is correctly formatted, the division byself.child_cnt
has no remainder. Myint( ... )
was a clumsy attempt to get rid of the.0
in the result of the division. (Becausebrs
needs to be an int, not a float.)I'll use
//
instead. I'll also rewrite the comment, because I'm having a hard time to understand myself after a few months.