<commit_before>#
# Unpacker for Dean Edward's p.a.c.k.e.r, a part of javascript beautifier
# by <NAME> <<EMAIL>>
#
#     written by <NAME> <<EMAIL>>
#
# usage:
#
# if detect(some_string):
#     unpacked = unpack(some_string)
#

"""Unpacker for Dean Edward's p.a.c.k.e.r"""

import re
import string
from jsbeautifier.unpackers import UnpackingError

PRIORITY = 1


def detect(source):
    global beginstr
    global endstr
    beginstr = ''
    endstr = ''
    begin_offset = -1
    """Detects whether `source` is P.A.C.K.E.R. coded."""
    mystr = re.search('eval[ ]*\([ ]*function[ ]*\([ ]*p[ ]*,[ ]*a[ ]*,[ ]*c[ ]*,[ ]*k[ ]*,[ ]*e[ ]*,[ ]*', source)
    if(mystr):
        begin_offset = mystr.start()
        beginstr = source[:begin_offset]
    if(begin_offset != -1):
        """ Find endstr"""
        source_end = source[begin_offset:]
        if(source_end.split("')))", 1)[0] == source_end):
            try:
                endstr = source_end.split("}))", 1)[1]
            except IndexError:
                endstr = ''
        else:
            endstr = source_end.split("')))", 1)[1]
    return (mystr != -1)


def unpack(source):
    """Unpacks P.A.C.K.E.R. packed js code."""
    payload, symtab, radix, count = _filterargs(source)

    if count != len(symtab):
        raise UnpackingError('Malformed p.a.c.k.e.r. symtab.')

    try:
        unbase = Unbaser(radix)
    except TypeError:
        raise UnpackingError('Unknown p.a.c.k.e.r. encoding.')

    def lookup(match):
        """Look up symbols in the synthetic symtab."""
        word = match.group(0)
        return symtab[unbase(word)] or word

    source = re.sub(r'\b\w+\b', lookup, payload)
    return _replacestrings(source)<commit_msg>Fix to make the unpacker pass the tests.<commit_after>#
# Unpacker for Dean Edward's p.a.c.k.e.r, a part of javascript beautifier
# by <NAME> <<EMAIL>>
#
#     written by <NAME> <<EMAIL>>
#
# usage:
#
# if detect(some_string):
#     unpacked = unpack(some_string)
#

"""Unpacker for Dean Edward's p.a.c.k.e.r"""

import re
import string
from jsbeautifier.unpackers import UnpackingError

PRIORITY = 1


def detect(source):
    global beginstr
    global endstr
    beginstr = ''
    endstr = ''
    begin_offset = -1
    """Detects whether `source` is P.A.C.K.E.R. coded."""
    mystr = re.search('eval[ ]*\([ ]*function[ ]*\([ ]*p[ ]*,[ ]*a[ ]*,[ ]*c[ ]*,[ ]*k[ ]*,[ ]*e[ ]*,[ ]*', source)
    if(mystr):
        begin_offset = mystr.start()
        beginstr = source[:begin_offset]
    if(begin_offset != -1):
        """ Find endstr"""
        source_end = source[begin_offset:]
        if(source_end.split("')))", 1)[0] == source_end):
            try:
                endstr = source_end.split("}))", 1)[1]
            except IndexError:
                endstr = ''
        else:
            endstr = source_end.split("')))", 1)[1]
    return (mystr != None)


def unpack(source):
    """Unpacks P.A.C.K.E.R. packed js code."""
    payload, symtab, radix, count = _filterargs(source)

    if count != len(symtab):
        raise UnpackingError('Malformed p.a.c.k.e.r. symtab.')

    try:
        unbase = Unbaser(radix)
    except TypeError:
        raise UnpackingError('Unknown p.a.c.k.e.r. encoding.')

    def lookup(match):
        """Look up symbols in the synthetic symtab."""
        word = match.group(0)
        return symtab[unbase(word)] or word

    source = re.sub(r'\b\w+\b', lookup, payload)
    return _replacestrings(source)
{'fraction_non_alphanumeric': 0.1755703147559919, 'fraction_numerical': 0.006064106266243142, 'mean_word_length': 2.498989898989899, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4138664', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1240, 'n_words': 286}