From cb6b94a323fb581730e75b285804a8aab6e3847c Mon Sep 17 00:00:00 2001 From: Xuzz Date: Sat, 25 Jul 2009 13:14:02 -0700 Subject: [PATCH] updated compression.py and fixed common.py from printing random shit --- common.py | 2 -- compression.py | 37 +++++++++---------------------------- 2 files changed, 9 insertions(+), 30 deletions(-) diff --git a/common.py b/common.py index 5cc6a3c..966ef0b 100644 --- a/common.py +++ b/common.py @@ -40,8 +40,6 @@ def hexdump2(src, length = 16): # dumps to a "hex editor" style output printable = s.translate(''.join([(len(repr(chr(x))) == 3) and chr(x) or '.' for x in range(256)])) result.append("0x%04X %-*s %s\n" % (i, (length * 3) + 2, hexa, printable)) return ''.join(result) - -print hexdump2("RANDOM STRING \x01 TESTING \x214 TEST OF STrasneljkasdhfleasdklhglkaje;shadlkghehaosehlgasdlkfhe;lakhsdglhaelksejdfffffffjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjasdfsadf") class Crypto(object): """This is a Cryptographic/hash class used to abstract away things (to make changes easier)""" diff --git a/compression.py b/compression.py index ca767b2..d8d0d95 100644 --- a/compression.py +++ b/compression.py @@ -1,7 +1,7 @@ from common import * -class LZ77(): - class WiiLZ77: #class by marcan +class LZ77(WiiHeader): + class WiiLZ77: # class by marcan, used under scope of BSD license TYPE_LZ77 = 1 def __init__(self, file, offset): self.file = file @@ -42,34 +42,15 @@ class LZ77(): break self.data = dout return self.data - def __init__(self, f): - self.f = f - def decompress(self, fn = ""): - """This uncompresses a LZ77 compressed file, specified in f in the initializer. It outputs the file in either fn, if it isn't empty, or overwrites the input if it is. Returns the output filename.""" - file = open(self.f, "rb") - hdr = file.read(4) + def remove(self): + hdr = self.data[:4] if hdr != "LZ77": - if(fn == ""): - return self.f - else: - data = open(self.f, "rb").read() - open(fn, "wb").write(data) + return self.data + file = StringIO.StringIO(self.data) + file.seek(4) unc = self.WiiLZ77(file, file.tell()) data = unc.uncompress() - file.close() - if(fn != ""): - open(fn, "wb").write(data) - return fn - else: - open(self.f, "wb").write(data) - return self.f + return data def compress(self, fn = ""): - """This will eventually add LZ77 compression to a file. Does nothing for now.""" - if(fn != ""): - #subprocess.call(["./gbalzss", self.f, fn, "-pack"]) - return fn - else: - #subprocess.call(["./gbalzss", self.f, self.f, "-pack"]) - return self.f - + raise NotImplementedError