|
我可没这个水平
; n& T0 V4 V6 L. w1 g.686p
M! F$ M7 ?0 g/ L.model flat, stdcall
8 B4 C6 [* }. H9 g3 ^option casemap :none ; case sensitive* O/ R* Q9 u k1 d: ^
; #########################################################################; y, S$ ]2 ]7 e4 ~+ S6 `* W$ f
include \masm32\include\windows.inc/ v) H0 D7 E' Q
include \masm32\include\user32.inc7 O- O$ V! @5 [6 a/ H* a9 _8 F
include \masm32\include\kernel32.inc
0 x5 Q& H7 u2 Q3 hinclude \masm32\include\advapi32.inc
5 c3 x+ f) Q1 ]+ A4 C
A' n/ B" w* {; q) {includelib \masm32\lib\user32.lib
/ t d* d* ~8 _7 a: S: S3 Vincludelib \masm32\lib\kernel32.lib
+ h8 d' b# A$ v) M9 _# Bincludelib \masm32\lib\advapi32.lib
8 }9 c: @) h i4 g4 `DEBUG = TRUE
5 J4 A) V. W# x2 _
5 s- l& \& ~2 {/ f8 f/ d* X" L0 R1 sHMODULE typedef dword
- {6 N5 j1 J. k- i0 S0 z' i2 j5 FNTSTATUS typedef dword
* k9 i8 z4 @1 y$ bPACL typedef dword. z: \; V# Z6 f
PSECURITY_DESCRIPTOR typedef dword9 S. ~" [% `! |/ h
" H$ F% N, C5 a4 z, u: m: O/ {OBJ_INHERIT=2
) s; X7 Z8 H( X( iOBJ_PERMANENT=10h" B) u/ z- w9 X, b8 Z& M7 w
OBJ_EXCLUSIVE=20h
. T9 U1 J6 d |7 s: M7 Z. o' m5 HOBJ_CASE_INSENSITIVE=40h
1 c; ~ l8 s" dOBJ_OPENIF=80h
' D! X; [( @' n- O4 KOBJ_OPENLINK =100h
8 m& l& i# l8 m) R/ ^3 R( i7 aOBJ_KERNEL_HANDLE=200 ) m( A" i$ M/ {9 R" q% u9 K
OBJ_VALID_ATTRIBUTES=3F2h 6 H1 ^( p ^# x1 `
+ E4 t) f( |# w: ~* c3 c) b( QSE_KERNEL_OBJECT = 6
/ H4 G: ]: C4 }8 n: ?; z4 vGRANT_ACCESS =1
2 c% B* P" e9 ^2 ]+ KNO_INHERITANCE =0* Z, r0 {% y7 r; _, H$ [7 e1 x( N
TRUSTEE_IS_NAME=11 M5 U8 k# z3 U8 e) _
TRUSTEE_IS_USER=1
: Y6 h( I& l7 B% dSTATUS_SUCCESS =0
" K, V: f, j3 r. H1 v% vSTATUS_ACCESS_DENIED =0C0000022h
- T9 }0 i1 y0 `# Y/ x+ h) m
, N! l$ ~. Z. dSTATUS_ACCESS_VIOLATION equ 0C0000005h
! D. H3 q: O& d8 T" M3 ASTATUS_INFO_LENGTH_MISMATCH equ 0C0000004h
' x& @7 \8 t, D4 q6 c; d- XSystemModuleInformation equ 115 c2 V/ N6 j) j
PVOID TYPEDEF DWORD9 ^/ \4 I3 _- q0 ~; Z2 Z
UNLONG TYPEDEF DWORD3 a' J9 z) h* @; i4 s
CHAR TYPEDEF BYTE
6 q- Z$ r. g6 Q" D, o. ~1 S' C; S2 \* ^7 P! n6 F, {! ?
UNICODE_STRING struct
( u" z4 E4 e" Q' o nLength word ?
8 W% q& U! ]1 A2 N$ x MaximumLength word ? 3 B* x2 j. m" X
Buffer dword ?
, T! ^" q- h g- v9 FUNICODE_STRING ends
$ I1 y- E' Q# O! W% K8 v t- T* ?" k4 n% q
OBJECT_ATTRIBUTES struct
9 c4 n0 v0 x' ^ nLength dword ? - O4 {+ c2 W1 h9 O* P
RootDirectory HANDLE ? & w, s+ _ f0 `9 k2 g- z& O/ U
ObjectName dword ?UNICODE_STRING 0 n( [" v' t0 j2 D/ _
Attributes dword ?; 7 K/ `+ t' X' W) a8 y
SecurityDescriptor dword ?; PVOID // Points to type SECURITY_DESCRIPTOR
6 R) R4 ?$ ?; k SecurityQualityOfService dword ?VOID // Points to type SECURITY_QUALITY_OF_SERVICE
* s/ M' S6 n/ N2 Q( W3 }$ OOBJECT_ATTRIBUTES ends / c$ s+ a8 G& M( e, k
. t0 |5 b( U" D' J5 V' |0 p* _7 \7 ^$ C! l5 l
TRUSTEE struct
4 V( y8 p' v. _8 U y! ^( T pMultipleTrustee dword ?TRUSTEE # R2 i& y+ C7 S2 W/ Y* U
MultipleTrusteeOperation dword ?; MULTIPLE_TRUSTEE_OPERATION
4 k1 `1 P+ i" v0 Q& V I1 M i TrusteeForm dword ?;TRUSTEE_FORM
" Z! ^+ v& ]( h9 Q5 F0 _) ? TrusteeType dword ?;TRUSTEE_TYPE 2 }) `. Z% _. g! V4 l1 w
ptstrName dword ?;LPTSTR
) [, {/ e/ h! u! Y0 F9 GTRUSTEE ends7 T6 Q! Y& x1 F
, c% O3 A+ l( q0 ^3 t
7 O* x( n# F3 Z$ }
EXPLICIT_ACCESS struct1 d8 q9 i4 s0 q1 ?4 x. b
grfAccessPermissions DWORD ?
! Y+ a4 I M; q _, Q9 b grfAccessMode dword ? ;ACCESS_MODE 0 N [& N3 m& t1 F; o. w
grfInheritance DWORD ? ;
, A6 K( z( d, D2 r: o' D* \& Y& E Trustee TRUSTEE <> ;2 Z# j0 V) p) j: s2 q
EXPLICIT_ACCESS ends
( x" E) @; }4 h& X4 o6 n
0 ~$ c& R3 _# _" vMyGATE struct ;门结构类型定义
- n e. |% m! v# d, D' p OFFSETL WORD ? ;32位偏移的低16位
/ S7 J1 P$ n; q ?% g7 r% v SELECTOR WORd ? ;选择子$ O) A+ ^: m# } Q8 ~! A
DCOUNT BYTE ? ;双字计数字段
* U# P- Y7 {9 O& E- T! `( Y2 d GTYPE BYTE ? ;类型; A( [/ P4 E3 u* E. k
OFFSETH WORD ? ;32位偏移的高16位
) _+ D2 n# j$ ]7 O5 |+ q4 CMyGATE ends
3 Q$ q8 c4 }. ]# J8 J# `) @ ^- K. n, L* u8 D$ {
IDEINFO struct; v6 Z. c( h' ~, t$ B; X
wGenConfig dw ?& k4 M7 w" q' H j! p/ [$ j% N O
wNumCyls dw ?;拄面数/ \9 j- k, t# Q. G
wReserved dw ?* u& N, r" Y. p9 @
wNumHeads dw ?;磁头数& _7 J; X8 h& X9 M
wBytesPerTrack dw ?;每道字节数
5 Q. Q9 Q- L' @7 R' T$ d: ~wBytesPerSector dw ?;每扇区字节数1 g( E# f: i9 b# ?$ @9 Q% |
wSectorsPerTrack dw ?;每道山区数
9 ? y* H* q- Y' _) V* i, ZwVendorUnique dw 3 dup (?); I3 j8 Y5 w# ^; [: u
sSerialNumber db 20 dup (?);硬盘序列号
4 x; H' i. T' s' R( z+ ~wBufferType dw ?;
" V1 \, N# C- r+ S* iwBufferSize dw ?; ;n * 512* L, d6 N' ^0 [9 H# v
wECCSize dw ?0 ~4 q- Z* k. A, o; c, u1 _
sFirmwareRev db 8 dup (?);
1 X; \9 @+ C2 u, T* d( C* jsModelNumber db 40 dup (?)
2 K! f, M; {, q5 \ A% T: L% r( ^wMoreVendorUnique dw ?
9 K/ O! N0 m; HwDoubleWordIO dw ?
: F/ |8 v# d8 AwCapabilities dw ?
' J" h U1 N, _* o9 wwReserved1 dw ?4 M$ X% r5 P% c2 j3 B3 J4 P
wPIOTiming dw ?;
8 n2 d4 u1 N5 v& Q* l1 e$ swDMATiming dw ?;
/ g6 Y8 p6 l9 [ [" n- A+ ^- H. ?wBS dw ?
# c, X+ J; o) d0 I0 x4 Z" _wNumCurrentCyls dw ?;
" o& _, f/ R2 twNumCurrentHeads dw ?;7 D* l! B6 r3 b: Q3 E
wNumCurrentSectorsPerTrack dw ?;9 u! k) i- v& F- w7 Y; H
dwCurrentSectorCapacity dd ?;8 y( `" c6 g3 d! h
wMultSectorStuff dw ?;
& }% M e& l+ |- K# b1 g& M! udwTotalAddressableSectors dd ?;, S( S1 O' I& p+ m6 |! N
wSingleWordDMA dw ?;
9 M6 C3 y6 a6 C) c* E% pwMultiWordDMA dw ?;. u6 _4 _" }5 D$ d0 w7 s( W
bReserved db 128 dup (?)( ?" u* w: z- k
IDEINFO ends+ J% l& G- ?# D* H" O, `9 G: _6 w
- [0 K# d9 F: p, l; ?$ L2 L
1 P X5 T0 f: r3 ^/ d/ f3 tSetPhyscialMemorySectionCanBeWrited proto :dword
% J* p4 |, u- v) f7 HMiniMmGetPhysicalAddress proto :dword1 J0 X+ a4 G. d) W
W' J5 ?" V8 D; ]7 M% |
ENTERRING0 macro3 \2 v5 L+ Q! N4 q/ J7 L: a8 d0 {4 G
pushad ! p3 H' Q l" ^( t2 A# t! H
pushfd
! n3 ~7 n& K4 Z2 c' @: [cli( ]% v+ E0 d# C' Q& E0 n# r
mov eax,cr0 ;get rid off readonly protect
2 h8 S& X V; f' Dand eax,0fffeffffh
6 {2 r: W0 N* b8 u, mmov cr0,eax
8 |2 O1 t# m+ y7 c- Hendm' J% q1 d8 V& f: o: ^
5 R+ B. y0 O5 H0 v& S- k
LEAVERING0 macro
) h3 u" e7 w0 y, h# M) amov eax,cr0 ;restore readonly protect
/ t- O: n- \* ?9 k- E2 I0 {or eax,10000h
; \2 o- H; t! I# e6 P+ i8 ~" Omov cr0,eax
8 S7 E& n6 b/ [ z8 ssti; u/ W( a, e% |/ B
popfd
% \3 `, K0 Q p3 \, [popad 0 a- T2 a) s# I5 u* h8 ?2 i+ x& M# }
retf5 ]% h- j1 D1 d+ b. V7 d6 W
endm% ]. \ ?/ I% }, p8 e, g
/ Y, j& a! a/ @; A, c- Y) R5 g7 s7 `2 B
UNICODE_STR macro str
6 A4 G/ S$ H: _irpc _c,<str>, K/ [4 R, E" |* [# |
db '&_c'+ [2 F! b" z$ E1 C) ?
db 02 U) T: Q8 @. O) A
endm8 _& E3 c! d* J& h6 t' l
endm. d( s/ ?3 e# |5 Y1 C4 s
; \2 w# Q3 H7 B& j8 e) N% m
.data?& t& O/ _ Y' w4 ?
GdtLimit dw ?
0 _& t) L8 k8 b2 ], e; T) R" V2 ?GdtAddr dd ?% U5 X1 \( |2 [# T! C
, K6 s( P# z( ]4 `7 e* emapAddr dd ?
% l% y, ~ @1 f/ o' TOldEsp dd ?' `* i% b+ ?" {( [5 n( o
, a- `/ ~% l! C, W! n, w- H8 a% _5 creaded dw ?
: B% Z5 K0 g7 a, \- Abuffer db 512 dup(?)
2 d8 ?3 s: V8 t b' `8 XShowText db 512*3 dup (?)1 y3 p9 L0 l4 q: @" I7 a
9 \, H9 S3 I7 y* m- CszBuffer db 1024 dup (?)3 g; f) {. V' S. U
szModelNumber db 41 dup (?): T, d1 `0 n# k& S
szSerialNumber db 21 dup (?)/ G6 Z' R2 u" v: x$ h
szFirmwareRev db 9 dup (?)
7 z+ J: w. F7 p8 Z& s
8 I) M; f1 v" c9 B2 k, q6 G: pstIDEINFO IDEINFO > m7 V7 p i/ \1 U. I- {
; i0 z* G$ l+ v9 k6 c- a* l
.data* p$ {: B, ^" G/ H8 ]
align 4
# _7 z F5 C h ?$ D* uobjname dw objnamestr_size,objnamestr_size+2& g! k, o' j! m3 a- u& P
objnameptr dd 07 N) x- H/ ?2 P9 K ~
objnamestr equ this byte$ T. D, F, d; c) j6 s
UNICODE_STR <\Device\PhysicalMemory>
7 U% u+ z( P2 @" b& fobjnamestr_size equ $-objnamestr& D# ]9 T5 X4 h% `. K- V
: s# O/ X# u" Q0 b, l& x6 F6 I$ \szTitle db 'IDE 硬盘信息',0
9 L7 I/ l1 C6 W; JszErrInfo db '无法读取硬盘信息',0
8 g# d/ c$ Y; A8 u# k" |szIDEInfo db '柱面数 : %d',0dh,0ah" M: h) J! M! q. |( c2 }
db '磁头数 : %d',0dh,0ah: A1 D% ?/ h$ D# p0 j: w2 g
db '每道扇区数 : %d',0dh,0ah
" _; g/ z: A# b db '缓冲大小 : %d 扇区',0dh,0ah
& q* c- F) d' C db '硬盘型号 : %40s',0dh,0ah$ I2 w+ E$ ?0 x% }2 _5 g
db '序列号 : %20s',0dh,0ah
/ |8 s. M' ?! w. [- _3 z1 X: P db '版本号 : %8s',0
7 Y. a9 [6 P# t/ f0 g
- q# J* r0 _, A* W% r0 g" balign 4& H6 @; k! h. b% \: J& R% D0 e) M6 I
ObjAttr db 24 dup (0)
! ~3 S- @9 d# @7 D7 ^5 [2 s8 T2 F# R4 k9 _4 V
Callgt dq 0 ;call gate's selff
( m( ^/ h/ W; i7 b5 `. c4 UCaption db 'Windows XP绝对磁盘读写',0" \: w! w) `3 }& B" b* b
Digit db '0123456789ABCDEF',0
. S; s3 F1 W2 E$ s4 _.code
* u8 G+ h' q1 e" s' x0 x4 E8 G_ShowBuffer proc ;显示所读出的信息% M* G" `* q: d* F( G6 C. }0 i
;把数据转换成16进制的形式
% f: t6 O( F: I& K mov [readed],512* e' B- @0 e0 V* z
mov esi,offset buffer ;数据
4 E3 T0 A# F+ J( t2 ]5 Z* L mov edi,offset ShowText ;转换后的数据9 ?# i Q# x! n" b$ l U5 f$ @
mov ebx,offset Digit& A6 X( J( @* q$ S6 C; o
xor ecx,ecx
: H" X/ ~& q! d% N; v% t O, p$ u# f+ o xor eax,eax' z- a3 G1 O7 {, w0 i% L
computeAgain:
2 s3 a7 E$ `0 e7 F cmp [readed],03 y$ j: j+ _5 Y% Q# }0 J) i3 Y6 E
jz endCompute# h7 u* J5 T. f
dec [readed]( Q3 {: j( j' A2 {7 y3 V& u( o0 ^% v
lodsb8 R C J3 L* T- [: w0 a
push eax) R3 z/ Q, d/ @$ J
shr eax,4 ;高4位
8 w- t7 a6 w9 o- U3 | xlatb1 I1 J# x' T( C" b' c u! o6 g8 E
stosb
9 w, Q1 X; a& d% r5 t9 X- Z& n pop eax
2 Z8 _; e5 m, J and eax,0fH ;低4位) s8 i: ~& c" n6 T" R- o2 C
xlatb
- ~4 k# {. e5 @0 Z7 P% d stosb# E& E6 O5 o/ o% b+ M6 ]. N: q
mov byte ptr[edi],' ' ;空格( I1 W! \4 Y0 v, D5 |: r
inc edi- N. ]' _8 `" `# g6 ^
inc ecx
5 A5 e; g; B8 w cmp ecx,16
, [2 G, ~' \0 f& Q9 S7 q jnz computeAgain
6 a3 L8 h5 f5 K/ u! ~; \; u/ t xor ecx,ecx0 O7 e$ K; b- x6 D7 B
mov byte ptr[edi-1],13 ;回车
# ~1 @' W9 i4 M& X6 q jmp computeAgain2 o7 r% R5 q2 C/ c9 P$ d% }' L
endCompute:
6 y- a; R. k% m ;显示1 M% [5 T( |5 W8 e
invoke MessageBoxA,NULL,offset ShowText,offset Caption,MB_OK
5 a( [7 K8 a1 Z6 F ret3 q, m1 c! T' W" b/ A5 E2 X( ?
_ShowBuffer endp1 a# L, W- [5 U- v6 U
5 Y- z( F$ S! k% {8 h: L' l+ q) ?SetPhyscialMemorySectionCanBeWrited proc uses ebx esi edi hSection:HANDLE 3 R/ c' y5 x7 R% N4 c g0 a( _
local pDacl: PACL ' @) F1 e) l$ R5 C4 i
local pNewDaclACL - J; @- C7 L Q2 h
local pSD SECURITY_DESCRIPTOR
4 P h/ e# f3 |" {2 X! E& Nlocal dwRes:DWORD ;
6 O Y# V8 w y* G7 i, ]local ea:EXPLICIT_ACCESS ;4 ~, V5 n% q* @& _: _0 I+ m C
invoke GetSecurityInfo,hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION, NULL,NULL, addr pDacl,NULL, addr pSD
/ v, {4 Q: B; U% n# pcmp eax,ERROR_SUCCESS- I5 v2 {6 M3 c x1 Z
jz @f
$ |/ ?/ g! }" I2 M( _jmp OutSet1 W# Q1 V( }4 k
@@:0 M5 k0 D# P4 x" l' [7 {, o* c" I
mov dwRes,eax' T c% c( s2 l- p( T
mov ea.grfAccessPermissions ,SECTION_MAP_WRITE;2
* I0 j* l& k" [+ R2 Dmov ea.grfAccessMode ,GRANT_ACCESS;1+ Z/ C1 q4 X$ S" T
mov ea.grfInheritance,NO_INHERITANCE;0- p, z# t% o( r; T
mov ea.Trustee.pMultipleTrustee,0
1 P0 e* d1 [5 o/ h" omov ea.Trustee.MultipleTrusteeOperation,0
6 y3 N; e7 D: A" i# V3 hmov ea.Trustee.TrusteeForm,TRUSTEE_IS_NAME;1
" j1 Q$ I) o( N2 Rmov ea.Trustee.TrusteeType,TRUSTEE_IS_USER;1
' v5 K8 S9 `7 |# K# \2 Gcall @f$ q T( I2 U6 b V
db "CURRENT_USER",0! C n+ s1 V0 l' z3 A8 p' R" ^5 \
@@:
1 B$ t; G/ B$ o/ V9 mpop edx
) P; u+ {7 k/ E/ Amov ea.Trustee.ptstrName,edx$ C5 I, g2 n% k( a1 w8 c5 u
invoke SetEntriesInAcl,1,addr ea,pDacl,addr pNewDacl
& U, u- u. y( e! O7 u; |% p1 }$ G/ acmp eax,ERROR_SUCCESS
8 E# x3 f8 C# Q' [jz @f
* I2 d/ c% I u0 U, ?- Djmp OutSet
) N$ B; d4 m& J9 U5 R% t' W& a+ S4 I@@:
6 ~' j: K8 Q; \: w% J" Q' R: H5 ^invoke SetSecurityInfo,hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION, NULL,NULL,pNewDacl,NULL
3 b) k3 y5 ]3 i } v9 lOutSet:% T8 N+ |1 Z- w
cmp pSD,0
~+ ^1 ^, v& D, o6 @$ g' Z5 tjz @f" Q0 d, M& x( N, K0 A
invoke LocalFree,pSD4 t+ g7 i1 k- i' m
@@:
, k( v# o# a! D% O0 Y% dcmp pNewDacl,0. J( l( l k% \- h: n
jz @f
/ ]% H& M _9 h: K. @! O$ S7 W- Finvoke LocalFree,pNewDacl
3 F( X) c- T) U$ r L( u7 T@@:
$ F% M& X& ~8 }% u# Z8 Qret
5 y% k# p4 ^' @; t# eSetPhyscialMemorySectionCanBeWrited endp
% [( V# c4 v6 { m5 O; D( t8 j, i2 a. R( a% I5 b
MiniMmGetPhysicalAddress proc virtualaddress:dword
& C3 L" \, z1 q0 Z" @ mov eax,virtualaddress
- n5 y3 R0 A8 v" G4 d {/ v cmp eax,80000000h
- O* a9 {0 I6 ^, r jb @f
" l. ]& x$ o' v5 { w0 P cmp eax,0a0000000h
0 `( N, U+ G7 Q- w. }7 x( @ jae @f
6 Q2 D1 t E* m6 L) U* | and eax,1FFFF000h) e: z- h, {2 C1 |/ a7 O
ret
" S, v5 ^" ^ Z# H/ e @@:
. \7 f \) i; c& x' {8 y3 h mov eax,0" Z. V" r: w p2 ^7 ?7 S5 {
ret! c9 M+ V2 F6 m7 o2 ?, \, e
MiniMmGetPhysicalAddress endp
$ P( k' ^- B" o; K: w5 x
5 b- T) n, a, g6 F, y& jExecRing0Proc proc 5 Z1 r% h. e' L+ r
local tmpSel:dword) x3 l; W" C. o" i$ ~# d% U4 u( ]
local setcg:dword
0 L5 Z1 u7 s; q5 glocal BaseAddress:dword
. m7 }$ N6 _/ s* P8 w4 R! L! x2 Dlocal NtdllMod :dword; N0 A) a5 p0 v0 w/ r+ W1 W' h# p
local hSection:HANDLE
- Z2 F5 b+ c! T0 D+ llocal status:NTSTATUS0 ?$ E' `8 X% S0 P( q( i! Q
local objectAttributes:OBJECT_ATTRIBUTES
% n) s* H* Q- h- Z, m/ glocal objName:UNICODE_STRING" z2 u1 v& |. B O) I1 N
mov status,STATUS_SUCCESS;
( F; G1 Z) ]- H" X& fsgdt GdtLimit& {2 a; h5 b5 j, q: J
invoke MiniMmGetPhysicalAddress,GdtAddr
_0 W, z1 t+ {8 hmov mapAddr,eax# r, k! A9 S8 c9 V+ H# d
test eax,eax
4 w+ R) |$ L& V1 m; q3 d4 njz Exit1
& l* i+ j- M/ Ecall @f- C5 J1 i7 S- M5 f/ W8 \( x" V% Q
db "Ntdll.dll",0
0 K0 g- S% C3 I@@:$ T# V6 Z* B* I4 F9 q/ s* y. n3 s
call LoadLibraryA. G& E0 ^ C& E+ [1 U. v
mov NtdllMod,eax
; y+ Q) ~" `0 z/ Z. {& ?# n8 I% G* D N' d2 e% ^0 Q
lea edx,objnamestr. C3 h4 |; E: w, a t7 i4 S6 q
mov objnameptr,edx
0 M# @, O6 K2 M G7 p& Flea edi,ObjAttr/ Z5 `7 K2 Q) ?, d1 i- y) \( y0 `
and di,0fffch ;align to 4 bytes,or ZwOpenSection will fail1 V- E8 l& I$ F7 s) y
push edi ;edi->ObjAttr. l5 b; i/ Y" N1 k' s; K
push 24 ;length of <\Device\PhysicalMemory>2 W. k$ D7 a$ u: E1 q+ b4 K
pop ecx9 u& [7 L* |7 w3 z" |6 P
push ecx% Q; \9 x8 _1 X9 I+ c. ^% P
xor eax,eax! c2 \5 w5 o; ~7 l
rep stosb ;put ObjAttr with 08 J' f& Q6 d8 @5 k* y
pop ecx( p! s0 J( r, Q! q' {. Z' j7 t5 r" Y; H
pop edi
" b# \3 b0 [, v9 b! V) D, M& [mov esi,edi
* b& o; U7 L4 ?, g; X0 _stosd' {! O2 }3 N3 W* ~/ x( K* F- k
mov dword ptr[esi],ecx/ F+ h" O0 Y, U3 @( F7 ?- U8 A! s8 {
stosd 8 S7 {! i( j3 |" ~1 {
lea eax,[edx-8] ;eax->objname
* q, U: @6 Y3 `9 k. @* [! ustosd ;ObjAddr(18h,00,00,00,00,00,00,00,offset objname,40,02,00,00,dd 2 dup(0)
+ y0 K. F) c4 v# v' R. R2 gmov dword ptr [edi],240h
1 s# x3 c9 R: C: Y/ T G. l
( J n( r; u. J! [0 I k* @call @f6 }( L1 ?5 q0 L/ D( E! ]8 h$ u% V& l
db "ZwOpenSection",0, s X7 n; Z" c
@@:5 j4 m( r5 S3 W' p+ m+ j' w
push NtdllMod
- g% Z5 r2 e, l7 Q Rcall GetProcAddress: M4 x7 O* S9 H
mov ebx,eax ;ebx=ZwOpenSection* F3 S) N& f4 ?1 v! F6 l
; U7 b$ A; z& A; e0 E4 _- t
push esi ;esi->ObjAttr
# Q% b1 @7 |9 _+ p+ H6 }1 zpush SECTION_MAP_READ or SECTION_MAP_WRITE
9 A+ a. P' V. q# J Wlea edi,hSection) P. `" A( H7 K# i) r
push edi ;edi->hSection
e, n- H1 _# _; K, scall eax ;ZwOpenSection(&hSection,SECTION_MAP_READ or SECTION_MAP_WRITE,ObjAttr)" Y' t$ u+ C0 K: \/ f) F" Q
* ]4 I+ I! w( G0 C' O' q
mov status,eax
) |+ z+ o0 F# @7 y4 Kcmp status,STATUS_ACCESS_DENIED/ j& }; @, s& i Z, s9 f
jnz AccessPermit
7 ?) A7 E9 S$ X9 T& omov eax,ebx9 o, x2 H8 d' e" v" i+ O- ]( d% H
, C( v- S/ P2 dpush esi ' ^0 {9 T) X6 x% m6 s
push READ_CONTROL or WRITE_DAC 0 W7 c [: ?7 U7 z3 M7 H: q# Q
push edi
2 n M$ E& `2 }* xcall eax 3 \* ~$ Q& F) W
! X5 K) w! l. j, { ?8 w& O% u
mov status,eax
: R1 b% i" b" V8 {invoke SetPhyscialMemorySectionCanBeWrited,hSection
! S$ t" t5 E" x" b) d
# P# [; T4 g& b+ F- T7 \call @f0 [1 D+ K& H* P) ?- {$ |
db "ZwClose",0
- B: f1 o- ~6 a& t@@:
- [+ j# `+ P6 Fpush NtdllMod' ]1 Q" v1 T7 \# n' {
call GetProcAddress
1 s8 C+ n" `3 h/ O7 E* g# B* A% N+ `8 b+ M
push hSection
/ C' L( M; V' F6 V3 pcall eax ;zwClose hSection
" }8 k: p+ U5 I' ^& H- w3 P" s; p' u' z/ [3 y$ k
mov eax,ebx
1 v6 e" h- O" U/ n$ i: p/ b$ m6 V- Q" p6 F) I7 ]
push esi 3 w' A2 V& k3 I2 X
push SECTION_MAP_READ or SECTION_MAP_WRITE
# G# M7 ?7 \, Q' K. I; a" Ylea edi,hSection
, W% k/ S0 y. G( t$ B* M% |push edi
& O/ y( b H9 d3 q5 qcall eax
, @8 B/ B+ t8 F: L% X5 cmov status ,eax( {7 O: a/ _+ F" s
;status =ZwOpenSection(&hSection,SECTION_MAP_WRITE|SECTION_MAP_WRITE,&objectAttributes); 4 p8 o3 `9 F# R, u
AccessPermit:+ ^4 h8 ~9 V- [2 h
cmp status ,STATUS_SUCCESS : X9 S6 _; @$ k7 u. }/ c, q
jz @f2 V4 m9 @7 I5 K: o
;printf("Error Open PhysicalMemory Section Object,Status:%08X\n",status); 8 e& N+ g% U5 m1 v2 {
;return 0;( x( q, o# e1 r/ J$ W
mov eax,0
0 f: v+ O J0 @ret% D' k1 I' ]5 G
@@: 4 G7 f& d, x) Z: L" z: K+ X- F8 a
movzx eax,word ptr[GdtLimit]3 D7 G6 U# O: ]% v% Y
inc eax
# \' v) Y& I( `invoke MapViewOfFile,hSection, FILE_MAP_READ or FILE_MAP_WRITE, 0, mapAddr, eax 3 l$ d; Z# v& b9 D
mov BaseAddress,eax7 Y' {" P1 f- [
cmp BaseAddress,0
# \- u$ F+ Y, W' e: cjnz @f4 N+ o1 N1 i2 I* H; ?6 s
;printf("Error MapViewOffile:");
2 |; J! n' N& O; V% brintWin32Error(GetLastError()); return 0;
4 X: x9 E5 `- `; N, n- h6 H! Gmov eax,0
( W+ U1 r+ S7 k% R$ R# S7 f* }0 Gret; m# w. ~% S* J/ h6 g) D& S1 S p- D
@@:
3 s' ^: F$ p' |' I7 ~$ mmov esi,eax ;esi->gdt base0 ]/ N6 `$ }" e$ [. P' `% Q
mov ecx,3e0h" X( i+ i/ Y6 A2 B! \5 D
mov eax,GdtAddr @0 o( {% w6 g2 p) ?: M9 Q
.if dword ptr [esi+ecx+2]!=0ec0003e8h
4 I1 V) f5 j/ q4 _/ F2 [3 m zmov byte ptr [esi],0c3h$ A# j/ H. b+ `8 J
$ s0 x( ^. S! Q& A" h
mov word ptr [esi+ecx],ax, Z! _5 u( E, m" }1 o' M
shr eax,16
6 F5 y6 q; ~; A3 U# j* }7 Hmov word ptr [esi+ecx+6],ax1 p( y. @6 }0 r! ~; i% a
mov dword ptr [esi+ecx+2],0ec0003e8h& f6 M0 e4 l- i. k! G; t" R- g' \
9 _4 {2 ?$ F3 o
mov dword ptr [esi+ecx+8],0000ffffh/ t& h t* v6 t: M& {
mov dword ptr [esi+ecx+12],00cf9a00h
6 {5 l: ?) k0 p7 _ r$ V" a/ v.endif* Q+ |+ p$ L' N0 R$ M7 n" O! \
$ i ] D) \% w+ }mov setcg,TRUE
/ \" R8 [8 A k5 h0 n6 a# Ucmp setcg,0
$ ^, ~, U9 Q0 a% k3 ?! t; Rjnz ChangeOK6 Z* n. }5 y3 u. _
call @f$ f5 T2 K, Z! o0 B% Q( T" v& p. R
db "ZwClose",09 d# W% M2 Q! X* r1 n/ C
@@:
3 X; t& [, \6 ^4 R0 spush NtdllMod
8 c0 |! \% P9 L0 E# x% B3 I3 i% a: Fcall GetProcAddress
1 t, M: Z3 O% d- ]5 o5 u/ }( Apush hSection' G0 `7 A& H' u8 u
call eax
8 O0 L; v! ^, G& _. Yxor eax,eax
' `- e% Z* |* w3 q2 Sret
' J9 T7 b6 Q1 HChangeOK:. v3 Y" K+ |+ v. Y V: _* k
and dword ptr Callgt,0
/ R" Z: D0 G3 m7 exor eax,eax$ R2 J! b$ R: w1 b5 x
mov ax,3e0h. \( Z, e/ |) E9 G* L- c
or al,3h5 M: S! |, J7 y, t L$ }0 f) d5 z1 Z& J8 K
mov word ptr [Callgt+4],ax o2 C( o% R @: F9 @
;farcall[2]=((short)((ULONG)cg-(ULONG)BaseAddress))|3; //Ring 3 callgate; : j: `3 `$ e2 t6 \" a
lea eax,_Ring0Proc' i$ d5 z! k% e1 R4 h: G& F
;invoke VirtualLock,eax,seglen , O) T7 \* L. A$ ^+ D+ ^
test eax,eax: U2 S* w: n6 p1 j/ O, q
jnz @f- y; K/ ~, A# B# j: A# j& l
xor eax,eax
+ j8 e$ S+ ~4 T1 ^ret
7 E# k" b' Y2 i@@:; H4 ^: X9 ]) n$ s/ F
invoke GetCurrentThread+ ?' H; k2 k8 F
invoke SetThreadPriority,eax,THREAD_PRIORITY_TIME_CRITICAL
; V; h0 Z" C4 l( R$ ~4 B& {& o8 [ _" H' G/ m9 s! c
invoke Sleep,0
8 P3 B' k8 A! v1 q9 ^call fword ptr [Callgt] ;use callgate to Ring0!
( D- Z; r7 t4 k8 v" e6 `3 k2 M3 t;_asm call fword ptr [farcall]
' ~. n$ h! o, o_Ring0Proc: ; Ring0 code here..
+ E2 ]" m$ l6 mmov eax,esp ;save ring0 esp
6 y$ c* }# D, v' Amov esp,[esp+4];->ring3 esp
" o& J" K- p/ b2 ^, p! jpush eax
, g0 d) h) m3 N$ z8 D& p/ W- X mov ebx,offset stIDEINFO8 F3 Z7 i' g y O
assume ebx:ptr IDEINFO Z# }) x, |+ n2 C/ E7 r# |0 t4 ]
;********************************************************************
! ^8 C% L. p: l9 F; 等待硬盘就绪4 D) E9 m) D6 I
;********************************************************************
+ i8 ?$ r, ~8 U5 v. N mov ecx,10000h7 y. ?+ c! C h f, w/ x
mov dx,01f7h1 s3 @+ s7 y( t8 K a9 s! ?( B
@@:* \. A& j) ?' ^ T8 B1 }8 k9 A
in al,dx
' {! f6 x9 u; T4 L cmp al,50h
7 B, U' J/ G! q, ?( c/ G jz @F
& `, t2 u/ o( d Q! G; `3 b, M loop @B5 y& F1 X) X0 e% Y4 g# a
jmp _II_TimeOut
7 v. O( @0 T1 O: [: ~( l% F/ B @@:2 t: N2 n5 \2 f' n$ W
;********************************************************************
4 y1 {! Y) ]5 e$ Z. P; 发送命令$ f5 H& U3 m+ z9 |2 X. G3 C& l" y
; 如果向主控制发送命令,则端口为 1f0h-1f7h
- |$ u7 Y) C* @; o# V$ o5 n: n2 t5 H# }3 p; 如果向副控制发送命令,则端口为 170h-177h
$ D# S: A6 F, H/ W; 1f6h 如果要检测的设备为该IDE接口的主(MASTER)设备,
- B0 Z' v. b4 ` o# s; 那么发送 a0,如果为从那么发送 b0
8 u' V( J4 R3 t- K) o; 1f7h 如果要检测的设备为 ATA 设备那么发送 ec# U% E9 W$ c+ s9 H
; 如果为 ATAPI 设备那么发送 a1
- I' f8 l2 e2 E9 {: ^4 h y- D;********************************************************************
: |- l9 E" M% x" {+ P mov al,0a0h ;Drive 0,Head 0
* X6 _% f# D" _$ e$ } mov dx,01f6h ;Drive and head port$ S5 S( Q# @" q
out dx,al
( Q, _# F) h$ a; p! ~2 @4 F" A+ g; m, O, c' H: c, f$ C+ L, k$ P
mov al,0ech
. r: o& d5 G+ J7 `! t inc dx ;Command port# r' s; @' k' B. U* v. I
out dx,al
0 A; c8 ^% w# ~7 k0 K* a;********************************************************************
4 b: S: o5 G1 t9 }' \& k7 p& q* X; 等待硬盘就绪
4 F; h7 n4 ^4 F; N# N2 p& n% n! H;********************************************************************
2 _! a- E1 |3 y- N mov ecx,10000h1 ]/ M! G# u- M" }: y/ o: c
@@:, {- p: W* [3 B/ `* k! G
in al,dx;1f7 (r-status register)$ x, J, Y9 _5 i" i- W4 y
cmp al,58h;(driver is ready ,and seek complete)
; h9 v8 t; |: |+ N( S' Q jz @F; o6 P) p% W: G. k
loop @B u8 P5 k; D7 q$ R/ r# e4 E
jmp _II_TimeOut
: h6 m$ U; U. m* V2 g1 i2 U% Y9 I @@:& P" O0 O" s! {
;********************************************************************
& q3 k' B6 j- m9 q; 将返回信息读回
# m9 U- l$ c f0 ?* }/ M( v: e; 注意一定要读满 100h 个字长
* z, T* m* C, m: E$ q k/ v;********************************************************************: o7 W I: e9 Y( h9 m
cld
8 k1 u/ C" `5 I; M( P mov edx,01f0h;data port - data comes in and out here1 s& H% E: S8 d/ R
mov edi,ebx
) R8 r) r+ J9 s3 c* V7 n* r6 J mov ecx,0100h
: K J. s% i3 }1 O8 h8 `% G rep insw2 p+ h4 |; c/ t$ w' G- ]8 F8 y
;********************************************************************- N0 e/ ]# e9 [8 P
; 返回的信息中,型号、序列号、版本号为字形式. J" Q. N- @1 r1 L
; 需要整理到字符串的形式
9 _; J1 M& h6 n;********************************************************************
. d' k2 X) H( L V' ~ lea esi,[ebx].sSerialNumber
, T8 z- H7 k* s+ ~ C! B: A3 E mov edi,esi
# f3 A: g9 Y) r# ~& j/ y v mov ecx,10# d, g* o6 A, V' O% b/ F
@@:( M+ r* g$ e* [& K: c" t$ @
lodsw
) A+ |9 Q; q. S& D xchg ah,al
8 Y1 n+ D3 w2 }+ } stosw
' b& z3 G/ p: n P1 e4 ~6 N1 G: ] O loop @B
; ?% D% B- c) R7 y* [9 }% V6 v3 a9 _% X1 M+ |
lea esi,[ebx].sFirmwareRev
. @1 N8 ?6 W+ _) o/ Z: V mov edi,esi- {9 V Q) Y$ D6 o' _6 Q9 [
mov ecx,24
9 M% n8 r+ l3 o @@:# c: H: U- H `. m1 M% s( A2 O
lodsw4 _- I8 S. P( O* ~+ I
xchg ah,al
, }! [5 T) C1 J( i7 N9 i W stosw
- Y5 [6 A6 I/ B" K' V% M loop @B
4 A/ J7 i- q4 Z, N& T_II_TimeOut:
/ T" U0 o" X1 f2 \$ n1 n2 j s7 Bassume ebx:nothing% N1 ?3 s" R! G0 _: S1 |3 g
$ b6 X4 D) W8 N0 h8 Dpop esp ;restore ring0 esp9 [) {4 Y) x$ V, Z; n2 V3 R
push offset Ring3/ `, z( z8 Q7 `/ g# f& g! D) h2 v% H
retf
) S- F! Q) r# G7 q* U0 A& H8 ERing0CodeLen=$-_Ring0Proc4 h3 J3 H) n3 _- G; X
, |* P* l, s4 z- Z2 |" S1 ]Ring3:
4 \0 a1 k* z' s! `) ainvoke GetCurrentThread& P5 H% I( }% @2 G0 a
invoke SetThreadPriority,eax,THREAD_PRIORITY_NORMAL
: A! C2 S* t! [; \' g
4 ]" H# B! M; n, i, [;invoke VirtualUnlock,Entry,seglen
' W2 I$ U4 E) Y/ l3 R9 A& \6 U* s+ B% w" z/ P) |0 B, m$ ~0 T
call @f/ Q5 n, B3 S1 n% _; Y; j L) r
db "ZwClose",04 r, P8 C/ d7 ?# x0 `
@@:
. {* R( {& N! V; wpush NtdllMod
. B6 J6 `2 j3 x& z3 ucall GetProcAddress
2 ?1 U) N: K2 f* O9 Bpush hSection
5 r, R: U! w4 K* A5 ?4 ccall eax. D" d# v+ X1 v# {
mov eax,TRUE E6 T5 S" J( ^. M7 E9 K0 v6 P
ret' }2 c# Q9 i2 C9 I0 o
ExecRing0Proc endp / }# x9 E! L, t+ s, @
1 ]0 p4 f3 g. |" Vmain:
5 `' Y2 h3 Y# {0 ]assume fs:nothing
7 L& m" Z8 M* ]- \0 ]3 Opush offset MySEH; N* ]3 \" [. N( t$ t+ `. A
push fs:[0]9 z/ H! s7 o6 M# n/ v5 f
mov fs:[0],esp: p/ \( m4 Z% @/ }
mov OldEsp,esp+ T( @/ x6 y) h% Y( ~
mov ax,ds ;if Win9x?
, @9 u! d& @) k) E/ q. j, ctest ax,4
' G! l9 L2 M' e( u# S3 ]% rjnz Exit13 z3 a2 V. ^1 H8 ~+ W, L
invoke ExecRing0Proc
. f8 J' ]% z* k& h8 J
: R9 J1 [0 _. P3 ]* I6 P.if stIDEINFO.wNumCyls
- r4 e0 B9 \* M, u lea esi,stIDEINFO.sModelNumber4 ~/ X& ?( S- c& I4 V: Z% j
mov edi,offset szModelNumber ]% e; a/ a A7 X
mov ecx,sizeof stIDEINFO.sModelNumber
3 C% Y/ ?6 ?: d, _. o rep movsb
; I# `+ ~' F& @8 @7 H: Q0 t9 p4 R8 n* Y" i9 n$ F$ A% p2 r7 O+ G p
lea esi,stIDEINFO.sSerialNumber
7 F8 `8 R+ d3 R4 v; N+ X1 W7 g mov edi,offset szSerialNumber
5 G! q/ J, h, @* r& k mov ecx,sizeof stIDEINFO.sSerialNumber Q# `& Q; c& ]: q
rep movsb4 S% W/ ~: N6 Z" j$ L
6 f# h6 o7 Y0 f* C) |7 ~
lea esi,stIDEINFO.sFirmwareRev
9 m8 E) B+ _8 V mov edi,offset szFirmwareRev7 S8 t3 K, h6 v, Q& m Y
mov ecx,sizeof stIDEINFO.sFirmwareRev6 A; t. G6 g: \! O+ Y# b
rep movsb
) ~6 \- [; d$ B9 F2 Q" d. q! J7 c; f O
movzx eax,stIDEINFO.wNumCyls$ d9 I, X4 T& \0 K8 g' s' W
movzx ebx,stIDEINFO.wNumHeads
2 J3 i* q% j8 Q. F4 U2 i! I8 Q$ a* E movzx ecx,stIDEINFO.wSectorsPerTrack
" p- h% F7 Z5 J4 d( X2 h' h movzx edx,stIDEINFO.wBufferSize( }# z" r/ X5 T) W' K) x% j
invoke wsprintf,addr szBuffer,addr szIDEInfo, eax,ebx,ecx,edx, addr szModelNumber, addr szSerialNumber, addr szFirmwareRev8 T: V. f+ s0 j( M; W7 s- f
mov eax,offset szBuffer, [1 }- t2 I/ Z
.else
0 m" `4 S7 |9 o- I) g- D+ l: G mov eax,offset szErrInfo* x% z" N0 ~ k0 v# ~; f8 z( r% t3 ]$ u
.endif
7 k+ c/ v9 r1 m! |@@:, U9 y( f2 l& n& q
invoke MessageBox,NULL,eax,addr szTitle,MB_ICONINFORMATION or MB_OK
8 g p# k2 k. u& c4 f* HExit1:
/ f6 X/ ~+ p# F) m0 wpop fs:[0]) z3 B# h9 z2 p7 f, ? N; X
add esp,41 T4 M& O: H0 o* A
invoke ExitProcess,08 }: o$ j- s, x% v3 j
! W: h7 M4 v# ^; p% ~ |MySEH :
1 M7 i1 @) q4 G1 _, r7 Gmov esp,OldEsp8 Q+ b6 p W' X1 }! T; {0 t
pop fs:[0]4 }. ^% D0 I; x" {5 ]
add esp,43 O2 z$ @- N5 q; \
invoke ExitProcess,-1
3 X7 g! F4 H# B! f, E7 Yend main# |. u! R* y$ i. K
* U$ v5 D% C1 e/ @9 w: K
[此贴子已经被作者于2003-11-2 18:14:02编辑过] * F+ W. L! o$ ^1 R; }2 M; Y
|
|