Esempio n. 1
0
 def de(self, encryptedStr):
     if type(encryptedStr) == unicode:
         s = StringIO.StringIO(encryptedStr)
         t = StringIO.StringIO(u"")
         binhex.hexbin(s, t)
         return libs.utils.xorEncryptorUnicode.PEcrypt(self.encKey).Crypt(t)
     raise nonUnicodeError
Esempio n. 2
0
def binhex_dec():
    """Decode with BinHex4."""
    temp_filename = f"temp_{random_key(32)}"
    binhex.hexbin(get("filename").decode(), temp_filename)
    with open(temp_filename, "rb") as infile:
        show("plaintext", infile.read().decode())
    os.unlink(temp_filename)
Esempio n. 3
0
def test():

    try:
        fname1 = tempfile.mktemp()
        fname2 = tempfile.mktemp()
        f = open(fname1, 'w')
    except:
        raise ImportError, "Cannot test binhex without a temp file"

    start = 'Jack is my hero'
    f.write(start)
    f.close()
    
    binhex.binhex(fname1, fname2)
    if verbose:
        print 'binhex'

    binhex.hexbin(fname2, fname1)
    if verbose:
        print 'hexbin'

    f = open(fname1, 'r')
    finish = f.readline()

    if start <> finish:
        print 'Error: binhex <> hexbin'
    elif verbose:
        print 'binhex == hexbin'

    try:
        import os
        os.unlink(fname1)
        os.unlink(fname2)
    except:
        pass
Esempio n. 4
0
def main():
    folder = tempfile.gettempdir()

    local_filename = urllib.request.urlretrieve(
        'http://www.hacker.org/challenge/misc/file.compressed')[0]

    zip_file = pyunpack.Archive(local_filename)
    folder += '/rar'
    zip_file.extractall(folder, auto_create_dir=True)
    rar_filename = get_regular_filename(folder)

    rar_file = pyunpack.Archive(os.path.join(folder, rar_filename))
    folder += '/arj'
    rar_file.extractall(folder, auto_create_dir=True)
    arj_filename = get_regular_filename(folder)

    arj_file = pyunpack.Archive(os.path.join(folder, arj_filename))
    folder += '/cab'
    arj_file.extractall(folder, auto_create_dir=True)
    cab_filename = get_regular_filename(folder)

    cab_file = pyunpack.Archive(os.path.join(folder, cab_filename))
    folder += '/hqx'
    cab_file.extractall(folder, auto_create_dir=True)
    hqx_filename = get_regular_filename(folder)

    hqx_path = os.path.join(folder, hqx_filename)
    folder += '/sitx'
    os.makedirs(folder, exist_ok=True)
    os.chdir(folder)
    binhex.hexbin(hqx_path, None)
    sitx_filename = get_regular_filename(folder)

    sitx_path = os.path.join(folder, sitx_filename)
    folder += '/gz'
    os.makedirs(folder, exist_ok=True)
    os.chdir(folder)
    subprocess.run(['unar', '-f', sitx_path], stdout=open(os.devnull, 'w'))
    gz_filename = get_regular_filename(folder)

    gz_file = pyunpack.Archive(os.path.join(folder, gz_filename))
    folder += '/bz2'
    gz_file.extractall(folder, auto_create_dir=True)
    bz2_filename = get_regular_filename(folder)

    bz2_file = pyunpack.Archive(os.path.join(folder, bz2_filename))
    folder += '/7z'
    bz2_file.extractall(folder, auto_create_dir=True)
    _7z_filename = get_regular_filename(folder)

    _7z_file = pyunpack.Archive(os.path.join(folder, _7z_filename))
    folder += '/txt'
    _7z_file.extractall(folder, auto_create_dir=True)
    txt_filename = get_regular_filename(folder)

    print(open(os.path.join(folder, txt_filename)).read())
Esempio n. 5
0
 def __call__(self, path, target):
     """Decode C{path} into C{target} using the C{binhex} module.
     @todo: Confirm that this will always extract within C{target}"""
     import binhex
     cwd = os.getcwd()
     try:
         os.chdir(target)
         binhex.hexbin(path)
     finally:
         os.chdir(cwd)
Esempio n. 6
0
 def test_binhex(self):
     f = open(self.fname1, 'wb')
     f.write(self.DATA)
     f.close()
     binhex.binhex(self.fname1, self.fname2)
     binhex.hexbin(self.fname2, self.fname1)
     f = open(self.fname1, 'rb')
     finish = f.readline()
     f.close()
     self.assertEqual(self.DATA, finish)
Esempio n. 7
0
 def __call__(self, path, target):
     """Decode C{path} into C{target} using the C{binhex} module.
     @todo: Confirm that this will always extract within C{target}"""
     import binhex
     cwd = os.getcwd()
     try:
         os.chdir(target)
         binhex.hexbin(path)
     finally:
         os.chdir(cwd)
 def test_binhex_encode_decode(self, payload):
     with TemporaryDirectory() as dirname:
         input_file_name = os.path.join(dirname, "input.txt")
         encoded_file_name = os.path.join(dirname, "encoded.hqx")
         decoded_file_name = os.path.join(dirname, "decoded.txt")
         with open(input_file_name, "wb") as input_file:
             input_file.write(payload)
         binhex.binhex(input_file_name, encoded_file_name)
         binhex.hexbin(encoded_file_name, decoded_file_name)
         with open(decoded_file_name, "rb") as decoded_file:
             decoded_payload = decoded_file.read()
         assert payload == decoded_payload
