Changeset View
Changeset View
Standalone View
Standalone View
contrib/linearize/linearize-data.py
Show All 11 Lines | |||||
import re | import re | ||||
import os | import os | ||||
import os.path | import os.path | ||||
import sys | import sys | ||||
import hashlib | import hashlib | ||||
import datetime | import datetime | ||||
import time | import time | ||||
from collections import namedtuple | from collections import namedtuple | ||||
from binascii import hexlify, unhexlify | from binascii import unhexlify | ||||
settings = {} | settings = {} | ||||
def hex_switchEndian(s): | def hex_switchEndian(s): | ||||
""" Switches the endianness of a hex string (in pairs of hex chars) """ | """ Switches the endianness of a hex string (in pairs of hex chars) """ | ||||
pairList = [s[i:i + 2].encode() for i in range(0, len(s), 2)] | pairList = [s[i:i + 2].encode() for i in range(0, len(s), 2)] | ||||
return b''.join(pairList[::-1]).decode() | return b''.join(pairList[::-1]).decode() | ||||
Show All 35 Lines | def calc_hdr_hash(blk_hdr): | ||||
return hash2_o | return hash2_o | ||||
def calc_hash_str(blk_hdr): | def calc_hash_str(blk_hdr): | ||||
hash = calc_hdr_hash(blk_hdr) | hash = calc_hdr_hash(blk_hdr) | ||||
hash = bufreverse(hash) | hash = bufreverse(hash) | ||||
hash = wordreverse(hash) | hash = wordreverse(hash) | ||||
hash_str = hexlify(hash).decode('utf-8') | hash_str = hash.hex() | ||||
return hash_str | return hash_str | ||||
def get_blk_dt(blk_hdr): | def get_blk_dt(blk_hdr): | ||||
members = struct.unpack("<I", blk_hdr[68:68 + 4]) | members = struct.unpack("<I", blk_hdr[68:68 + 4]) | ||||
nTime = members[0] | nTime = members[0] | ||||
dt = datetime.datetime.fromtimestamp(nTime) | dt = datetime.datetime.fromtimestamp(nTime) | ||||
dt_ym = datetime.datetime(dt.year, dt.month, 1) | dt_ym = datetime.datetime(dt.year, dt.month, 1) | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | def run(self): | ||||
if (not inhdr or (inhdr[0] == "\0")): | if (not inhdr or (inhdr[0] == "\0")): | ||||
self.inF.close() | self.inF.close() | ||||
self.inF = None | self.inF = None | ||||
self.inFn = self.inFn + 1 | self.inFn = self.inFn + 1 | ||||
continue | continue | ||||
inMagic = inhdr[:4] | inMagic = inhdr[:4] | ||||
if (inMagic != self.settings['netmagic']): | if (inMagic != self.settings['netmagic']): | ||||
print("Invalid magic: " + hexlify(inMagic).decode('utf-8')) | print("Invalid magic: " + inMagic.hex()) | ||||
return | return | ||||
inLenLE = inhdr[4:] | inLenLE = inhdr[4:] | ||||
su = struct.unpack("<I", inLenLE) | su = struct.unpack("<I", inLenLE) | ||||
inLen = su[0] - 80 # length without header | inLen = su[0] - 80 # length without header | ||||
blk_hdr = self.inF.read(80) | blk_hdr = self.inF.read(80) | ||||
inExtent = BlockExtent( | inExtent = BlockExtent( | ||||
self.inFn, self.inF.tell(), inhdr, blk_hdr, inLen) | self.inFn, self.inF.tell(), inhdr, blk_hdr, inLen) | ||||
▲ Show 20 Lines • Show All 98 Lines • Show Last 20 Lines |