11"""
2- resolveurl XBMC Addon
3- Copyright (C) 2018 jsergio
2+ ResolveUrl Kodi Addon
3+ Copyright (C) 2013 Bstrdsmkr
4+ Additional fixes by mortael, jairoxyz
45
56 This program is free software: you can redistribute it and/or modify
67 it under the terms of the GNU General Public License as published by
3233"""
3334
3435import re
36+ import six
3537
3638PRIORITY = 1
3739
3840
3941def detect (source ):
42+ global beginstr
43+ global endstr
44+ beginstr = ""
45+ endstr = ""
46+ begin_offset = - 1
4047 """Detects whether `source` is P.A.C.K.E.R. coded."""
41- return source .replace (' ' , '' ).startswith ('eval(function(p,a,c,k,e,' )
48+ mystr = re .search (
49+ r"eval[ ]*\([ ]*function[ ]*\([ ]*p[ ]*,[ ]*a[ ]*,[ ]*c["
50+ r" ]*,[ ]*k[ ]*,[ ]*e[ ]*,[ ]*" ,
51+ source ,
52+ )
53+ if mystr :
54+ begin_offset = mystr .start ()
55+ beginstr = source [:begin_offset ]
56+ if begin_offset != - 1 :
57+ """ Find endstr"""
58+ source_end = source [begin_offset :]
59+ if source_end .split ("')))" , 1 )[0 ] == source_end :
60+ try :
61+ endstr = source_end .split ("}))" , 1 )[1 ]
62+ except IndexError :
63+ endstr = ""
64+ else :
65+ endstr = source_end .split ("')))" , 1 )[1 ]
66+ return mystr is not None
4267
4368
4469def unpack (source ):
@@ -56,10 +81,13 @@ def unpack(source):
5681 def lookup (match ):
5782 """Look up symbols in the synthetic symtab."""
5883 word = match .group (0 )
59- word2 = symtab [int (word )] if radix == 1 else symtab [unbase (word )]
60- return word2 or word
84+ return symtab [int (word )] if radix == 1 else symtab [unbase (word )] or word
6185
62- source = re .sub (r'\b\w+\b' , lookup , payload )
86+ payload = payload .replace ("\\ \\ " , "\\ " ).replace ("\\ '" , "'" )
87+ if six .PY2 :
88+ source = re .sub (r"\b\w+\b" , lookup , payload )
89+ else :
90+ source = re .sub (r"\b\w+\b" , lookup , payload , flags = re .ASCII )
6391 return _replacestrings (source )
6492
6593
@@ -88,6 +116,8 @@ def _filterargs(source):
88116
89117
90118def _replacestrings (source ):
119+ global beginstr
120+ global endstr
91121 """Strip string lookup table (list) and replace values in source."""
92122 match = re .search (r'var *(_\w+)\=\["(.*?)"\];' , source , re .DOTALL )
93123
@@ -99,16 +129,19 @@ def _replacestrings(source):
99129 for index , value in enumerate (lookup ):
100130 source = source .replace (variable % index , '"%s"' % value )
101131 return source [startpoint :]
102- return source
132+ return beginstr + source + endstr
103133
104134
105135class Unbaser (object ):
106136 """Functor for a given base. Will efficiently convert
107137 strings to natural numbers."""
138+
108139 ALPHABET = {
109- 62 : '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ,
110- 95 : (' !"#$%&\' ()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ'
111- '[\\ ]^_`abcdefghijklmnopqrstuvwxyz{|}~' )
140+ 62 : "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ,
141+ 95 : (
142+ " !\" #$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"
143+ "[\\ ]^_`abcdefghijklmnopqrstuvwxyz{|}~"
144+ ),
112145 }
113146
114147 def __init__ (self , base ):
@@ -128,7 +161,8 @@ def __init__(self, base):
128161 try :
129162 self .dictionary = dict (
130163 (cipher , index ) for index , cipher in enumerate (
131- self .ALPHABET [base ]))
164+ self .ALPHABET [base ])
165+ )
132166 except KeyError :
133167 raise TypeError ('Unsupported base encoding.' )
134168
0 commit comments