Exemple #1
0
def decrypt_and_patch_pycfile(zf, pycfile):
	_marshal._FastUnmarshaller.dispatch[_marshal.TYPE_CODE] = load_code_with_patching
	f = zf.open(pycfile, "r")
	data = f.read()
	f.close()
	try:
		c = _marshal.loads(data[8:])
	except Exception, e:
		return str(e)
Exemple #2
0
def decrypt_and_patch_pycfile(zf, pycfile):
    _marshal._FastUnmarshaller.dispatch[
        _marshal.TYPE_CODE] = load_code_with_patching
    f = zf.open(pycfile, "r")
    data = f.read()
    f.close()
    try:
        c = _marshal.loads(data[8:])
    except Exception, e:
        return str(e)
Exemple #3
0
def fix_dir(path):
    import os
    for root, dirs, files in os.walk(path):
        for name in files:
            if not name.endswith('pyc'): continue
            name = os.path.join(root, name)
            print "fixing", name
            data = open(name).read()
            try:
                c = _marshal.loads(data[8:])
            except Exception, e:
                print "error", e, repr(e)
                #print repr(data[8:])
                continue
            # fix the version indicator and save
            open(name,
                 "w").write("\xb3\xf2\r\n" + data[4:8] + _marshal.dumps(c))
Exemple #4
0
def fix_dir(path):
    import os

    for root, dirs, files in os.walk(path):
        for name in files:
            if not name.endswith("pyc"):
                continue
            name = os.path.join(root, name)
            print "fixing", name
            data = open(name).read()
            try:
                c = _marshal.loads(data[8:])
            except Exception, e:
                print "error", e, repr(e)
                # print repr(data[8:])
                continue
            # fix the version indicator and save
            open(name, "w").write("\xb3\xf2\r\n" + data[4:8] + _marshal.dumps(c))
Exemple #5
0
m = {}
v = {}


def fill(c, d):
    if len(c.co_code) != len(d.co_code):
        print "len mismatch", c, d
        return
    for i, j in zip(c.co_code, d.co_code):
        # if i in m and not m[i] == j:
        #    print "mismatch %c (%x) => %c (%x)" % (ord(i),ord(i),ord(j),ord(j))
        v = m.setdefault(i, {})
        v[j] = v.get(j, 0) + 1

c = _marshal.loads(open(name).read()[8:])
d = marshal.loads(open(f2).read()[8:])
fill(c, d)
codes_c = filter(lambda x: type(x) == type(c), c.co_consts)
codes_d = filter(lambda x: type(x) == type(c), d.co_consts)
for i, j in zip(codes_c, codes_d):
    fill(i, j)


def print_table(m):
    k = m.keys()
    k.sort()
    table = {}
    for i in k:
        # print "%c (%02x %s) =>" % (ord(i),ord(i),bin(ord(i))),
        for j, count in m[i].iteritems():
Exemple #6
0
def fix_file(f):
    f = f.read()
    open("/tmp/test.pyc", "w").write("\xb3\xf2\r\n" + f[4:8] + _marshal.dumps(_marshal.loads(f[8:])))
Exemple #7
0
m = {}
v = {}


def fill(c, d):
    if len(c.co_code) != len(d.co_code):
        print "len mismatch", c, d
        return
    for i, j in zip(c.co_code, d.co_code):
        # if i in m and not m[i] == j:
        #    print "mismatch %c (%x) => %c (%x)" % (ord(i),ord(i),ord(j),ord(j))
        v = m.setdefault(i, {})
        v[j] = v.get(j, 0) + 1


c = _marshal.loads(open(name).read()[8:])
d = marshal.loads(open(f2).read()[8:])
fill(c, d)
codes_c = filter(lambda x: type(x) == type(c), c.co_consts)
codes_d = filter(lambda x: type(x) == type(c), d.co_consts)
for i, j in zip(codes_c, codes_d):
    fill(i, j)


def print_table(m):
    k = m.keys()
    k.sort()
    table = {}
    for i in k:
        # print "%c (%02x %s) =>" % (ord(i),ord(i),bin(ord(i))),
        for j, count in m[i].iteritems():
Exemple #8
0
	libfile = libfile[:-1] + "o"
	try:
		st = os.stat(libfile)
		lf = open(libfile, "rb")
		lfdata = lf.read()
		lf.close()
		d = marshal.loads(lfdata[8:])			
		domapping = True
	except Exception, e:
		return

	if not domapping:
		return

	try:
		c = _marshal.loads(data[8:])
	except Exception, e:
		return

	fill_opcode_mapping(c, d)
	codes_c = filter(lambda x: type(x) == type(c), c.co_consts)
	codes_d = filter(lambda x: type(x) == type(d), d.co_consts)
	for i, j in zip(codes_c, codes_d):
		fill_opcode_mapping(i, j)

if __name__ != "__main__":
	raise Exception("don't import this file")

if len(sys.argv) != 4:
	print "Usage: %s <dropbox binary> <python dir> <output.zip>" % sys.argv[0]
	sys.exit(1)
Exemple #9
0
    libfile = libfile[:-1] + "o"
    try:
        st = os.stat(libfile)
        lf = open(libfile, "rb")
        lfdata = lf.read()
        lf.close()
        d = marshal.loads(lfdata[8:])
        domapping = True
    except Exception, e:
        return

    if not domapping:
        return

    try:
        c = _marshal.loads(data[8:])
    except Exception, e:
        return

    fill_opcode_mapping(c, d)
    codes_c = filter(lambda x: type(x) == type(c), c.co_consts)
    codes_d = filter(lambda x: type(x) == type(d), d.co_consts)
    for i, j in zip(codes_c, codes_d):
        fill_opcode_mapping(i, j)


if __name__ != "__main__":
    raise Exception("don't import this file")

if len(sys.argv) != 4:
    print "Usage: %s <dropbox binary> <python dir> <output.zip>" % sys.argv[0]
Exemple #10
0
def fix_file(f):
    f = f.read()
    open('/tmp/test.pyc', "w").write("\xb3\xf2\r\n" + f[4:8] +
                                     _marshal.dumps(_marshal.loads(f[8:])))