Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix incorrectly appended byte, add support for python3. #759

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions tools/pump.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
"""
File pumper. Increase file size with null byte(s) at the end of the file.
"""

import sys
#python fpump.py [file] [size] [-mb/-kb]
import os

# python pump.py [file] [size] [-mb/-kb]

# Also refer to KiB/MiB
KB = 1024
MB = KB * 1024

if len(sys.argv) < 4:
sys.exit('[-] Missing argument!\n[+] Usage: python pumper.py [file] [size] [-mb/-kb]')
sys.stderr.write('[-] Missing argument!\n')
sys.stderr.write('[+] Usage: python pumper.py [file] [size] [-mb/-kb]\n')
exit(1)

fp = sys.argv[1]
fileName = sys.argv[1]
size = int(sys.argv[2])
tp = sys.argv[3]
unit = sys.argv[3]

if not os.path.exists(fileName):
sys.stderr.write('[-] File {!r} is not exists!\n'.format(fileName))
exit(1)

f = open(fp, 'ab')
if tp == '-kb':
b_size = size * 1024
elif tp == '-mb':
b_size = size * 1048576
else:
sys.exit('[-] Use -mb or -kb!')
if unit != '-mb' and unit != '-kb':
sys.stderr.write('[-] Use -mb or -kb!\n')
exit(1)

bufferSize = 256
for i in range(b_size/bufferSize):
f.write(str('0' * bufferSize))
with open(fileName, 'ab') as fp:
if unit == '-kb':
blockSize = size * KB
elif unit == '-mb':
blockSize = size * MB

f.close()
bufferSize = 256
for i in range(blockSize // bufferSize):
fp.write(('\0' * bufferSize).encode('utf-8'))

print '[+] Finished pumping', fp, 'with', size, tp
print('[+] Finished pumping {!r} with {}{}'.format(fileName, size, unit[1:]))