forked from idaholab/WiiBin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RollingWindowExtractor.py
60 lines (45 loc) · 1.52 KB
/
RollingWindowExtractor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#Copyright 2020 Battelle Energy Alliance, LLC, ALL RIGHTS RESERVED.
#python RollingWindowSplitPortionExtractor.py <Input Directory> <Output Directory> <Chunk Size in Bytes> <Slide Percent>
import subprocess
import sys
import glob
import random
import os
CGREEN = '\033[92m'
CRED = '\033[91m'
CEND = '\033[0m'
try:
binaries = glob.glob(sys.argv[1] + '*')
except:
print('Argument Error')
sys.exit()
try:
outPath = sys.argv[2]
except:
print('Argument Error')
sys.exit()
if not os.path.exists(sys.argv[2]):
os.makedirs(sys.argv[2])
try:
chunkSize = int(sys.argv[3])
except:
print('Argument Error')
sys.exit()
try:
slidePercent = int(sys.argv[4])
except:
print('Argument Error')
sys.exit()
print(CGREEN + 'Chunking File into ' + str(chunkSize) + 'byte' + ' Pieces' + CEND)
count = 1
totalBinaries = len(binaries)
totalBytes = 0
for i in binaries:
print(CGREEN + '\n(' + str(count) + '/' + str(totalBinaries) + ')' + CEND)
totalBytes = os.path.getsize(i)
currentByte = 0
while currentByte < totalBytes:
subprocess.call('dd if=' + str(i) + ' of=' + outPath + str(i.split(os.sep)[-1]) + '__bytes-'+ str(chunkSize) +'__offset-'+ str(currentByte).zfill(8) +' skip=' + str(currentByte) + ' count=' + str(chunkSize) + ' iflag=skip_bytes,count_bytes', shell=True)
currentByte = int(currentByte + (chunkSize*(int(slidePercent)/100))) #50% slidePercent 1=0%, 2=50%, 4=75%,
count = count + 1
print(CGREEN + '----------- All Completed -------------' + CEND)