Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python unpacker can not handle if radix given as [] and not as a number #1381

Closed
swan46 opened this issue May 2, 2018 · 3 comments
Closed

Comments

@swan46
Copy link
Contributor

swan46 commented May 2, 2018

Description

python unpacker can not handle if radix given as [] and not as a number
jsbeautifier.org handles this well.

Input

eval(function(p,a,c,k,e,r){e=function(c){return c.toString(36)};if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'[0-9ab]'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\b'+e(c)+'\b','g'),k[c]);return p}('$(5).a(6(){ $('.8').0(1); $('.b').0(4); $('.9').0(2); $('.7').0(3)})',[],12,'html|52136|555|65103|8088|document|function|r542c|r8ce6|rb0de|ready|rfab0'.split('|'),0,{}))

Expected Output

$(document).ready(function() {
$('.r8ce6').html(52136); $('.rfab0').html(8088); $('.rb0de').html(555); $('.r542c').html(65103)})

Actual Output

Beautified version of the input code, packing remains unacknowledged.

Steps to Reproduce

Environment

Linux mint 18

Settings

Example:

{
    "indent_size": 4,
    "indent_char": " ",
    "indent_level": 0,
    "indent_with_tabs": false,
    "preserve_newlines": true,
    "max_preserve_newlines": 10,
    "jslint_happy": false,
    "space_after_anon_function": false,
    "brace_style": "collapse,preserve-inline",
    "keep_array_indentation": false,
    "keep_function_indentation": false,
    "space_before_conditional": true,
    "break_chained_methods": false,
    "eval_code": false,
    "unescape_strings": false,
    "wrap_line_length": 0
}
@swan46
Copy link
Contributor Author

swan46 commented May 2, 2018

Created a fix in packer.py:

def _filterargs(source):
"""Juice from a source file the four args needed by decoder."""
juicers = [ (r"}('(.*)', *(\d+|[]), *(\d+), '(.)'.split('|'), (\d+), (.)))"),
(r"}('(.
)', *(\d+|[]), *(\d+), '(.)'.split('|')"),
]
for juicer in juicers:
args = re.search(juicer, source, re.DOTALL)
if args:
a = args.groups()
if a[1] == "[]" :
a = list(a)
a[1] = 62
a = tuple(a)
try:
return a[0], a[3].split('|'), int(a[1]), int(a[2])
except ValueError:
raise UnpackingError('Corrupted p.a.c.k.e.r. data.')

Also added a test sequence to test-packer to test this case:
str = "eval(function(p,a,c,k,e,r){e=function(c){return c.toString(36)};if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'[0-9ab]'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\b'+e(c)+'\b','g'),k[c]);return p}('$(5).a(6(){ $('.8').0(1); $('.b').0(4); $('.9').0(2); $('.7').0(3)})',[],12,'html|52136|555|65103|8088|document|function|r542c|r8ce6|rb0de|ready|rfab0'.split('|'),0,{}))"
expected = "$(document).ready(function() {\n $('.r8ce6').html(52136);\n $('.rfab0').html(8088);\n $('.rb0de').html(555);\n $('.r542c').html(65103)\n})"

res = test_str(str, expected)

Please update packer.py and test-packer.py like above listed. Thank you.

@bitwiseman
Copy link
Member

@swan46
Your last pull request was great. Please PR.

@swan46
Copy link
Contributor Author

swan46 commented May 3, 2018

Added a PR.

@bitwiseman bitwiseman added this to the v1.7.x milestone May 5, 2018
@bitwiseman bitwiseman modified the milestones: v1.7.x, v1.7.6 May 21, 2018
@bitwiseman bitwiseman modified the milestones: v1.8.0-rc2, 1.8.0 Aug 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants