Skip to content

Commit

Permalink
Add verbosity, ignore phantom slices, small important bugfix
Browse files Browse the repository at this point in the history
Sometimes code reuse is a Bad Thing(tm).  The masking step for "next" was
needed, but that should be rounding *down* and *not* up.  Ignore phantom
slices if asked to turn them into chunks, most likely they would be
requested by running with `image2chunks *` so this seems the right
approach.

Add verbosity.  A rather important part of UI design is you want to
provide feedback and indications you're doing something.  While the data
output isn't too crucial, it at least hints we're actively doing
something.
  • Loading branch information
Elliott Mitchell authored and ehem committed Oct 25, 2016
1 parent 1aca64c commit 984b92c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions image2chunks.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def loadParams(self, name):
self.paramsFile.close()
del self.paramsFile

if 'phantom' in params and params['phantom']:
print("[!] {:s} is a phantom slice, skipping!".format(name))
return False

for k in 'blockShift', 'startLBA', 'endLBA', 'lastWipe':
if k not in params:
print("Parameter value \"{:s}\" is missing, unable to continue".format(k))
Expand All @@ -91,6 +95,8 @@ def loadParams(self, name):
self.endLBA = params['endLBA']
self.lastWipe = params['lastWipe']

return True


def makeChunks(self, name):
"""
Expand All @@ -111,18 +117,22 @@ def makeChunks(self, name):
hole = (self.file.seek(current, SEEK_HOLE) + self.blockSize-1) & ~(self.blockSize-1)
# Python's handling of this condition is suboptimal
try:
next = (self.file.seek(hole, SEEK_DATA) + self.blockSize-1) & ~(self.blockSize-1)
next = self.file.seek(hole, SEEK_DATA) & ~(self.blockSize-1)
wipeCount = (next - current) >> self.blockShift
except IOError:
next = eof
wipeCount = self.lastWipe - targetAddr

md5 = hashlib.md5()
crc = crc32(b"")
zobj = zlib.compressobj(1)
self.file.seek(current, io.SEEK_SET)

chunkName = baseName + str(targetAddr) + ".bin"
out = io.FileIO(chunkName + ".chunk", "wb")

print("[+] Compressing {:s} to {:s} ({:d} empty blocks)".format(name, chunkName, (next - hole) >> self.blockShift))

chunkName = chunkName.encode("utf8")
out.seek(self._dz_length, io.SEEK_SET)
zlen = 0
Expand Down Expand Up @@ -162,6 +172,8 @@ def makeChunks(self, name):
current = next
targetAddr = self.startLBA + (current >> self.blockShift)

print("[+] done\n")


def __init__(self, name):
"""
Expand All @@ -172,9 +184,9 @@ def __init__(self, name):

self.openFiles(name)

self.loadParams(name)
if self.loadParams(name):

self.makeChunks(name)
self.makeChunks(name)


if __name__ == "__main__":
Expand Down

0 comments on commit 984b92c

Please sign in to comment.