<s> import os <EOL> import re <EOL> import sys <EOL> from types import ModuleType <EOL> from . import internal <EOL> from . . import constants <EOL> from . . context import context <EOL> class module ( ModuleType ) : <EOL> def __init__ ( self , name , directory ) : <EOL> super ( module , self ) . __init__ ( name ) <EOL> self . __dict__ . update ( { <EOL> '<STR_LIT>' : __file__ , <EOL> '<STR_LIT>' : __package__ , <EOL> '<STR_LIT>' : __path__ , <EOL> } ) <EOL> self . _dir = directory <EOL> self . _absdir = os . path . join ( os . path . dirname ( os . path . abspath ( __file__ ) ) , '<STR_LIT>' , self . _dir ) <EOL> with open ( os . path . join ( self . _absdir , "<STR_LIT>" ) ) as fd : <EOL> self . __doc__ = fd . read ( ) <EOL> sys . modules [ self . __name__ ] = self <EOL> def __lazyinit__ ( self ) : <EOL> self . _submodules = { } <EOL> self . _shellcodes = { } <EOL> for name in os . listdir ( self . _absdir ) : <EOL> path = os . path . join ( self . _absdir , name ) <EOL> if os . path . isdir ( path ) : <EOL> self . _submodules [ name ] = module ( self . __name__ + '<STR_LIT:.>' + name , os . path . join ( self . _dir , name ) ) <EOL> elif os . path . isfile ( path ) and name != '<STR_LIT>' and name [ <NUM_LIT:0> ] != '<STR_LIT:.>' : <EOL> funcname , _ext = os . path . splitext ( name ) <EOL> if not re . match ( '<STR_LIT>' , funcname ) : <EOL> raise ValueError ( "<STR_LIT>" % name ) <EOL> self . _shellcodes [ funcname ] = name <EOL> self . __dict__ . update ( self . _submodules ) <EOL> self . __all__ = sorted ( self . _shellcodes . keys ( ) + self . _submodules . keys ( ) ) <EOL> self . __lazyinit__ = None <EOL> def __getattr__ ( self , key ) : <EOL> self . __lazyinit__ and self . __lazyinit__ ( ) <EOL> if key in self . __dict__ : <EOL> return self . __dict__ [ key ] <EOL> if key in self . _shellcodes : <EOL> real = internal . make_function ( key , self . _shellcodes [ key ] , self . _dir ) <EOL> setattr ( self , key , real ) <EOL> return real <EOL> for m in self . _context_modules ( ) : <EOL> try : <EOL> return getattr ( m , key ) <EOL> except AttributeError : <EOL> pass <EOL> raise AttributeError ( "<STR_LIT>" % key ) <EOL> def __dir__ ( self ) : <EOL> self . __lazyinit__ and self . __lazyinit__ ( ) <EOL> result = list ( self . _submodules . keys ( ) ) <EOL> result . extend ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> result . extend ( self . __shellcodes__ ( ) ) <EOL> return result <EOL> def _context_modules ( self ) : <EOL> self . __lazyinit__ and self . __lazyinit__ ( ) <EOL> for k , m in self . _submodules . items ( ) : <EOL> if k in [ context . arch , context . os ] : <EOL> yield m <EOL> def __shellcodes__ ( self ) : <EOL> self . __lazyinit__ and self . __lazyinit__ ( ) <EOL> result = self . _shellcodes . keys ( ) <EOL> for m in self . _context_modules ( ) : <EOL> result . extend ( m . __shellcodes__ ( ) ) <EOL> return result <EOL> template_dir = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> templates = [ ] <EOL> for root , subfolder , files in os . walk ( template_dir ) : <EOL> for file in filter ( lambda x : x . endswith ( '<STR_LIT>' ) , files ) : <EOL> value = os . path . splitext ( file ) [ <NUM_LIT:0> ] <EOL> value = os . path . join ( root , value ) <EOL> value = value . replace ( template_dir , '<STR_LIT>' ) <EOL> value = value . replace ( os . path . sep , '<STR_LIT:.>' ) <EOL> value = value . lstrip ( '<STR_LIT:.>' ) <EOL> templates . append ( value ) <EOL> templates = sorted ( templates ) <EOL> def eval ( self , item ) : <EOL> return constants . eval ( item ) <EOL> import registers <EOL> tether = sys . modules [ __name__ ] <EOL> shellcraft = module ( __name__ , '<STR_LIT>' ) <EOL> class LazyImporter : <EOL> def find_module ( self , fullname , path ) : <EOL> if not fullname . startswith ( '<STR_LIT>' ) : <EOL> return None <EOL> parts = fullname . split ( '<STR_LIT:.>' ) [ <NUM_LIT:2> : ] <EOL> cur = shellcraft <EOL> for part in parts : <EOL> cur = getattr ( cur , part , None ) <EOL> if not isinstance ( cur , ModuleType ) : <EOL> return None <EOL> return self <EOL> def load_module ( self , fullname ) : <EOL> return sys . modules [ fullname ] <EOL> sys . meta_path . append ( LazyImporter ( ) ) </s>
