<s> """<STR_LIT>""" <EOL> import re <EOL> import string <EOL> from jsbeautifier . unpackers import UnpackingError <EOL> PRIORITY = <NUM_LIT:1> <EOL> def detect ( source ) : <EOL> """<STR_LIT>""" <EOL> return source . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) . startswith ( '<STR_LIT>' ) <EOL> def unpack ( source ) : <EOL> """<STR_LIT>""" <EOL> payload , symtab , radix , count = _filterargs ( source ) <EOL> if count != len ( symtab ) : <EOL> raise UnpackingError ( '<STR_LIT>' ) <EOL> try : <EOL> unbase = Unbaser ( radix ) <EOL> except TypeError : <EOL> raise UnpackingError ( '<STR_LIT>' ) <EOL> def lookup ( match ) : <EOL> """<STR_LIT>""" <EOL> word = match . group ( <NUM_LIT:0> ) <EOL> return symtab [ unbase ( word ) ] or word <EOL> source = re . sub ( r'<STR_LIT>' , lookup , payload ) <EOL> return _replacestrings ( source ) <EOL> def _filterargs ( source ) : <EOL> """<STR_LIT>""" <EOL> argsregex = ( r"<STR_LIT>" <EOL> r"<STR_LIT>" ) <EOL> args = re . search ( argsregex , source , re . DOTALL ) . groups ( ) <EOL> try : <EOL> return args [ <NUM_LIT:0> ] , args [ <NUM_LIT:3> ] . split ( '<STR_LIT:|>' ) , int ( args [ <NUM_LIT:1> ] ) , int ( args [ <NUM_LIT:2> ] ) <EOL> except ValueError : <EOL> raise UnpackingError ( '<STR_LIT>' ) <EOL> def _replacestrings ( source ) : <EOL> """<STR_LIT>""" <EOL> match = re . search ( r'<STR_LIT>' , source , re . DOTALL ) <EOL> if match : <EOL> varname , strings = match . groups ( ) <EOL> startpoint = len ( match . group ( <NUM_LIT:0> ) ) <EOL> lookup = strings . split ( '<STR_LIT>' ) <EOL> variable = '<STR_LIT>' % varname <EOL> for index , value in enumerate ( lookup ) : <EOL> source = source . replace ( variable % index , '<STR_LIT>' % value ) <EOL> return source [ startpoint : ] <EOL> return source <EOL> class Unbaser ( object ) : <EOL> """<STR_LIT>""" <EOL> ALPHABET = { <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> } <EOL> def __init__ ( self , base ) : <EOL> self . base = base <EOL> if <NUM_LIT:2> <= base <= <NUM_LIT> : <EOL> self . unbase = lambda string : int ( string , base ) <EOL> else : <EOL> try : <EOL> self . dictionary = dict ( ( cipher , index ) for <EOL> index , cipher in enumerate ( self . ALPHABET [ base ] ) ) <EOL> except KeyError : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> self . unbase = self . _dictunbaser <EOL> def __call__ ( self , string ) : <EOL> return self . unbase ( string ) <EOL> def _dictunbaser ( self , string ) : <EOL> """<STR_LIT>""" <EOL> ret = <NUM_LIT:0> <EOL> for index , cipher in enumerate ( string [ : : - <NUM_LIT:1> ] ) : <EOL> ret += ( self . base ** index ) * self . dictionary [ cipher ] <EOL> return ret </s>
