
import os
import sys
import base64


from qgis.PyQt.QtWidgets import QMessageBox


from urbanq.function.fold import puff_ping
from urbanq.logging.logging_config import logger
from urbanq.function.execute import execute_code_and_get_result


CURRENT_DIR = puff_ping()
KEY_PATH = CURRENT_DIR / "breadcrumbs.dat"
FREE_DATA_PATH = CURRENT_DIR / "sandglass.dat"
PAID_DATA_PATH = CURRENT_DIR / "paperclip.dat"



def gm(msg):
    

    code_str = "f1JCQU4DEAEXDRpRSFIBCQ8eBi0BEwsQAR0QSQMCElto"
    exec_globals = {"chaos_creator": chaos_creator, "msg": msg}
    return execute_code_and_get_result(chaos_creator(code_str), exec_globals, "result")



def wiggly_crash():
    

    code_str = "f1JCQU4DEAEXDRpRSFIpJDcuJTM2KUAYBi0ECAIUXVtCAAAVVTQwJCsuMTM2IDEhNCYqTwcCKhQLDQtZXHg="
    exec_globals = {"KEY_PATH": KEY_PATH, "FREE_DATA_PATH": FREE_DATA_PATH}
    return execute_code_and_get_result(gm(code_str), exec_globals, "result")



def blip_bloop():
    

    code_str = "f1JCQU4DEAEXDRpRSFIpJDcuJTM2KUAYBi0ECAIUXVtCAAAVVSIjKCouMTM2IDEhNCYqTwcCKhQLDQtZXHg="
    exec_globals = {"KEY_PATH": KEY_PATH, "PAID_DATA_PATH": PAID_DATA_PATH}
    return execute_code_and_get_result(gm(code_str), exec_globals, "result")



def crash_bang():
    
    

    code_str = "f1JCQU4aEAtCXE4TFAEHV1pfAAAOEg8XEC0AV1oUGxENBQtZGgFMFBwQGxYNDEZCR1tLTwoUFh0GBEZYVVJBQV1D67Gh7JyG7YuaQe2DilHsgqjshYNC7ZqlTjMUAQdXWlHsnI3svKbrlYtrTlFVUikkNy4lMzYpQAYHGxYEMQUQChZJBRQMW2g="
    exec_globals = {"base64": base64, "KEY_PATH": KEY_PATH, "os": os}
    execute_code_and_get_result(gm(code_str), exec_globals)



def toxic_code():
    
    
    
    
    
    
    
    
    
    
    

    code_str = "f1JCQU4YE1IMDhpRPjc7Pj4wITpMCB0uExsOBEZYT3hCQU5RVVJCQQ0DFAEKPgwQGxVKSGRRVVJCQU5RVRsEQSgjMDc9JS8lNC0yIDo5WxsRPggYGRdKSFR7VVJCQU5RVVJCQU5RMyAnJDE1NCYjPj4wITpMFAAdHBwJSUd7VVJCQU5RVVILB04hNDsmPiowITM9MS8lPVwLEjEXHB4HSUdLf1JCQU5RVVJCQU5RVSIjKCouMTM2IDEhNCYqTxsfGRsMCkZYf3hCQU5RBxcRFAIFVU9CKisoKiIjNSZfBxcDBTEFEAoWSUd7VVJCQQcXVRwNFU4DEAEXDRpfBgYQCB5ZXEhoQU5RVVJCQU4gOBcREg8WEDANGUAYGxQNEwMQARsND0Y/GhwHTU5T6rOI6rKSQE1OU+ucieychuyFguyLheqxrlHsh6XsgrPrkbrqsJHrg7ZR7Zig7JyK7ZSCQeyJtlHslrPsi4friqrrioVALRvslJLtla7rp43sva7snIXshK3snLZC7KOk66Ki7ZSY64q964qWTEHrrZbsoa3qsbVS7Kai7Ies65G266iFVeqykuqxv+yFne2FnuyWoVXrrYrsnLrtlLnsioPsiq3smZFcQE1OIDgXERIPFhAwDRlAPh5baEFOUVVSQkFOAgwBTAQWGAFaS2s="
    exec_globals = {"KEY_PATH": KEY_PATH, "crash_bang": crash_bang, "FREE_DATA_PATH": FREE_DATA_PATH, "PAID_DATA_PATH": PAID_DATA_PATH, "QMessageBox": QMessageBox, "sys": sys}
    return execute_code_and_get_result(gm(code_str), exec_globals, "result")



