Esempio n. 1
0
        public void Initialize(int processId, ErrorHandler errorHandler)
        {
            _process   = null;
            _processId = 0;
            _processMainWindowHandle = IntPtr.Zero;
            _baseAddress             = IntPtr.Zero;
            _errorHandler            = errorHandler;

            // get a reference to the process
            try
            {
                _process = Process.GetProcessById(processId);
            }
            catch
            {
                _process = null;
                return;
            }

            _processId = _process.Id;
            _processMainWindowHandle = _process.MainWindowHandle;
            _baseAddress             = GetBaseAddress();

            //Open the process and load all memory regions of game into the MemoryRegions list
            //Each entry in list is a struct (MemoryBasicInformation)
            _processHandle = MemoryApi.OpenProcess(MemoryApi.ProcessAccessFlags.All, 1, (uint)_processId);
            MemoryRegions  = new List <MemoryApi.MemoryBasicInformation>();
            LoadMemoryRegions();
        }
Esempio n. 2
0
        /// <summary>
        /// Will open the process and get the handle for reading. If successful returns true.
        /// </summary>
        public bool OpenProcess(int processId)
        {
            // get reference to the process
            _process = Process.GetProcessById(processId);

            // open the process
            _processHandle = MemoryApi.OpenProcess(MemoryApi.ProcessAccessFlags.All, 1, (uint)processId);

            if (_processHandle == null)
            {
                return(false);
            }

            MemoryRegions = new List <MemoryApi.MemoryBasicInformation>();

            LoadMemoryRegions();

            return(true);
        }
Esempio n. 3
0
        public void Initialize(string processName, ErrorHandler errorHandler)
        {
            _process   = null;
            _processId = 0;
            _processMainWindowHandle = IntPtr.Zero;
            _baseAddress             = IntPtr.Zero;
            _errorHandler            = errorHandler;
            Process[] processList;

            try
            {
                processList = Process.GetProcessesByName(processName);
            }
            catch
            {
                _process = null;
                return;
            }

            if (processList.Length < 1)
            {
                return;
            }

            // get a reference to the process
            _process   = processList[0];
            _processId = _process.Id;
            _processMainWindowHandle = _process.MainWindowHandle;
            _baseAddress             = GetBaseAddress();

            //Open the process and load all memory regions of game into the MemoryRegions list
            //Each entry in list is a struct (MemoryBasicInformation)
            _processHandle = MemoryApi.OpenProcess(MemoryApi.ProcessAccessFlags.All, 1, (uint)_processId);
            MemoryRegions  = new List <MemoryApi.MemoryBasicInformation>();
            LoadMemoryRegions();
        }