该用户从未签到
|
我可没这个水平
9 e0 e, f2 s/ e) I! B$ ]8 C.686p0 o0 d) c7 J" @3 L
.model flat, stdcall
/ }! i/ Y% F; {option casemap :none ; case sensitive( @; d7 ~* }- k0 s$ b
; #########################################################################
/ X l: h- k m3 u, a1 tinclude \masm32\include\windows.inc
1 P' }* q" ^' iinclude \masm32\include\user32.inc
& b& e3 U% ?" l+ F# Tinclude \masm32\include\kernel32.inc
1 R# O* {6 V6 |" vinclude \masm32\include\advapi32.inc" \1 D# _# W9 i$ r1 v; A) I
' \! h2 v" J) ]. ]! V% r
includelib \masm32\lib\user32.lib2 {/ J r2 _) K9 k; C' q7 q% G
includelib \masm32\lib\kernel32.lib, L, E* l; e/ ?$ D, O+ N6 z
includelib \masm32\lib\advapi32.lib
0 [- [- {3 Z* w+ H8 y/ l9 I* C0 EDEBUG = TRUE
6 A- N8 U) E r
H2 D6 P' C% {: JHMODULE typedef dword: q5 n6 d" D# O0 p1 j3 u6 q- P
NTSTATUS typedef dword7 n0 i0 L$ P I8 _. r' S! Y
PACL typedef dword
, C) T4 ^. E0 f0 K& M# ]# S" C1 pPSECURITY_DESCRIPTOR typedef dword3 B$ } T2 z3 A6 Q( J8 A& c% {
: ^3 N- z% T5 z8 `% K: |
OBJ_INHERIT=2 ! m. `2 m, s' \1 S0 |1 n2 k
OBJ_PERMANENT=10h
% G6 B C3 K9 h8 f* l0 e: j, KOBJ_EXCLUSIVE=20h 5 u+ f2 i8 F7 {, ?: g% b
OBJ_CASE_INSENSITIVE=40h
" M6 d6 j" s3 w* R qOBJ_OPENIF=80h , m& z1 q% @2 e4 Y3 H0 c
OBJ_OPENLINK =100h 2 N7 A9 r1 R d9 ^, }) V
OBJ_KERNEL_HANDLE=200 ) X9 H1 O8 l3 f3 m: ]
OBJ_VALID_ATTRIBUTES=3F2h + L" v% S( ~0 `; j. ~! c6 B" |7 A
% D1 ]" N, O: a
SE_KERNEL_OBJECT = 61 J1 ` z) V2 m
GRANT_ACCESS =19 X: @6 N; m( P6 q: G& U
NO_INHERITANCE =0
- t: y4 u0 Y3 c6 u5 q( fTRUSTEE_IS_NAME=1
0 L6 R! I" K; vTRUSTEE_IS_USER=1- z" m$ p+ l% U% U1 P
STATUS_SUCCESS =0 1 ?) f* Z; w# }% T, z
STATUS_ACCESS_DENIED =0C0000022h+ w4 Z, z& [5 \& Q
1 A6 F- |* ]) T
STATUS_ACCESS_VIOLATION equ 0C0000005h$ S- |( A+ d' P2 U1 Q7 a4 h
STATUS_INFO_LENGTH_MISMATCH equ 0C0000004h* l4 u5 R" j8 t+ k7 A5 U( O: R6 h
SystemModuleInformation equ 11
4 O( _7 b+ Q) T( T' GPVOID TYPEDEF DWORD3 ~3 C* f) p) j+ e* Q3 n
UNLONG TYPEDEF DWORD
$ ^& u: X5 P1 ?5 r. QCHAR TYPEDEF BYTE+ @- P. e$ v6 ?. F' o$ [
& v- J. \! e q6 O r
UNICODE_STRING struct 7 b: Q3 |- o& q3 O
nLength word ?
9 d# C& b# ]. n+ T1 y; X MaximumLength word ? 7 ]; m; x: y/ Z# V& h
Buffer dword ?
; a8 q+ U$ i- j3 X9 _2 x" w9 |5 r0 aUNICODE_STRING ends
3 t4 n* t2 a b( Z5 @) \
! F/ `, O2 g- G7 i, w2 A! TOBJECT_ATTRIBUTES struct
9 f* s" V# }5 Y6 |! A! c nLength dword ?
V6 u2 G( r4 r) V. U$ K+ u RootDirectory HANDLE ?
6 S5 }7 Z3 G4 l/ g8 ^, U+ S% x, Z+ H ObjectName dword ?UNICODE_STRING
5 K( A0 K5 b& V! R Q Attributes dword ?; - `4 u' r5 t6 ?- ~ b2 F$ w
SecurityDescriptor dword ?; PVOID // Points to type SECURITY_DESCRIPTOR
' R$ i' k. f$ o! v+ H SecurityQualityOfService dword ?VOID // Points to type SECURITY_QUALITY_OF_SERVICE " q6 a6 j" m0 E# M8 L
OBJECT_ATTRIBUTES ends
! o- {' C/ v8 j1 @6 j7 Y1 q
: J I8 R/ M* b: }' s3 x, X1 |9 |0 S* O- m5 p, p- [
TRUSTEE struct
! U+ O0 B+ K6 r/ y- h5 ^ pMultipleTrustee dword ?TRUSTEE
" g! }8 s9 S K, ?2 x MultipleTrusteeOperation dword ?; MULTIPLE_TRUSTEE_OPERATION 3 ~. \6 g1 f# e! g! y9 P
TrusteeForm dword ?;TRUSTEE_FORM2 f4 p5 w3 H n; X0 f0 ^3 o0 R$ S
TrusteeType dword ?;TRUSTEE_TYPE
/ L! c! o8 p6 B5 D ptstrName dword ?;LPTSTR
& m, _* @# ~4 g$ x1 Z6 b/ TTRUSTEE ends
8 ]2 M8 ^3 m Y# d3 c# K3 z6 }( p0 Y5 i
3 S% Z! n+ @$ HEXPLICIT_ACCESS struct
& V1 ^1 a! ?$ l4 n9 b* w grfAccessPermissions DWORD ? # E! D9 i7 H; j/ t4 {. S
grfAccessMode dword ? ;ACCESS_MODE
' |* r2 V9 E" h5 ^7 U4 e1 y grfInheritance DWORD ? ;
6 A- A& _% r* [3 c ]$ l0 q Trustee TRUSTEE <> ;
9 A. ]! U3 g9 y8 p# d+ G: sEXPLICIT_ACCESS ends
4 j q/ p$ u: Z' K0 ]: t4 N8 t, o- ?) `2 ~: }/ [8 p% x9 f6 ]
MyGATE struct ;门结构类型定义
" w% W1 _0 \. {3 Q7 h OFFSETL WORD ? ;32位偏移的低16位; ?! y, B4 W& f6 g
SELECTOR WORd ? ;选择子& l& H# x7 ^- ]8 O, S, b+ ]
DCOUNT BYTE ? ;双字计数字段6 R+ [5 e W7 e* q
GTYPE BYTE ? ;类型0 Y2 Q1 x% t* V/ t& U3 |
OFFSETH WORD ? ;32位偏移的高16位$ w; A, b$ ^' n9 x: y
MyGATE ends
* Z9 l R+ z+ ?* d
% ^) s A- N; J; tIDEINFO struct' k* x' }) m' {$ I
wGenConfig dw ?
( H/ Y9 r% }6 R rwNumCyls dw ?;拄面数
w: m4 E# d! S5 ^: v, W+ NwReserved dw ?
, I7 e& E1 K& J0 k- Z5 }5 PwNumHeads dw ?;磁头数
( P4 c: j4 e+ k7 v" i# gwBytesPerTrack dw ?;每道字节数
6 b6 O p! K! I/ y$ Q+ IwBytesPerSector dw ?;每扇区字节数3 h6 s; Q) N& g7 q. d6 R5 q
wSectorsPerTrack dw ?;每道山区数$ S' A. S. Q$ d, M
wVendorUnique dw 3 dup (?)$ n* W7 l; m& E% N; I
sSerialNumber db 20 dup (?);硬盘序列号/ ^" w9 p, |8 g. r' |' b- J7 c
wBufferType dw ?;
/ Z& a9 w. f+ bwBufferSize dw ?; ;n * 512& K# N1 e1 m( @! L
wECCSize dw ?: B8 f6 a5 @7 L' c9 V/ m: b# `5 ^' _
sFirmwareRev db 8 dup (?);
$ L! ]% b4 E; Z2 H! l3 KsModelNumber db 40 dup (?)
) ^# B% Z3 u1 K$ bwMoreVendorUnique dw ?% b0 |" E5 u0 o( {0 r1 z4 z" E4 O5 `
wDoubleWordIO dw ?
0 S+ V9 g/ W( ~wCapabilities dw ?
" h2 Z1 V& n2 X' m% z9 awReserved1 dw ?0 [9 n* z; F" k& `3 _4 y
wPIOTiming dw ?;6 b5 x. R* k* h% M
wDMATiming dw ?;& ?! ] K* M2 U# q; }# v! B9 I! g
wBS dw ?& A/ S3 y3 E4 S6 D
wNumCurrentCyls dw ?;1 f) w5 E/ ?7 D
wNumCurrentHeads dw ?;
' C( A7 M; i8 N% t! hwNumCurrentSectorsPerTrack dw ?;4 B! G2 Y w' F3 ^+ J
dwCurrentSectorCapacity dd ?;+ m0 m4 t. E W' I
wMultSectorStuff dw ?;
9 z9 K" g0 I, x5 N5 qdwTotalAddressableSectors dd ?;. A9 o) Z; R) ^
wSingleWordDMA dw ?;# M' g) _/ ^8 D: l) z( C7 k T
wMultiWordDMA dw ?;
% @6 D: H, @4 P9 _+ [9 q0 }* HbReserved db 128 dup (?)
2 M5 W0 y/ K; w3 y( _. WIDEINFO ends
5 u( s+ l- l8 e+ `! K3 S' X! j# c# ^ c: t' B% x0 u! L8 h% d6 @; y
: J6 G3 M/ R! y" P2 K- \SetPhyscialMemorySectionCanBeWrited proto :dword
7 J5 S1 D8 [ iMiniMmGetPhysicalAddress proto :dword0 G1 v" v' b- @% h
. H2 ~* B- `6 \% X6 PENTERRING0 macro! T, M+ N! b( _" `
pushad + Y' ?! F* Z) J i, v0 ]* Y$ f
pushfd
( x* c# G* J v& Pcli+ s6 r, i& N6 c5 s) ~
mov eax,cr0 ;get rid off readonly protect
1 |5 ^" |* p5 r) eand eax,0fffeffffh
$ X# S8 }/ O: L0 D9 H/ ?* Hmov cr0,eax
1 c0 D6 d/ ]* m% s" Dendm0 o) P7 F# h2 a/ p% j9 G+ S
. ]0 K& t0 V4 o1 U1 g, l
LEAVERING0 macro! F0 N$ g6 R& t T
mov eax,cr0 ;restore readonly protect" I$ ~( f# A w0 ~5 {
or eax,10000h H* w2 A8 o) O% b/ }
mov cr0,eax! Z- E, X5 q" l8 J2 g" O6 l
sti& x4 |# z \6 O/ J: X8 p" H6 p
popfd
, i, t: [4 q, J3 ppopad
) N: a+ f+ Y0 v1 i/ A/ R( \: tretf2 h3 T1 f5 M; [2 H( ~
endm
. [( H# Z( R# E( N, k
% f! x9 Z* w E5 E$ N* S. k( s) L! D- b m( ^
UNICODE_STR macro str
) X: P' m$ b+ X9 q R2 Birpc _c,<str>
2 P) N* I# _! b* Ddb '&_c'
% N. z: t* x* i ?db 02 |8 k% G+ M* ]: X$ c3 b% [7 _/ B* ?$ R
endm& ?1 P' p/ N# ?2 s
endm
2 t2 Z2 C5 h' u1 m% I' w4 ? J$ M4 ~0 \' t( Y* m1 D
.data?
9 N9 U+ n* M; i1 B$ ZGdtLimit dw ?# E# X6 o9 e+ e+ M4 w. q, x* c% Q
GdtAddr dd ?# K4 o% v' s! P8 ]1 P) y) y
) ]7 _4 U4 s% p' l v% MmapAddr dd ?
, V1 A) a5 }7 ]2 _OldEsp dd ?- f- k% W+ W& M8 w; ~0 ^: Z6 A4 F9 |
% t: k( M$ r1 }1 U- @2 q6 j
readed dw ?5 s; a& f8 {$ |, n E& m
buffer db 512 dup(?) O1 x; E) N( j& ^5 l
ShowText db 512*3 dup (?)
, A, ~' T" b+ D5 g8 v5 W- z# J( U3 y4 a# a- J d1 `5 Z) w r
szBuffer db 1024 dup (?)
7 E+ ?8 N: M( AszModelNumber db 41 dup (?)
+ Y" e- B/ s' G& Z. `szSerialNumber db 21 dup (?)
. y4 O. Q0 @5 V% VszFirmwareRev db 9 dup (?): U$ m1 G5 Z+ O+ B2 i# X- R# B
: w/ {6 V! L! H' F& d* @' ]
stIDEINFO IDEINFO >
: a: i9 W7 u, h' X) v/ _5 C7 w/ b y" ]* y0 }, G+ Z
.data
/ ]" j% U7 |" U/ j% h$ ialign 4$ [/ N; [( q! B% W
objname dw objnamestr_size,objnamestr_size+2, G j- {3 u1 M6 }. c
objnameptr dd 0
! e; K3 \9 }# Qobjnamestr equ this byte7 M( [: l5 C: c+ ~" E# k1 B1 n
UNICODE_STR <\Device\PhysicalMemory>
, O$ i8 l6 v! I2 y! Q, S, t7 Oobjnamestr_size equ $-objnamestr
0 i; T9 m: }, ]% r+ e
; c4 \ ?4 A# Z' O0 t8 j# D, v; z1 PszTitle db 'IDE 硬盘信息',01 ?5 y) ], N- @* H
szErrInfo db '无法读取硬盘信息',0
7 R; S- d0 ] w5 M; G" i& yszIDEInfo db '柱面数 : %d',0dh,0ah& P% E3 [# D$ W' u
db '磁头数 : %d',0dh,0ah
& m" M. K/ b2 C3 f* H- Q9 R db '每道扇区数 : %d',0dh,0ah. O) G- h1 B5 M) P- g- u( h5 e
db '缓冲大小 : %d 扇区',0dh,0ah/ Q# g9 W3 }: A* o/ Q- ]* V
db '硬盘型号 : %40s',0dh,0ah9 X. B: V, g% m2 e3 c: C! R) p9 Y
db '序列号 : %20s',0dh,0ah$ Y+ ~. Z! ^/ d9 w, U* N
db '版本号 : %8s',0/ I# I' `8 j4 p6 r& i% Z; B& _4 _* d8 x
% i$ N. `. p4 balign 4( H& p* f- T/ ?" x' N
ObjAttr db 24 dup (0)
2 Z$ }2 i; `. [' p& y6 n
7 w# F# Y" f5 B+ w+ O& p9 G4 mCallgt dq 0 ;call gate's selff
6 c: X* Y; R( c c: ACaption db 'Windows XP绝对磁盘读写',0
4 J0 S* b7 ~+ o- f: eDigit db '0123456789ABCDEF',0
- T( j, v9 E; [3 B+ q2 _.code% v/ z6 x: i K( h. i8 L M. a1 V+ q
_ShowBuffer proc ;显示所读出的信息
5 G& w. d3 L4 w ;把数据转换成16进制的形式7 i2 n, c& M. [- G7 m' z" r1 \# G0 y
mov [readed],5127 W. t9 }" O4 n/ ] I: {1 _
mov esi,offset buffer ;数据8 k2 E* b, G$ I
mov edi,offset ShowText ;转换后的数据8 a6 U @, X+ d7 K3 M) W
mov ebx,offset Digit# U+ r: T& K2 F/ x
xor ecx,ecx
* x0 }. Q9 W$ |- a xor eax,eax
% z8 b9 |- b8 {4 i9 S7 scomputeAgain:
( Y( O S2 @" H# }8 e- ?; v cmp [readed],05 B/ p0 N- X3 H! _% j7 D
jz endCompute
0 h0 k6 q/ ^& b" ? dec [readed]
% _- k$ J% i, x( N% p# c p lodsb
: t$ J7 r) P( i, p* t push eax- k2 M, `0 ^6 N4 b% w0 W; Q
shr eax,4 ;高4位% r8 D. E" V# _2 r
xlatb
5 x9 {, v6 b2 b( }5 | stosb4 e$ m8 `' u0 {/ U- H: F8 A; |
pop eax
& ~# C$ e6 C `7 E and eax,0fH ;低4位
: X# j. k: L, b# }% O p) d xlatb3 K% V' G- I3 y) @, H$ D7 n
stosb
9 u0 n7 b! H8 \ H5 _1 Q8 e [ mov byte ptr[edi],' ' ;空格
3 e! }. L6 h2 P; | inc edi1 t# O* h( v( n8 q
inc ecx
4 u8 k V4 A& Y5 d6 l/ s cmp ecx,16
_3 G6 m( E- G8 |' P jnz computeAgain
( l' B2 Y- b3 f+ A# t0 w: \ xor ecx,ecx1 d9 d9 X! u9 u( `' M
mov byte ptr[edi-1],13 ;回车; f; q8 `3 ~# K
jmp computeAgain2 ~* L5 s- j( {) {7 L
endCompute:; n4 s. }8 e p9 `! N
;显示4 M% t/ [. a1 h8 E; ~
invoke MessageBoxA,NULL,offset ShowText,offset Caption,MB_OK
' l) t3 Y! R3 L3 F/ S" x& {6 d ret
5 t: ]) N, n: e, s9 k7 z. t_ShowBuffer endp' `7 g1 S( Z& q6 B
" [. M( E$ Z' j6 i; M* l
SetPhyscialMemorySectionCanBeWrited proc uses ebx esi edi hSection:HANDLE 6 J' J/ k1 i4 {: z
local pDacl: PACL
) c0 s9 u# ~ J8 W4 w* Tlocal pNewDaclACL
$ z4 J. z! \2 Mlocal pSD SECURITY_DESCRIPTOR
0 i0 P, |. E& X b4 K% U* T, }% Mlocal dwRes:DWORD ;4 r2 H" `, `! G0 w
local ea:EXPLICIT_ACCESS ;. @+ v, W6 q$ w0 l. Q' {$ n
invoke GetSecurityInfo,hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION, NULL,NULL, addr pDacl,NULL, addr pSD
1 M" a' h; j7 m' `# tcmp eax,ERROR_SUCCESS
, q) a1 ]) |$ A# E$ s, hjz @f" C* I$ G9 ?% S1 n
jmp OutSet
. B4 F b+ r% ] n8 r3 ^@@:
# u0 M1 R4 V+ J8 Wmov dwRes,eax
( L$ m3 O3 W$ `- j! jmov ea.grfAccessPermissions ,SECTION_MAP_WRITE;2' ?% v9 {8 F4 X
mov ea.grfAccessMode ,GRANT_ACCESS;1! {' M& \* g( Q5 u8 C5 n5 S
mov ea.grfInheritance,NO_INHERITANCE;0- C7 s+ l( R" k8 P
mov ea.Trustee.pMultipleTrustee,0# T( h9 v0 O) [
mov ea.Trustee.MultipleTrusteeOperation,0 z/ u' W, Y6 h! |, F) R
mov ea.Trustee.TrusteeForm,TRUSTEE_IS_NAME;1
x) l, ?2 k, }2 Kmov ea.Trustee.TrusteeType,TRUSTEE_IS_USER;14 I; I' }9 ^, L$ K
call @f7 u% C7 [) @% K' Z8 x' P
db "CURRENT_USER",0
( }, p* `8 R$ K@@:
4 G/ N. ~4 f0 V! U/ Q3 Ypop edx
, s, H+ ?( ~3 L* ?) o h9 q Qmov ea.Trustee.ptstrName,edx6 M) I e; b, B2 W, f0 b
invoke SetEntriesInAcl,1,addr ea,pDacl,addr pNewDacl# |4 L# v$ ?& _ w" _( @
cmp eax,ERROR_SUCCESS
- k- E* H0 }5 u; E7 m& Ljz @f0 b$ Z0 }! `7 c4 `8 N+ o# g
jmp OutSet
* y" @& W2 [; u1 f* E+ C@@:7 S: k$ ~% G) F9 ]$ N4 E* L8 w
invoke SetSecurityInfo,hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION, NULL,NULL,pNewDacl,NULL$ i: X# i# ^4 b# g. Z! ^/ M& z3 l/ D
OutSet:3 H6 ^$ _) n% G
cmp pSD,0
5 H4 E) e# [+ e9 Z8 q2 |+ bjz @f
8 v# x5 ]* x# g C- F X# Hinvoke LocalFree,pSD+ `6 H' }, k/ q
@@:5 ^0 A2 |- u5 S" e5 o& g9 X
cmp pNewDacl,0
g8 \1 |1 U1 `7 Y% [jz @f w: A/ W0 L" }% K1 ~4 C2 D
invoke LocalFree,pNewDacl
! b4 y! o l7 K8 ]2 o; B3 o6 a@@:
1 }4 h, g, ]/ Nret! W2 Z& D* P Y. x/ d
SetPhyscialMemorySectionCanBeWrited endp7 f1 S S D: O' _* U
- Y' H0 e; U% j! v/ Z8 P8 n2 jMiniMmGetPhysicalAddress proc virtualaddress:dword
F% W/ }! e- ]; I. y. L0 p mov eax,virtualaddress6 k7 s! S3 X/ \# e: r* J8 p# Z
cmp eax,80000000h0 h# N* ^9 V. |) I4 r" O+ @/ I* X& k
jb @f7 x; ?9 ` T( ]8 m* u0 y
cmp eax,0a0000000h4 U9 f6 h1 J# {1 N5 R
jae @f7 h$ |( T. ~1 {. l9 n0 Y0 [) Z/ A W
and eax,1FFFF000h
' n: k2 [ P7 a2 j ret/ u8 l7 t: F" L
@@:
2 [: E0 t$ i/ O1 y mov eax,0
6 h% S: ~3 ~" [. V) h3 B q7 Z ret
+ d( N8 A% t. A6 v. WMiniMmGetPhysicalAddress endp
7 ]* j" j y3 J! n) C# U% P4 j, W
ExecRing0Proc proc 2 a( W- O4 `; ]
local tmpSel:dword+ e' @" w' S4 W+ ]8 p/ |8 l, P
local setcg:dword1 H3 C4 x) v( l" B1 k: C; r
local BaseAddress:dword/ Z: q* o% N1 y3 x1 f
local NtdllMod :dword
6 m0 e# m6 c/ n1 Nlocal hSection:HANDLE ! T" x$ I0 v. R3 R* e" Z
local status:NTSTATUS
* _0 D( k: F* q' z0 i, Z+ k- olocal objectAttributes:OBJECT_ATTRIBUTES
4 P2 S7 K, J' r7 Plocal objName:UNICODE_STRING$ `2 n# n2 k$ u. n# m
mov status,STATUS_SUCCESS;
& T; \2 Y5 E$ M" `5 `sgdt GdtLimit8 ^. w" x1 l$ I/ ^( X
invoke MiniMmGetPhysicalAddress,GdtAddr
7 o. m$ z3 Q' v9 Y% zmov mapAddr,eax
4 t7 d/ B ~7 N" ~3 ^, ztest eax,eax
! l8 \! p# ], J* Djz Exit18 t5 H" h, Q1 z! e+ a
call @f
8 R! g& T; Q6 P! Vdb "Ntdll.dll",0
2 O' ^" a- Y- B1 |. z7 {6 n: H@@:
0 S) t6 A" D, t& R; \call LoadLibraryA
. ]) a% h! S( Bmov NtdllMod,eax3 y% U3 i+ O- ~1 o5 j
9 T3 q- z0 i- d$ w* c
lea edx,objnamestr
% g! V. c1 ?! u$ K$ f8 x- Bmov objnameptr,edx8 v: s" G$ X& `8 `/ c3 e4 W
lea edi,ObjAttr* E% n+ k! ^6 v1 x" C6 B
and di,0fffch ;align to 4 bytes,or ZwOpenSection will fail
+ e/ \7 R. D, x- r: r9 Hpush edi ;edi->ObjAttr
+ X; J) {' D. r; cpush 24 ;length of <\Device\PhysicalMemory>6 h% n1 L0 I8 N7 _: T- s, k
pop ecx; i- x. X3 D, A
push ecx% i7 J: p0 H9 M7 M s, Y: `: \
xor eax,eax
/ `" F7 t7 ?8 qrep stosb ;put ObjAttr with 0
( V% \. w( A" F0 J$ P, q z& X9 ypop ecx
2 Q: d% R3 z8 S) c; Qpop edi
! B8 |. T& K/ _4 G: C/ g, v6 Y6 Dmov esi,edi$ ?, z8 u* I ~* U; z1 \, K
stosd- E9 w7 |9 s$ Z4 U2 d
mov dword ptr[esi],ecx
+ r/ I; t9 H( Z+ R; t+ n8 qstosd ! \' u( }# I7 t* W) [
lea eax,[edx-8] ;eax->objname8 ?# e5 W" V; h+ I# P
stosd ;ObjAddr(18h,00,00,00,00,00,00,00,offset objname,40,02,00,00,dd 2 dup(0)6 M/ M: {% o- E# {7 u
mov dword ptr [edi],240h
6 Z: {$ F6 R- @- w# _, L7 d _9 O# R6 ?
call @f
3 @+ p* H p) q( `db "ZwOpenSection",00 P' _1 \6 p0 o
@@:7 A9 U0 L1 [9 G% C: M5 i
push NtdllMod& M' S8 b; ^" C- ^- g, Q3 ?7 H
call GetProcAddress
! ~4 t! N7 }0 d) f0 Wmov ebx,eax ;ebx=ZwOpenSection
! a6 h! r0 ?% m" `% @' F5 n# q9 d0 Y6 X+ {2 T
push esi ;esi->ObjAttr% B& n ^$ @% G. ~9 }. L+ a
push SECTION_MAP_READ or SECTION_MAP_WRITE/ m; X: B! S' I# {% D5 b
lea edi,hSection# E/ O( k' P% J2 ^1 R
push edi ;edi->hSection
, p7 V+ R: p0 p8 J/ A( K2 P* w8 hcall eax ;ZwOpenSection(&hSection,SECTION_MAP_READ or SECTION_MAP_WRITE,ObjAttr)5 B) n( h& O. S, J8 b* k
+ l! z1 q: x8 v2 r( Amov status,eax, T L! V, V, v0 L) D. Y4 h$ G7 h
cmp status,STATUS_ACCESS_DENIED
, H% [; n( F6 x. J( u* Tjnz AccessPermit( X5 r: K. J0 N7 b0 N
mov eax,ebx
. P! a i) i0 o9 h% U0 l9 G' r- ^
4 H# ?6 V* o+ ]9 l: {. O; j8 D4 qpush esi % A3 {; {. W5 I% E& ]: e# Y$ H
push READ_CONTROL or WRITE_DAC 5 i* c6 g Q0 _
push edi
0 L/ D1 s+ o. p' W/ ]( e, B0 Ucall eax
; T- \2 L# L& m- t. ^4 F; f" |
/ j% @5 _' V# E9 G7 y: tmov status,eax3 \. R9 z3 z7 Z1 G$ Y
invoke SetPhyscialMemorySectionCanBeWrited,hSection
1 h) ~8 j5 N$ H5 H2 J
0 m' s1 P6 V6 |9 q6 e* T( ~. Ycall @f
1 d% S6 _# L, B& pdb "ZwClose",0! L3 m$ I" E& a, R0 |* X
@@:
5 ~- L$ I0 y/ N9 Y. J2 E; S0 h4 ppush NtdllMod" A; H, j# `9 x) H
call GetProcAddress
# {3 M, M' Z5 d0 C. o% G8 y. P1 `8 f. I+ {
push hSection5 N/ `' l$ D- C1 w3 t, d- T
call eax ;zwClose hSection
/ c2 Q/ F/ C* F$ t9 i/ y' I5 _0 ~8 b, i4 \" p( P$ W
mov eax,ebx! w/ N* e, l) g' y) q
7 Z: `+ N1 l4 [
push esi
" e1 D! y; Z2 ~! Upush SECTION_MAP_READ or SECTION_MAP_WRITE 6 e1 A9 ]: h8 L8 r, b
lea edi,hSection p6 Y5 j: k8 @0 l1 t! Z8 h
push edi
2 J8 K1 U$ h" f+ h$ d9 d, ]6 Jcall eax
0 ^7 a, r- ~! q j3 Z% V* ~, Z6 _mov status ,eax& I. I# u# Y* H5 e3 ] T+ y1 a
;status =ZwOpenSection(&hSection,SECTION_MAP_WRITE|SECTION_MAP_WRITE,&objectAttributes); ( y. R: b: z3 ^% {# y
AccessPermit:! v7 _; ~1 f% {% t2 j3 x0 ?* w
cmp status ,STATUS_SUCCESS 4 c \8 Z' n9 g2 v7 ]8 ~
jz @f
9 v2 f. C$ ^2 c6 N1 q& ?;printf("Error Open PhysicalMemory Section Object,Status:%08X\n",status); % o3 t5 g6 }. \
;return 0;% \1 e" ?+ k3 Y- J
mov eax,0$ i/ b; n& ^ a" F
ret
0 s2 P7 E5 C3 E9 P% ]@@:
) E! F) @& c% nmovzx eax,word ptr[GdtLimit]* S, ~3 Q4 x; ?' j
inc eax8 z/ D( x3 w" k7 e/ j# |9 d
invoke MapViewOfFile,hSection, FILE_MAP_READ or FILE_MAP_WRITE, 0, mapAddr, eax
* C1 E( x* Z1 `( s+ |7 q! Gmov BaseAddress,eax$ i# m9 ?+ J$ o$ T% P
cmp BaseAddress,02 |+ ~; f$ W: |* y1 B
jnz @f
7 G/ }% w/ ]9 r3 W, Q1 ];printf("Error MapViewOffile:"); " J2 y9 |' F' s9 y
rintWin32Error(GetLastError()); return 0;
2 d% J( B1 k- p. c7 Pmov eax,0 F, X5 H& [* l3 v1 D
ret$ A6 M* X. k6 I$ v
@@:
5 m+ r; g3 m3 r4 p; |mov esi,eax ;esi->gdt base( A: {+ @! i" s, b; Y* U. O! N
mov ecx,3e0h* i* r }- R! {
mov eax,GdtAddr
z, f, l1 m- }6 v.if dword ptr [esi+ecx+2]!=0ec0003e8h
, \) b8 j4 }" y2 r2 h) Y7 w; S6 emov byte ptr [esi],0c3h* L4 H d: p5 X) E0 [1 |* K; c+ ~
0 b3 l q- o% b( { l, r
mov word ptr [esi+ecx],ax$ M S# O2 ^* j! `& n+ y
shr eax,16
% h7 X+ o, E, {, Z3 amov word ptr [esi+ecx+6],ax
* }; a# V9 q( G8 S' R6 L; gmov dword ptr [esi+ecx+2],0ec0003e8h7 G% J" m& _/ a; `) V+ O. g4 ~
$ j! _2 i1 w. h! o+ C1 T( p8 t' ?
mov dword ptr [esi+ecx+8],0000ffffh
4 b$ g/ U6 u9 _* n/ ^2 Dmov dword ptr [esi+ecx+12],00cf9a00h
6 k9 g/ Z" j/ O0 k/ [.endif7 Q/ J$ e: A/ {% {1 [
% t- v% I0 F" t5 fmov setcg,TRUE" a$ p+ ^( M) l+ a s$ C! y8 ^
cmp setcg,0* ^; Y5 A9 x: j! q+ A
jnz ChangeOK9 w3 Z/ A* X7 X
call @f: E5 P& |+ u% L+ r5 h
db "ZwClose",0% V& }6 \6 Z. Q& k
@@:: k# h8 a( C% u" O
push NtdllMod( f: K7 o: ^+ q) Z
call GetProcAddress7 `" f4 j, h5 A+ Z6 X$ V. A
push hSection
0 {+ `! z! e! M6 E; y( q; j$ ccall eax
" L* u* m, S4 g) y0 Y5 Hxor eax,eax
. h6 H1 e! L- B2 R! Z: i& Nret
- o( C) }4 Q# C o0 ZChangeOK:
5 g6 N; P4 Q# c3 P w5 @! C# a, qand dword ptr Callgt,0 8 N4 }* w1 \2 Q; A `2 V/ M
xor eax,eax4 n5 Z. b& |: R b0 D# D1 ^
mov ax,3e0h8 M+ z* r9 z L5 m8 k- o
or al,3h
; o5 [( T0 a1 j$ L% J" ?% R! [mov word ptr [Callgt+4],ax
3 m% G& p0 w4 J4 D;farcall[2]=((short)((ULONG)cg-(ULONG)BaseAddress))|3; //Ring 3 callgate;
6 t. |2 _* w" m3 l8 F3 E, ^5 llea eax,_Ring0Proc
* O8 S0 {& B" y: @; ^;invoke VirtualLock,eax,seglen
8 |, \: {) C- G1 F' Jtest eax,eax
& \8 ]3 { Y0 Vjnz @f
* h# y) n% R6 ?+ u) C1 e" Yxor eax,eax6 M0 f% T' }1 ]0 k l1 p
ret
) x( b1 h0 X0 k1 M@@:" s0 N) r( D& {
invoke GetCurrentThread& M, b' k' p2 N& r
invoke SetThreadPriority,eax,THREAD_PRIORITY_TIME_CRITICAL 3 e" B: l" ~8 x2 z5 d8 }3 W4 f$ N
$ t1 a+ S* t- I% n* @3 P2 ^2 finvoke Sleep,0 0 I0 T( z5 ^* V) P
call fword ptr [Callgt] ;use callgate to Ring0!* L' ^4 n! j, w& \ ~- o& Q) Z. ^+ o
;_asm call fword ptr [farcall]
) X/ b$ [2 y: z_Ring0Proc: ; Ring0 code here.. ; A7 H" J9 Z& z+ j n
mov eax,esp ;save ring0 esp# E, J. R( o( ?5 k1 i( ^4 g
mov esp,[esp+4];->ring3 esp
- B; E, R! u, |* p' `3 P! Q8 Mpush eax
! B: W0 u; x9 T& F9 | mov ebx,offset stIDEINFO3 N, v& a! w9 h& H( q
assume ebx:ptr IDEINFO
* r$ t+ r% z4 ^% v# Y4 ^6 b6 O2 H6 m, l;********************************************************************0 o9 j+ `+ n( J& L( Y _2 [! c' P+ ]: B
; 等待硬盘就绪
0 R6 v( G4 |* o9 s3 t& E;********************************************************************; @* S% [- z* d3 i) p$ _: X
mov ecx,10000h
% h. s# x. G- f2 s mov dx,01f7h4 @- S0 @ {; B+ P+ l/ b7 ?
@@:
# z, l0 x& r( ]* H in al,dx
9 g: ^7 z7 e9 c) S cmp al,50h. V, M4 b" [ @0 ?4 i9 @* @/ S
jz @F
( y8 J' t: p! Q8 X% ` loop @B
1 A _' F! B: b& h5 F2 i jmp _II_TimeOut
1 m; T$ y8 w0 i; u, F$ T. h @@:/ E: ]5 }' q' A: s
;********************************************************************
! x) L* D1 _2 _; 发送命令
& B8 J5 G8 e( _4 r; h; 如果向主控制发送命令,则端口为 1f0h-1f7h* V& U8 F$ G- c9 h4 g8 w
; 如果向副控制发送命令,则端口为 170h-177h; v: s% V% ?* g/ A4 c0 j8 R. }9 `
; 1f6h 如果要检测的设备为该IDE接口的主(MASTER)设备,
1 B3 A. V3 p. D$ `! R; 那么发送 a0,如果为从那么发送 b0+ W- l. Q4 j0 X3 X% U
; 1f7h 如果要检测的设备为 ATA 设备那么发送 ec; j: o( |, i8 R, p; h. o
; 如果为 ATAPI 设备那么发送 a15 x8 G( E# v$ i" K, X
;********************************************************************
9 D- m* q# J% {. G mov al,0a0h ;Drive 0,Head 0
' [- z( n8 Q3 P6 I) h; j2 Q mov dx,01f6h ;Drive and head port" T: L O T; ~7 y' |4 k
out dx,al$ f0 f q9 V$ X8 H* M/ c. G: m% }
; ]; a5 }" K7 Y+ F: j6 K
mov al,0ech . [) @' n5 C. _ P5 f
inc dx ;Command port* J( }2 s$ u. @$ |
out dx,al% R9 N3 y/ ~0 v* K4 I
;********************************************************************: c+ {3 Y8 {; ?& p& l1 Q0 _. |& D
; 等待硬盘就绪! H5 x0 l% B5 F7 R- \0 z7 ~, J
;********************************************************************
' [5 J) `1 o" ], X" n ^ mov ecx,10000h
+ c) y% n* y9 |5 e4 W @@:
8 q1 B g/ O9 m6 r) I" s- o in al,dx;1f7 (r-status register)3 M" m/ p) A$ K2 `, s4 ^9 I% r
cmp al,58h;(driver is ready ,and seek complete)
4 S* @8 O X. Y& i3 ` jz @F
8 ~' @+ X6 E0 ~; Z loop @B
6 b! X/ h o. \- @* Q; `4 j5 n jmp _II_TimeOut; z9 C2 t6 P! c! S; \2 x
@@:2 V* N2 P- L/ A2 p, T( W
;********************************************************************
4 l1 H: C) y1 ~- Y; 将返回信息读回
2 z2 F/ m" b- l; 注意一定要读满 100h 个字长% Z& f9 [' h/ `& p
;********************************************************************
0 c5 O0 g c+ g$ I& C cld' }- V# Y" X6 q( z, f" P5 x
mov edx,01f0h;data port - data comes in and out here
) k! L* u5 v z/ E2 B8 g# v mov edi,ebx5 n' k" h. f- v0 P$ T! I
mov ecx,0100h, i& s- C; ]6 R7 G, N" \5 i
rep insw: W& U0 v2 L* e w# }4 R
;********************************************************************
$ |- O/ n H+ z6 r; 返回的信息中,型号、序列号、版本号为字形式. w. Z; W1 X, _; u9 w# U( o# G
; 需要整理到字符串的形式
" H3 ]4 G; a% y8 m- u3 {;********************************************************************) |* ^5 ^; @' c6 M+ }3 M
lea esi,[ebx].sSerialNumber
4 b; H! G9 j3 ?; Z1 G% X1 ~# Y mov edi,esi1 B! J' b% l" f2 i1 ]
mov ecx,10# C- O" ]# p$ G: c4 t3 V) d
@@:
- b% w+ s5 O( t lodsw6 ]9 \% ^8 q- h) z7 b
xchg ah,al
. v" s9 T! h/ L9 z% e stosw& C; n! _2 _! |" i
loop @B
+ T8 v5 L3 @. u9 N" n+ t8 Y2 R( o' c/ R2 [
lea esi,[ebx].sFirmwareRev* X9 N6 M Y* E- Q! i- i
mov edi,esi# y2 i8 @% Y( L) M$ }# U* w+ C
mov ecx,24
/ m- }4 j; x, g* F @@:% L& h/ s+ C0 v" z+ L0 Q6 |
lodsw
/ X7 [5 a- a) M/ `* x/ N* D: c Q' J xchg ah,al
+ [* D; u* E9 i" X4 n: \ stosw
- N' J6 Z/ Y( d loop @B% h! p2 q, n% H e: B7 b* x0 _
_II_TimeOut:
) B, A" }3 L) }+ sassume ebx:nothing, [ E8 L ?+ m- e$ }5 K
6 Y8 E! B; T/ h. J! A0 X/ G3 ~
pop esp ;restore ring0 esp
+ l# O$ W# h8 [; I" `8 G$ Mpush offset Ring3
! a- C" j* p; U" `' h' u* J5 eretf3 T$ G- \* A+ e9 _0 U( R
Ring0CodeLen=$-_Ring0Proc3 M$ I9 S! K8 s
5 y; T! M( {0 D
Ring3:
, @" _: L: R0 f7 Uinvoke GetCurrentThread1 u$ a* f; a- _! @: ^. L
invoke SetThreadPriority,eax,THREAD_PRIORITY_NORMAL 2 {; v; X& Q: q( X
% J4 p. F3 y* G, `2 P" k;invoke VirtualUnlock,Entry,seglen ( j5 o' g) f6 J8 k
5 j ?/ S3 B$ f' `4 _
call @f5 b& |3 f t# ?+ |7 @) H6 m$ k$ ?
db "ZwClose",0' D; g" |! h# j& l( d5 c$ y
@@:
' e2 r9 V0 q/ e& r0 w6 {" j% l( Npush NtdllMod
# n% b1 i: Y* a) dcall GetProcAddress$ t ?6 L5 Q4 c, P# T3 x
push hSection
: j* \/ S4 K" r- n0 ^. ucall eax' Y0 E, f7 t+ P
mov eax,TRUE2 Q1 W- M0 V- f, i% [+ G1 L8 S* a& d
ret/ [* a h% f; @) Q
ExecRing0Proc endp
; K" D1 _/ x6 {$ [8 x" |) L) Z) }
9 v' W3 C9 U0 smain:
" f7 a6 N& Z& R7 ~/ {& Passume fs:nothing' ]' h, s/ T- ~/ K$ G5 O2 M& ~" L
push offset MySEH1 }8 L& {. p. ]6 b
push fs:[0]" o5 R' p- @/ B* t0 \/ U- G( G
mov fs:[0],esp
/ H* N9 i5 O& S, k+ v/ Cmov OldEsp,esp$ y$ v- _8 W2 J# J* u
mov ax,ds ;if Win9x?
; j# q* D3 t3 L* x: K. `test ax,4
9 w6 S. X; N& y7 p1 ]jnz Exit1
4 e) F# U! d3 {4 S( N3 A6 einvoke ExecRing0Proc- G+ D: Z% Q: N
: ]# ^% ?$ W; Q7 X7 D# N! y9 u.if stIDEINFO.wNumCyls
; e% [6 m( B- K/ l% `. g- W- l lea esi,stIDEINFO.sModelNumber
( \% j0 C+ f, v3 [+ \ mov edi,offset szModelNumber4 x; S p& X6 V
mov ecx,sizeof stIDEINFO.sModelNumber
/ d. p' U9 N3 Y- c rep movsb/ j9 }! i+ A7 h& w) a
9 D- M6 P) K- l5 U0 {
lea esi,stIDEINFO.sSerialNumber
2 Z5 m G& w' d9 c$ H mov edi,offset szSerialNumber" W3 s3 K$ }, Z* b2 c% o
mov ecx,sizeof stIDEINFO.sSerialNumber
- h& @' [8 |1 G) L; x3 j7 i# I% E rep movsb2 V2 }1 b+ [! e) q4 }
]5 A; [. @! E
lea esi,stIDEINFO.sFirmwareRev
1 U8 k9 A' L3 F7 s mov edi,offset szFirmwareRev; f( b' g. I1 f0 S0 x
mov ecx,sizeof stIDEINFO.sFirmwareRev
; X' D, ^2 m% { rep movsb
' I( z; ?* \5 c7 J! o
* d. Z. u, H, @3 j; b+ C movzx eax,stIDEINFO.wNumCyls
" D+ B+ U o5 n/ ?2 g movzx ebx,stIDEINFO.wNumHeads
+ t9 P3 C- I5 I; S movzx ecx,stIDEINFO.wSectorsPerTrack
- ^8 _5 H( b9 |1 n1 \ movzx edx,stIDEINFO.wBufferSize. U0 }# T: g2 f5 H& x
invoke wsprintf,addr szBuffer,addr szIDEInfo, eax,ebx,ecx,edx, addr szModelNumber, addr szSerialNumber, addr szFirmwareRev3 _4 `: u7 y' e6 E8 N2 g7 D
mov eax,offset szBuffer! |+ r9 K" \2 o" {2 `" R' r
.else5 H0 }. S& w8 h/ r0 o1 H4 R; |- ]9 z
mov eax,offset szErrInfo+ @& m7 p# T8 d( e! `
.endif
' Y7 I2 b H" N% D5 M6 Z@@:
0 H L0 l+ W7 L4 A2 h6 U8 dinvoke MessageBox,NULL,eax,addr szTitle,MB_ICONINFORMATION or MB_OK
7 W7 |5 _& G) d' B5 BExit1:, y: |5 @3 X4 l6 e- z9 ?
pop fs:[0]6 r9 v" {( G$ W: h7 f# ^' f* {% Q' ]
add esp,4# g- w9 d8 h( y# V& G/ ]
invoke ExitProcess,0
- a, I+ ~' S- Y* D3 E* l, I' A- `3 B% Z" i4 l1 P; `
MySEH :
" Y6 F+ E* J" w8 s* zmov esp,OldEsp
! ]) R% F# x/ F& Q& E- lpop fs:[0]
4 p, K# }3 O$ Z( ^: v, Radd esp,4% d* }0 S. J9 z. w( c4 ^) m: t
invoke ExitProcess,-1$ e1 ]- ^$ ^, v+ Q" |; Z
end main7 i* w' M( ^" k, l5 z* V6 n
/ K. r& E- [) K( ]1 R
[此贴子已经被作者于2003-11-2 18:14:02编辑过] 7 l- S: K/ _# l+ x( j! }5 Y
|
|