Beispiel #1
0
def test_compress():
    assert list(_compress(b'abcdabcd')) == [97, 98, 99, 100, (4, -4)]
    assert list(_compress(b'xaaabaaaaa')) == [120, 97, 97, 97, 98, (3, -4), 97, 97]

    assert list(_compress(b'a' + b'b' * 4095 + b'abb'))[-1] == (3, -4096)
    assert list(_compress(b'a' + b'b' * 4096 + b'abb'))[-1] == 98

    #print( list(_compress(b'abcdefg' * 10)) )
    assert list(_compress(b'abcdefg' * 10)) == \
        [97, 98, 99, 100, 101, 102, 103, (18, -7), (18, -21), (18, -42), (9, -56)]

    assert list(_compress(b'abcdefg' * 10, NLZ11Window)) == \
        [97, 98, 99, 100, 101, 102, 103, (63, -7)]

    out = BytesIO()
    compress_nlz11(b'abcdefg' * 10, out)
    assert out.getvalue()[12:15] == b'\x02\xe0\x06'
Beispiel #2
0
def test_roundtrip():
    #assert False
    with open("lzss3.py", "rb") as f:
        indata = f.read()
    out = BytesIO()
    compress(indata, out)
    compressed_data = out.getvalue()
    assert len(compressed_data) < len(indata)

    decompressed_data = decompress(out.getvalue())
    assert indata == decompressed_data


    #same as above, but with lz11
    out = BytesIO()
    compress_nlz11(indata, out)
    compressed_data = out.getvalue()
    assert len(compressed_data) < len(indata)

    decompressed_data = decompress(out.getvalue())
    assert indata == decompressed_data
Beispiel #3
0
# cut as much of a from compression block of type t with length l
def cutAsMuch(t, l, a):
	d = min(l - minlen[t], a)
	return (a - d, l - d)

# data which will be written right after the buffer
if len(sys.argv)>=7:
	val = [int(v,0) for v in sys.argv[3:3+4]]
	data = struct.pack("<IIII",val[0],val[1],val[2],val[3])
	overwriteData = list(data)
else:
	overwriteData = [0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x69, 0x20, 0x61, 0x6D, 0x20, 0x64, 0x61, 0x74, 0x61, 0x2E]

# out = [0x11, 0x00, 0x00, 0x30]
rop_data = bytearray(open(ropdata_fn,"rb").read())
ropDecompSize = len(rop_data) + compress.compress_nlz11(rop_data, open("tmp","wb"))
out = list(bytearray(open("tmp", "rb").read()))

# start by generating the end data so we know how much room we have to fill later on
endStuff = []
if shuffle_flag==0:
	# first write data over already-processed compressed blob
	endStuff += superBlock(overwriteData[:8])
	endStuff += superBlock(overwriteData[8:])
	# then copy it a few times to overwrite the memchunk header
	endStuff += superBlock([compressionBlockExtraExtended(0x1000, 0x10), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
	fillAmount = 0x2a0000 - len(endStuff)
else:
	fillAmount = 0x150000 - len(endStuff)

print(["0x%02X"%v for v in endStuff])

# data which will be written right after the buffer
if len(sys.argv) >= 7:
    val = [int(v, 0) for v in sys.argv[3:3 + 4]]
    data = struct.pack("<IIII", val[0], val[1], val[2], val[3])
    overwriteData = list(data)
else:
    overwriteData = [
        0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x69, 0x20, 0x61, 0x6D, 0x20, 0x64,
        0x61, 0x74, 0x61, 0x2E
    ]

# out = [0x11, 0x00, 0x00, 0x30]
rop_data = bytearray(open(ropdata_fn, "rb").read())
ropDecompSize = len(rop_data) + compress.compress_nlz11(
    rop_data, open("tmp", "wb"))
out = list(bytearray(open("tmp", "rb").read()))

# start by generating the end data so we know how much room we have to fill later on
endStuff = []
if shuffle_flag == 0:
    # first write data over already-processed compressed blob
    endStuff += superBlock(overwriteData[:8])
    endStuff += superBlock(overwriteData[8:])
    # then copy it a few times to overwrite the memchunk header
    endStuff += superBlock([
        compressionBlockExtraExtended(0x1000, 0x10), 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00
    ])
    fillAmount = 0x2a0000 - len(endStuff)
else: