Beispiel #1
0
    def inject_file(imagepath: str, secretpath: str, outputpath: str):

        secretfilename = basename(secretpath).encode()

        with open(secretpath, "rb") as f:
            secretdata = f.read()

        header = bytearray(b"\0" * 128)
        header[0:4] = pack("<I", len(secretdata))
        header[4:4 + len(secretfilename)] = secretfilename
        header = header[:128]  # cap anything that's too long

        pixelmanipulator = PixelManipulator(imagepath)

        maxfilesize = (pixelmanipulator.get_maximum_size() - 128)
        if maxfilesize < len(secretdata):
            print(
                "The target container is too small for the secret. Maximum file size is",
                maxfilesize, "bytes")
            sys.exit(1)

        bitfactory = BitFactory(secretdata)

        pixelmanipulator.apply_bits(header, bitfactory)
        pixelmanipulator.save(outputpath)
Beispiel #2
0
    def inject_file(imagepath: str, secretpath: str, outputpath: str):

        secretfilename = basename(secretpath).encode()

        with open(secretpath, "rb") as f:
            secretdata = f.read()

        header = bytearray(b"\0" * 128)
        header[0:4] = pack("<I", len(secretdata))
        header[4:4 + len(secretfilename)] = secretfilename
        header = header[:128]  # cap anything that's too long

        pixelmanipulator = PixelManipulator(imagepath)

        maxfilesize = (pixelmanipulator.get_maximum_size() - 128)
        if maxfilesize < len(secretdata):
            print("The target container is too small for the secret. Maximum file size is", maxfilesize, "bytes")
            sys.exit(1)

        bitfactory = BitFactory(secretdata)

        pixelmanipulator.apply_bits(header, bitfactory)
        pixelmanipulator.save(outputpath)