Esempio n. 1
0
        public static bool ExtractResourceToFile(ConsoleContent console, string resourceName, string filename)
        {
            using (Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
            {
                if (stream == null)
                {
                    console.Error("cannot find resource " + resourceName);
                    return(false);
                }

                using (FileStream fs = new FileStream(filename, FileMode.Create))
                {
                    byte[] buf = new byte[stream.Length];
                    stream.Read(buf, 0, buf.Length);

                    try
                    {
                        fs.Write(buf, 0, buf.Length);
                    }
                    catch (IOException err)
                    {
                        console.Error("cannot write to " + filename + ": " + err);
                        return(false);
                    }
                }
            }

            console.Info("OpenGameCamera extracted to " + filename);
            return(true);
        }
Esempio n. 2
0
        public MainWindow()
        {
            InitializeComponent();

            DataContext = console;
            console.SetScrollViewer(Scroller);

            DateTime?buildDate = ResourceExtractor.GetBuildUTCTimestamp(console);

            if (buildDate != null)
            {
                buildTimestampUTC = buildDate.Value;
                buildVersion      = buildDate.Value.ToString("yyyy.MM.dd-HHmmss");

                CheckForLatestRelease();
            }

            console.Info("Welcome to OpenGameCamera. To begin, ensure your game is running before starting OGC.\n\n");
        }
Esempio n. 3
0
        public static bool Inject(ConsoleContent console, string dll_path)
        {
            IntPtr wnd = FindWindow(null, "STAR WARS Battlefront II");

            if (wnd == null)
            {
                console.Error("failed to find an active Star Wars Battlefront II game: code=" + Marshal.GetLastWin32Error());
                return(false);
            }

            uint processId = 0;

            GetWindowThreadProcessId(wnd, out processId);

            if (processId == 0)
            {
                console.Error("failed to obtain process ID for Star Wars Battlefront II game: code=" + Marshal.GetLastWin32Error());
                return(false);
            }

            console.Info("found SWBF2 at pid " + processId);

            IntPtr procHandle = OpenProcess(
                PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ,
                false,
                (int)processId
                );

            if (procHandle == null)
            {
                console.Error("failed to open pid=" + processId + ": code=" + Marshal.GetLastWin32Error());
                return(false);
            }

            try
            {
                IntPtr loadLibraryPtr = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryW");

                console.Info("LoadLibraryW found at " + loadLibraryPtr.ToInt64().ToString("X16"));

                byte[] pathBuf = Encoding.Unicode.GetBytes(dll_path);

                IntPtr targetAddr = VirtualAllocEx(
                    procHandle,
                    IntPtr.Zero,
                    (uint)(pathBuf.Length + Marshal.SizeOf(typeof(ushort))),
                    MEM_COMMIT | MEM_RESERVE,
                    PAGE_READWRITE
                    );
                if (targetAddr == null)
                {
                    console.Error("failed to allocate memory in target process: code=" + Marshal.GetLastWin32Error());
                    return(false);
                }

                console.Info("memory allocated in SWBF2: 0x" + targetAddr.ToInt64().ToString("X16"));

                UIntPtr bytesWritten;

                if (!WriteProcessMemory(procHandle, targetAddr, pathBuf, (uint)pathBuf.Length, out bytesWritten))
                {
                    console.Error("failed to write memory in target process: code=" + Marshal.GetLastWin32Error());
                    return(false);
                }

                console.Info("wrote " + bytesWritten.ToUInt64() + " bytes to allocated memory");

                IntPtr threadId;

                if (CreateRemoteThread(procHandle, IntPtr.Zero, 0, loadLibraryPtr, targetAddr, 0, out threadId) == null)
                {
                    console.Error("failed to launch remote thread: code=" + Marshal.GetLastWin32Error());
                    return(false);
                }

                console.Info("OGC injected into SWBF2: threadId=" + threadId.ToInt64());
            }
            finally
            {
                CloseHandle(procHandle);
            }

            return(true);
        }