Esempio n. 9
0
    def test_binhex(self):
        with open(self.fname1, 'wb') as f:
            f.write(self.DATA)

        binhex.binhex(self.fname1, self.fname2)

        binhex.hexbin(self.fname2, self.fname1)

        with open(self.fname1, 'rb') as f:
            finish = f.readline()

        self.assertEqual(self.DATA, finish)
Esempio n. 10
0
    def test_binhex(self):
        with open(self.fname1, 'wb') as f:
            f.write(self.DATA)

        binhex.binhex(self.fname1, self.fname2)

        binhex.hexbin(self.fname2, self.fname1)

        with open(self.fname1, 'rb') as f:
            finish = f.readline()

        self.assertEqual(self.DATA, finish)
Esempio n. 11
0
def func(foo, bar, baz, bang, foobang, foobar, foobazbar, foobazbarbang):
    return foobang

    import asynchat
    obj = asynchat.async_chat()
    obj.collect_incoming_data()
    import _winreg
    _winreg.CreateKey()
    import binhex
    binhex.hexbin()

    if foobazbar < 5:
        pass
Esempio n. 12
0
def func(foo, bar, baz, bang, foobang, foobar, foobazbar, foobazbarbang):
    return foobang
    
    import asynchat
    obj = asynchat.async_chat()
    obj.collect_incoming_data()
    import _winreg
    _winreg.CreateKey()
    import binhex
    binhex.hexbin()
    
    if foobazbar < 5:
        pass
Esempio n. 13
0
    def test_binhex(self):
        f = open(self.fname1, 'wb')
        f.write(self.DATA)
        f.close()

        binhex.binhex(self.fname1, self.fname2)

        binhex.hexbin(self.fname2, self.fname1)

        f = open(self.fname1, 'rb')
        finish = f.readline()
        f.close()

        self.assertEqual(self.DATA, finish)
Esempio n. 14
0
    def test_binhex(self):
        f = open(self.fname1, 'w')
        f.write(self.DATA)
        f.close()
        if not test_support.due_to_ironpython_bug("http://tkbgitvstfat01:8080/WorkItemTracking/WorkItem.aspx?artifactMoniker=317834"):
            binhex.binhex(self.fname1, self.fname2)

            binhex.hexbin(self.fname2, self.fname1)

        f = open(self.fname1, 'r')
        finish = f.readline()
        f.close()

        self.assertEqual(self.DATA, finish)
Esempio n. 15
0
def fuzz(workfile_in, workfile_out):
    # Only copy the first 8 kilobytes to limit the corpus file sizes:
    with open(sys.argv[1], "rb") as ifp, open(workfile_in, "wb") as ofp:
        ofp.write(ifp.read(8 * 1024))

    try:
        binhex.hexbin(workfile_in, "/dev/null")
    except binhex.Error:
        pass

    with open(workfile_in, "rb") as fp:
        data = fp.read()
    out_hex = CloseIgnoringBytesIO()
    binhex.binhex(workfile_in, out_hex)
    infile = io.BytesIO(out_hex.getvalue())
    binhex.hexbin(infile, workfile_out)
    with open(workfile_out, "rb") as fp:
        data_new = fp.read()
    assert data == data_new
Esempio n. 16
0
    def run(cls, _input: Decodable, **kwargs) -> Optional[bytes]:
        """Decodes binhex encoded bytes-like object or a string.

        :param _input: String or bytes
        :param kwargs:
        :return: Bytes string if decoded successfully, else None
        """
        if isinstance(_input, str):
            _input = bytes(_input, "utf8")

        p = os.path.join(tempfile.gettempdir(),
                         tempfile.gettempprefix() + "bhx123")
        try:
            binhex.hexbin(BytesIO(_input), p)
            with open(p, "rb") as tf:
                return tf.read()
        except:
            return None
        finally:
            try:
                os.remove(p)
            except:
                pass
Esempio n. 17
0
def test():

    try:
        fname1 = tempfile.mktemp()
        fname2 = tempfile.mktemp()
        f = open(fname1, 'w')
    except:
        raise TestSkipped, "Cannot test binhex without a temp file"

    start = 'Jack is my hero'
    f.write(start)
    f.close()

    binhex.binhex(fname1, fname2)
    if verbose:
        print 'binhex'

    binhex.hexbin(fname2, fname1)
    if verbose:
        print 'hexbin'

    f = open(fname1, 'r')
    finish = f.readline()
    f.close()   # on Windows an open file cannot be unlinked

    if start != finish:
        print 'Error: binhex != hexbin'
    elif verbose:
        print 'binhex == hexbin'

    try:
        import os
        os.unlink(fname1)
        os.unlink(fname2)
    except:
        pass
Esempio n. 18
0
#! /usr/bin/env python
Esempio n. 19
0
import binhex
import time
password = '******'
youpass = input("Enter the password :"******"Enter the infile name :"))
	outfilename = str(input("Enter the outfile name :"))
	binhex.hexbin(infilename,outfilename)
Esempio n. 20
0
#! /usr/bin/env python
Esempio n. 21
0
 def update_event(self, inp=-1):
     self.set_output_val(0, binhex.hexbin(self.input(0), self.input(1)))