;这个程序中有不少程序细节的技巧,要认真体会有注释的地方
opt("MouseClickDelay", 0);设置鼠标移动及点击延时为0
opt("MouseClickDownDelay", 0)
opt('MouseCoordMode', 0);设置用于鼠标函数的坐标参照
$i_pid = Run('winmine.exe')
ProcessWait($i_pid)
$v_Open = _MemOpen($i_pid)
;Width 0x1005334
;$i_Width = _MemRead($v_Open, 0x1005334, "Byte") ;注释部分是到内存中取值的做法,不过在注册表中有一份,所以两种方法都可以
$i_Width = RegRead('HKEY_CURRENT_USER\Software\Microsoft\winmine', 'Width')
;Height 0x1005338
;$i_Height = _MemRead($v_Open, 0x1005338, "Byte") ;注释部分是到内存中取值的做法,不过在注册表中有一份,所以两种方法都可以
$i_Height = RegRead('HKEY_CURRENT_USER\Software\Microsoft\winmine', 'Height')
;Number 0x1005330
;$i_NonMines = _MemRead($v_Open, 0x1005330, "Short")
;$i_NonMines = $i_Width * $i_Height - $i_NonMines ;注释部分是到内存中取值的做法,不过在注册表中有一份,所以两种方法都可以
$i_NonMines = $i_Width * $i_Height - RegRead('HKEY_CURRENT_USER\Software\Microsoft\winmine', 'Mines')
Dim $i_Array = 0;非雷数
Dim $ai_Loc[$i_NonMines][2];用于存放非雷的坐标
For $y = 0 To $i_Height - 1
For $x = 0 To $i_Width - 1
;mine 0x1005340 + 32 * y + x
$Mine = _MemRead($v_Open, 0x1005340 + 32 * ($y + 1) + ($x + 1), "Byte")
If $Mine = -113 Then ;8F
ConsoleWrite("X ")
ContinueLoop
Else
ConsoleWrite("O ")
$ai_Loc[$i_Array][0] = 23 + $x * 16
$ai_Loc[$i_Array][1] = 112 + $y * 16
$i_Array += 1
EndIf
Next;~
ConsoleWrite(@LF)
Next ;获取非雷的坐标完毕
_MemClose($v_Open)
$v_Open = UBound($ai_Loc) - 1
opt('WinTitleMatchMode', 4);更改窗口函数在执行搜索操作时的标题匹配模式。
For $i = 0 To $v_Open
MouseClick('left', $ai_Loc[$i][0], $ai_Loc[$i][1], 1, 0)
If StringInStr(WinGetText('active'), '确定') Then ExitLoop;如果过关要留记录说明雷扫完了,这个窗口不一定弹出来
Next;扫雷主程序结束
Func _MemOpen($i_Pid, $i_Access = 0x1F0FFF, $i_Inherit = 0)
Local $av_Return[2] = [DllOpen('kernel32.dll') ]
Local $ai_Handle = DllCall($av_Return[0], 'int', 'OpenProcess', 'int', $i_Access, 'int', $i_Inherit, 'int', $i_Pid)
If @error Then
DllClose($av_Return[0])
SetError(1)
Return 0
EndIf
$av_Return[1] = $ai_Handle[0]
Return $av_Return
EndFunc ;==>_MemOpen
Func _MemClose($ah_Mem)
Local $av_Ret = DllCall($ah_Mem[0], 'int', 'CloseHandle', 'int', $ah_Mem[1])
DllClose($ah_Mem[0])
Return $av_Ret[0]
EndFunc ;==>_MemClose
Func _MemRead( $ah_Mem, $i_Address, $s_Type = '' )
If $s_Type = '' Then
Local $v_Return = ''
Local $v_Struct = DllStructCreate('byte[1]')
Local $v_Ret
While 1
DllCall($ah_Mem[0], 'int', 'ReadProcessMemory', 'int', $ah_Mem[1], 'int', $i_Address, 'ptr', DllStructGetPtr($v_Struct), 'int', 1, 'int', '')
$v_Ret = DllStructGetData($v_Struct, 1)
If $v_Ret = 0 Then ExitLoop
$v_Return &= Chr($v_Ret)
$i_Address += 1
WEnd
Else
Local $v_Struct = DllStructCreate($s_Type)
DllCall($ah_Mem[0], 'int', 'ReadProcessMemory', 'int', $ah_Mem[1], 'int', $i_Address, 'ptr', DllStructGetPtr($v_Struct), 'int', _SizeOf($s_Type), 'int', '')
Local $v_Return = DllStructGetData($v_Struct, 1, 1)
EndIf
Return $v_Return
EndFunc ;==>_MemRead
Func _SizeOf( $s_Type )
Local $v_Struct = DllStructCreate($s_Type), $i_Size = DllStructGetSize($v_Struct)
If @error Then
SetError(1)
Return 0
EndIf
$v_Struct = 0
Return $i_Size
EndFunc ;==>_SizeOf
以上是从源码区找来的扫雷外挂的代码,想知道其中的内存基址(0x1005334)是如何获取到的。