Skip to content

Instantly share code, notes, and snippets.

@thvortex
Created August 13, 2012 08:21
Show Gist options
  • Save thvortex/3338163 to your computer and use it in GitHub Desktop.
Save thvortex/3338163 to your computer and use it in GitHub Desktop.
MCP Commands.unpackreobfclasses() change to build reobfuscated .zip with no temp files
diff --git a/runtime/commands.py b/runtime/commands.py
index cd7f615..6d81854 100644
--- a/runtime/commands.py
+++ b/runtime/commands.py
@@ -1490,6 +1490,7 @@ class Commands(object):
md5reoblk = {CLIENT: self.md5reobfclient, SERVER: self.md5reobfserver}
outpathlk = {CLIENT: self.dirreobfclt, SERVER: self.dirreobfsrv}
srglk = {CLIENT: self.srgsclient, SERVER: self.srgsserver}
+ zipoutlk = {CLIENT: 'client_mod.zip', SERVER: 'server_mod.zip'}
# HINT: We need a table for the old md5 and the new ones
md5table = {}
@@ -1534,7 +1535,9 @@ class Commands(object):
os.makedirs(outpathlk[side])
# HINT: We extract the modified class files
+ zipoutpath = outpathlk[side] + os.sep + zipoutlk[side]
with closing(zipfile.ZipFile(jarlk[side])) as zipjar:
+ with closing(zipfile.ZipFile(zipoutpath, 'w', zipfile.ZIP_DEFLATED)) as zipout:
for in_class in trgclasses:
parent_class, sep, inner_class = in_class.partition('$')
if in_class in classes:
@@ -1547,8 +1550,8 @@ class Commands(object):
if out_class[0] == '/':
out_class = out_class[1:]
try:
- zipjar.extract(out_class, outpathlk[side])
- self.logger.info('> Outputted %s to %s as %s', in_class.ljust(35), outpathlk[side], out_class)
+ zipout.writestr(out_class, zipjar.read(out_class))
+ self.logger.info('> Outputted %s to %s as %s', in_class.ljust(35), zipoutpath, out_class)
except KeyError:
self.logger.error('* File %s not found for %s', out_class, in_class)
except IOError:
diff --git a/runtime/commands.py b/runtime/commands.py
index cd7f615..6d81854 100644
--- a/runtime/commands.py
+++ b/runtime/commands.py
@@ -1490,6 +1490,7 @@ class Commands(object):
md5reoblk = {CLIENT: self.md5reobfclient, SERVER: self.md5reobfserver}
outpathlk = {CLIENT: self.dirreobfclt, SERVER: self.dirreobfsrv}
srglk = {CLIENT: self.srgsclient, SERVER: self.srgsserver}
+ zipoutlk = {CLIENT: 'client_mod.zip', SERVER: 'server_mod.zip'}
# HINT: We need a table for the old md5 and the new ones
md5table = {}
@@ -1534,25 +1535,27 @@ class Commands(object):
os.makedirs(outpathlk[side])
# HINT: We extract the modified class files
+ zipoutpath = outpathlk[side] + os.sep + zipoutlk[side]
with closing(zipfile.ZipFile(jarlk[side])) as zipjar:
- for in_class in trgclasses:
- parent_class, sep, inner_class = in_class.partition('$')
- if in_class in classes:
- out_class = classes[in_class] + '.class'
- elif parent_class in classes:
- out_class = classes[parent_class] + sep + inner_class + '.class'
- else:
- out_class = in_class + '.class'
- out_class = out_class.replace(self.nullpkg, '')
- if out_class[0] == '/':
- out_class = out_class[1:]
- try:
- zipjar.extract(out_class, outpathlk[side])
- self.logger.info('> Outputted %s to %s as %s', in_class.ljust(35), outpathlk[side], out_class)
- except KeyError:
- self.logger.error('* File %s not found for %s', out_class, in_class)
- except IOError:
- self.logger.error('* File %s failed extracting for %s', out_class, in_class)
+ with closing(zipfile.ZipFile(zipoutpath, 'w', zipfile.ZIP_DEFLATED)) as zipout:
+ for in_class in trgclasses:
+ parent_class, sep, inner_class = in_class.partition('$')
+ if in_class in classes:
+ out_class = classes[in_class] + '.class'
+ elif parent_class in classes:
+ out_class = classes[parent_class] + sep + inner_class + '.class'
+ else:
+ out_class = in_class + '.class'
+ out_class = out_class.replace(self.nullpkg, '')
+ if out_class[0] == '/':
+ out_class = out_class[1:]
+ try:
+ zipout.writestr(out_class, zipjar.read(out_class))
+ self.logger.info('> Outputted %s to %s as %s', in_class.ljust(35), zipoutpath, out_class)
+ except KeyError:
+ self.logger.error('* File %s not found for %s', out_class, in_class)
+ except IOError:
+ self.logger.error('* File %s failed extracting for %s', out_class, in_class)
def downloadupdates(self, force=False):
if not self.updateurl:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment