Advertisement
YourMain12

Synapse X API

May 4th, 2023
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.87 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Net;
  5. using System.Runtime.InteropServices;
  6.  
  7. namespace SynapseX_API
  8. {
  9.     class Program
  10.     {
  11.         [DllImport("kernel32.dll")]
  12.         static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
  13.  
  14.         [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  15.         static extern IntPtr GetModuleHandle(string lpModuleName);
  16.  
  17.         [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
  18.         static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
  19.  
  20.         [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
  21.         static extern bool VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, int dwSize, int dwFreeType);
  22.  
  23.         [DllImport("kernel32.dll", SetLastError = true)]
  24.         static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);
  25.  
  26.         [DllImport("kernel32.dll", SetLastError = true)]
  27.         static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, out IntPtr lpNumberOfBytesWritten);
  28.  
  29.         [DllImport("kernel32.dll")]
  30.         static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);
  31.  
  32.         static void Main(string[] args)
  33.         {
  34.             Process[] robloxProcesses = Process.GetProcessesByName("RobloxPlayerBeta");
  35.  
  36.             if (robloxProcesses.Length == 0)
  37.             {
  38.                 Console.WriteLine("RobloxPlayerBeta is not running!");
  39.                 return;
  40.             }
  41.  
  42.             Process robloxProcess = robloxProcesses[0];
  43.             IntPtr robloxHandle = OpenProcess(0x1F0FFF, false, robloxProcess.Id);
  44.  
  45.             if (robloxHandle == IntPtr.Zero)
  46.             {
  47.                 Console.WriteLine("Failed to open Roblox process!");
  48.                 return;
  49.             }
  50.  
  51.             string scriptPath = "C:\\scripts\\myscript.lua";
  52.             string scriptContent = File.ReadAllText(scriptPath);
  53.  
  54.             IntPtr allocAddress = VirtualAllocEx(robloxHandle, IntPtr.Zero, (uint)(scriptContent.Length + 1), 0x1000, 0x40);
  55.  
  56.             if (allocAddress == IntPtr.Zero)
  57.             {
  58.                 Console.WriteLine("Failed to allocate memory in Roblox process!");
  59.                 return;
  60.             }
  61.  
  62.             byte[] scriptBytes = System.Text.Encoding.UTF8.GetBytes(scriptContent);
  63.             IntPtr bytesWritten;
  64.  
  65.             if (!WriteProcessMemory(robloxHandle, allocAddress, scriptBytes, (uint)scriptBytes.Length, out bytesWritten))
  66.             {
  67.                 Console.WriteLine("Failed to write script to allocated memory!");
  68.                 VirtualFreeEx(robloxHandle, allocAddress, scriptContent.Length + 1, 0x8000);
  69.                 return;
  70.             }
  71.  
  72.             IntPtr loadScriptAddr = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
  73.  
  74.             if (loadScriptAddr == IntPtr.Zero)
  75.             {
  76.                 Console.WriteLine("Failed to get LoadLibraryA address!");
  77.                 VirtualFreeEx(robloxHandle, allocAddress, scriptContent.Length + 1, 0x8000);
  78.                 return;
  79.             }
  80.  
  81.             IntPtr threadHandle = CreateRemoteThread(robloxHandle, IntPtr.Zero, 0, loadScriptAddr, allocAddress, 0, IntPtr.Zero);
  82.  
  83.             if (threadHandle == IntPtr.Zero)
  84.             {
  85.             Console.WriteLine("Failed to create remote thread!");
  86.             VirtualFreeEx(robloxHandle, allocAddress, scriptContent.Length + 1, 0x8000);
  87.             return;
  88.             }
  89.  
  90.             Console.WriteLine("Successfully executed script!");
  91.             VirtualFreeEx(robloxHandle, allocAddress, scriptContent.Length + 1, 0x8000);
  92.             }
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement