|
我可没这个水平; y' Z/ c7 a- W4 @, e2 F
.686p
* b1 r. t/ j6 F.model flat, stdcall
3 j( N* S9 O( ^# q( Q( \1 ? {. Loption casemap :none ; case sensitive
. R5 K: u0 J5 D; #########################################################################
; [/ l0 v4 R1 l1 w4 |: _2 finclude \masm32\include\windows.inc
" \# k6 V2 w# l8 a; G/ A! ~include \masm32\include\user32.inc. S1 {/ `+ [: E0 b9 X } o
include \masm32\include\kernel32.inc: b7 g3 w7 H& ]/ z; k6 V
include \masm32\include\advapi32.inc' i& C; f" n4 l
5 q! S- c) R8 @. }/ j: M% Aincludelib \masm32\lib\user32.lib# s W% v6 v- r7 i. z
includelib \masm32\lib\kernel32.lib
^7 u. Q% v I; r5 Qincludelib \masm32\lib\advapi32.lib& n; e9 s, ], K8 E& v
DEBUG = TRUE
' k* K- b! T: Y5 G: y# D$ A
) V% {' c% V( Y, H+ R" h* |HMODULE typedef dword% e0 X) t% p& H: S2 d
NTSTATUS typedef dword! Y3 _' b# Q1 F
PACL typedef dword
3 ?- t* }0 P& X% Y7 L9 iPSECURITY_DESCRIPTOR typedef dword5 L7 A: Y& y/ N2 M# c b6 N" u+ Y0 Y
7 G6 c5 F, t: w3 E! _8 T1 x& Z; K
OBJ_INHERIT=2 9 m# ~1 ~' c7 l# L$ p+ W
OBJ_PERMANENT=10h
/ P5 l3 ]- ~% O; v( {+ IOBJ_EXCLUSIVE=20h
5 @% \# \4 D4 O2 R1 Z2 F, NOBJ_CASE_INSENSITIVE=40h
1 K- |, X/ ^+ Q( a4 vOBJ_OPENIF=80h 8 r& R- w6 X! y' V) g
OBJ_OPENLINK =100h
8 L2 N2 [8 H! @: @OBJ_KERNEL_HANDLE=200 $ W9 w, h/ L! Z; {
OBJ_VALID_ATTRIBUTES=3F2h
: W. q4 D. T5 v+ L# t1 [* g) M8 } y0 P5 m1 Z) M& W
SE_KERNEL_OBJECT = 6- }$ @( C* g- U6 M
GRANT_ACCESS =1
# h, F% c& J' `5 [* [NO_INHERITANCE =0
% `' q5 e: i6 L8 y9 {5 aTRUSTEE_IS_NAME=1
' T$ |! {6 e' ~% @TRUSTEE_IS_USER=1
7 G+ p1 t2 }4 ]5 |4 I0 F/ R3 l7 k8 WSTATUS_SUCCESS =0 ; d3 r: q: k, z. o; T! y9 B
STATUS_ACCESS_DENIED =0C0000022h
& t: u8 ?2 O1 ~- u8 O* x% W. u6 j4 |- H! \$ N7 E4 Y
STATUS_ACCESS_VIOLATION equ 0C0000005h
1 H5 g$ D( R1 i* G" Y; \/ o6 MSTATUS_INFO_LENGTH_MISMATCH equ 0C0000004h
( {3 K$ b1 E% S4 X3 u1 ^SystemModuleInformation equ 11' e. \7 u3 ~( L( f7 @# y, m- l
PVOID TYPEDEF DWORD
1 V" ~4 y& A) K9 R3 O$ H i4 nUNLONG TYPEDEF DWORD; u6 r$ y) `9 q) ~0 m. Q
CHAR TYPEDEF BYTE2 Y/ v$ ?# F# @: k. ]' x
1 v* w% \2 U) z5 B
UNICODE_STRING struct
0 a9 i6 W" R4 D" e4 f nLength word ? 6 d0 t5 \$ n/ x3 n- J1 L3 l
MaximumLength word ? + W8 H+ p0 B. M' ` L/ h+ b
Buffer dword ?
8 o: S& g* B" }- PUNICODE_STRING ends3 Y1 \3 i8 {/ M9 K# N# d- `2 c( D# n
( d; _1 X# x2 L, f) y2 e( jOBJECT_ATTRIBUTES struct
}1 Q9 e0 b2 Y- s& y& K# k nLength dword ? ) x$ |7 z9 S$ S5 [6 c. ]- M
RootDirectory HANDLE ? 3 g3 }. n. i3 e% z a; }
ObjectName dword ?UNICODE_STRING
$ Q9 v% f6 ~, W8 s0 Y+ z$ J! B6 ^ Attributes dword ?; 1 [% `+ y5 y& @) m1 k
SecurityDescriptor dword ?; PVOID // Points to type SECURITY_DESCRIPTOR
3 ^4 G! ?# u1 _2 `6 d3 y SecurityQualityOfService dword ?VOID // Points to type SECURITY_QUALITY_OF_SERVICE 0 n* \5 I# K8 u' Y7 n" M* Q
OBJECT_ATTRIBUTES ends ) }9 N) \' s! S6 c9 R. s0 J7 n' {
+ ^% m/ u7 e' n) z/ F+ z; l
/ M- H$ q) l8 O* d9 o) l& `$ e1 _) U% E9 |TRUSTEE struct
( D& _. V4 h3 h. X* w pMultipleTrustee dword ?TRUSTEE
6 z& W, i6 k+ ^8 t& U/ s$ L/ I MultipleTrusteeOperation dword ?; MULTIPLE_TRUSTEE_OPERATION $ Q. E3 R) w& B9 j% y! T- q
TrusteeForm dword ?;TRUSTEE_FORM
8 h* p4 X" y; L2 r TrusteeType dword ?;TRUSTEE_TYPE
& p0 I/ v( K0 A; H3 t6 [1 I' D ptstrName dword ?;LPTSTR
: p& |) [: d! y$ t' ?, f3 u( N% h0 c5 OTRUSTEE ends p) @& }0 H. q
* n5 Y) p4 a7 N$ S( \" {% r6 |
* z# r P9 V: U
EXPLICIT_ACCESS struct7 i+ _ a* A+ r% Q/ R
grfAccessPermissions DWORD ? 8 f: [8 f) G( F8 Z# S, v n
grfAccessMode dword ? ;ACCESS_MODE
% m8 S% T9 m3 v1 s$ V% g' p& j grfInheritance DWORD ? ;' \# Z0 O/ ~& |2 f
Trustee TRUSTEE <> ;
& P7 q& n8 i+ w) _' i- o U4 NEXPLICIT_ACCESS ends9 g' U' ]# l g( e; \
T' g. W1 g3 T5 \3 HMyGATE struct ;门结构类型定义
! c" G( G, w, q i5 N$ o OFFSETL WORD ? ;32位偏移的低16位
! T6 { j5 ^5 R% M3 q' O" t SELECTOR WORd ? ;选择子* `& {$ ? @# E! {( I2 y+ |
DCOUNT BYTE ? ;双字计数字段
9 [* y- ^3 B9 l3 l; ?3 O GTYPE BYTE ? ;类型
$ f8 o4 X! ]1 x! |3 j OFFSETH WORD ? ;32位偏移的高16位
6 Q4 q1 a4 ~- s* m$ a0 X4 {MyGATE ends
5 r" S7 L) E8 C, g0 ]7 S2 S1 p( }7 [; I
IDEINFO struct2 J9 K2 O. Q5 z- z2 |
wGenConfig dw ?! c ?. ?5 W/ P5 X9 X- ]1 D9 ~3 G! R
wNumCyls dw ?;拄面数
3 t f8 I7 K. K5 w+ v6 H( N2 s7 {1 Z# {wReserved dw ?
0 ?. x2 }( ^ k! swNumHeads dw ?;磁头数' E$ s6 C1 b# [; c" y. A
wBytesPerTrack dw ?;每道字节数, x* g% S- Y1 e) z# f) ?. R; i
wBytesPerSector dw ?;每扇区字节数
$ a2 h/ o& ?; M( ?, R. MwSectorsPerTrack dw ?;每道山区数
+ ^: @! \* b+ v4 ?wVendorUnique dw 3 dup (?): Q' V( w5 Q# X
sSerialNumber db 20 dup (?);硬盘序列号
( V& ]6 Y1 f1 d& a+ xwBufferType dw ?;
h6 n. K! ~! ]. \1 m0 pwBufferSize dw ?; ;n * 512
6 Y& l) ~6 `4 a, t8 g3 l1 ~' YwECCSize dw ?
o% H+ _' _; N" T& `" I, EsFirmwareRev db 8 dup (?);; V! r; A" Z7 c: T3 @' K
sModelNumber db 40 dup (?)+ E; b0 C1 N j/ J
wMoreVendorUnique dw ?
, F% {/ p& p$ _3 ?) RwDoubleWordIO dw ?
) s, p) m4 Y. p4 }& iwCapabilities dw ?
`/ h! N4 ]/ Z% J3 ]; G, ywReserved1 dw ?/ ]: N% m2 F6 o
wPIOTiming dw ?;
( B# ?+ u& {' l/ r4 E5 d2 ?wDMATiming dw ?;7 j$ Q; ?2 z0 t# k1 y
wBS dw ?
% q* S/ a6 d- }1 lwNumCurrentCyls dw ?;
$ O; I: e- @% @" OwNumCurrentHeads dw ?;
}0 L, B, i+ J* q( M% b" h7 iwNumCurrentSectorsPerTrack dw ?;
9 x: \8 Z, q' |* UdwCurrentSectorCapacity dd ?;
) c, z1 m: j r" r0 W3 Z2 X# V5 W8 XwMultSectorStuff dw ?;
6 @/ b* B& n7 F! c" b1 @0 n0 q# NdwTotalAddressableSectors dd ?;
e, {% y1 s9 z" ^. KwSingleWordDMA dw ?;
) _4 W( O5 I" V% f4 kwMultiWordDMA dw ?;
) [. ~& N9 O- o; Q# Q8 B! MbReserved db 128 dup (?)
9 Y0 g+ ]2 d$ m: N" TIDEINFO ends
2 _; x% z3 z4 s% [* ^
; ?5 _! I! p4 e, {6 o9 p
' u& ]0 x% r7 {1 K2 MSetPhyscialMemorySectionCanBeWrited proto :dword
1 z* u# D+ p( t" p. kMiniMmGetPhysicalAddress proto :dword/ z( p; C1 V7 {+ ?5 i4 g
$ P# ^0 |3 C# L. ^& v2 p
ENTERRING0 macro
- [7 x: F9 a7 X# apushad ! h2 n' e8 [" v4 Z. N
pushfd 0 F6 w3 _, p3 }
cli& [8 E7 p! E4 A( V# \
mov eax,cr0 ;get rid off readonly protect9 u4 i9 w1 o. G
and eax,0fffeffffh
% o# [* z! n8 _, Vmov cr0,eax
0 H, S7 y: g; G4 y7 b' R5 d1 mendm
3 a+ _. x/ G E$ ?* x7 ? {8 W7 T5 s1 Q$ _, M$ @/ V' e. F* ]: P
LEAVERING0 macro
& Q' _4 |9 s% r3 G1 Xmov eax,cr0 ;restore readonly protect- x; U5 u. j0 |3 F
or eax,10000h4 J% w4 X" y* ] M4 i7 h
mov cr0,eax1 i% P4 _6 U: \; Y9 y; c
sti
2 @+ ?* p4 s+ w" X3 Jpopfd $ C5 O. M2 ?0 u1 W X
popad : L# }6 k+ D* | C* [* u1 e, \
retf4 P: M/ D. P& e4 N( q6 B
endm6 _* w3 x x8 m( _! \# p
9 e/ _' h7 Y8 d9 ~) p
) |6 K. `( M5 R4 L6 h+ }' hUNICODE_STR macro str( e8 J) L+ g- W, @+ {* n! B
irpc _c,<str>% F) d2 A, P( D& m& d4 K
db '&_c'
* L5 @; ^( k5 e/ U5 r3 ^' h& t. Cdb 0
0 ?* `) ], d4 E1 n9 ^& }1 Bendm) n/ Z0 M" i# z) C3 Z
endm: e2 N8 S& s/ T- o, F
/ E( D; J+ V, e+ W M! [$ u0 k1 p* ^0 Y6 D
.data?
0 r0 Y3 A4 D* }! GGdtLimit dw ?- B2 ?9 i! x7 I3 d& B
GdtAddr dd ?, v e9 ?) w' r5 N; K U8 ^" @
- P3 C$ X& a+ MmapAddr dd ?
) G+ o+ K* j$ t( hOldEsp dd ?
! Q i7 y3 ^; F/ m7 O! Q7 i( q6 d) I% e7 b, F x" P
readed dw ?
7 O5 P0 ?; M* o% qbuffer db 512 dup(?)2 T. `& y7 t$ c
ShowText db 512*3 dup (?)
% z8 X6 I9 U" J8 Z# u* w2 t& e6 F( `8 E1 {( s
szBuffer db 1024 dup (?)* c; P3 s+ I/ [0 g; M" _
szModelNumber db 41 dup (?)' Y+ J1 V6 c4 `0 Z1 H
szSerialNumber db 21 dup (?)
! ]$ Z, L% P) o+ O" U" B' j5 yszFirmwareRev db 9 dup (?), N( C# x# T7 y5 M, V3 e* v9 ?
B+ x% O1 f. Z6 ~
stIDEINFO IDEINFO >! E) \: N* O' d7 S2 n- u
4 d5 t5 x, `; B' j.data, m: }7 }6 f1 o! \& t+ G) s
align 4
& f+ X0 N% |! S% e9 |0 \objname dw objnamestr_size,objnamestr_size+25 U# b! U+ _2 a7 P3 E6 `/ a
objnameptr dd 0
* g! [, A& t; [/ t. j$ J5 \) Bobjnamestr equ this byte
4 p& h1 v, b1 S, C! W' gUNICODE_STR <\Device\PhysicalMemory>- w0 {* b/ x4 A+ d
objnamestr_size equ $-objnamestr5 k8 F: m( B, ]
6 c$ F" r; L/ r9 _8 H
szTitle db 'IDE 硬盘信息',0! E! s& {' H- S8 y1 F2 N8 [0 H
szErrInfo db '无法读取硬盘信息',0
$ |) Q$ K2 G; MszIDEInfo db '柱面数 : %d',0dh,0ah& t, t- \$ }0 o/ |) M
db '磁头数 : %d',0dh,0ah
' O h9 W% ^: Q! A/ m db '每道扇区数 : %d',0dh,0ah. m# C4 X3 \# e' Y x. F; A; W
db '缓冲大小 : %d 扇区',0dh,0ah
( z* h2 g3 s; W4 } db '硬盘型号 : %40s',0dh,0ah
8 b; I: H" H {$ m) l7 C1 D) r db '序列号 : %20s',0dh,0ah
) v# Y7 E% O$ D5 [ db '版本号 : %8s',0& L# v+ A2 ]" C* [# _
! N8 D8 o- x1 L
align 4' S3 V' j# ~$ w- ^
ObjAttr db 24 dup (0)9 y6 X4 _. u8 ^2 F" O# f5 Z
, r- F+ M2 g5 f$ X, X' o* I+ WCallgt dq 0 ;call gate's selff
9 @! e3 Q1 [' U4 \! m% K: C/ u- bCaption db 'Windows XP绝对磁盘读写',0
2 m7 J/ P- u$ {' ?. W, vDigit db '0123456789ABCDEF',0
( m" \/ `* P% C. w/ A' `1 G2 N* f.code
: I# f1 ~% G( F* g) k# h5 r: c9 K% E_ShowBuffer proc ;显示所读出的信息- l; v! c* Q* ]# ~( V! H9 J
;把数据转换成16进制的形式: o& ~- c( f- V+ B1 `
mov [readed],512
: K% I& q: q$ g+ L; M" O mov esi,offset buffer ;数据
8 n" m% x, \7 d0 ~ o( o" w' P$ R* L mov edi,offset ShowText ;转换后的数据% N3 X* C, g2 [# T8 _
mov ebx,offset Digit" l, V1 X- R( \* i8 r6 ]
xor ecx,ecx
5 V5 c1 y( c4 S- H% f xor eax,eax# L% I8 D: G' d2 U
computeAgain:
# e1 b' s% k3 |6 n& P cmp [readed],0
! P" H) q' `) G% N( k# B jz endCompute* i/ q4 d5 T. O X! a1 k) w
dec [readed]
' E& o( \( s" x lodsb
' J( B5 p( A) p3 ~: } push eax" }* w7 _7 K# h$ P
shr eax,4 ;高4位& K; M6 c, X% r, [ ?3 q6 ^+ X
xlatb3 g$ ~8 F3 N& B* j: X, y% B$ \
stosb
- _% W0 j5 M& g. q1 j) T! \, B pop eax7 c4 ]$ j* M: T$ V- o! V$ h
and eax,0fH ;低4位# z& O! U( i: z
xlatb
' ^3 X! @' E( S$ h4 T stosb* ]8 ^$ R& c, ~9 z7 I+ b) }% G
mov byte ptr[edi],' ' ;空格, p5 C; F! T$ t% }# B
inc edi
! V* d4 k; A5 m: o5 a- r% X inc ecx" P5 ]& e' o+ h% n4 M
cmp ecx,16+ X! d' n$ U7 }& G
jnz computeAgain+ o- e" U8 B! i+ P% M1 {- Z w, f( X6 E( i
xor ecx,ecx
: _2 c* D0 ~. Z% ? mov byte ptr[edi-1],13 ;回车& i# P( Q, _, H0 N& k" H9 d. h
jmp computeAgain9 v# o7 A: a* @
endCompute:6 P( T, {3 f/ M) m1 L
;显示
3 \ `. Z R6 [5 B' h. h invoke MessageBoxA,NULL,offset ShowText,offset Caption,MB_OK( e0 m# m. ~: }# S) u$ m# E
ret- ?' d- S( |8 p |& ^# i
_ShowBuffer endp0 b J+ c8 U8 U' q8 Q0 W
2 P; A: Y7 T# p, F: c/ X
SetPhyscialMemorySectionCanBeWrited proc uses ebx esi edi hSection:HANDLE 5 x7 l+ m7 _) K' B$ v
local pDacl: PACL
^* {+ F! G8 j9 mlocal pNewDaclACL # n% Z, t3 n! y3 ]( \
local pSD SECURITY_DESCRIPTOR 1 r( e9 p0 [: K
local dwRes:DWORD ;8 @& @' ]+ B2 e0 }/ Y% f7 P
local ea:EXPLICIT_ACCESS ; a. l# |. S! O: X
invoke GetSecurityInfo,hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION, NULL,NULL, addr pDacl,NULL, addr pSD
' [1 ?& ]' @1 y- |0 J* Pcmp eax,ERROR_SUCCESS
& S/ F, n6 \' x3 V$ d4 Ajz @f
9 ?, I8 y2 O; L& Mjmp OutSet. M" C4 u3 O' C% B9 b5 |. l5 }$ K
@@:
7 J6 ^% |# @5 L" ]& a: E% h: Smov dwRes,eax1 I2 D$ W9 `7 O! Y$ @5 g
mov ea.grfAccessPermissions ,SECTION_MAP_WRITE;2
* d9 _$ @, W' Kmov ea.grfAccessMode ,GRANT_ACCESS;1
& E% V# }. U: ^* Umov ea.grfInheritance,NO_INHERITANCE;0! w# N) {8 F! o% F$ ^
mov ea.Trustee.pMultipleTrustee,0& _, \9 Q/ x% A! A, n. g0 z
mov ea.Trustee.MultipleTrusteeOperation,0
$ ^: K, w2 i0 y, }& v4 Fmov ea.Trustee.TrusteeForm,TRUSTEE_IS_NAME;18 E+ _% z) r' K! D3 K& g8 o
mov ea.Trustee.TrusteeType,TRUSTEE_IS_USER;1
) @" @/ }3 w( K' Z) Ocall @f
! O- {4 t8 R( z4 _& m1 ]db "CURRENT_USER",0$ E) I' W) Y, t# L
@@:; L' C* B: {) o N9 X1 t# P/ N
pop edx
O+ t- o8 ]. X; j4 j- m; `. hmov ea.Trustee.ptstrName,edx
1 S6 D$ ~: v) p% d, finvoke SetEntriesInAcl,1,addr ea,pDacl,addr pNewDacl+ P0 I; O0 }- V, S# ^
cmp eax,ERROR_SUCCESS4 [: S; F- u6 l/ C4 z/ C+ G8 A
jz @f9 K# B4 W2 _7 B* [; m
jmp OutSet
! j5 n2 t4 g g# D@@:
' U# C$ p$ J0 q5 a! \5 m/ o8 F* jinvoke SetSecurityInfo,hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION, NULL,NULL,pNewDacl,NULL
0 g' q: w7 o: ?! B6 T/ L" ]9 FOutSet:( g( O$ W: S# t' f$ I
cmp pSD,0
; S; |6 k* V( p! X) Qjz @f& \. G3 e& ]& t: ^0 h8 y) b
invoke LocalFree,pSD$ V6 `0 |9 b$ T
@@:* ~) i3 i. A4 T6 F# E" V2 i
cmp pNewDacl,0
" ?# D& g" T/ F, F" pjz @f, V/ O' _9 c7 i, ]* m; y k) |: [
invoke LocalFree,pNewDacl
4 x; L9 {0 x8 M9 t3 {; x2 ?3 D@@:+ k3 Q% Y. W; {2 Q7 M1 I3 M
ret
/ u1 Y) s- t* K1 ^SetPhyscialMemorySectionCanBeWrited endp
& t7 s3 n1 c4 X# I: h) x6 N- \6 |: ]8 W" u
MiniMmGetPhysicalAddress proc virtualaddress:dword* `0 G& g' W1 \3 b9 d3 n
mov eax,virtualaddress7 i/ D/ Y; b* L8 R9 E
cmp eax,80000000h; Z* H8 b. d, h8 g z
jb @f
- {1 y( ]/ s1 A( \' d cmp eax,0a0000000h5 \7 d# f% a) U; s% A+ O8 O; p
jae @f5 Z, W; Q; ~. E7 _9 q( R
and eax,1FFFF000h
+ W$ h G/ j+ T, R5 I, b ret
( m9 f" X' H$ y, C. L1 j @@:
* c: c2 U1 e( w5 O1 v# I" q mov eax,0
4 G! V, \0 ]3 d ret' @+ g) {4 E% T" v% v2 v7 o
MiniMmGetPhysicalAddress endp( V) |0 Y1 p$ _( u8 c
* l j) C/ }8 X- RExecRing0Proc proc & S# }% F7 ^$ x8 g* a2 x
local tmpSel:dword
+ L( y* T0 k, d; e5 [& olocal setcg:dword
7 K: I' {) W& llocal BaseAddress:dword
3 G5 J$ s: D3 w% d; R6 @local NtdllMod :dword
0 x2 x- V6 A$ I/ U/ B; F2 N# C4 Qlocal hSection:HANDLE
_6 c0 l4 R# ^3 B7 clocal status:NTSTATUS5 e% j/ o: Y: P1 \1 Q$ O# f' K4 z+ a
local objectAttributes:OBJECT_ATTRIBUTES
( D6 t- B- g$ m! ?0 G0 H9 A, ]5 k4 flocal objName:UNICODE_STRING! N' W: Y; c) l. z& K) q
mov status,STATUS_SUCCESS; 7 f% d- O* R: U& R$ K
sgdt GdtLimit
9 e. W7 e! m# Einvoke MiniMmGetPhysicalAddress,GdtAddr& I0 s. _, u# `, H# f* |* g; d, S
mov mapAddr,eax. m9 |: V2 s2 C6 J7 N
test eax,eax
7 c4 d* K( o- kjz Exit1
* E. \2 l+ ]# ]call @f
* d2 G, w# Z$ f0 R$ }, N# Zdb "Ntdll.dll",09 X6 B+ U: z0 O3 W
@@:9 y4 b0 K8 L4 l+ y$ g$ t& t5 v
call LoadLibraryA
+ k N& l2 Z) ]& F" Dmov NtdllMod,eax
. Q* S: x7 B7 m0 {$ P" C( ?
) q4 }1 L$ I% b. q: R6 p, slea edx,objnamestr
) ^* n, n# M: o M$ `: A8 \. H2 R$ `mov objnameptr,edx
* L* ~+ @( l" f. ^lea edi,ObjAttr( m9 i. W, t- x
and di,0fffch ;align to 4 bytes,or ZwOpenSection will fail
Q. e' b3 z! Z9 ]) ]push edi ;edi->ObjAttr* G; L% k, t9 B7 ` {6 V9 w! k* x
push 24 ;length of <\Device\PhysicalMemory>
/ } K. J0 v8 I: I4 j2 i( Lpop ecx
5 M2 q6 r7 g% C+ ^push ecx
- v% b* `$ Y5 b$ n/ oxor eax,eax q, w2 ]/ X" G8 F+ f' l
rep stosb ;put ObjAttr with 0. R7 Y5 F9 f, [/ {* m4 T
pop ecx T0 D ^$ k* b. f {7 G
pop edi
7 z1 a J$ O0 l2 _( _ a1 @6 n6 m$ J0 }mov esi,edi
& P# H# G+ P! v, ^8 `stosd2 }6 I7 ?& f1 Y; c" Z% N( J7 c5 B
mov dword ptr[esi],ecx1 T7 c ~9 c1 f8 q& F3 i
stosd ! I' ~ z D0 a! P, T+ }2 W
lea eax,[edx-8] ;eax->objname8 f2 K8 T$ a- H+ H2 k
stosd ;ObjAddr(18h,00,00,00,00,00,00,00,offset objname,40,02,00,00,dd 2 dup(0)! {2 @2 H& m. f" ?' E }" s
mov dword ptr [edi],240h
% \% y# ^( `) x* a1 `4 h8 u
% B) A l$ |6 j. p. ?% ocall @f& x7 z" p$ [/ _' u9 [" v
db "ZwOpenSection",0" q$ B% J; F& F+ f
@@:( c& l# G3 ?+ }+ S2 i4 d
push NtdllMod
& E% K0 S3 d! X+ c7 A! T& ?call GetProcAddress
6 l$ g- F4 u4 D% pmov ebx,eax ;ebx=ZwOpenSection6 R @2 v0 U. u0 A, b7 V4 }
" z7 k3 ^% y8 b! H, q* t, rpush esi ;esi->ObjAttr# C; I7 j V. t* V2 z
push SECTION_MAP_READ or SECTION_MAP_WRITE
$ Z* `; r$ c- f) A; plea edi,hSection+ I# K# ^4 h1 y) c0 d( j3 E
push edi ;edi->hSection
) ]" c" V6 b3 t0 bcall eax ;ZwOpenSection(&hSection,SECTION_MAP_READ or SECTION_MAP_WRITE,ObjAttr)1 K& L* ~3 P0 R% b9 R+ ], F
0 [* A2 N" o4 k9 A3 y5 dmov status,eax
7 r8 m# x3 Z1 ^8 K, vcmp status,STATUS_ACCESS_DENIED" w) v0 S- ?! c3 a6 x: h
jnz AccessPermit
$ h. O- N, K" w$ x1 Z P1 m) Umov eax,ebx
2 F/ [$ l/ d, w8 Y; T/ X3 A8 _, u+ ?9 {- z# A
push esi ! U+ @7 x2 g+ h9 t; j
push READ_CONTROL or WRITE_DAC
5 l! t9 S# F' A) p9 \" y1 Vpush edi $ v* t1 u9 |& a) [) {" W1 w
call eax
+ {' x" ?) K y4 d! T
6 F: @& |# R2 b) d# U# k, K, b7 omov status,eax
, [7 n9 k5 e9 U# b4 I! Kinvoke SetPhyscialMemorySectionCanBeWrited,hSection
~5 t! C* i' Z% F$ ]6 r* ~
5 [, ~6 Q& @; C$ ucall @f
, y: H1 R" E+ y; J Ndb "ZwClose",0
2 q+ S) [* J+ j) I D@@:3 X1 `2 g1 K Q) Z) {' J
push NtdllMod
* f2 w' J v( Bcall GetProcAddress
: k6 h: K3 O# C* F% ]
: ]" T3 a4 \; qpush hSection
. _7 [- J! p" lcall eax ;zwClose hSection2 l. X- V3 Q4 U0 {! E) ]
3 a, S4 q2 {7 I# q/ O' V/ U, bmov eax,ebx
" ]' P9 {6 l9 d, t7 n' q+ ^; d. `9 M
push esi
! |, }* Q4 H- v4 P; n0 Fpush SECTION_MAP_READ or SECTION_MAP_WRITE 6 n/ l9 }2 v& A1 e: T. k4 b8 d3 h
lea edi,hSection) F+ v- i$ Q& i- B! V
push edi
$ b9 C. Y2 M% U l, wcall eax2 I4 D5 `4 s y" k6 p; U/ G: X
mov status ,eax4 d: \) m4 \2 B! w) f
;status =ZwOpenSection(&hSection,SECTION_MAP_WRITE|SECTION_MAP_WRITE,&objectAttributes); : _$ Q& S3 G8 P5 {* K9 R
AccessPermit:9 ~" f' B0 O8 n/ C
cmp status ,STATUS_SUCCESS - c8 n; }1 P Z# C9 D) @
jz @f3 f- f9 T& W8 ]
;printf("Error Open PhysicalMemory Section Object,Status:%08X\n",status);
3 ~) Q5 R8 f' z+ p$ \- K/ v;return 0;
Z9 P# T, n t9 p* X; r! Nmov eax,0! T% m1 e7 `4 @2 l& m
ret
9 {% L4 d" w" Z1 I- {) p \! U@@: . g; j! c; v$ t) }- @+ w0 E$ Z
movzx eax,word ptr[GdtLimit]: u1 r' k3 B# M, [. D: P" A* r3 t
inc eax
9 ]9 b% ]' r' k5 Y+ w5 d2 V( Pinvoke MapViewOfFile,hSection, FILE_MAP_READ or FILE_MAP_WRITE, 0, mapAddr, eax - Q. g: T7 y; D' f5 z% Z# V5 c% [
mov BaseAddress,eax% W$ r u. L; W. V: d/ g
cmp BaseAddress,0- z" n: ~: w1 @! L) S7 |) t9 o" _
jnz @f. C+ [* i. {' b5 i s' n' @: ^
;printf("Error MapViewOffile:");
+ h. f( i3 e- T5 D( frintWin32Error(GetLastError()); return 0;
! G: o" u# {2 Rmov eax,0
( n7 c, N: a) k- N& eret8 U, Q2 `0 H+ d; {
@@: + ~2 V5 Z! i% D1 _( p' h. ]
mov esi,eax ;esi->gdt base& v2 D. L0 B! c4 Z4 d
mov ecx,3e0h. H; m# j1 L" i$ }( g j6 Z
mov eax,GdtAddr
# H/ |& `* H: @1 x.if dword ptr [esi+ecx+2]!=0ec0003e8h
% y2 a" H4 \. l1 l" xmov byte ptr [esi],0c3h4 }: E* _# z7 j! S% N/ d6 y
. c m; H- J7 F- V. H1 ^: T Z
mov word ptr [esi+ecx],ax
2 V Z8 }2 w( B9 Yshr eax,16
& S9 A- D& j4 jmov word ptr [esi+ecx+6],ax1 ^, X8 w' r( Y& V' g2 I! V9 T
mov dword ptr [esi+ecx+2],0ec0003e8h
& R# W/ c3 [- {$ T' O$ v+ C% h
( ?( u+ r e9 F2 O8 }mov dword ptr [esi+ecx+8],0000ffffh" ?; l S7 t! P- U+ q7 z, _/ a
mov dword ptr [esi+ecx+12],00cf9a00h) I V; u" b- Y2 R( ~% X+ ~4 D
.endif
+ ~9 F2 Q' R6 G$ }* O2 b, D n3 D/ `* W# d+ W
mov setcg,TRUE E9 l- v$ {- A
cmp setcg,00 a& X$ q1 ]% f2 s% {# _
jnz ChangeOK& I$ ~7 `5 h2 A% s+ w _
call @f
: T9 K( ^$ f7 {. Ddb "ZwClose",0
1 O3 h5 ^2 b, `1 l8 w@@:
1 s. z' ~* _7 j/ M$ X5 I/ wpush NtdllMod* S: b! X% V1 G2 L5 T, S% w
call GetProcAddress3 r' D# F/ I' k: `- y/ g
push hSection0 i. U8 E6 N/ m' e
call eax
$ }( D1 Z8 f4 W U6 t4 Nxor eax,eax
! Y2 G' _1 h" ^+ a! h3 Uret
: r2 T$ T1 b: ?1 c5 T7 nChangeOK:1 D/ Y/ X+ {7 v8 W0 L
and dword ptr Callgt,0 ! H2 u, V# Y' _1 T% D" m8 F
xor eax,eax
4 G5 f2 g# I+ s/ _mov ax,3e0h
' o) n* [ k8 W8 w9 v% H* Uor al,3h
; s* |) z$ P0 ~3 o( _5 \6 M% Dmov word ptr [Callgt+4],ax
$ R0 Y: q; ]3 |8 N9 N( L$ W;farcall[2]=((short)((ULONG)cg-(ULONG)BaseAddress))|3; //Ring 3 callgate;
) Q$ S# d3 m6 Nlea eax,_Ring0Proc
: J1 d$ e/ I: }& B# e# X/ z;invoke VirtualLock,eax,seglen 8 g) m& S. w. R$ Y
test eax,eax6 d+ k4 m- Y! Y+ k
jnz @f
" S1 U; U4 l# ~% A2 Sxor eax,eax' }5 a/ c, {9 }
ret
$ g H0 E7 d! N9 a, ]; Y@@:: c I7 K7 S6 R' G; H; o+ r6 Y& u
invoke GetCurrentThread/ d+ j8 d+ J4 q0 P8 F" i9 U
invoke SetThreadPriority,eax,THREAD_PRIORITY_TIME_CRITICAL 3 u3 ]4 B2 o% L. S4 H6 S
# }, j+ Q0 y* g+ rinvoke Sleep,0 1 _1 w" b8 N8 W( e; y
call fword ptr [Callgt] ;use callgate to Ring0!
9 y: j- I" u h6 }# h;_asm call fword ptr [farcall]1 I% z; \1 O) H7 M$ }1 ]
_Ring0Proc: ; Ring0 code here..
) Y# q- {) W$ Umov eax,esp ;save ring0 esp- C2 p: A0 f8 J; P' O2 ~" `: c8 }; e
mov esp,[esp+4];->ring3 esp
" h: o+ \$ o7 m, v, Q) kpush eax
) n- Q) f- z8 ?$ t. P mov ebx,offset stIDEINFO
1 F: z* }1 ^) Z5 I* h assume ebx:ptr IDEINFO ; D8 _" i& i, ~+ ? b/ I
;********************************************************************
' T& `1 v" _9 N6 A3 i; 等待硬盘就绪
. V, Z5 d8 U& E; O5 R. D;********************************************************************% w6 @/ F1 S9 {. @6 w5 ~ e5 A
mov ecx,10000h8 E8 ]2 O! {' ~
mov dx,01f7h3 Z. ]4 v1 |$ |2 d/ C% {( U
@@:
( ]$ ^2 f: |& U; C6 L in al,dx6 F+ @9 S. ~8 ~. Y9 o
cmp al,50h: p9 u7 e. m+ ~# ^$ w' E; [- ]
jz @F/ d, k8 v; Z; `7 ]0 A3 f
loop @B
' w8 ~' N) D8 }( y. T jmp _II_TimeOut
' D/ l, D, c/ b9 [$ f @@:& ?0 N- {+ z y! [1 u" H
;******************************************************************** J' A9 `6 X+ |
; 发送命令( l: D: Z; {7 s6 c
; 如果向主控制发送命令,则端口为 1f0h-1f7h# O% f N! C' q* r! k
; 如果向副控制发送命令,则端口为 170h-177h
+ v, s+ A+ P, e" r r& m; 1f6h 如果要检测的设备为该IDE接口的主(MASTER)设备,5 w; S) l: _: Z2 B& f
; 那么发送 a0,如果为从那么发送 b0" j0 N" d9 z. I
; 1f7h 如果要检测的设备为 ATA 设备那么发送 ec d% B# ?9 T# g5 f4 i
; 如果为 ATAPI 设备那么发送 a1
: R. o8 O' u. N;********************************************************************9 H" Q. V. U. E+ T: O: o: y0 i
mov al,0a0h ;Drive 0,Head 0
/ H6 D1 K8 v/ j# c mov dx,01f6h ;Drive and head port
+ V# S% F9 j* ~: \ out dx,al
: T8 \6 @6 j3 s' x7 o& n7 l$ l3 Y0 G4 P' z$ G+ z
mov al,0ech
9 _2 s X1 ?3 f/ h inc dx ;Command port
" c% D) D: Z+ x3 x out dx,al
3 B7 q! N& {4 w [8 l;********************************************************************
1 _" s- j1 J) Z1 N% d; 等待硬盘就绪, g6 R A* r9 T" y
;********************************************************************
: w, k& k7 d2 D0 c, S& i! y: z" b mov ecx,10000h0 p1 d, F: P9 E5 r
@@:" [+ U& o" F5 t# @% M
in al,dx;1f7 (r-status register)
* n. }3 Z2 ~. X$ }! t' p cmp al,58h;(driver is ready ,and seek complete)% C9 M' |' q; ~( q% W
jz @F- g2 a9 Y) Y1 S+ y0 }9 j: r
loop @B9 P2 |4 m3 i/ i7 c) Q
jmp _II_TimeOut
' b8 a( s2 _2 r0 k0 K @@:
3 l+ }0 ~- e! N;********************************************************************$ B' `% u6 N: _1 v, w; `0 ~& @3 Z
; 将返回信息读回" N5 }0 R d: p
; 注意一定要读满 100h 个字长
7 H: {- ^4 X- ~4 P;********************************************************************
& K& A/ j& v: P cld
) M/ ?( T* B& b% \- b mov edx,01f0h;data port - data comes in and out here: |" D: `& H3 i8 @
mov edi,ebx( I3 R/ {% U7 l4 B& q$ i
mov ecx,0100h
; k" L* x7 M# j; Z0 z* {8 p rep insw
7 g8 ~2 Y6 _2 ~9 D/ e! w9 _;********************************************************************! R; S Z0 a3 R: P/ X, {' Z
; 返回的信息中,型号、序列号、版本号为字形式: i' M1 @' X; E& Q. k/ k
; 需要整理到字符串的形式
/ d: u( W7 B) h;********************************************************************
" z1 h/ J. c) t f% o lea esi,[ebx].sSerialNumber9 }* f/ D( s2 M. o; Q
mov edi,esi
* g" U6 y1 u: v, N% h mov ecx,105 D, c' D! Y* Z) A
@@:+ S$ X4 J! J( T
lodsw$ \2 p4 I* K$ P( z* G
xchg ah,al2 F: D; C7 L# a9 n& e& ]
stosw- W( P' A8 ~! K, s6 m- }2 y
loop @B4 f# P3 t3 C" r0 ?
* l4 L& Y3 c+ z
lea esi,[ebx].sFirmwareRev: n- {4 q$ V' n+ V) \ t! t! G
mov edi,esi& o( C1 u* c' H1 ^3 ^$ |- P
mov ecx,243 {6 T* r( P- h! W- R. ?; y6 F, f: ]6 ~
@@: t' }5 K- B) J' Q+ X- v; p) I
lodsw/ p% w+ }/ u8 D, p9 L% Q4 S. x. w
xchg ah,al* U% ~2 T. [ F3 H9 A
stosw
/ c1 x& Q" e6 g' A loop @B, K z8 h) z& c4 ?9 I* ~- g
_II_TimeOut:
9 V: X/ H, u2 e- u( Q ]assume ebx:nothing
( n1 d/ S5 b. Z( W5 ^4 y2 R 3 F3 [0 \$ u& J* P9 c! o w! `/ T
pop esp ;restore ring0 esp
4 q! ?+ x4 g% `; \5 [, Cpush offset Ring3
9 s J# m2 F/ }6 Cretf
! |4 S, p+ G: m& y. Y bRing0CodeLen=$-_Ring0Proc, |0 u" [1 i* A' M! t$ a
/ g- \7 y/ o0 _* @# N9 j" i2 ~5 K
Ring3:
5 B/ l% m5 R3 e9 n' u) Binvoke GetCurrentThread+ q: r, |& N) ~9 \
invoke SetThreadPriority,eax,THREAD_PRIORITY_NORMAL ) e' v- T7 V' k$ w' {
5 z! c o8 e( G# n
;invoke VirtualUnlock,Entry,seglen $ r) _7 B' ?! o) ~: Z3 _
9 N, G9 n5 H, |- v; v$ c7 @0 z
call @f- A6 I l7 [0 f
db "ZwClose",0
" {7 ~: B2 v3 ?, o4 C/ z; K@@:5 T2 r- g1 E( E+ Y" V
push NtdllMod
1 x, d6 w/ a+ t4 H2 B' Vcall GetProcAddress
- d! A( t0 y" j' `# E P, Opush hSection
2 X# @7 j/ f$ bcall eax
6 z. ?8 Q4 m. t4 K: D4 k/ \mov eax,TRUE
# f/ n7 N8 a' J8 z9 sret
$ H4 ?& T; v f6 s4 r! A6 @: N. |ExecRing0Proc endp ; J9 N9 f M% r- {0 `& v9 C3 R
: S4 h$ v6 {6 u4 ?main:( W+ G0 Q! B/ n/ ]8 m7 W
assume fs:nothing) _# Y8 _+ y% f; _
push offset MySEH/ k5 f1 L" ?. D
push fs:[0]4 }/ G9 [* K9 _
mov fs:[0],esp8 Q) C8 U9 s, A* N2 Z5 Y
mov OldEsp,esp
% a7 M. n+ B$ N2 m4 z4 hmov ax,ds ;if Win9x?
, |3 \# A( ~$ {! x0 P6 k9 H& Btest ax,4
; J0 m: O% H5 X3 [& ?jnz Exit18 I$ M! y: r" z1 t2 j( N# p
invoke ExecRing0Proc
9 {* L9 s) w0 z* H) K( H9 S' c, J: w+ T+ Z2 ~
.if stIDEINFO.wNumCyls
, \" x+ N' t T lea esi,stIDEINFO.sModelNumber. B" Q0 B9 s. T/ W$ q5 ?; d
mov edi,offset szModelNumber
0 m" a+ i' m2 p* o- T) q5 m mov ecx,sizeof stIDEINFO.sModelNumber* x/ n# U* x' g6 {5 Q1 K/ j
rep movsb; m7 z2 w( E, U1 b& P# t
' g( Q7 ]; y+ I }# {& p. J N' j
lea esi,stIDEINFO.sSerialNumber
+ f B3 n# {7 f) C) ^; Q: `, Z ~ mov edi,offset szSerialNumber
/ k2 S. k! t7 Y' E+ |/ M3 H" M0 P mov ecx,sizeof stIDEINFO.sSerialNumber
1 _3 O+ I; \: d( ~+ h$ E+ B rep movsb
3 Q, d1 n- ~( i9 E# v# T: i- y: |4 p q/ W9 v% k
lea esi,stIDEINFO.sFirmwareRev) V% |1 {8 p( Y( d$ c' c7 {
mov edi,offset szFirmwareRev
3 i. T+ b) h) W mov ecx,sizeof stIDEINFO.sFirmwareRev
; I! G- S& M( v rep movsb+ {7 B9 r) X8 O
+ M7 L- r* s, E movzx eax,stIDEINFO.wNumCyls
) v# G$ l; D6 [4 M3 s3 F& |! q* Y movzx ebx,stIDEINFO.wNumHeads
3 d; Y, i( l% l movzx ecx,stIDEINFO.wSectorsPerTrack
. K+ @+ q* a/ S, [: v5 B movzx edx,stIDEINFO.wBufferSize
, P( b8 q7 h0 ]) Q& j/ x invoke wsprintf,addr szBuffer,addr szIDEInfo, eax,ebx,ecx,edx, addr szModelNumber, addr szSerialNumber, addr szFirmwareRev6 }9 D p6 g9 `# u8 ^
mov eax,offset szBuffer
- A+ G" m8 d% D+ n& D; `( z6 x0 d.else
- a$ g5 M6 U' Z6 e% Q3 M, b3 V mov eax,offset szErrInfo
& H3 ]9 D+ X: x8 C.endif
8 t. C+ V4 |, P3 b' M@@:
% W) V j5 L4 d0 O2 jinvoke MessageBox,NULL,eax,addr szTitle,MB_ICONINFORMATION or MB_OK! q- I( C) f$ w% ?/ X
Exit1:
3 i: D; _# I' Zpop fs:[0]/ j$ B7 U6 r& U. R% j) }7 c4 C* R
add esp,4
/ l5 c6 |( i4 L; D' N2 C4 `invoke ExitProcess,0- _9 f6 p3 {, q
7 U7 x" @! }) h$ R& A. [7 W, {* \MySEH :
$ Q) x8 l: L2 w3 zmov esp,OldEsp; D8 }. d! ]4 X& B+ W; k1 k
pop fs:[0]9 T' I h$ i. Y1 d1 T2 W/ y) {
add esp,4
% f% G. N% s, J' `( E' Z4 ]' u( finvoke ExitProcess,-1
% ]* _+ m, U" k0 p. A' _& G4 pend main
5 b9 \& d0 M' S4 A1 Y
' v. l# k' g4 L* O" a [此贴子已经被作者于2003-11-2 18:14:02编辑过]
8 j' q% k6 O8 e2 \7 o" i |
|