1
mirror of https://github.com/rapid7/metasploit-payloads synced 2025-04-12 04:12:05 +02:00
OJ 3c17f4e9aa Fix package script, update package
The package script was (stupidly) written (by me) to replace '\\' with
'.' when generating python import module names. Of course, this works
great on windows, but it means if you generate the package on linux
things break horribly. The result was that the latest package wouldn't
resolve anything useful when importing key stuff like ctypes or pty.

This PR fixes the issue so that the modules are correctly wired in
regardless of the OS that the package was constructed on.
2016-03-31 11:14:19 +10:00

45 lines
1.1 KiB
Python

#!/usr/bin/env python
import os,struct,py_compile,zlib,marshal
def w(f,c):
with open(f,'wb') as f:
f.write(c)
def r(f):
with open(f,'rb') as f:
return f.read()
def p(d):
return struct.pack('<L', d)
modules = {}
here = os.getcwd()
folder = '../Lib'
os.chdir(folder)
for entry in os.listdir('.'):
if os.path.isfile(entry):
if entry.endswith('.py'):
path = entry.split('.')[0]
print path
modules[path] = (entry, False, compile(r(entry), entry, 'exec'))
else:
for root, _, files in os.walk(entry):
for f in [x for x in files if x.endswith('.py')]:
path = os.path.join(root, f)
print path
modname = path.split('.')[0].replace(os.path.sep, '.').replace('.__init__', '')
print modname
modules[modname] = (path, True, compile(r(path), path, 'exec'))
os.chdir(here)
importer = compile(r('met_importer.py'), 'met_importer.py', 'exec')
print 'Total modules: {0}'.format(len(modules.keys()))
content = zlib.compress(marshal.dumps([importer, modules]), 9)
w('python_core.cz', p(len(content)) + content)