diff --git a/extra/safe2bin/safe2bin.py b/extra/safe2bin/safe2bin.py index 8298255f8..9cc26479c 100755 --- a/extra/safe2bin/safe2bin.py +++ b/extra/safe2bin/safe2bin.py @@ -24,6 +24,9 @@ HEX_ENCODED_CHAR_REGEX = r"(?P\\x[0-9A-Fa-f]{2})" # Raw chars that will be safe encoded to their slash (\) representations (e.g. newline to \n) SAFE_ENCODE_SLASH_REPLACEMENTS = "\t\n\r\x0b\x0c" +# Characters that don't need to be safe encoded +SAFE_CHARS = "".join(filter(lambda x: x not in SAFE_ENCODE_SLASH_REPLACEMENTS, string.printable.replace('\\', ''))) + # String used for temporary marking of slash characters SLASH_MARKER = "__SLASH__" @@ -40,15 +43,15 @@ def safecharencode(value): retVal = value if isinstance(value, basestring): - retVal = retVal.replace('\\', SLASH_MARKER) + if any(_ not in SAFE_CHARS for _ in value): + retVal = retVal.replace('\\', SLASH_MARKER) - for char in SAFE_ENCODE_SLASH_REPLACEMENTS: - retVal = retVal.replace(char, repr(char).strip('\'')) + for char in SAFE_ENCODE_SLASH_REPLACEMENTS: + retVal = retVal.replace(char, repr(char).strip('\'')) - retVal = retVal.replace(SLASH_MARKER, '\\\\') - - retVal = reduce(lambda x, y: x + (y if (y in string.printable or ord(y) > 255) else '\\x%02x' % ord(y)), retVal, unicode()) + retVal = retVal.replace(SLASH_MARKER, '\\\\') + retVal = reduce(lambda x, y: x + (y if (y in string.printable or ord(y) > 255) else '\\x%02x' % ord(y)), retVal, unicode()) elif isinstance(value, list): for i in xrange(len(value)): retVal[i] = safecharencode(value[i]) diff --git a/lib/core/common.py b/lib/core/common.py index 5e01444cd..036138d64 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -1332,12 +1332,12 @@ def parseUnionPage(output, unique=True): if output is None: return None - data = BigArray() - if output.startswith(kb.chars.start) and output.endswith(kb.chars.stop): + data = BigArray() + _ = [] + regExpr = '%s(.*?)%s' % (kb.chars.start, kb.chars.stop) output = re.finditer(regExpr, output, re.DOTALL | re.IGNORECASE) - _ = [] for entry in output: entry = entry.group(1)