SHARE
TWEET

MineSweeper.asm

finalshare Oct 26th, 2017 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .486                                    ; create 32 bit code
  2. .model flat, stdcall                    ; 32 bit memory model
  3. option casemap :none                    ; case sensitive
  4.  
  5. include \masm32\include\windows.inc     ; always first
  6. include \masm32\macros\macros.asm       ; MASM support macros
  7.  
  8. include \masm32\include\masm32.inc
  9. include \masm32\include\gdi32.inc
  10. include \masm32\include\user32.inc
  11. include \masm32\include\kernel32.inc
  12. include \masm32\include\msvcrt.inc
  13.  
  14. includelib \masm32\lib\masm32.lib
  15. includelib \masm32\lib\gdi32.lib
  16. includelib \masm32\lib\user32.lib
  17. includelib \masm32\lib\kernel32.lib
  18. includelib \masm32\lib\msvcrt.lib
  19.  
  20. ;proto type function
  21.  
  22. getAdressOfXY PROTO ro:DWORD,co:DWORD
  23.  
  24. readByte PROTO address:DWORD
  25. readDWORD PROTO address:DWORD
  26. printStatus PROTO result:DWORD
  27. setTextColor PROTO color:DWORD
  28. .const
  29.     ;Base address
  30.     ptrBase equ 1005340h
  31.     ;Some propertiess
  32.     ptrNumRow equ 010056A8h
  33.     ptrNumCol   equ   010056ACh
  34.     ptrNumFlagLeft equ 01005194h
  35.     ptrNumBomb    equ 01005330h
  36.     ptrTimer       equ 0100579Ch
  37.  
  38.     ;Array Flag
  39.  
  40.     isSafe  equ 0Fh
  41.     isBomb  equ 8Fh
  42.     isOpen  equ 40h
  43.     is1bomb equ 41h
  44.     is2bomb equ 42h
  45.     is3bomb equ 43h
  46.     is4bomb equ 44h
  47.     is5bomb equ 45h
  48.     is6bomb equ 46h
  49.     is7bomb equ 47h
  50.     is8bomb equ 48h
  51.     isFlag  equ 8Eh
  52.     unKnown equ 8Dh
  53.     isExploded  equ 204
  54.     isRevealed  equ 8Ah
  55.  
  56. .data
  57.     debug BYTE 15
  58.  
  59.     numRow DWORD ?
  60.     numCol DWORD ?
  61.     numFlagLeft DWORD ?
  62.     numBomb DWORD ?
  63.     timer DWORD ?
  64.     res BYTE ?
  65.     row DWORD ?
  66.     col DWORD ?
  67.     i DWORD ?
  68.     j DWORD ?
  69.  
  70. .code
  71.  
  72. ;return address of num,col coordinate
  73.  
  74. setTextColor proc color:DWORD
  75. LOCAL hConsole:DWORD
  76. invoke GetStdHandle,STD_OUTPUT_HANDLE
  77. mov hConsole,eax
  78. invoke SetConsoleTextAttribute,hConsole, color;
  79. ret
  80. setTextColor endp
  81.  
  82. readByte proc address:DWORD
  83. LOCAL value:BYTE,pid:DWORD,pHandle:DWORD,hwnd:DWORD
  84.      invoke FindWindow,0,chr$("Minesweeper")
  85.     test eax,eax
  86.     je FindWindowsFail
  87.     mov hwnd,eax
  88.     invoke GetWindowThreadProcessId , hwnd, addr pid
  89.     invoke OpenProcess,PROCESS_VM_READ,0,pid
  90.     test eax,eax
  91.     je GetHandleFail
  92. mov pHandle,eax
  93.  
  94.  
  95.  
  96.     invoke ReadProcessMemory,pHandle,address,addr value,1,0
  97.     mov al,value
  98.     ret
  99. FindWindowsFail:
  100.     print chr$("Can't find windows",13,10)
  101.     mov eax,-1
  102.     ret
  103.  
  104. GetHandleFail:
  105.     print chr$("Can't get Handle",13,10)
  106.     mov eax,-1
  107.     ret
  108. readByte endp
  109.  
  110. readDWORD proc address:DWORD
  111.     LOCAL value:DWORD,pid:DWORD,pHandle:DWORD,hwnd:DWORD
  112.     invoke FindWindow,0,chr$("Minesweeper")
  113.     test eax,eax
  114.     je FindWindowsFail
  115.      mov hwnd,eax
  116.  
  117.     invoke GetWindowThreadProcessId , hwnd , addr pid
  118.     invoke OpenProcess,PROCESS_VM_READ,0,pid
  119.     test eax,eax
  120.     je GetHandleFail
  121.     mov pHandle,eax
  122.     invoke ReadProcessMemory,pHandle,address,addr value,4,0
  123.     mov eax,value
  124.     ret
  125. FindWindowsFail:
  126.     print chr$("Can't find windows",13,10)
  127.     mov eax,-1
  128.     ret
  129.  
  130. GetHandleFail:
  131.     print chr$("Can't get Handle",13,10)
  132.     mov eax,-1
  133.     ret
  134. readDWORD endp
  135. printStatus proc result:DWORD
  136.         CMP result, isSafe
  137.  
  138.         JE IS_SAFE
  139.  
  140.         CMP result,isBomb
  141.         JE IS_BOMB
  142.  
  143.         CMP result,isOpen
  144.         JE IS_OPEN
  145.  
  146.         CMP result,is1bomb
  147.         JE IS_1BOMB
  148.  
  149.         CMP result,is2bomb
  150.         JE IS_2BOMB
  151.  
  152.         CMP result ,is3bomb
  153.         JE IS_3BOMB
  154.  
  155.         CMP result,is4bomb
  156.         JE IS_4BOMB
  157.  
  158.         CMP result,is5bomb
  159.         JE IS_5BOMB
  160.  
  161.         CMP result, is6bomb
  162.         JE IS_6BOMB
  163.  
  164.         CMP result,is7bomb
  165.         JE IS_7BOMB
  166.  
  167.         CMP result,is8bomb
  168.         JE IS_8BOMB
  169.  
  170.         CMP result,isFlag
  171.         JE IS_FLAG
  172.  
  173.         CMP result,isExploded
  174.         JE IS_EXPLODED
  175.  
  176.         CMP result,isRevealed
  177.         JE IS_REVEALED
  178.  
  179.         print chr$("? ")
  180.         ret
  181. IS_SAFE:
  182.     print chr$(". ")
  183.     ret
  184. IS_BOMB:
  185.     invoke setTextColor,12
  186.     print chr$("* ")
  187.     invoke setTextColor,15
  188.     ret
  189. IS_FLAG:
  190.     invoke setTextColor,10
  191.     print chr$("F ")
  192.     invoke setTextColor,15
  193.     ret
  194. IS_1BOMB:
  195.     print chr$("1 ")
  196.     ret
  197. IS_2BOMB:
  198.     print chr$("2 ")
  199.     ret
  200. IS_3BOMB:
  201.     print chr$("3 ")
  202.     ret
  203. IS_4BOMB:
  204.     print chr$("4 ")
  205.     ret
  206. IS_5BOMB:
  207.     print chr$("5 ")
  208.     ret
  209. IS_6BOMB:
  210.     print chr$("6 ")
  211.     ret
  212. IS_7BOMB:
  213.     print chr$("7 ")
  214.     ret
  215. IS_8BOMB:
  216.     print chr$("8 ")
  217.     ret
  218. IS_OPEN:
  219.     print chr$("  ")
  220.     ret
  221. IS_EXPLODED:
  222.     invoke setTextColor,14
  223.     print chr$("* ")
  224.     invoke setTextColor,15
  225.     ret
  226. IS_REVEALED:
  227. invoke setTextColor,12
  228.     print chr$("  ")
  229.     invoke setTextColor,15
  230.     ret
  231.  
  232. printStatus endp
  233.  
  234. getAdressOfXY proc ro:DWORD,co:DWORD
  235.  
  236.     mov eax,ro
  237.     shl eax,5
  238.     add eax,co
  239.     add eax,ptrBase
  240.     ret
  241.  
  242. getAdressOfXY endp
  243.  
  244. start:
  245.  
  246. InfLoop:
  247.     invoke readDWORD,ptrNumRow
  248.     mov numRow,eax
  249.     invoke readDWORD,ptrNumCol
  250.     mov numCol,eax
  251.     invoke readDWORD,ptrNumFlagLeft
  252.     mov numFlagLeft,eax
  253.     invoke readDWORD,ptrNumBomb
  254.     mov numBomb,eax
  255.     invoke readDWORD,ptrTimer
  256.     mov timer,eax
  257.  
  258.     invoke crt_printf,chr$("Row: %d Col: %d Bomb: %d Flag Left: %d Time: %d",13,10), numRow, numCol, numBomb, numFlagLeft, timer ;
  259.     mov i,1
  260.     mov j,1
  261. FORI:
  262.     print chr$(13,10)
  263.     mov j,1
  264. FORJ:
  265.     invoke getAdressOfXY,i,j
  266.     invoke readByte,eax
  267.     mov res,al
  268.     invoke printStatus,res
  269.     INC j
  270.     mov eax,j
  271.     CMP eax,numCol
  272.     JBE FORJ
  273.     INC i
  274.     mov eax,i
  275.     CMP eax,numRow
  276.     JBE FORI
  277.  
  278.     invoke Sleep,1000
  279.     invoke crt_system,chr$("cls",0)
  280.  
  281.     jmp InfLoop
  282.  
  283.     invoke crt_system,chr$("pause",0)
  284.     invoke ExitProcess,0
  285. end start
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top