Esempio n. 1
0
        private IMAGE_SECTION_HEADER findSection(ProcessMemoryReader pmr, IntPtr baseAddr, int modSize, string secName)
        {
            byte[]           buffer = pmr.ReadProcessMemory(baseAddr, modSize);
            IMAGE_DOS_HEADER idh    = buffer.ToStruct <IMAGE_DOS_HEADER>();

            IMAGE_NT_HEADERS32 inh = bytesToStruct <IMAGE_NT_HEADERS32>(pmr, baseAddr + idh.e_lfanew);

            IMAGE_SECTION_HEADER ish = new IMAGE_SECTION_HEADER();

            for (int i = 0; i < inh.FileHeader.NumberOfSections; i++)
            {
                ish = bytesToStruct <IMAGE_SECTION_HEADER>(
                    pmr,
                    baseAddr + idh.e_lfanew + Marshal.SizeOf(typeof(IMAGE_NT_HEADERS32)) + (Marshal.SizeOf(typeof(IMAGE_SECTION_HEADER)) * i)
                    );

                if (new string(ish.Name).ToLower().TrimEnd('\0') == secName.ToLower())
                {
                    break;
                }
            }
            return(ish);
        }
Esempio n. 2
0
        private int[,] pointersToMinesArray(ProcessMemoryReader pmr, Board board, List <ArrayB> lArrayB, out bool isEmpty)
        {
            int[,] iMines = new int[board.Height, board.Width];
            isEmpty       = true;
            int sum = 0;

            for (int y = 0; y < board.Width; y++)
            {
                for (int x = 0; x < board.Height; x++)
                {
                    int mine = readMemoryToT <byte>(
                        pmr,
                        (IntPtr)lArrayB[y].ByteArrayPtr + x,
                        new Func <byte[], byte>(delegate(byte[] buffer)
                    {
                        return(buffer[0]);
                    }));
                    sum         += mine;
                    iMines[x, y] = mine;
                }
            }
            isEmpty = sum == 0;
            return(iMines);
        }
Esempio n. 3
0
        private void solve()
        {
            Process pMine = findProcess(MINESWEEPER_PROCESS_NAME, MINESWEEPER_EXE_PATH);

            Thread.Sleep(1000);                 // Sleep a while

            ProcessModule pmMine    = pMine.MainModule;
            IntPtr        ipBaseAdd = pmMine.BaseAddress;
            int           iModSize  = pmMine.ModuleMemorySize;
            IntPtr        ipHwnd    = getHwnd(pMine);


            bringWindowToFront(ipHwnd);
            setTopMost(ipHwnd, false);

            Thread.Sleep(1000);             // Sleep, just sleep

            Rect rRect = getWindowRect(ipHwnd);

            ProcessMemoryReader  _pmr = readerOpenProcess(pMine);
            IMAGE_SECTION_HEADER ish  = findSection(_pmr, ipBaseAdd, iModSize, ".data");

            // Anonymous method FTW!
            IntPtr iGamePtr = (IntPtr)readMemoryToT <UInt32>(
                _pmr,
                ipBaseAdd + (int)ish.VirtualAddress + 0x88B4,
                new Func <byte[], UInt32>(delegate(byte[] buffer)
            {
                return(BitConverter.ToUInt32(buffer, 0));
            }));

            Game game = bytesToStruct <Game>(_pmr, iGamePtr);

            IntPtr iBoardPtr = (IntPtr)game.BoardPtr;
            Board  board     = bytesToStruct <Board>(_pmr, iBoardPtr);

            IntPtr iArrayAPtr = (IntPtr)board.MineArrayPtr;
            ArrayA arrayA     = bytesToStruct <ArrayA>(_pmr, iArrayAPtr);

            IntPtr        iArrayBPtr = (IntPtr)arrayA.ArrayBPtr;
            List <UInt32> lArrayBPtr = pointersToList(
                _pmr,
                (int)board.Width,
                new Func <int, IntPtr>(delegate(int index)
            {
                return(iArrayBPtr + Marshal.SizeOf(typeof(UInt32)) * index);
            }),
                new Func <byte[], UInt32>(delegate(byte[] buffer)
            {
                return(BitConverter.ToUInt32(buffer, 0));
            }));

            List <ArrayB> lArrayB = pointersToList(
                _pmr,
                lArrayBPtr.Count,
                new Func <int, IntPtr>(delegate(int index)
            {
                return((IntPtr)lArrayBPtr[index]);
            }),
                new Func <byte[], ArrayB>(delegate(byte[] buffer)
            {
                return(buffer.ToStruct <ArrayB>());
            }));

            bool isEmpty;

            int[,] iMines = pointersToMinesArray(_pmr, board, lArrayB, out isEmpty);
            if (isEmpty)
            {
                initMinesweeper(rRect);
                iMines = pointersToMinesArray(_pmr, board, lArrayB, out isEmpty);
            }

            printMinesArray(iMines, (int)board.Height, (int)board.Width);

            int[,] processedArray = processMinesArray(iMines, (int)board.Height, (int)board.Width);
            //visualizeArray(processedArray, (int)board.Height, (int)board.Width);

            clickMines(rRect, processedArray, (int)board.Height, (int)board.Width);

            readerCloseHandle(_pmr);
        }
Esempio n. 4
0
 private void readerCloseHandle(ProcessMemoryReader pmr)
 {
     pmr.CloseHandle();
 }