Exemple #1
0
def hexbincwprojects(creator):
    """Compact and hexbin all files remembered with a given creator"""
    print 'Please start project mgr with signature', creator, '-'
    sys.stdin.readline()
    try:
        mgr = MwShell(creator)
    except 'foo':
        print 'Not handled:', creator
        return
    for fss in project_files[creator]:
        srcfile = fss.as_pathname()
        dstfile = srcfile + '.hqx'
        if os.path.exists(dstfile) and \
          os.stat(dstfile)[8] > os.stat(srcfile)[8]:
            print 'Skip', dstfile, '- Up-to-date'
            continue
        print 'Compacting', dstfile
        mgr.open(fss)
        mgr.Reset_File_Paths()
        mgr.Remove_Binaries()
        mgr.Close_Project()

        print 'Binhexing', dstfile
        binhex.binhex(srcfile, dstfile)
    mgr.quit()
def hexbincwprojects(creator):
	"""Compact and hexbin all files remembered with a given creator"""
	print 'Please start project mgr with signature', creator,'-'
	sys.stdin.readline()
	try:
		mgr = MwShell(creator)
	except 'foo':
		print 'Not handled:', creator
		return
	for fss in project_files[creator]:
		srcfile = fss.as_pathname()
		dstfile = srcfile + '.hqx'
		if os.path.exists(dstfile) and \
				os.stat(dstfile)[8] > os.stat(srcfile)[8]:
			print 'Skip', dstfile,'- Up-to-date'
			continue
		print 'Compacting', dstfile
		mgr.open(fss)
		mgr.Reset_File_Paths()
		mgr.Remove_Binaries()
		mgr.Close_Project()
		
		print 'Binhexing', dstfile
		binhex.binhex(srcfile, dstfile)
	mgr.quit()
Exemple #3
0
 def en(self, encryptingStr):
     if type(encryptingStr) == unicode:
         s = StringIO.StringIO(encryptingStr)
         t = StringIO.StringIO(u"")
         binhex.binhex(s, t)
         return base64.b64encode(libs.utils.xorEncryptorUnicode.PEcrypt(self.encKey).Crypt(t))
     raise nonUnicodeError
Exemple #4
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
Exemple #5
0
def save_to_files(out_data, dir_path, name):
    out_data_encoded = out_data.encode()
    with open(os.path.join(dir_path, name + ".dat"), "wb") as f:
        f.write(out_data_encoded)
    save_to_archives(out_data_encoded, dir_path, name + ".dat")

    base16_data = binascii.hexlify(out_data_encoded)
    with open(os.path.join(dir_path, name + ".base16"), "wb") as g:
        g.write(base16_data)
    # save_to_archives(base32_data, dir_path, name + ".base32")

    base32_data = base64.b32encode(out_data_encoded)
    with open(os.path.join(dir_path, name + ".base32"), "wb") as g:
        g.write(base32_data)
    # save_to_archives(base32_data, dir_path, name + ".base32")

    # base58_data = base58.b58encode(out_data_encoded)
    # with open(os.path.join(dir_path, name + ".base58"), "wb") as g:
    #     g.write(base58_data)
    # save_to_archives(base58_data, dir_path, name + ".base58")

    base64_data = base64.b64encode(out_data_encoded)
    with open(os.path.join(dir_path, name + ".base64"), "wb") as g:
        g.write(base64_data)
    # save_to_archives(base64_data, dir_path, name + ".base64")

    base85_data = base64.b85encode(out_data_encoded)
    with open(os.path.join(dir_path, name + ".base85"), "wb") as g:
        g.write(base85_data)
    # save_to_archives(base85_data, dir_path, name + ".base85")

    ascii85_data = base64.a85encode(out_data_encoded)
    with open(os.path.join(dir_path, name + ".ascii85"), "wb") as g:
        g.write(ascii85_data)
    # save_to_archives(ascii85_data, dir_path, name + ".ascii85")

    res = out_data_encoded + b"=" * ((4 - len(out_data_encoded) & 3) & 3)
    z85_data = z85.encode(res)
    with open(os.path.join(dir_path, name + ".z85"), "wb") as g:
        g.write(z85_data)
    # save_to_archives(z85_data, dir_path, name + ".z85")

    base91_data = base91.encode(out_data_encoded).encode()
    with open(os.path.join(dir_path, name + ".base91"), "wb") as g:
        g.write(base91_data)
    # save_to_archives(base91_data, dir_path, name + ".base91")

    uu_data = codecs.encode(out_data_encoded, encoding="uu")
    with open(os.path.join(dir_path, name + ".uu"), "wb") as g:
        g.write(uu_data)
    # save_to_archives(uu_data, dir_path, name + ".uu")

    quopri_data = quopri.encodestring(out_data_encoded)
    with open(os.path.join(dir_path, name + ".quopri"), "wb") as g:
        g.write(quopri_data)
    # save_to_archives(quopri_data, dir_path, name + ".quopri")

    binhex.binhex(os.path.join(dir_path, name + ".dat"),
                  os.path.join(dir_path, name + ".binhex"))
