Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy,scipy.misc, os, array, argparse
- ap = argparse.ArgumentParser()
- ap.add_argument("-p", "--path", required=True,
- help="path to the binaries")
- args = vars(ap.parse_args())
- count = 0
- root = args["path"]
- def convert(root):
- for _, _, files in os.walk(root):
- for file in files:
- filepath = os.path.join(root, file)
- f = open(filepath, 'rb')
- ln = os.path.getsize(filepath); # length of file in bytes
- width = 256; # depends on file size
- rem = ln % width;
- a = array.array("B"); # uint8 array
- a.fromfile(f, ln - rem);
- f.close();
- img = numpy.reshape(a, (len(a) / width, width));
- img = numpy.uint8(img);
- scipy.misc.imsave(filepath + '.png', img);
- if __name__ == '__main__':
- convert(args['path'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement