This repository has been archived by the owner on Apr 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
669 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
import argparse | ||
|
||
from . import main, extract | ||
from . import extract | ||
|
||
def wc(path): | ||
with open(path) as f: | ||
for i, l in enumerate(f): | ||
|
||
def line_count(path): | ||
i = 0 | ||
with open(path) as lines: | ||
for i, _ in enumerate(lines): | ||
pass | ||
return i + 1 | ||
|
||
|
||
def test_parse(): | ||
extract(argparse.Namespace(carver='apsb', export=['bodyfile', 'files'], image='test/wsdf.dmg', log='INFO', method='parse', offset=40)) | ||
extract( | ||
argparse.Namespace( | ||
carver='apsb', export=['bodyfile', 'files'], image='test/wsdf.dmg', log='INFO', method='parse', offset=40)) | ||
|
||
# should extract 290 items | ||
assert 26 == wc('test/wsdf.dmg.parse.bodyfile') | ||
assert line_count('test/wsdf.dmg.parse.bodyfile') == 26 | ||
|
||
|
||
def test_carve(): | ||
extract(argparse.Namespace(carver='apsb', export=['bodyfile', 'files'], image='test/wsdf.dmg', log='INFO', method='carve', offset=40)) | ||
extract( | ||
argparse.Namespace( | ||
carver='apsb', export=['bodyfile', 'files'], image='test/wsdf.dmg', log='INFO', method='carve', offset=40)) | ||
|
||
# should extract 290 items | ||
assert 290 == wc('test/wsdf.dmg.carve_apsb.bodyfile') | ||
assert line_count('test/wsdf.dmg.carve_apsb.bodyfile') == 290 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
|
||
|
||
def get_block(idx, block_size, file_io): | ||
""" Get data of a single block """ | ||
file_io.seek(idx * block_size) | ||
return file_io.read(block_size) | ||
return file_io.read(block_size) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,33 @@ | ||
import numpy as np | ||
|
||
|
||
def create_checksum(data): | ||
sum1 = np.uint64(0) | ||
sum2 = np.uint64(0) | ||
|
||
modValue = np.uint64(4294967295) # 2<<31 - 1 | ||
mod_value = np.uint64(4294967295) # 2<<31 - 1 | ||
|
||
for i in range(int(len(data)/4)): | ||
dt = np.dtype(np.uint32) | ||
dt = dt.newbyteorder('L') | ||
d = np.frombuffer(data[i*4:(i+1)*4], dtype=dt) | ||
for i in range(int(len(data) / 4)): | ||
dtype = np.dtype(np.uint32) | ||
dtype = dtype.newbyteorder('L') | ||
data = np.frombuffer(data[i * 4:(i + 1) * 4], dtype=dtype) | ||
|
||
sum1 = (sum1 + np.uint64(d)) % modValue | ||
sum2 = (sum2 + sum1) % modValue | ||
sum1 = (sum1 + np.uint64(data)) % mod_value | ||
sum2 = (sum2 + sum1) % mod_value | ||
|
||
check1 = modValue - ((sum1 + sum2) % modValue) | ||
check2 = modValue - ((sum1 + check1) % modValue) | ||
check1 = mod_value - ((sum1 + sum2) % mod_value) | ||
check2 = mod_value - ((sum1 + check1) % mod_value) | ||
|
||
return (check2 << 32) | check1 | ||
|
||
|
||
def check_checksum(data): | ||
dt = np.dtype(np.uint64) | ||
dt = dt.newbyteorder('L') | ||
return (np.frombuffer(data[:8], dtype=dt) == create_checksum(data[8:]))[0] | ||
dtype = np.dtype(np.uint64) | ||
dtype = dtype.newbyteorder('L') | ||
return (np.frombuffer(data[:8], dtype=dtype) == create_checksum(data[8:]))[0] | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
with open('test.blk', 'rb') as io: | ||
data = io.read() | ||
print(check_checksum(data)) | ||
print(check_checksum(io.read())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.