def binhexit(path, name):
	dstfile = path + '.hqx'
	if os.path.exists(dstfile) and \
			os.stat(dstfile)[8] > os.stat(path)[8]:
		print 'Skip', path,'- Up-to-date'
		return
	print 'Binhexing', path
	binhex.binhex(path, dstfile)
Exemple #7
0
def binhexit(path, name):
    dstfile = path + '.hqx'
    if os.path.exists(dstfile) and \
      os.stat(dstfile)[8] > os.stat(path)[8]:
        print 'Skip', path, '- Up-to-date'
        return
    print 'Binhexing', path
    binhex.binhex(path, dstfile)
def binhex_enc():
    """Encode with BinHex4."""
    temp_filename = f"temp_{random_key(32)}"
    with open(temp_filename, "wb") as outfile:
        outfile.write(get("plaintext"))
    dest_filename = get("filename").decode()
    binhex.binhex(temp_filename, dest_filename)
    os.unlink(temp_filename)
    show("outfile", dest_filename)
Exemple #9
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)
Exemple #10
0
    def test_binhex_line_endings(self):
        # bpo-29566: Ensure the line endings are those for macOS 9
        with open(self.fname1, 'wb') as f:
            f.write(self.DATA)

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

        with open(self.fname2, 'rb') as fp:
            contents = fp.read()

        self.assertNotIn(b'\n', contents)
Exemple #11
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)
 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
Exemple #13
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)
    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)
    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)
Exemple #16
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
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
Exemple #18
0
#
Exemple #19
0
#
Exemple #20
0
#! /usr/bin/env python
Exemple #21
0
 def update_event(self, inp=-1):
     self.set_output_val(0, binhex.binhex(self.input(0), self.input(1)))
'''
binhex 模块

binhex 模块用于到 Macintosh BinHex 格式的相互转化.
'''
# 使用 binhex 模块
import binhex
import sys

infile = 'samples/sample.jpg'
print(type(sys.stdout), sys.stdout)
print(type(infile), infile)
binhex.binhex(infile, sys.stdout)
Exemple #23
0
#!/usr/bin/python

import binhex

binhex.binhex("rnd.bin", "out.bin");

import binhex

import sys
infile = "samples/sample.png"
binhex.binhex(infile, sys.stdout)
Exemple #25
0
#! /usr/bin/env python
Exemple #26
0
import binhex
import time
password = '******'
youpass = input("Enter the password :"******"Enter the infile name :"))
    outfilename = str(input("Enter the outfile name :"))
    binhex.binhex(infilename, outfilename)
Exemple #27
0
def main():
    ''' main '''
    A = 'rnd.bin'
    B = 'out.bin'
    binhex.binhex(A, B)
    print('binhex({}, {})'.format(A, B))