def simpleDecode(openPath, zeroTerm=True, file=None):
	"""decode data from an text file using homoglyphs

	Args:
		openPath (string): path to the stego-text file to decode
		zeroTerm (boolean, optional): stop decoding on \x00 (NUL). Defaults to True.
		file (<file>, optional): file pointer. Defaults to None.

	Returns:
		bytes: data from the text file
	"""
	with open(openPath, encoding="utf-8") as openData:
		fileData = openData.read()
	position = 0
	data = []
	for _char in fileData:
		byte = 0
		shift = 0
		while shift < 8:
			byte, shift = decodeGlyph(fileData, position, byte, shift)
			position += 1
		if byte == 0 and zeroTerm:
			break
		data.append(byte)
	result = bytes(data)
	return toFile(result, file) if file else result
def decode(openPath, mapSeed, password="", zeroTerm=True, file=None):
	"""decode data from an text file using homoglyphs

	Args:
		openPath (string): path to the stego-text file to decode
		mapSeed (string): seed to generate the lsb map
		password (str, optional): password to encrypt the data with. Defaults to "".
		zeroTerm (boolean, optional): stop decoding on \x00 (NUL). Defaults to True.
		file (<file>, optional): file pointer. Defaults to None.

	Returns:
		bytes: data from the text file
	"""
	with open(openPath, encoding="utf-8") as openData:
		fileData = openData.read()
	position = 0
	data = []
	decodeMap = getMap(fileData, mapSeed)
	for _char in fileData:
		byte = 0
		shift = 0
		while shift < 8:
			if decodeMap[position] > 0:
				byte, shift = decodeGlyph(fileData, position, byte, shift)
			position += 1
		if byte == 0 and zeroTerm:
			break
		data.append(byte)
	result = otp(bytes(data), password, False)
	return toFile(result, file) if file else result
Exemple #3
0
    def decode(self, mapSeed, password="", zeroTerm=True, file=None):
        """decode data from an array using lsb steganography

		Args:
		mapSeed (string): seed to generate the lsb map
		password (str, optional): password to encrypt the data with. Defaults to "".
		zeroTerm (boolean, optional): stop decoding on \x00 (NUL). Defaults to True.
		file (<file>, optional): file pointer. Defaults to None.

		Returns:
		bytes: data from the image
		"""
        lsbMap = getMap(self.array, mapSeed)
        data = []
        while self.pointer in range(self.arrayLen):
            byte = 0
            shift = 0
            while shift < 8:
                if lsbMap[self.pointer] > 0:
                    bit = self.getLsb()  # Little endian
                    byte += bit << shift
                    shift += 1
                else:
                    self.pointer += 1  # Increment pointer anyway
            if byte == 0 and zeroTerm:
                break
            data.append(byte)
        result = otp(bytes(data), password, False)
        return toFile(result, file) if file else result
Exemple #4
0
def decodeFile(openPath, password="", filePointer=None):
    """ decode data as a file """
    # Look for "/*.[* not .xml]" or "/application.xml"
    with ZipFile(openPath, "r", compression=ZIP_DEFLATED) as zipFile:
        files = []
        for file in zipFile.namelist():
            if not file.endswith(
                (".xml", "mimetype")) or file.endswith("application.xml"):
                files.append(file)
        with zipFile.open(files[0], "r") as dataFile:
            data = otp(dataFile.read(), password, False)
        return toFile(data, filePointer) if filePointer else data
Exemple #5
0
    def simpleDecode(self, zeroTerm=True, file=None):
        """ decode a flat array with no encryption

		Args:
		zeroTerm (boolean, optional): stop decoding on \x00 (NUL). Defaults to True.
		file (<file>, optional): file pointer. Defaults to None.
		"""
        data = []
        for _char in range(self.arrayLen // 8):
            char, zero = self.getLsb8()
            if zero and zeroTerm:
                break
            data.append(char)
        result = bytes(data)
        return toFile(result, file) if file else result
def decode(openPath, password="", file=None):
    """decode data from a file by extracting data after end of file

	Args:
		openPath (string): path to the stego-file to decode
		password (str, optional): password to encrypt the data with. Defaults to "".
		file (<file>, optional): file pointer. Defaults to None.

	Returns:
		bytes: data from the image
	"""
    """ decode an image with data """
    data, fileExt = openFile(openPath)
    readData = data[data.find(endKeys[fileExt]) + len(endKeys[fileExt]):]
    result = otp(readData, password, False)
    return toFile(result, file) if file else result
Exemple #7
0
def decodeFile(openPath, password="", filePointer=None):
    """decode data from a microsoft office file by extracting the file

	Args:
		openPath (string): path to the stego-document to decode
		password (str, optional): password to encrypt the data with. Defaults to "".
		filePointer (<file>, optional): pointer to the file. Defaults to None.

	Returns:
		bytes: data from the image
	"""
    # Look for "/docProps/*.[* not .xml]" or "/docProps/application.xml"
    with ZipFile(openPath, "r", compression=ZIP_DEFLATED) as zipFile:
        files = []
        for file in zipFile.namelist():
            if file.startswith("docProps") and (not file.endswith(
                (".xml", ".rels")) or file.endswith("application.xml")):
                files.append(file)
        with zipFile.open(files[0], "r") as dataFile:
            data = otp(dataFile.read(), password, False)
        return toFile(data, filePointer) if filePointer else data
Exemple #8
0
def simpleDecode(openPath, zeroTerm=True, file=None, safe=True):
    """decode data from a text file using zero width chars

	Args:
		openPath (string): path to the stego-text file to decode
		zeroTerm (boolean, optional): stop decoding on \x00 (NUL). Defaults to True.
		file (<file>, optional): file pointer. Defaults to None.
		safe (boolean, optional): use a reduced set of chars to show in fewer
		editors. Defaults to True.

	Returns:
		bytes: data from the text file
	"""
    with open(openPath, "rb") as openData:
        fileData = openData.read()
    position = 0
    data = []
    for _char in fileData:
        position, byte = decodeCharZero(fileData, position, safe)
        if byte == 0 and zeroTerm:
            break
        data.append(byte)
    result = bytes(data)
    return toFile(result, file) if file else result
Exemple #9
0
def decode(openPath,
           mapSeed,
           password="",
           zeroTerm=True,
           file=None,
           safe=True):
    """decode data from a text file using zero width chars

	Args:
		openPath (string): path to the stego-text file to decode
		mapSeed (string): seed to generate the lsb map
		password (str, optional): password to encrypt the data with. Defaults to "".
		zeroTerm (boolean, optional): stop decoding on \x00 (NUL). Defaults to True.
		file (<file>, optional): file pointer. Defaults to None.
		safe (boolean, optional): use a reduced set of chars to show in fewer
		editors. Defaults to True.

	Returns:
		bytes: data from the text file
	"""
    with open(openPath, "rb") as openData:
        fileData = openData.read()
    position = 0
    data = []
    zwcMap = getMap(fileData, mapSeed)
    for _char in fileData:
        if zwcMap[position] > 0:
            position, byte = decodeCharZero(fileData, position, safe)
            if byte == 0 and zeroTerm:
                break
            data.append(byte)
        else:
            position += getUtf8Size(fileData,
                                    position)[0]  # increment by char size
    result = otp(bytes(data), password, False)
    return toFile(result, file) if file else result