Skip to content
New issue

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

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

Already on GitHub? # to your account

Attempt additional base64 decoding on cursed stamps #264

Open
reinamora137 opened this issue May 16, 2024 · 1 comment
Open

Attempt additional base64 decoding on cursed stamps #264

reinamora137 opened this issue May 16, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed indexer Indexer related issues

Comments

@reinamora137
Copy link
Collaborator

There are several where the decoding could be successful on cursed for instances where stamp_base64 is malformed

todo:

strip chars before and including a , (some with base64,)
strip chars before and including a : (some with stamp:)
strip invalid base64 chars

currently these decode to: application/octet-stream

this function was added in stamp.py to strip non base64, pre-checks will be needed to strip the others beforehand.

#  NOTE: this can be used for cursed, but will change the txlist hash
def remove_non_base64_chars(base64_string):
    """
    Removes any non-base64 characters from the given base64 string.

    Args:
        base64_string (str): The base64 string to remove non-base64 characters from.

    Returns:
        str: The base64 string with non-base64 characters removed.
    """
    return ''.join(c for c in base64_string if c in base64.b64encode(base64.b64decode(base64_string)).decode())
@reinamora137
Copy link
Collaborator Author

this is a little complex with how the current functions are arranged setting the ident based upon the base64 initial decoding. These functions should do the trick when those are arranged properly.



def strip_chars_before_and_including_comma(s):
    """
    Strips characters before and including a comma from the given string.

    Args:
        s (str): The string to strip characters from.

    Returns:
        str: The string with characters before and including a comma stripped.
    """
    return s[s.find(',') + 1:] if ',' in s else s


def strip_chars_before_and_including_colon(s):
    """
    Strips characters before and including a colon from the given string.

    Args:
        s (str): The string to strip characters from.

    Returns:
        str: The string with characters before and including a colon stripped.
    """
    return s[s.find(':') + 1:] if ':' in s else s


def remove_non_base64_chars(base64_string):
    """
    Removes any non-base64 characters from the given base64 string.

    Args:
        base64_string (str): The base64 string to remove non-base64 characters from.

    Returns:
        str: The base64 string with non-base64 characters removed.
    """
    return ''.join(c for c in base64_string if c in base64.b64encode(base64.b64decode(base64_string)).decode())


def post_process_base64_strings(s):
    """
    Processes the given string by stripping certain characters and removing non-base64 characters.
    This is for cursed stamps thath previously decoded as octet-stream

    Args:
        s (str): The string to process.

    Returns:
        str: The processed string.
    """
    s = strip_chars_before_and_including_comma(s)
    s = strip_chars_before_and_including_colon(s)
    return remove_non_base64_chars(s)

@reinamora137 reinamora137 added enhancement New feature or request indexer Indexer related issues help wanted Extra attention is needed labels May 16, 2024
@reinamora137 reinamora137 changed the title Attempt further base64 decoding on cursed stamps Attempt additional base64 decoding on cursed stamps May 21, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request help wanted Extra attention is needed indexer Indexer related issues
Projects
None yet
Development

No branches or pull requests

1 participant