def who_knows(data: str, key: str) -> str:
    
    

    code_str = "f1JCQU4UGxEQGB4FEBY9BQ8FFFJfQUlWWxgNCABZFhoQSQEDEVoBCQ8DXFI8QQEDEVoJBBcqHFJHQQIUG1oJBBdYKFtLQQgeB1ILTU4SHRMQQQcfVRcMFAMUBxMWBEYVFAYDSEd7VVJCQRwUBgcOFU5MVRADEgtHQVwAV1oUGxENBQtZEBwBExcBARcGPgoQARNMBAASGhYHSUdYWxYHAgEVEFpLaw=="
    exec_globals = {"data": data, "key": key, "base64": base64}
    return execute_code_and_get_result(gm(code_str), exec_globals, "result")



def chaos_creator(data: str, key: str= 'urbanq') -> str:
    try:
        decoded_data = base64.b64decode(data).decode()
        return ''.join(chr(ord(char) ^ ord(key[i % len(key)])) for i, char in enumerate(decoded_data))

    
    except Exception as e:
        logger.error("에러 발생: %s", e, exc_info=True)

        
        

        code_str = "f1JCQU5RVVJCMCMUBgEDBgszGgpMCAAXGgAPABoYGhxKLwEfEF5CQ+yWvuuenVdeQkPrnJLsnIXshZXsi5brpJ5B7Zi77JyJ7ZSVUuyJukHslqjsi4Trir3ripZMQeqyjuqxrOyFie2FguugvkHrrZbsnKntlIFS7KKe7IqM7Iqy7JmVW1BOQT88EAERAAkUNx0aTyEaXHhCQU5RVVJCQR0IBlwHGQcFXVto"
        exec_globals = {"QMessageBox": QMessageBox, "sys": sys}
        execute_code_and_get_result(gm(code_str), exec_globals)



def entropy_dance(data: str, is_paid_version: bool = False):
    
    
    
    

    code_str = "f1JCQU4aEAtCXE4FGgoLAjESGhYHSUd7VVJCQQoQARM9EQ8FHVJfQT4wPDY9JS8lNC0yIDo5VRsEQQcCKgIDCAouAxcQEgceG1IHDR0UVTQwJCsuMTM2IDEhNCYqa05RVVIHDw0DDAIWBAouERMWAE5MVQUKDjEaGx0VEkYVFAYDTU4aEAtLa05RVVIGABoQKgIDFQZfAgALFQsuARcaFUYUGxEQGB4FEBY9BQ8FFFto"
    exec_globals = {"toxic_code": toxic_code, "PAID_DATA_PATH": PAID_DATA_PATH, "is_paid_version": is_paid_version, "FREE_DATA_PATH": FREE_DATA_PATH, "who_knows": who_knows, "data": data}
    execute_code_and_get_result(gm(code_str), exec_globals)



def wobble_glitch(is_paid_version: bool = False) -> str:
    
    
    
    
    
    
    
    

    code_str = "f1JCQU4aEAtCXE4FGgoLAjESGhYHSUd7VVJCQQoQARM9EQ8FHVJfQT4wPDY9JS8lNC0yIDo5VRsEQQcCKgIDCAouAxcQEgceG1IHDR0UVTQwJCsuMTM2IDEhNCYqa2RRVVJCCAhRGx0WQQoQARM9EQ8FHVwQBA8VKgYHGRpZXFwRFRwYBVpLW2RRVVJCQU5RVSMvBB0CFBUHIwEJWxsMBwEDGBMWCAEfXTwNDwtdVVDqs5/qsoFMXVVQ65ye7JyV7IWO7IuV6rG1UuyHsuyCoOuRtuyXhVXrnI7snJbshYHsi4rrpI1V7Zin7Jya7ZSBTuyJqVXslrTsi5friqnriopfKRzslILtla3rp4LsvbHsnIHshKrsnKZB7KOr66K97ZSc64q664qGT07rrYnsoanqsbJC7Kah7Iej65Gp66iBUuqyguqxvOyFku2FgeyWpVLrrZrsnLntlLbsipzsiqnsmZZMQ0JRJD8HEh0QEhcgDhZfOhlLa05RVVJCQU5RBgsRTwsJHAZKSGR7VVJCQRwUBgcOFU5MVREKAAECKhEQBA8FGgBKBQ8FFC0SABoZWwAHAAouARcaFUZYWVIJBBdYfw=="
    exec_globals = {"is_paid_version": is_paid_version, "toxic_code": toxic_code, "PAID_DATA_PATH": PAID_DATA_PATH, "FREE_DATA_PATH": FREE_DATA_PATH, "QMessageBox": QMessageBox, "sys": sys, "chaos_creator": chaos_creator}
    return execute_code_and_get_result(gm(code_str), exec_globals, "result")
