|
本帖最后由 differentrain 于 2014-6-20 16:05 编辑
! m$ L! w: O2 f- c: i. P& T) a6 d7 F" u
不怎么用Office系列,今天偶然和朋友聊起来,突发奇想用Excel做了个扫雷的修改器....[em1127]1 _1 Y& q+ B1 B3 G k/ L4 S
虽然不会Excel,不过VB咱小时候还是学过的...[em1124]
1 C3 b5 |2 W& N- p) h9 w2 l# m' z+ e ~1 k/ V& Q* v8 W( r
我用的Win7的扫雷,其他版本的估计不行..可以停止计时和在表格中现实地雷位置...
& h1 ?4 W* R, U附件就是那个表格...如果版本不对就直接看代码部分自己复制过去也行..
% ^' u* e+ \$ T6 @顺便说,VBA简直反人类..MS为什么不出VBA.NET啊...大段的代码要自己写,而且抽象性巨差....3 X& w! N9 U! q+ i. T# g6 z/ B
3 e/ J5 `) z$ W6 ]# L2 L3 V$ y# C
MineSweeperTrainer.rar
(22.27 KB, 下载次数: 6)
4 X: v4 |" L( s6 c, Q0 N- ^ l2 Q" M# o( ^* j" I7 A2 D
: w* g7 B# h' E: X
/ k, x k8 N! u0 M9 O+ g2 w z- E& X! G, i; e
- 【控件】( O" @( }% R1 K( T# ?
- k2 A/ P( N h7 Q; N- 窗体:frmMain
% Q( R6 o7 j1 S, R" P$ V2 ~ - 按钮:btnCatchGame,btnRefresh+ \& C9 f) a& F8 o
- 选择框:chkGameTime
复制代码 ; h2 g+ F& V4 T* z
* ]1 V' q+ f- l9 N& b* C+ m1 A% E" y3 m5 w8 U" R' y
) O; [( L/ v$ W5 Q+ i
- 【代码】2 @) d2 l3 o, {" l z$ ~- R; T
- 6 W+ E- d* R7 \& p7 Q7 F
- ! r( r+ C4 ^" d' S( j/ g
- Option Explicit
' p% a+ V7 S' \ - ( e6 H B+ V" k8 ^/ h8 d
- d' ]" n7 s8 @' a& D- Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long, l! F* d! d, ~+ b' H$ ^) e$ b
- Private Declare Function module32First Lib "kernel32" Alias "Module32First" (ByVal hSnapShot As Long, lppe As moduleENTRY32) As Long/ }3 d+ s+ ^) W7 `% n$ {
- Private Declare Function module32Next Lib "kernel32" Alias "Module32Next" (ByVal hSnapShot As Long, lppe As moduleENTRY32) As Long6 V2 s, a/ o, {5 N9 N: @8 ?8 [
- Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, lppe As PROCESSENTRY32) As Long8 f' s+ V n- P2 N& v8 k/ U
- Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, lppe As PROCESSENTRY32) As Long
3 P8 E1 ?4 }1 k2 w0 L( m* K - Private Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long$ \3 Z* d: {; h2 l& c& [ D' f
) O- h2 c: \$ w; F9 ]' h
' X: ?9 F# q( [- @2 y, j8 C" s- Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
1 R3 D- u6 x. L: w - Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long; f8 k e6 F# o4 t0 Z6 A
- Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long' O" T! G4 m7 W* }* A
- Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long0 O; u* X. K, ^
4 Y5 @% S6 r( d
# Z+ P5 V5 K# Z4 p+ E% z2 a- Private Const TH32CS_SNAPPROCESS = &H2# o8 u. P+ J* J; I# Q$ y2 i
- Private Const TH32CS_SNAPmodule = &H8
" \4 p/ V* T1 r- ?3 n- { - Private Const CB_SHOWDROPDOWN = &H157
, {7 z9 u0 J) }( o& ] - Private Type moduleENTRY32
! i$ s7 s; S1 S' g" l* q$ N5 }& u - dwSize As Long
1 V; W" [6 ~/ q5 s% Q/ d - th32ModuleID As Long9 ?7 c$ m0 B+ z9 H6 G
- th32ProcessID As Long; B6 _, \" i( _* R" x3 r
- GlblcntUsage As Long- m: E! q' w& Z0 `
- ProccntUsage As Long: C2 |. U' c% P& r3 w/ f
- modBaseAddr As Long
v8 a1 v& m8 z2 v: x' \; T5 z - modBaseSize As Long
, V% d! m2 k ^# r0 B/ ~- o - hModule As Long
: F6 z, z& [/ R - szModule As String * 256
7 J" `9 ]* _, u% G6 v7 a - szExePath As String * 1024
; G* z* ~) ?( u" e" B8 g5 O - End Type; P8 M4 {$ @4 Z2 H6 o
1 {2 q- T" ]! }# L2 y7 d. C- Private Type PROCESSENTRY32
|! z# I7 Z) ]9 c( |- d5 k - dwSize As Long% y$ S( u3 |( m+ ?4 k2 f) z: Y
- cntUsage As Long2 n" V7 ?9 D6 M+ h' s
- th32ProcessID As Long6 T! }- ?. _/ j% F
- th32DefaultHeapID As Long
( N. d Z6 `! D' ]* i - th32ModuleID As Long* k: y4 Y- ~6 y$ |1 ^
- cntThreads As Long7 f: s/ d" _. B
- th32ParentProcessID As Long
( V/ u; [" X n: I% R+ k. Z9 p& ] - pcPriClassBase As Long& x) r# a( O, ?8 ~6 Q
- dwFlags As Long
4 [+ f: b* a6 U" y5 u% A8 M Y; s* _5 Z - szExeFile As String * 10247 M; r# `( B2 X6 Y( p! F. }) e
- End Type/ d8 g0 b" T& _( q
- o! O8 T6 @' r$ g: X3 B' L- : l/ r3 Y `" m
9 N; l6 O# ]- _- Private Const PROCESS_ALL_ACCESS = &H1F0FFF% U0 N, c) Z7 h# k
- Private hProcess As Long
; i6 N' {8 Y2 M { - Private PID As Long5 \! L. @ u. ]" M
- 8 G$ }, r2 e4 c3 W. N' Q
- 7 k: x! B% _) v' g/ X
- Private Type asmNum
) c, O& m$ @' y# E - nuM1 As Byte l# ], W# y$ M
- nuM2 As Byte
' a& h9 N$ ]: E - nuM3 As Byte
, v# Q. g/ E1 e8 F* N: r7 x; d - End Type
. H0 Q3 k* ?, {# E, Q U - ' K5 t3 M* o) ?" ~: r7 ]8 I
- Private adrTime As Long4 f: s% E1 C2 j$ Q; `
- Private adrMine As Long1 i; {8 b( z+ X1 q# f% _9 ?% z2 f m
- m. d. r8 Q1 Q& X% L( A6 P- Private Function GetProcIdByName(ByVal ProcName As String) As Long
% \0 W. F7 [' N* g) Y; u7 O - Dim PE32 As PROCESSENTRY32
! F1 q ?0 y+ r8 e- H) A. e& Z - Dim Procid As Long+ t" A2 L: u% c( `" e9 \1 D* X( z
- Dim hSnapShot As Long, Z$ [! ^. R, l8 x
- hSnapShot = CreateToolhelp32Snapshot(ByVal TH32CS_SNAPPROCESS, ByVal 0)
3 F- X/ @; X( H; |' Z( h: {5 `, X - PE32.dwSize = LenB(PE32)
$ X5 H8 l( t4 |3 `9 d7 W$ U" ^$ o" b - Process32First hSnapShot, PE328 @5 W i2 x! `, R2 `9 B2 G
- Do% z, U- [( R9 o4 p; r& n! l
- If lstrcmpi(Trim$(ProcName), Trim$(PE32.szExeFile)) = 0 Then( W% s/ z: L/ j# w$ w6 {8 e4 ]
- Procid = PE32.th32ProcessID* y5 E6 l9 f' J7 P; H2 r; a
- Exit Do
) d4 E( ^$ L u0 ] - End If0 J! O% G" z2 ?8 M- @+ C/ M ^2 O
- PE32.szExeFile = vbNullString
* g7 Y8 L5 i) K; O _! u+ u - Loop Until Process32Next(hSnapShot, PE32) = 0) B1 H- B( `* `( q7 Z: a
- CloseHandle hSnapShot8 b0 G: [0 ]- o
- GetProcIdByName = Procid
4 S! t, e- r7 V - End Function
" o- e; D! S" _( x
* Z& `! F% Y; o& v {9 G- * p+ O# i. ]- L# i) F
( ?1 \) z" t0 {" j5 d8 O- Private Function GetModuleBaseByProcName(ByVal ModuleName As String) As Long
8 C% b9 d' w' U0 ^
: y4 C" A# H( Y+ W! { H, n- Dim ME32 As moduleENTRY32, ModuleBase As Long
9 w B2 E$ p7 H5 D- j% T% _ - Dim hSnapShot As Long
$ u6 f' Z* |6 C( V" G% Z - hSnapShot = CreateToolhelp32Snapshot(ByVal TH32CS_SNAPmodule, ByVal PID)* x. {- q, p" m6 [
- ME32.dwSize = LenB(ME32), e$ ~1 q8 H+ Q* w4 i
- module32First hSnapShot, ME32
4 z# e) ?. n1 D/ v. a! i, B9 A - - P7 \: z3 }% j7 u2 f. \
- Do# O! G5 {( i" t# U6 V2 x% G
- ) _3 D5 D3 Y1 `6 e
- If lstrcmpi(Trim$(ModuleName), Trim$(ME32.szModule)) = 0 Then2 \. v2 X: c3 _1 q
- ModuleBase = ME32.modBaseAddr
, L+ G; N; I5 G4 V. J/ Q. }/ A - Exit Do- _+ l/ G6 f& G! n ]& ]
- End If; b; j, e3 {/ i( J, j6 r
- - ~* a& s, M% s
- ME32.szModule = vbNullString4 I# T h p3 ?( ^: G. H0 I8 r3 r
- 5 k+ Z- g- \( A. E- Y6 a
- Loop Until module32Next(hSnapShot, ME32) = 0
( Z* t" v) u+ _3 Q, y, d6 l# i - CloseHandle hSnapShot
0 W' S5 T- _. v" l% g0 i - GetModuleBaseByProcName = ModuleBase6 f$ } [- S d7 F( z! r" G
- 3 [( `+ l% c) v* I7 I
- End Function6 F& O! i# @3 m' I2 B; M! f* o) B
; ~8 O9 t2 w# W& B( {5 W+ V3 e3 w; v
: v: m) x) x! ~9 ~* T! r b" Q1 _- Private Function GetMemory(ByVal Adderss As Long, Optional Length As Byte = 4) As Long+ z& l. k, v% {& [5 ~. x* C, J9 ]
- ReadProcessMemory hProcess, Adderss, GetMemory, Length, 0- {& i& u7 o: i2 C q! H6 E
- End Function
( s$ G: D5 S& W& z - Private Sub SetMemoryAsm(ByVal Adderss As Long, NumVal As asmNum)5 a4 Q) z, P3 o* x0 V3 f8 T
- WriteProcessMemory hProcess, Adderss, NumVal, 3, 0
8 G7 x! W) o2 Q% [) g8 M6 W - End Sub" R) ]3 a- b5 \, E) |
- d0 a+ l$ i" I& \+ f$ V7 w- 7 p% d7 p/ t+ l: @5 h9 V
- Private Function FindGame() As Boolean
( k; k+ I4 A$ w1 H; k; o# N -
2 T! t# I7 l# C" d+ X, {$ T - PID = GetProcIdByName("MineSweeper.exe")
" X" F! P" t2 n1 X -
+ g. h% A7 H# K9 ~/ L3 Y7 f - Select Case PID
1 B& X7 M, @2 ?* T/ p% u - Case 05 R; j% ]: f$ p$ D- d/ h
- FindGame = False4 }2 ] Y, _/ v
- Case Else( S; s) X& }0 p6 \, V& S
- Dim adrBase As Long7 T2 j9 h( a9 H( M2 d
- adrBase = GetModuleBaseByProcName("MineSweeper.exe")
2 \7 B1 a4 P* O9 N2 @: G/ S - adrTime = adrBase + &H21446
% v0 e% X0 b, }* d3 n3 E - adrMine = adrBase + &H868B4
8 V* C' S o, G2 P- k* L+ | - FindGame = True* ?3 Q' K& w% L6 b; O5 V
- End Select
. |' S" x& Y1 P$ B - End Function
' m! w7 x& w$ j% }1 Z' E3 z - C4 `7 A+ }0 n; h
- Private Sub TrainerState(ByVal State As Boolean)
4 ]+ ?7 r0 @5 T( V7 J& ~+ N - chkGameTime.Enabled = State
' q) l+ S1 L# w, M - btnRefresh.Enabled = State
2 f- l9 Y3 q5 ? - Select Case State
/ q/ t; n# G5 T' E - Case True
; _- R, \$ \% R3 R& b) a - btnCatchGame.Caption = "ReleaseGame"6 D/ ?* {) m( K- _
- Case False
1 L. O: b+ |# n% U - btnCatchGame.Caption = "CatchGame"8 j+ o: |+ L7 _; M; m
- chkGameTime.Value = False
) j3 S! n. a7 B4 F- O" @9 _3 a" I - End Select7 v) E' r* w6 Z' p, @8 z0 P$ s
- End Sub
" I- D' j* U" Y# z% E" L - & B6 U) N" j% d6 [
- & Z; B0 k# V6 t4 b% ?- S# i; c
- Private Sub AsmState(ByVal State As Boolean)) P+ m% |1 W6 u1 X% n$ J
- Dim asm As asmNum
$ |! _# ?4 I0 _* [ - Select Case State
* G% ~' ]+ R; {6 R. J - Case True
9 b; N; q4 D9 i) v$ G+ m3 r - asm.nuM1 = &H90
0 g7 z& m6 q; s - asm.nuM2 = &H90
, U: W( u( ~+ K% l* U9 z - asm.nuM3 = &H906 ^( W# N# y, u0 z" m- D
- Case False
' S/ i' [! ^* {: n& K3 n - asm.nuM1 = &HD9
) s0 k( N s4 C. J( T( U. a5 W - asm.nuM2 = &H58
% i" @# \" r, D - asm.nuM3 = &H1C& j2 H0 g7 H0 [, x
- End Select
4 {( B: U6 N! N- C7 r8 B1 T - Call SetMemoryAsm(adrTime, asm)
/ m& d8 ?. @! V. X1 x& j - End Sub
4 y2 H3 y0 g/ x& `2 d ~ - 8 D% k+ V! f0 |- F1 g. Z
- * T. w+ C3 W4 }/ y
- Private Sub chkGameTime_Click()
5 }4 o$ @1 d: @; e( a2 f# m - AsmState (chkGameTime.Value)9 Q0 K: Q$ B1 L1 a) e
- End Sub
6 M C; [, {- j- H - $ m } o* K3 N, p( M
- - h$ w4 O# u+ b L7 K
- Private Sub isOpen(ByVal State As Boolean)
" l+ L3 I) z. I; m) G/ |. O - Select Case State
4 k- |$ u! Z; p8 d - Case True
2 z5 u" Z- ~3 G# y% H; Q8 m - If FindGame = True Then" p- H; {9 T% J1 x
- hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, PID)+ S- M; d1 j# ^- i& |
- TrainerState (True)3 f: L% P5 `6 z4 S2 F0 Y
- End If
% l* B! {2 Q* K/ @$ f2 h- |" H - Case False
- j6 R5 B0 G" K - If FindGame = True Then
, `: Y* B* l) p% J% C2 l& _+ ] - AsmState (False)
* O/ Y: {* m7 Y. k - CloseHandle hProcess
! v, Q7 |, U: q - End If* P0 v9 L# ]- \5 ?* P( e! P
- End Select
# P( n$ x- w- j% R2 | - End Sub g' f2 e' a" b! [" q/ ~7 C
- 0 ~5 G# m# h: B7 m: U$ V: F) g
4 R. R0 `2 {! A' a) Q; [6 E- Private Sub btnCatchGame_Click()
% I+ p/ {5 }, P7 \ - Select Case btnCatchGame.Caption
6 B( I4 k# q" s* c3 \ - Case "CatchGame"$ l8 \+ {% G$ r" b2 |7 f
- isOpen (True)
: U5 j& ?0 y& d - Case "ReleaseGame"
/ J* @9 A# U0 f; X( J# }4 F - isOpen (False)
& N4 @. P# ~" ` - TrainerState (False)0 y- j9 S/ z7 ^6 `: V1 u
- End Select
% Q/ w8 \$ p% e% \, B; g - End Sub
- e9 N0 H( h5 ~
# f8 ?1 `- C. F- Private Sub btnRefresh_Click()
# e4 E- W- L; R
/ R1 \3 u5 j% u7 Y+ E9 S7 W0 }% L- Dim mineColumn As Byte, mineLine As Byte
% o- Z$ |$ p2 V$ a% n - Dim adrPoint As Long, adrTemp As Long, adrColumn As Long
5 T; e1 T+ S% U9 i$ P; W0 K7 C - Dim i As Byte, j As Byte
; I3 z( k$ L* ^' a: ]
- }1 o3 L. x& Z' _, Q-
% s6 E& }8 P/ {: `8 | -
p& f- D. F/ I1 S0 | - btnRefresh.Enabled = False% N; c( h. g( R7 U/ A( C, v9 g
- " t- u4 Y& o& P' `8 N2 |( ?& ?
- adrTemp = GetMemory(adrMine); M, f5 m) a" b
- adrPoint = GetMemory(adrTemp + &H10)
5 k6 a& U" j5 Z: D# v# K -
: b* T( H$ U1 B2 K5 g+ ? - mineLine = GetMemory(adrPoint + &H8) - 15 q0 \7 b% O0 B/ o; M3 V& ?( D
- mineColumn = GetMemory(adrPoint + &HC) - 1
3 i7 w2 P: @* a& U* _ - ) R* u" o. `9 w# x* E+ `3 O, H D
- adrPoint = GetMemory(adrPoint + &H44)4 }; g" [- @! H% O
- adrPoint = GetMemory(adrPoint + &HC)
) T1 B# V- i2 q' J3 a -
# ~) @( P5 A2 m- O) M5 r9 X - 9 g [" f( Y* O. Z9 K/ T- C: C
- u7 h* ?: `; U( S
- For i = 0 To 302 n% d8 L8 k1 \1 O& `
- adrColumn = GetMemory(adrPoint + i * 4)8 ] Z2 Y) E% J
- adrColumn = GetMemory(adrColumn + &HC)
2 i4 x' o" G+ {' h' E3 l0 A - For j = 0 To 23
7 T- i. d" D& h - If i > mineColumn Or j > mineLine Then
. f2 k% T9 W# B# D6 G - Sheet1.Cells(j + 1, i + 1) = ""2 a$ ]8 w! V$ e% |
- Else. S, j6 K1 `6 e
- Sheet1.Cells(j + 1, i + 1) = GetMemory(adrColumn + j, 1)1 F3 ]$ E4 L0 X/ k: U2 Q8 W
- End If O! R! T$ T) y0 ^
- Next j
. ?* e$ d v. S: e- f/ u - Next i
) M7 f3 |8 p% \) T+ j - btnRefresh.Enabled = True f9 r7 w# C* s7 C. Z7 h' _) a
- 8 B9 h& G! ]- k5 ]; Z. T+ O/ e
-
: i8 K# b- h* M4 Q" ^! Y - End Sub" f# i4 B8 q# O$ k* t+ d( o+ i8 X
- , c6 M4 H& i( |- C
- Private Sub UserForm_Initialize()
# l7 E4 Z: p) p g* q$ M7 F* V - TrainerState (False)
8 O3 t2 _8 f3 r2 Y6 L8 N - Sheet1.Cells(1, 2) = 1( b9 f! r$ w, |; I4 z; Z
- End Sub
8 j/ c/ I4 H6 L; o- n( A9 K - ( G: b. f# p2 I$ Y, E
- Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer), ^/ x0 ?$ U8 p
- isOpen (False) M+ z2 z9 @! v( Y, _1 j/ Y1 A& @
- End Sub; i5 m# I0 A( l7 }
复制代码 4 f9 d# l' h( d' m1 v0 U9 O
; g4 O! o |0 F7 }% x2 b" {
8 T. q5 V% w/ Z2 t: ^7 U9 \, {9 Z9 \5 K& |& p( x$ H2 T
|
|