|
我可没这个水平! {5 i# H& ^& ~
.686p0 z, n" G) h2 O% J/ p
.model flat, stdcall% q- B: J) i8 R
option casemap :none ; case sensitive
! } E/ N. f% r. L; #########################################################################
5 _9 ~5 }0 W( C/ yinclude \masm32\include\windows.inc
4 f% T. A0 c3 U: t$ ?% binclude \masm32\include\user32.inc
# P( Y" N7 [( J; M4 i, pinclude \masm32\include\kernel32.inc# r, m% j4 o. Z7 E. L+ X
include \masm32\include\advapi32.inc& e! D; H/ y, K( B' \3 x
' h, u2 k& |" ^6 M
includelib \masm32\lib\user32.lib3 ~8 b8 t7 A+ R z% k4 `
includelib \masm32\lib\kernel32.lib( K/ @3 r& V3 f n' B
includelib \masm32\lib\advapi32.lib
3 T a! {8 I: o" K1 PDEBUG = TRUE3 p2 S& Q/ W7 I3 Y- u% @, i
+ I% q) V' m5 C; [' f5 A
HMODULE typedef dword
6 a+ \( t. f. s9 a' H8 W+ cNTSTATUS typedef dword
) d$ H6 }( ?8 E5 I; ]% j: _4 dPACL typedef dword
. B4 V1 s! @+ }1 ?: hPSECURITY_DESCRIPTOR typedef dword, j; A; u( u8 K$ @/ i/ `3 P
! E6 @8 \4 J9 e. r7 iOBJ_INHERIT=2
1 U& ^5 I# ^, o4 }& o7 g% FOBJ_PERMANENT=10h8 t; l& u3 b0 h5 ^
OBJ_EXCLUSIVE=20h , m8 Q& r4 u U" e
OBJ_CASE_INSENSITIVE=40h
4 h: r& a9 \+ J2 N6 Z0 XOBJ_OPENIF=80h
& r( u$ K/ R3 Q8 ~0 TOBJ_OPENLINK =100h
# D0 S9 m8 h$ I P* W& P& b1 c bOBJ_KERNEL_HANDLE=200
& |" j4 O$ N$ U4 z! y# oOBJ_VALID_ATTRIBUTES=3F2h / W6 [/ ]( K( \
) Z+ C! h! p. L5 N. R
SE_KERNEL_OBJECT = 62 H6 E# _5 A5 c: [' D: Q0 n
GRANT_ACCESS =1" R/ p# R" ~; W& L
NO_INHERITANCE =0- @4 D' m2 U0 e# I! }+ V" |) V8 `
TRUSTEE_IS_NAME=1
# t1 N( S' A8 t% V8 ]$ S( @) KTRUSTEE_IS_USER=1
9 j4 J# r: O% K9 `) c$ ~& tSTATUS_SUCCESS =0 ! U0 l0 k7 u( S3 f' V: q) t
STATUS_ACCESS_DENIED =0C0000022h
7 N; L# N4 v- `3 Z. v- K0 t9 T& C$ R4 [& ~
STATUS_ACCESS_VIOLATION equ 0C0000005h* I+ ^0 N3 F- P" j
STATUS_INFO_LENGTH_MISMATCH equ 0C0000004h
/ P9 J+ p5 P$ C, ^SystemModuleInformation equ 11
3 w2 t% C: T" J/ z' c. APVOID TYPEDEF DWORD
! Z. F" {! f5 }4 T6 @ ]UNLONG TYPEDEF DWORD% @0 _/ O" _6 N3 N4 J6 N0 G: W3 B K
CHAR TYPEDEF BYTE
! T( k. `& D, O: z. w
; t1 @5 m. s4 D. wUNICODE_STRING struct
+ |& g5 I! m/ `7 }3 q2 e5 Q nLength word ? : P! e0 u7 u4 \+ X; A" R
MaximumLength word ?
5 a# L! y9 C1 Q Buffer dword ?
2 y9 L1 n, D! P- E3 \UNICODE_STRING ends" z$ R: J; E/ n( {( @
# y& B! D5 |- z2 \/ p' u2 u* R
OBJECT_ATTRIBUTES struct 6 u% v+ Q+ d' Q$ `
nLength dword ?
7 K. `' o0 e2 B. _$ j- Z RootDirectory HANDLE ? % [8 p% K% R) h
ObjectName dword ?UNICODE_STRING
& H! ?4 [; m: b M Attributes dword ?; " Y; [" {3 ^9 D" q& G
SecurityDescriptor dword ?; PVOID // Points to type SECURITY_DESCRIPTOR
# R C% p$ M6 A: q( W) y SecurityQualityOfService dword ?VOID // Points to type SECURITY_QUALITY_OF_SERVICE
+ _; Z1 H- g7 g! b6 ]OBJECT_ATTRIBUTES ends 5 z) x, c: O+ Z, n1 ^
9 `; t" @8 K# L5 ~
* V: @0 p, J( y* F8 i8 h r! R
TRUSTEE struct 4 m; _ p+ n/ Z$ M8 ]
pMultipleTrustee dword ?TRUSTEE 0 z% r, }3 n d* a
MultipleTrusteeOperation dword ?; MULTIPLE_TRUSTEE_OPERATION 4 e! N. L8 W" q
TrusteeForm dword ?;TRUSTEE_FORM
6 ~1 G$ L* y- t+ k# \2 f" } TrusteeType dword ?;TRUSTEE_TYPE
$ [2 Y b' f3 f) P3 A ptstrName dword ?;LPTSTR
) r; b8 s9 W+ @$ ^( d2 LTRUSTEE ends
8 o* d! w- v% q- H
- ^+ X4 _& W# h4 r# _6 I8 v6 Q* w- u8 R$ r. P* W) x
EXPLICIT_ACCESS struct( `/ a$ W2 b2 ]0 g' p
grfAccessPermissions DWORD ?
- b e0 v% J0 |; P* }) A( g" X5 i grfAccessMode dword ? ;ACCESS_MODE : X% J- s8 ~7 V! k2 _$ T' v
grfInheritance DWORD ? ;; {. [, R( F3 C9 q
Trustee TRUSTEE <> ;
9 E4 a1 H% p1 g1 u3 M$ m+ `EXPLICIT_ACCESS ends
! L. M9 z9 _6 y* D1 v+ u) \: M* N' p
MyGATE struct ;门结构类型定义+ S4 t' X( ?: q. d: A6 z
OFFSETL WORD ? ;32位偏移的低16位5 P- R1 s' a! l/ z8 R
SELECTOR WORd ? ;选择子
% _. V* Q- f" ?: F, { DCOUNT BYTE ? ;双字计数字段& G, m; g. Y( ? d1 V6 `' ?
GTYPE BYTE ? ;类型 C. j. A8 ]# ~( J2 ^/ t$ g7 P
OFFSETH WORD ? ;32位偏移的高16位
3 j4 z- `- |& c6 UMyGATE ends
# V" g7 H+ l" s" m- @+ l G2 q+ b3 o: m0 b4 W$ J4 i
IDEINFO struct
, _/ o; w7 ^0 x2 f: m: GwGenConfig dw ?
4 D$ j0 a0 \1 ?6 BwNumCyls dw ?;拄面数
6 n- y9 | q0 pwReserved dw ?
+ j/ J9 \: W) k1 \wNumHeads dw ?;磁头数
, `; P o& b- u+ twBytesPerTrack dw ?;每道字节数
; x* n' a. K' O3 h+ t" C, PwBytesPerSector dw ?;每扇区字节数
; Y/ `, t% b: U+ X/ {wSectorsPerTrack dw ?;每道山区数1 i4 D L C0 {4 h! Q. R4 ]
wVendorUnique dw 3 dup (?)1 a9 Q6 q0 G4 b% e& @8 u: F3 O
sSerialNumber db 20 dup (?);硬盘序列号
+ U4 ?$ o3 b, x, v/ q. l4 X1 _wBufferType dw ?;6 n1 s: {- v- h0 m* ~0 h
wBufferSize dw ?; ;n * 512
0 J6 ^" o) U) t& gwECCSize dw ?$ N3 n+ X8 r+ [* \( b0 b
sFirmwareRev db 8 dup (?);4 J; F# F: O# l% G4 s
sModelNumber db 40 dup (?)# }1 W) H% k$ Y( {8 p* g7 p2 D
wMoreVendorUnique dw ?* W) B2 V7 {4 I: _/ b4 m9 F1 x
wDoubleWordIO dw ?3 E8 b4 t8 i+ t3 t- F9 m
wCapabilities dw ?5 J4 V9 J W+ F6 M
wReserved1 dw ?
( V% e/ d& u) q0 _. @2 W4 KwPIOTiming dw ?;( O2 B$ @8 W: q' y) M
wDMATiming dw ?;
$ {0 `& A& O8 K% g2 }! w* u7 QwBS dw ?& Z+ n) v' `) [$ n" k. p
wNumCurrentCyls dw ?;1 B9 a( M) P; s/ O7 }: R
wNumCurrentHeads dw ?;
8 K4 t% ] ^! T3 p' E3 nwNumCurrentSectorsPerTrack dw ?;
9 F- [/ T7 K# c z' A9 gdwCurrentSectorCapacity dd ?;( u% T4 H, ?! Y, Y: ?- |3 |! J
wMultSectorStuff dw ?;
5 q/ J# \! M$ a/ b6 m/ j: k. s- UdwTotalAddressableSectors dd ?;
6 \4 i5 i0 T# R5 C4 O1 ?- nwSingleWordDMA dw ?;
, g( S$ g7 U6 z9 xwMultiWordDMA dw ?;4 k1 e4 F' d: [- [" r
bReserved db 128 dup (?)
2 x* J( p- W6 p5 `& h! @9 iIDEINFO ends+ W( {1 y, Z3 X5 N
: z+ v; S7 w7 k' i# s. N
% D4 P% r! L4 Y/ B3 H
SetPhyscialMemorySectionCanBeWrited proto :dword& v; @' F1 h+ N R3 U: K* l7 v
MiniMmGetPhysicalAddress proto :dword
# ^( \6 w3 L7 M" @. ?7 Q* E$ [. a; D2 h5 i; }
ENTERRING0 macro/ k. ~9 C% x) R% L1 u, ], [
pushad 3 C/ m: T& y V
pushfd / a) P2 H9 `# z( H: X
cli- o+ S6 d9 a# B% Q# b3 }
mov eax,cr0 ;get rid off readonly protect
7 ~' O! T9 k5 _" h/ jand eax,0fffeffffh. X4 U0 g3 f4 `8 t: P7 V
mov cr0,eax3 r+ P- l4 V- h- h+ _
endm
4 T+ u/ u9 O1 y" m* a* q9 T8 l
LEAVERING0 macro. v+ c" H& j+ Z- R# }4 ? [/ J5 Z5 ~
mov eax,cr0 ;restore readonly protect9 @; M$ b1 P$ a: H# w: t
or eax,10000h* f' f0 b3 U: `2 N8 L; {' t3 T: h/ ?
mov cr0,eax
# x6 D( g5 m- `1 `0 H- g- csti
7 i( b( h+ o' S& B( |popfd
: F6 D9 {5 Y7 `! ?- v; f# P( Tpopad 1 o6 }- a! p8 Z O
retf
2 \' W; T3 ?& l! D9 n; Pendm) ]2 I8 `- y: b" L* E
) s7 S/ P5 s4 E$ X: f+ c' B/ ^
* C2 z, L; c7 K5 A
UNICODE_STR macro str
; |/ p* o5 v4 G0 N3 r% @- w% {2 Kirpc _c,<str>8 I3 a8 u# _$ t8 K/ E+ R0 u
db '&_c'
% N( `5 s) F, u5 A; f" D0 n8 W! p; h: ydb 0$ s8 W: u4 G& {
endm
0 z) { U7 v+ s8 X) m$ c( Kendm
( n9 T" R" q# K7 H$ O( l+ j7 H- [$ i# H2 l2 y& m
.data?2 U; j- ~" P0 F9 F3 S
GdtLimit dw ?
. j9 D' s$ g* T( {GdtAddr dd ?# ?2 j. _) S6 f: |, t* C
1 i" F1 ?' z6 l, i5 v$ h& p1 {
mapAddr dd ?
* ^- N S$ v9 d6 M3 _8 h+ TOldEsp dd ?5 c! g- p, K' {$ |' N2 O
" `0 m1 Z! y4 e% F, yreaded dw ?. {$ I# ?7 v- |6 }- b. l* Z* r! g
buffer db 512 dup(?)* b1 P t8 S x8 d& a4 A' _
ShowText db 512*3 dup (?)
* R, u: y$ L3 o( [ Z* a. K
6 p" s+ e( i; |$ m4 YszBuffer db 1024 dup (?); s9 S% `. U% c* I, l
szModelNumber db 41 dup (?)
- G x! Q+ J2 _2 vszSerialNumber db 21 dup (?)6 p& Z% Q* a4 B& @! v4 H A
szFirmwareRev db 9 dup (?)
7 v/ {% c# @& P
4 E( I( G; ]- y$ g5 S6 @3 ?stIDEINFO IDEINFO >
- Y0 h8 m* G' Q+ D0 y! T( D& z2 K7 ^$ |+ h
.data' [& O' R% Z) V' k8 M' U! q7 F5 U+ w
align 4
1 p& Q$ W& P) }- T$ a) p. vobjname dw objnamestr_size,objnamestr_size+28 p4 T8 f* ~( k+ ]
objnameptr dd 0
2 ^6 E$ Q0 ]: Vobjnamestr equ this byte
& ^0 a0 o8 _8 U L" dUNICODE_STR <\Device\PhysicalMemory>
- Z9 b3 [2 ^' @7 yobjnamestr_size equ $-objnamestr8 J8 s8 R, V) M, F' C: d- ~5 Z8 X
$ o- j6 _- I/ }/ _ s- oszTitle db 'IDE 硬盘信息',08 y* u2 \! m0 F& F' y% p4 ]0 I$ `
szErrInfo db '无法读取硬盘信息',0( k( d/ p0 b. b6 p' l0 a4 m, |# O
szIDEInfo db '柱面数 : %d',0dh,0ah
9 A7 b }5 ^0 K# `! |' i db '磁头数 : %d',0dh,0ah
8 F/ d* v" o& }& s! \, c! D db '每道扇区数 : %d',0dh,0ah3 r+ k* {$ |, s% Q2 V6 E# d: I( I+ C
db '缓冲大小 : %d 扇区',0dh,0ah
9 ?% Y+ N- m! R( q e0 k db '硬盘型号 : %40s',0dh,0ah$ B& Y' X" f9 [) s% l2 V. _5 ^
db '序列号 : %20s',0dh,0ah6 T Q! r- u0 Q- l: B) }3 m
db '版本号 : %8s',02 i7 _2 X9 ` f' ]# F7 ~* Z
8 T# I4 q& N+ D- Aalign 4
( y$ v8 K5 m) {: R* k: CObjAttr db 24 dup (0)
0 p1 y; W/ P8 l& Y4 ?, i0 J$ e
- s6 a, \" s8 e, n1 Y sCallgt dq 0 ;call gate's selff7 t2 Q2 s$ @$ y( s
Caption db 'Windows XP绝对磁盘读写',03 T0 l# `0 G+ _. P" p
Digit db '0123456789ABCDEF',0
3 v/ U& p- N) k* M- C; x. b; }- J.code
5 s) }3 i+ f8 R2 R_ShowBuffer proc ;显示所读出的信息& Q b7 F7 b8 ~3 Y. u. c0 \3 G
;把数据转换成16进制的形式2 G( }+ b, X3 _7 N s& u
mov [readed],512
- l/ N+ a5 k1 h mov esi,offset buffer ;数据7 j" p/ G+ ^( t( P: f
mov edi,offset ShowText ;转换后的数据 R# \% E1 b l, [
mov ebx,offset Digit# _& ]0 \; D1 A$ S
xor ecx,ecx
0 x {- Q N( T* e xor eax,eax
, P& ?3 R' z7 M I" j' Z- s: \computeAgain:
7 N4 }, @$ _6 y$ q6 j* Q cmp [readed],0
4 [7 I6 v7 g& U( C9 W/ R* i jz endCompute+ z# {( v c. l& x& _8 V- x0 W6 |
dec [readed]5 `6 `& g+ |' i$ c
lodsb
0 s" K; n$ E5 A/ R) r O# Z% e0 ? push eax
5 Z; x# n/ e4 K2 d( `, Z- c* P) U shr eax,4 ;高4位
! N1 y$ V9 ^7 |) x9 T9 Q xlatb
# J- O& w0 U5 P3 q3 ]2 @ stosb8 e9 ]$ Z; u& Q+ [% Y- F% M
pop eax* x' }" K6 ^8 i l: w
and eax,0fH ;低4位
0 n& M7 y' _8 t% X8 S& ` xlatb' j k0 t: y9 m9 n0 f$ g
stosb
2 K9 A' y, h9 P0 Z H mov byte ptr[edi],' ' ;空格
- Q3 U) x: [+ l$ S7 ]. c& \ inc edi
6 j: g2 p3 t/ C7 B$ q inc ecx r, o b9 f& q4 X- ~6 J) V
cmp ecx,16% l' f. _9 S/ ~, D. @, j
jnz computeAgain1 B8 B( n, R( Y* B
xor ecx,ecx
. n2 m% K5 C- n& k# x. X* w mov byte ptr[edi-1],13 ;回车
2 m9 D6 N }) u( E4 D( E% |# H& J jmp computeAgain
+ G+ |/ I, u6 r1 q( LendCompute:
/ N: Z5 J; X& p% _' { ;显示
. }" D8 l" U- r2 n$ O0 J+ N$ F invoke MessageBoxA,NULL,offset ShowText,offset Caption,MB_OK
; m7 w7 g6 l: S! ^3 o' O; W ret3 P, P3 j! U, I
_ShowBuffer endp
! I/ w7 ]1 O/ E' w% P/ \$ y' ^9 E! z: g5 B8 g
SetPhyscialMemorySectionCanBeWrited proc uses ebx esi edi hSection:HANDLE / e5 w2 w, k1 `
local pDacl: PACL
" Z8 R& e! V( glocal pNewDaclACL
4 ? H* b r4 Q* K9 j; alocal pSD SECURITY_DESCRIPTOR
+ m @4 J2 I4 I. v' {local dwRes:DWORD ;0 _1 g E7 N+ i' C8 s! p. y" P$ u
local ea:EXPLICIT_ACCESS ;, ^4 A) z. m1 Q' j0 Y; D! g
invoke GetSecurityInfo,hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION, NULL,NULL, addr pDacl,NULL, addr pSD# F" B8 G8 F, g0 f1 k8 z
cmp eax,ERROR_SUCCESS& X: L0 \9 e1 _& E! Y' O
jz @f
# A. i. X9 ]. `0 Kjmp OutSet# R( j5 s. k; _$ J4 ?
@@:( h7 q2 L" D/ t& h6 X
mov dwRes,eax
) ^& o: F7 J4 [0 jmov ea.grfAccessPermissions ,SECTION_MAP_WRITE;2
; {; ]7 `. ]& Z1 q+ \: w* ymov ea.grfAccessMode ,GRANT_ACCESS;1
" U* k* p# | F! b8 [6 x& pmov ea.grfInheritance,NO_INHERITANCE;0) y3 q" U ^# g# t" o
mov ea.Trustee.pMultipleTrustee,00 z! g( k' [* v$ h0 O" G
mov ea.Trustee.MultipleTrusteeOperation,0
7 q4 g) u' S* P3 a8 R6 \; |/ Vmov ea.Trustee.TrusteeForm,TRUSTEE_IS_NAME;1+ p, m5 }0 |5 s' h/ o& k
mov ea.Trustee.TrusteeType,TRUSTEE_IS_USER;1( ?5 V) S- @; Q4 ]& a: I$ x
call @f
) j, p/ c S$ R6 cdb "CURRENT_USER",0
4 `0 V5 U* x% [@@:- S! X2 |" s5 R3 R
pop edx
I( ]& m+ Z5 e: U1 Cmov ea.Trustee.ptstrName,edx8 }2 k0 }! y# r0 t: A0 o5 t. }6 s
invoke SetEntriesInAcl,1,addr ea,pDacl,addr pNewDacl
' f7 z# M0 d* a& P, F5 E/ Y9 Acmp eax,ERROR_SUCCESS" l9 t1 z8 S6 `9 B0 i; d- C
jz @f& }' ~$ k# F z' w, X: }; n
jmp OutSet9 s; K& [0 G1 U
@@:: P2 U& b) u4 R$ G1 g; p, `6 ^
invoke SetSecurityInfo,hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION, NULL,NULL,pNewDacl,NULL% @) K5 Q. h3 ]0 Z
OutSet:2 ^( z7 i* C9 W% b/ S9 I
cmp pSD,0; ~5 I9 ?. v+ \% @" @
jz @f l0 K' F. }+ T8 {6 B( ^6 H2 F# U. p
invoke LocalFree,pSD! s! j+ I2 y5 ~; X) @1 z
@@:+ z! X: W& P/ \& B2 Q2 ~1 Y B
cmp pNewDacl,08 K! z" Y7 `2 g, I8 g7 G; o
jz @f+ _8 Q) ^5 r& h) x0 ?& X
invoke LocalFree,pNewDacl% P* t7 ^3 Z' y; D
@@:
9 ^$ `+ x; S; r# V& }2 e& Rret
, O& ~ u7 m. m4 \! {% p: a& iSetPhyscialMemorySectionCanBeWrited endp
. Y. B" F; i7 j' a) x: m3 F6 B$ J2 ?. a5 D
MiniMmGetPhysicalAddress proc virtualaddress:dword. _0 v8 K4 D; |! k$ d9 \9 l) }
mov eax,virtualaddress
. Q B9 a' k: h: ? n cmp eax,80000000h; h/ F: H* ?+ u
jb @f
# Y4 U, a4 b1 I! Z: ?# A( q cmp eax,0a0000000h
) }% j# a3 I X6 t# }& c1 K; U jae @f
' A- q- ?' n, m and eax,1FFFF000h* U$ R2 @3 x; R
ret
3 G- G% {2 h( I0 K @@:4 W5 ~3 d: q2 A
mov eax,04 v+ `/ K( s6 {0 e( H
ret2 P5 |7 H+ F0 [# `
MiniMmGetPhysicalAddress endp/ ]* b3 s8 f! g9 H
% v; l4 k1 B2 y) V/ B1 ^ lExecRing0Proc proc 4 y: y# s, M3 X% v- R* U
local tmpSel:dword7 H2 x7 F4 j# D) |7 Q+ d$ G
local setcg:dword8 A/ [1 E3 S0 E. e, r7 ]
local BaseAddress:dword
2 B$ n+ m0 R) jlocal NtdllMod :dword E+ P* J" B* v3 b
local hSection:HANDLE + ~6 l, M, w8 | ^0 s) |
local status:NTSTATUS
) C0 F! H4 {3 V6 Slocal objectAttributes:OBJECT_ATTRIBUTES
7 V: Q6 U+ f9 c+ ~local objName:UNICODE_STRING7 G; Q, A* ] x. t
mov status,STATUS_SUCCESS;
8 v( C z0 O n$ ? k B) m9 U5 Psgdt GdtLimit
; U: K4 {+ Y' z, F; x" x, s5 _invoke MiniMmGetPhysicalAddress,GdtAddr
$ q! |& k8 I2 d; d* i; zmov mapAddr,eax
# t$ e8 l2 z2 e+ Dtest eax,eax
y6 J( x6 U+ ^7 \' @, njz Exit1
9 x# m% W: N( V6 r: J# ~6 y/ {( Ncall @f7 R p' w0 g9 v8 s' @; B
db "Ntdll.dll",0+ Y1 l1 S& P* d; F/ d8 r
@@:/ ^, W& _0 a) l% L2 _' `5 b ^
call LoadLibraryA
: V: p0 V; D" l* Y7 ^1 C% U+ @3 hmov NtdllMod,eax
+ p9 u' ?5 c& L- Y' ?* N# O
/ a3 `3 [- l; T$ N. d$ l) Ilea edx,objnamestr- X; i7 G+ {7 H2 m8 E5 E* e- Z
mov objnameptr,edx
8 R" N7 c8 P4 Z7 J) klea edi,ObjAttr M/ `7 B" q3 y' L
and di,0fffch ;align to 4 bytes,or ZwOpenSection will fail
; {& R: ]% k5 G5 [3 v7 K6 P/ upush edi ;edi->ObjAttr. l: N6 W+ U# N2 [
push 24 ;length of <\Device\PhysicalMemory> j S8 @& i( j" }, Z
pop ecx
3 P9 {4 h( t! ipush ecx
K; R+ `( ?7 G0 i. Mxor eax,eax
0 d: B* u& Z' x' s* e Zrep stosb ;put ObjAttr with 0
3 n% K6 U# o& c6 `pop ecx
6 a8 m) Y Z5 ]pop edi
. o3 ^; e- q6 q% b1 b) ~+ Mmov esi,edi5 q" g& y( u* a9 [: ^: [, n1 h
stosd
p6 p6 b p4 K" i' W! V Pmov dword ptr[esi],ecx% ?/ ]8 G- [ {0 y/ k- Z* n
stosd ( G0 s2 w8 @8 q8 ]1 I' ]7 C6 ^ ^
lea eax,[edx-8] ;eax->objname
1 t0 P A' L; q; j6 W4 ]5 v$ c( sstosd ;ObjAddr(18h,00,00,00,00,00,00,00,offset objname,40,02,00,00,dd 2 dup(0)
8 l7 i* s6 M* |( E! m- d& \5 Ymov dword ptr [edi],240h& a: X) w7 Q/ ]- M+ b
; l6 i/ |& b; B E
call @f
* h0 a4 j% ^+ S: edb "ZwOpenSection",0
: I1 ~* P! l3 |@@:
% r# }" [- M/ Y Z G$ A( ^4 S+ bpush NtdllMod4 B( V9 K7 B a3 o+ L$ X8 A2 g; F
call GetProcAddress
$ Z; s5 T$ U9 a( P U3 g4 bmov ebx,eax ;ebx=ZwOpenSection( f2 j7 \# s; C' h, y( [* I
. A6 U ^8 z; _* Z9 M. k; U
push esi ;esi->ObjAttr* B, q# g3 O0 J4 z: _* S
push SECTION_MAP_READ or SECTION_MAP_WRITE
- ^9 K" J/ t3 S; m2 }$ Ylea edi,hSection
, p0 s6 B% ^1 Y7 Q& I5 p- b& }push edi ;edi->hSection1 U2 M& `4 W! W c) f
call eax ;ZwOpenSection(&hSection,SECTION_MAP_READ or SECTION_MAP_WRITE,ObjAttr)6 |0 ]6 U" n$ m; u: M1 J
# q1 Q$ F) L$ C x4 L/ Hmov status,eax# S) w3 W8 U3 S* `6 `2 ^
cmp status,STATUS_ACCESS_DENIED
1 I: A; e! r7 ^6 U" d0 Ljnz AccessPermit
; b, f9 a' Q1 W) O/ P! X; Smov eax,ebx. A3 O+ y' O! n o) T
7 U, ]$ ~# |& Y- n2 I$ Kpush esi / M& z+ p0 @ h$ W( C* N$ S8 Z
push READ_CONTROL or WRITE_DAC ; E3 x! z% W# Y0 `3 }4 ~2 r7 W
push edi 7 s2 f% H1 C4 \/ V2 v! @
call eax
9 [: Z5 ]' w3 r- [, D
+ b! o. | j+ pmov status,eax
/ F4 }: `0 J& q% sinvoke SetPhyscialMemorySectionCanBeWrited,hSection 4 v" I4 x5 [1 w4 ?" \$ F
7 w/ @& O( N9 ]+ {9 w
call @f6 |. t+ y) i7 q# j) i! Y, T, C" ~
db "ZwClose",0
8 K% ^9 \1 h) h/ x8 T! p- u5 o@@:( M2 A8 T6 M, x! ~- p
push NtdllMod. ]4 L$ c! j: P/ ~" _8 G
call GetProcAddress
- O, Z K5 x( U( z+ G& ?
6 j- s7 `$ C! p7 L0 |; kpush hSection
& M& Q8 J4 D4 G/ u& u4 ~call eax ;zwClose hSection1 M5 f& h4 g: E
" B, Z% n' j% v8 z4 Y8 ?" V# S! G
mov eax,ebx
+ Z8 A/ Z& P! A4 i- X8 V1 f
$ i# p" Z$ Q; D2 E3 |push esi
: Q9 ^- H4 u# c. x& l4 ^! _7 J6 qpush SECTION_MAP_READ or SECTION_MAP_WRITE . v. n6 g V0 ?4 P) m
lea edi,hSection( `1 Y- N6 _9 ^/ S
push edi . t7 p: ]( Z6 W% M
call eax0 Q; D. |5 o' l, T
mov status ,eax
- H9 I' G1 K. A;status =ZwOpenSection(&hSection,SECTION_MAP_WRITE|SECTION_MAP_WRITE,&objectAttributes);
( h( H+ t. b: M, l3 p% g' eAccessPermit:& l/ c0 L+ g5 a
cmp status ,STATUS_SUCCESS 5 U7 D- S: Y2 `9 Y
jz @f
+ G! W, w% Y% J! W: ^5 L6 J0 Q9 K;printf("Error Open PhysicalMemory Section Object,Status:%08X\n",status);
; O) m+ O# b" x# R. R) d;return 0;
' k4 o; |5 f) p) b1 ~/ N: ymov eax,0
3 r/ b5 e% {# I6 _6 A! e4 n, bret4 [$ G9 a1 B% m1 p& ]
@@:
# T' q3 }$ q9 F. W1 B6 [2 vmovzx eax,word ptr[GdtLimit]) J, K7 \, d& R/ h8 q3 L8 n
inc eax1 `8 p( h2 U5 e' K" A* D
invoke MapViewOfFile,hSection, FILE_MAP_READ or FILE_MAP_WRITE, 0, mapAddr, eax
! X) {- G9 W) @4 W9 L$ rmov BaseAddress,eax" Q! U2 B. J- h- Y5 I* `
cmp BaseAddress,0
& @ e, H# q) u- V7 X; J, b) Yjnz @f
+ J3 h$ O6 y, v$ J! U% j;printf("Error MapViewOffile:"); " k8 t7 p( N2 X% q: N6 T
rintWin32Error(GetLastError()); return 0; t: t$ t5 m# _+ i) I8 o! K, k
mov eax,07 N4 y, w$ h p" B
ret
0 ^- h+ k/ A& X4 R- J) T1 [ K0 x@@: 2 l0 ?0 t" Q7 {. m4 l0 |
mov esi,eax ;esi->gdt base0 s! Y3 d/ u+ q
mov ecx,3e0h
# p8 m! k: M- N' j" l. pmov eax,GdtAddr
8 T0 O8 W9 h2 u8 V9 b5 T0 x& X$ h' E.if dword ptr [esi+ecx+2]!=0ec0003e8h
$ q4 l6 ~* z% v1 \0 v! y7 Xmov byte ptr [esi],0c3h. Y6 F8 o5 E+ w0 `4 ~
3 p& y, Q! H( R8 Q; R1 J# O
mov word ptr [esi+ecx],ax
& H& U: f2 y4 i" _( U( Ishr eax,16
% ~* x" r3 z% D, Omov word ptr [esi+ecx+6],ax
* G8 a& o q# i5 ^mov dword ptr [esi+ecx+2],0ec0003e8h$ e P5 k$ |" K. R
, n3 e/ D4 A2 j' x- v
mov dword ptr [esi+ecx+8],0000ffffh4 a3 e# Y; U4 I0 x& S( @9 q
mov dword ptr [esi+ecx+12],00cf9a00h
; j. ?7 p# s6 F' z2 d6 {.endif
+ N8 v+ _, P5 O7 ] X6 I. H* W
; j) D! X, c, B, i6 amov setcg,TRUE4 U) ~4 _: A# w, I4 \
cmp setcg,0
7 x/ o$ b$ r, R7 ^jnz ChangeOK7 k' d& h7 z' E3 h0 f1 c0 y
call @f: e f; e% m0 {
db "ZwClose",0
) X; O! E: p, |, H( L0 [* o2 |3 y@@:
# V7 ^- l7 A' n' \; p7 e' o* Jpush NtdllMod: A2 z! f! ^* H$ _# R2 R$ a
call GetProcAddress
9 e4 b1 l M" P/ J, G8 fpush hSection
% F2 m7 H* N( a7 l5 i: `4 fcall eax
1 [' q, O- H$ ~xor eax,eax
% u+ i, ?( A% V. b, ]7 c. yret
& L# X. h- H2 U2 R5 LChangeOK: f9 M, N) u5 n# x& l! K5 I
and dword ptr Callgt,0
" `; ^# _% n* v6 \/ D7 uxor eax,eax
3 S- P! M7 h7 e, }* Hmov ax,3e0h
( ?" p7 N+ b' s# x* M1 Q- Oor al,3h
4 t+ u2 h0 W' f1 y- r' c" Umov word ptr [Callgt+4],ax ) u; t/ N8 S& z! n) Y: e
;farcall[2]=((short)((ULONG)cg-(ULONG)BaseAddress))|3; //Ring 3 callgate; ( n# M/ q- t% E! H u' ^
lea eax,_Ring0Proc/ a T' v$ K) a s5 ^& \
;invoke VirtualLock,eax,seglen $ C f' T' U1 ^/ A7 T: n
test eax,eax
' Z5 N. H9 e# j) J0 A$ x- A9 Y6 zjnz @f7 b2 R/ W; |# c: n$ E. s& ~8 \5 h
xor eax,eax9 u9 z7 P' q0 M' b4 }) S
ret
7 V& d# ~' d9 F; f@@:
5 v0 I/ H$ \* i. R. z0 Kinvoke GetCurrentThread
c* w- C$ A# ]$ einvoke SetThreadPriority,eax,THREAD_PRIORITY_TIME_CRITICAL + e; Y# V5 X9 z% [3 t* Z
2 H$ O8 T/ Z' j/ L6 k, Einvoke Sleep,0
+ u, |$ g9 E1 T: z4 Xcall fword ptr [Callgt] ;use callgate to Ring0!
) O2 D7 d! n) z' ~1 T;_asm call fword ptr [farcall]
8 O+ C, B: b3 k) q1 @; t4 X_Ring0Proc: ; Ring0 code here.. 9 l+ m" w( o/ ]# P- \
mov eax,esp ;save ring0 esp
* A; `. l) N3 S ?# ^5 z3 @mov esp,[esp+4];->ring3 esp
7 @/ }' R, G7 U3 Y$ F' E$ \5 ]0 ~( wpush eax
" S' U3 j4 W, D5 k. _ mov ebx,offset stIDEINFO. y7 {0 _3 R0 J& Y" o
assume ebx:ptr IDEINFO
3 r: H3 o( {) g/ g9 f- h% |: B;********************************************************************' B2 t# P* i6 i: O' p8 k3 D8 P. Z3 {/ Q
; 等待硬盘就绪
' V% }) m! S; }, M6 |+ X% X! ~;********************************************************************- k. r6 W% u( J/ _: ^$ E& B# ^
mov ecx,10000h: ]- I- W6 G* c$ f5 `3 W, S( Y6 m2 }
mov dx,01f7h8 R. Y: ]/ C# [2 O m" p; |6 u& b/ p
@@:
* r3 S8 A+ Y6 i& P& v" G( i in al,dx
# b, X: R0 f" a1 i; z6 z/ \ cmp al,50h; d- y) u8 T, b) z" ?
jz @F" ^2 T3 _) q, ~, L
loop @B
7 w8 F) A5 y+ o0 h# W7 f' P/ ?7 S1 A jmp _II_TimeOut% M0 K" C- l5 n2 V6 }0 w* r" E
@@:8 z3 X2 z- M3 E3 |& q, }
;********************************************************************' E+ |+ t! P7 _. Y0 u- m" a
; 发送命令
6 [1 i- n4 I7 x$ `9 | f6 o$ B9 Y! k9 U; 如果向主控制发送命令,则端口为 1f0h-1f7h
0 ~ M. K2 R R8 e3 A6 ?9 H9 v; 如果向副控制发送命令,则端口为 170h-177h$ v6 k" a+ T1 u6 y% H$ R3 v
; 1f6h 如果要检测的设备为该IDE接口的主(MASTER)设备,
j! W9 m' f2 z7 w2 ?; 那么发送 a0,如果为从那么发送 b0
; L3 N7 l' Y# s& w; 1f7h 如果要检测的设备为 ATA 设备那么发送 ec5 B+ r8 f3 f# h. G& A5 S% [! G O
; 如果为 ATAPI 设备那么发送 a1
& @+ x9 S7 b( X- {+ F! z, W. B* t;********************************************************************
2 ?# S% q+ F- W9 I2 \ mov al,0a0h ;Drive 0,Head 0' \) f/ {# ^8 j8 S. ]2 u2 Q
mov dx,01f6h ;Drive and head port, G$ K \5 _# m6 N
out dx,al
' Y+ {1 b( H$ [/ n( U( w4 y; D) z. a; X
mov al,0ech
1 `/ U- O; c: u3 ] inc dx ;Command port. W9 I/ E d9 f- ^ i9 j3 I
out dx,al
6 _% a- N, E( T! o+ ~- C;********************************************************************
7 ]8 N8 [* V; a6 e- m" p; 等待硬盘就绪
7 i' u/ W2 x$ u) w# w% M;********************************************************************
9 h" M- C4 d3 ]! X* @8 T6 `7 y1 Z mov ecx,10000h- ?! y# R% u# s$ Y
@@:6 I1 C/ X; A2 U& ]
in al,dx;1f7 (r-status register)
- l& t8 _% p8 k7 W8 D6 z1 M+ G6 N cmp al,58h;(driver is ready ,and seek complete)
7 b/ Q# Q% a- G4 d0 A, X jz @F
% A2 E8 r: Z+ [. A a loop @B
) J0 s! W8 {' Q3 O3 h9 ^8 E jmp _II_TimeOut* k" q1 U4 }3 j
@@:
' {9 N& [- N( v Z# J+ S2 z;********************************************************************) t* ]! z; e3 N7 N9 Z) ?/ {. ~
; 将返回信息读回8 p5 T( W' z4 ~+ k! i: I$ w( R
; 注意一定要读满 100h 个字长
0 D' v8 f* i8 g; o- t;********************************************************************
6 I3 N ]. m* u- m/ w cld
1 @- v' _) T& w% F3 M# f mov edx,01f0h;data port - data comes in and out here
! V5 b% X+ O; j& _% H" L4 C; w; Z ~ mov edi,ebx( A: |" X+ m/ f8 |7 x+ Z
mov ecx,0100h
& ~1 G+ w1 H0 t [# G6 Y9 F rep insw
6 C) O( R/ n) q4 u5 w% P, i- f) Z;********************************************************************" I6 D7 @# [) d& [; \) _: G
; 返回的信息中,型号、序列号、版本号为字形式
1 b, s6 |; s! W& |; 需要整理到字符串的形式
8 {# ~" g0 `1 D# E;********************************************************************3 H0 T/ H* {! o! z
lea esi,[ebx].sSerialNumber
& u2 o( t8 c% ?% e1 i* @1 k mov edi,esi
! B5 C5 ^/ M! a mov ecx,10
6 a: s7 d( ~3 A9 ? @@:5 ]- q& o0 T* Z* Z
lodsw
5 R8 B+ j) ]$ ^ xchg ah,al
1 `5 ?7 p# q' {$ O; | stosw
$ J3 ?) ^4 \6 u+ I4 T0 ~9 u% e loop @B
# E6 r" b9 o5 Y9 S$ u9 p" U0 s4 G9 ]; |- \' T
lea esi,[ebx].sFirmwareRev
2 n9 s" `% _: e" c; E mov edi,esi
) W* e3 i2 [2 G* g! C, ^: R mov ecx,247 [% N% C9 ^3 w3 n2 |, Z) a
@@:( j1 [; m. e8 X
lodsw
% G9 X3 h9 `- t3 r) n& ` xchg ah,al8 w/ M: O, I0 R8 l* `
stosw# ^# Q# v( u+ ^5 R( y
loop @B7 M2 O( \# N5 {: C8 V% d
_II_TimeOut:
% s# t* }9 j6 H( S) P2 E7 Passume ebx:nothing
" [, p) H! U( g+ a1 W4 i- i
! n( G5 U: [7 m# B% }2 M4 q6 Apop esp ;restore ring0 esp0 O. a2 V! B9 X3 O
push offset Ring3- y8 D7 L( [6 g5 D4 h9 Q
retf( J0 g# @2 _7 G; N' z
Ring0CodeLen=$-_Ring0Proc' ]; s+ c0 ~; w& T1 s3 `
- }7 [/ E! a2 Y* |
Ring3:
8 @( g8 P& o! ^2 q3 B6 U! A* [. qinvoke GetCurrentThread% S9 Y+ Z1 @8 [0 w5 B+ j7 S
invoke SetThreadPriority,eax,THREAD_PRIORITY_NORMAL & e+ L+ W9 y! x. ]2 ~9 d
5 {1 Y* s; V1 w3 [9 ^;invoke VirtualUnlock,Entry,seglen 6 g1 L( s$ I) d' G& q
& c* G7 ]2 t. g/ Y" F
call @f, {' o+ v8 c0 R- ^
db "ZwClose",05 U; X7 Z! F5 a9 p. z. T
@@:# I/ ^: s M5 ~, |4 a+ J
push NtdllMod
, `/ L/ ], f% x1 z3 o& ^call GetProcAddress
( R3 \& c! h) L' ?8 hpush hSection
* X0 a6 H3 C, A* j! E* Hcall eax
7 ^& v: S' ^$ H5 Q. r' }mov eax,TRUE
2 k3 Z9 H, n5 X3 J1 dret
& J, T. P" w; Q7 d: L/ @3 y" h$ z, _ExecRing0Proc endp
3 K8 |* n$ s9 h% ]
. \( ?( k: D, W6 Vmain:
% f0 g' H; ]) m: M0 c) @5 f; Aassume fs:nothing6 \6 P! Y3 y" T# R7 }2 b0 I
push offset MySEH" R) d/ j. P; \8 Q4 m% ^
push fs:[0]
0 B+ D* f6 `' `mov fs:[0],esp+ D2 j2 C3 r' g
mov OldEsp,esp) @' w* \" U7 c6 [& L: d0 }
mov ax,ds ;if Win9x?
+ P; e$ N8 s! b3 W" T) Wtest ax,4
! ~( \ { c) z- ojnz Exit17 b& j3 d" m" t3 p' \- ]: {
invoke ExecRing0Proc, i* [2 f5 k( w8 j3 }' D: K" G
' d, f R3 c, ` y8 y: h1 O8 Z
.if stIDEINFO.wNumCyls
9 \/ r; Z- O: l) t) Q lea esi,stIDEINFO.sModelNumber/ Q. c, _5 z* e6 p" Z5 {( g/ K5 Q9 f
mov edi,offset szModelNumber H9 ~8 v6 m" j3 }3 z& U
mov ecx,sizeof stIDEINFO.sModelNumber
$ D" }1 l5 g @& }% T# n3 E4 Z rep movsb) @3 U$ J% H* Z2 W; j
4 C- c. m1 y* {; S7 l: H& h lea esi,stIDEINFO.sSerialNumber8 T- H/ o# \" g, Z6 l* U
mov edi,offset szSerialNumber
/ r a8 `" Y% O! H- l mov ecx,sizeof stIDEINFO.sSerialNumber' z# [6 [% ?8 L9 ^8 m
rep movsb
5 Z" Z( J' |: g! O, K
; X- H$ ^/ y% B3 w, P w lea esi,stIDEINFO.sFirmwareRev
/ `" _/ k# W \' E mov edi,offset szFirmwareRev5 M$ e3 f) d. [, U" [8 J) x
mov ecx,sizeof stIDEINFO.sFirmwareRev
- \2 u( l0 {, E/ `* @' j5 y rep movsb' c( h2 U0 A2 f1 y" n; _0 q+ x! v
- M0 z$ C I% U P# D8 u3 a7 K- v movzx eax,stIDEINFO.wNumCyls6 e: \+ Z3 P @: _' [; c% V5 o
movzx ebx,stIDEINFO.wNumHeads
A$ A" f9 T. N9 z) A# N" I& c. h movzx ecx,stIDEINFO.wSectorsPerTrack" ~3 @' w# N% n' L [, ~
movzx edx,stIDEINFO.wBufferSize
5 H$ H% R% J# T9 R2 W invoke wsprintf,addr szBuffer,addr szIDEInfo, eax,ebx,ecx,edx, addr szModelNumber, addr szSerialNumber, addr szFirmwareRev% B( T, a l# i, J8 d8 S4 L6 d9 h
mov eax,offset szBuffer, [0 m% W$ ]( t3 m0 F
.else5 y/ |7 i2 c7 ?$ f3 @0 ~8 B& B& _2 H/ m0 c
mov eax,offset szErrInfo
0 ?% a6 ~ T( F; r# w.endif
6 B* O, x! A* j; K, [$ \7 y@@:" k+ r G6 n& v ?% s$ t
invoke MessageBox,NULL,eax,addr szTitle,MB_ICONINFORMATION or MB_OK
( t. w' L6 t) H& r. dExit1:
( e6 o1 [% z/ t1 S9 N6 |0 `pop fs:[0]+ p0 N: _# {6 n1 W+ ~. i' A
add esp,4
# ]: a8 T" V. |5 ainvoke ExitProcess,0
: N. t- L2 x/ q$ v4 y7 C2 |" F. s) S
MySEH :
% o! R/ C- p q$ qmov esp,OldEsp
( n& C: J" K- m7 Z- Dpop fs:[0]
y' N: m) o( b% P& [add esp,4. h' ~- P6 |- m
invoke ExitProcess,-11 @" y, ?% Q" r. X
end main
( n f7 h- `7 `. A( y$ H. G% P% `8 K- `- C$ z1 ~$ c4 `
[此贴子已经被作者于2003-11-2 18:14:02编辑过] 4 C" x2 \4 h+ o- Z2 w3 X& y
|
|