Example #1
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);
        }
Example #2
0
 public bool LINQ() => ArrayA.SequenceEqual(ArrayB);