返回列表 发帖

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

全局动态调用笔记
3 `) w3 w' Z8 P* @4 ]svchost files工程->插入->类(Generic Class DTDY)->DTDY.cpp DTDY.h
7 H0 K8 Q; ^0 j* A/ D----------------------------------------  d* u; C% K  Q( x
DTDY.h:
; }/ l3 m4 Q" P' x' `1 f7 l# O
! b0 L5 p) C) y, w#if _MSC_VER>1000  m. K+ O6 \5 @
#pragma once
- t3 o% g; Q! a0 L# E6 {& M0 u#endif //_MSC_VER>1000
8 [. o; \, [/ i2 [. q: x#include<windows.h>
5 Z5 b$ b, }# s" K8 S5 _* F' z! ]9 q9 E
typedef DWORD (__stdcall *pGetModuleFileNameA)(HMODULE,LPSTR,DWORD);
8 x* S( b2 \' U- B' C1 |5 y3 r2 Wclass DTDY
4 M  A, u" c( r1 A1 v5 n  g{
- Q/ D0 t3 I6 W/ Y: Ypublic:. h: q/ f9 l6 t
DTDY();
3 f+ u( y( d' j# }' O0 s. b+ Uvirtual ~DTDY();/ H5 ^1 O! ?' q5 a
public:$ Y7 u2 J. c1 j* A( e
static pGetModuleFileNameA MyGetModuleFileName;) M, F6 E. K$ _, o9 N  V
static BOOL FunInitiallization();4 z5 z' _0 @) J8 G; g
};
7 q: r5 D; [2 E7 |! w#endif
. D* ?1 V. w  B! P  ?----------------------------------------4 H0 y' x3 b" S2 r
" u  q: A9 s3 t& t' _
DTDY.cpp:
* Y4 r, Q  ^8 U# y- Z
$ j. y/ ~3 c. y! _* U, D#include "DTDY.h"% m# e% e" s4 V  W  ~3 N/ |
pGetModuleFileNameA DTDY::MyGetModuleFileName=NULL;
+ E; s1 A' M) ~7 X& z* D) B; ADTDY:TDY()
- }% H, l+ X  B6 r% a; r{
; i) e2 q* O: o; y5 e1 x}
8 V9 L8 ~8 c. v/ mDTDY::~DTDY()
2 p, m# `# [# c' O, V6 ]{
# F7 p$ u$ H9 A}8 k0 k" y0 b8 t0 w5 q7 P) ?
BOOL DTDY::FunInitiallization()4 o( ]( |! D% U& O1 j
{( X5 I5 F5 e8 B% j% X9 H& I
HMODULE hModule=LoadLibrary("kernel32.dll");) @) _, a' H6 t5 G, Y* c
MyGetModuleFileName=(pGetModuleFileNameA)GetProcAddress(hModule,"GetModuleFileNameA");: J0 @6 x% S+ C
if(!MyGetModuleFileName=) return FALSE;# G% D" f7 H, k6 |% G7 J
# x$ W- J# D, ~1 u  f- T8 _
return TRUE;. o: f. z9 S% ?. B
}" i  B% @5 N% s) d" `7 `: m" B- H. h" I
----------------------------------------
2 Z" Y2 E4 ]4 s. w( ]/ isvchost.cpp:4 O& g; W6 w% g, P, u
' [( V" _2 t- C1 t. P4 E/ o% Z
#include "DTDY.h"
3 a/ B* x6 ?1 j* [
5 U% G+ c) ~. T6 u' e1 \  fBOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)* k# a, ~9 G& U2 u% K% f
{# Z- c* y% N% R2 D
switch(ul_reason_for_call)8 e; j) _# P0 b1 X0 Q* M
{* _; J4 V# `( f, W
case DLL_PROCESS_ATTACH:8 O7 m) M, g$ M
if(!DTDY::FunInitiallization()) return FALSE;8 v$ j5 ^! Y3 u5 m& P
# f& Y  n* C% l5 @4 @, ]4 x
break;
" Z2 w- x. T" w+ X}( A" Y* k( {: l/ i' a6 J
}. J& L4 }) k" s
1 V1 `, G& h: U# H0 ?* d
2 {1 _# r3 A: n; H" x( _9 ]$ @  `
GetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));->goto def% M8 \4 E0 g2 L7 U8 j
改写为
2 u) L6 ?, s9 ?2 f2 hDTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strFileName,sizeof(strFileName));
9 N; M' e# D# e) _( `. v2 e/ Y----------------------------------------7 i; x+ d3 u$ C0 w! S$ e# j& E/ d9 {: o
KernelManager.cpp:. ]( W/ L, n& V7 s( f* m6 D

" K6 `2 |4 `- x+ p#include "../DTDY.h"
8 ?; ~" ~( \3 N1 C! PGetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));
2 n, x9 }$ }1 K. d& L. K改写为
! d! ], z3 b, j4 {DTDY::MyGetModuleFileName(CKeyboardManager::g_hInstance,strServiceDll,sizeof(strServiceDll));1 g- N6 c' S/ Z" Q; H8 i; h
----------------------------------------

返回列表