返回列表 发帖

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

全局动态调用笔记7 c/ v8 F: u/ l
svchost files工程->插入->类(Generic Class DTDY)->DTDY.cpp DTDY.h
& [2 G/ P- ^% e% M# j----------------------------------------
+ j( X8 r: N6 d2 ZDTDY.h:
- _  y# ?6 R8 d/ Q8 K, \5 s, K$ u, z, O+ ~. H- y
#if _MSC_VER>1000# C6 @) t7 e4 Z
#pragma once6 i4 L$ ?9 t: Q; |
#endif //_MSC_VER>1000) }1 j1 p* J* g  E5 a5 D# C
#include<windows.h>
: X6 B2 s- k5 V5 J' w; ~+ R) M  d! i; U* h
typedef DWORD (__stdcall *pGetModuleFileNameA)(HMODULE,LPSTR,DWORD);
5 A- i4 R4 q8 d2 t' F& @4 K4 yclass DTDY
4 _1 l9 i* ~! z8 `9 g{* e1 T9 N/ W! Y/ n6 I8 Z
public:
8 X& K, G: K" B- R5 Z% C, yDTDY();
2 P6 y3 V% [! |6 r% t/ Nvirtual ~DTDY();6 S$ A* P4 A& ?6 i2 ]
public:' r9 t: X- q( {1 u3 A
static pGetModuleFileNameA MyGetModuleFileName;2 v* B. e$ `% j3 @0 x
static BOOL FunInitiallization();; c7 O( i2 S0 @" d) [+ ^
};7 ~; a! Z( J2 a8 [+ g
#endif) k5 p* r" A: ?, q9 b4 U
----------------------------------------0 g# ~. V: d& X4 N. n4 t

4 T& X0 i. y& g$ {& V$ {DTDY.cpp:# f0 s; G2 t3 D# }5 c% P" Q# G* e6 }8 ?
4 S2 I% `+ T' D; \0 D0 P# u/ t! g
#include "DTDY.h"
8 W' \' y: t! b$ }pGetModuleFileNameA DTDY::MyGetModuleFileName=NULL;. @6 O7 r6 K; Q) A6 {
DTDY:TDY()
. M& h2 J& i: |) f; P{
3 Y6 {: b+ ?6 j$ h}
/ E$ V, B: d9 TDTDY::~DTDY()+ y& f9 u2 p+ n6 E+ c, S
{( H# U& R7 g0 a, Z
}
$ {. o2 S- F2 }+ J; v; P1 c+ XBOOL DTDY::FunInitiallization()3 g1 l6 L2 o5 n' C* e
{
; e% p2 c) [: }$ `9 _" r* rHMODULE hModule=LoadLibrary("kernel32.dll");1 U5 x. \$ H9 i0 x/ a2 e) d
MyGetModuleFileName=(pGetModuleFileNameA)GetProcAddress(hModule,"GetModuleFileNameA");; `. v* m- f2 Z
if(!MyGetModuleFileName=) return FALSE;. Z6 b/ _: J7 G* s
7 \: P4 P1 M/ d/ }! ~
return TRUE;
' K- i8 s1 V2 e1 }% W- `7 |" R) x}
+ ^/ g: ?0 {9 ~8 _% ~) Z----------------------------------------
% D7 f( \( o9 \" B( Lsvchost.cpp:! G; Y3 p5 N& n% l- A4 \5 x

7 s9 f: q) o/ G* Y& _( H/ V#include "DTDY.h"5 g0 U/ o+ E5 X) L
& d2 J" C+ s$ l" L5 _7 Z+ {4 e
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)9 A& u$ `) c% q4 G5 A! m# Q
{8 v1 ^* E) h! b
switch(ul_reason_for_call)
$ Q' }. [" q0 F{3 p; ?' P9 P8 D0 }# P/ Z
case DLL_PROCESS_ATTACH:
4 i* c4 j. F8 X3 ]3 J, m  K6 Pif(!DTDY::FunInitiallization()) return FALSE;
8 q: I: C/ n* C4 K) E# l
9 n* j7 o9 H3 ebreak;& s' N. o+ X( |4 c1 j# b7 J. z
}: }+ b, ]- N8 l
}0 t; \4 T  U! C0 V: e

4 F! t) f' @% w) v! B" x1 b
* d' m# w! J& s( |' pGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));->goto def$ ^6 p5 F7 A. Y
改写为/ a- S3 l! Z6 Q+ D" X# o
DTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));
0 E7 x( r. h: c( P! X; u- Y----------------------------------------( P, F5 B- h( ~1 `$ F& D
KernelManager.cpp:8 d# Q* r5 r' L2 a( u# a
, z! r; Q/ C0 \2 G* \; T( y, @
#include "../DTDY.h"2 \) O, _( H; v7 p" r0 n9 b0 s$ W
GetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));7 U2 b& ~3 `6 M) c; C  l
改写为
( A! n( P) k- B, g1 J: v& vDTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));( ^  j. S2 ^1 D& I* |
----------------------------------------

返回列表