Skip to content

Commit d6dedd0

Browse files
committed
jsunpack non ascii strings
1 parent 67fb8da commit d6dedd0

3 files changed

Lines changed: 51 additions & 21 deletions

File tree

lib/resolveurl/plugins/lib/helpers.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,8 @@ def append_headers(headers):
8383
def get_packed_data(html):
8484
packed_data = ''
8585
for match in re.finditer(r'(eval\s*\(function.*?)</script>', html, re.DOTALL | re.I):
86-
try:
87-
js_data = jsunpack.unpack(match.group(1))
88-
js_data = js_data.replace('\\', '')
89-
packed_data += js_data
90-
except:
91-
pass
86+
if jsunpack.detect(match.group(1)):
87+
packed_data += jsunpack.unpack(match.group(1))
9288

9389
return packed_data
9490

lib/resolveurl/plugins/lib/jsunpack.py

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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
@@ -32,13 +33,37 @@
3233
"""
3334

3435
import re
36+
import six
3537

3638
PRIORITY = 1
3739

3840

3941
def 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

4469
def 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

90118
def _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

105135
class 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

lib/resolveurl/plugins/userload.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525
class UserLoadResolver(ResolveUrl):
2626
name = "UserLoad"
2727
domains = ['userload.co']
28-
pattern = r'(?://|\.)(userload\.co)/f/([0-9a-zA-Z]+)'
28+
pattern = r'(?://|\.)(userload\.co)/(?:e|f)/([0-9a-zA-Z]+)'
2929

3030
def get_media_url(self, host, media_id):
3131
web_url = self.get_url(host, media_id)
3232
blurl = 'https://{0}/api/assets/userload/js/form.framework.js'.format(host)
3333
headers = {'User-Agent': common.RAND_UA}
3434
html = self.net.http_GET(web_url, headers=headers).content
3535
html = helpers.get_packed_data(html)
36+
headers.update({'Referer': web_url})
3637
bl = self.net.http_GET(blurl, headers=headers).content
3738
if jsunhunt.detect(bl):
3839
bl = jsunhunt.unhunt(bl)
@@ -50,8 +51,7 @@ def get_media_url(self, host, media_id):
5051
api_url = 'https://{0}{1}'.format(host, b1.group(1))
5152
headers.update({
5253
'X-Requested-With': 'XMLHttpRequest',
53-
'Origin': 'https://{0}'.format(host),
54-
'Referer': web_url
54+
'Origin': 'https://{0}'.format(host)
5555
})
5656
stream_url = self.net.http_POST(api_url, data, headers=headers).content
5757
headers.pop('X-Requested-With')
@@ -61,4 +61,4 @@ def get_media_url(self, host, media_id):
6161
raise ResolverError('File not found')
6262

6363
def get_url(self, host, media_id):
64-
return self._default_get_url(host, media_id, template='https://{host}/f/{media_id}')
64+
return self._default_get_url(host, media_id, template='https://{host}/e/{media_id}')

0 commit comments

Comments
 (0)