下沙论坛
标题:
[转帖]2000/xp下读硬盘序列号[汇编]
[打印本页]
作者:
游侠无极限
时间:
2003-11-2 18:09
标题:
[转帖]2000/xp下读硬盘序列号[汇编]
我可没这个水平
7 d! O# H" B+ I: \; h( h
.686p
8 X9 ~' Q, G) x. k$ W
.model
flat
,
stdcall
2 X: ^* L. ]( Q d. |, k
option
casemap
:
none
; case sensitive
$ f5 w# h& w; l& J# o
; #########################################################################
7 e; `1 l* y# N V& n
include
\masm32\
include
\windows.inc
8 }9 E9 `4 s9 Q/ O
include
\masm32\
include
\user32.inc
* T0 |( i6 X8 B, B9 A& v! j
include
\masm32\
include
\kernel32.inc
: ~9 v# a1 D8 d2 y( b
include
\masm32\
include
\advapi32.inc
: G) Z; h' Q3 I$ M( I' S! j0 t2 |& e
4 @" w6 P& ^' r8 m" s+ s8 ^4 T
includelib
\masm32\
lib
\user32.lib
8 m- z7 p% q1 H
includelib
\masm32\
lib
\kernel32.lib
! O# [& o8 P5 S& Q# s
includelib
\masm32\
lib
\advapi32.lib
% Q- K0 P( b+ r& n3 N7 Z' h
DEBUG =
TRUE
* \5 j" s$ V, d: V4 K# i
4 C" i, \: t% v/ M/ R# P3 f
HMODULE typedef
dword
8 V8 U8 i/ A, ~% v9 q$ i" X7 p3 e
NTSTATUS typedef
dword
' ]% g9 q4 [; j
PACL typedef
dword
- G) e5 s4 Z: R. Y0 I
PSECURITY_DESCRIPTOR typedef
dword
% K: n( }+ u0 f
1 H: J! @4 j/ f; C+ Z
OBJ_INHERIT=2
( g7 s" Z& Z" w0 z5 m: z
OBJ_PERMANENT=10h
; V/ p K+ t" l$ ~0 P
OBJ_EXCLUSIVE=20h
+ x5 G# ~* u E5 o9 x
OBJ_CASE_INSENSITIVE=40h
7 F; G5 h. H! M: a( X2 g U
OBJ_OPENIF=80h
' m4 D; h: J" O! v
OBJ_OPENLINK =100h
/ m+ K, ~. `$ _2 h& O8 X
OBJ_KERNEL_HANDLE=200
+ x' f4 e6 D! ^. p+ c) {
OBJ_VALID_ATTRIBUTES=3F2h
0 ]6 q, I- f& }3 X3 u+ H
6 |; O! t4 I+ `" v0 }7 V" G* Z
SE_KERNEL_OBJECT = 6
/ d, J7 I1 S5 V6 P- Y
GRANT_ACCESS =1
0 R0 c; C6 D. U, a; d
NO_INHERITANCE =0
2 c5 b; F9 ?' ^* Q3 Z
TRUSTEE_IS_NAME=1
: e% d% b+ l7 j" s* Y% G. G% v: v
TRUSTEE_IS_USER=1
0 \6 U- _' c: X7 p7 k
STATUS_SUCCESS =0
7 g% i8 Z% b7 N
STATUS_ACCESS_DENIED =0C0000022h
' M. k1 l9 H/ H1 F1 p
* e* |1 c: D! X$ `- A
STATUS_ACCESS_VIOLATION
equ
0C0000005h
L$ k/ ~, B, g) G
STATUS_INFO_LENGTH_MISMATCH
equ
0C0000004h
7 f( y3 t% P4 d5 \4 o+ l
SystemModuleInformation
equ
11
8 J' P- p- Q/ ]' S0 s! F
PVOID TYPEDEF
DWORD
7 s3 T3 v0 W4 f/ D; f( C
UNLONG TYPEDEF
DWORD
, l- q/ f& E5 n; @# q
CHAR TYPEDEF
BYTE
* Y5 w+ l9 T/ Q5 w( q
0 u$ o: ^: U, `2 k% @2 |$ H
UNICODE_STRING struct
' |# c/ p5 @! c- Z
nLength
word
?
& ]4 M9 N- {/ b( J: m0 @/ N X
MaximumLength
word
?
( @/ t, K5 k8 V2 E/ y4 V
Buffer
dword
?
( y/ `- a6 k& ]' t4 w
UNICODE_STRING
ends
1 k2 s( I& O' \) ~' H( [
% e5 K* a5 D' _' l
OBJECT_ATTRIBUTES struct
, F+ u3 {/ K, o4 P$ p$ [. \
nLength
dword
?
! E* {9 }" G% C u. D! e ]+ { U% ]
RootDirectory HANDLE ?
# A& E2 g" h i) p; y
ObjectName
dword
?
UNICODE_STRING
8 k5 f2 q4 j/ T2 ?* Z4 a& I
Attributes
dword
?
;
, w. o3 a# [ K! N, O2 H& \, w1 E
SecurityDescriptor
dword
?
; PVOID // Points to type SECURITY_DESCRIPTOR
7 ?) x+ t+ {6 }* e
SecurityQualityOfService
dword
?
VOID // Points to type SECURITY_QUALITY_OF_SERVICE
- y% J$ z$ n7 {* E3 \8 I3 _% }3 w
OBJECT_ATTRIBUTES
ends
, ^ P/ ]5 w" }3 r, E+ I. b
l$ h2 x& e2 J) R9 Q3 ^; \/ L: K9 G
, p# _2 ]7 n; n7 [3 O6 ]% ^
TRUSTEE struct
: y" V2 p/ ]: |$ Z
pMultipleTrustee
dword
?
TRUSTEE
: }. p( G T/ M8 u5 U1 O
MultipleTrusteeOperation
dword
?
; MULTIPLE_TRUSTEE_OPERATION
4 d( F+ p" k) e
TrusteeForm
dword
?
;TRUSTEE_FORM
9 N; p' i. z' Z/ T" Z2 R
TrusteeType
dword
?
;TRUSTEE_TYPE
/ L [( @3 H+ i! j
ptstrName
dword
?
;LPTSTR
: ]$ W z5 P- U( E( t
TRUSTEE
ends
9 ]$ x+ s- c, g3 J. B9 _$ w w+ r
# D9 Q7 X& ?2 S) D
- \4 h- t9 u. I0 x
EXPLICIT_ACCESS struct
6 p& a. h W' A
grfAccessPermissions
DWORD
?
& k2 J) k' \, n+ ~
grfAccessMode
dword
?
;ACCESS_MODE
" l4 O2 ?8 a4 r# D, o
grfInheritance
DWORD
?
;
6 Z4 ?: V3 C" O* k/ V
Trustee TRUSTEE <>
;
( G5 _6 m {6 d# w! M& K+ f
EXPLICIT_ACCESS
ends
; U' \1 G0 \; k( }
5 L, p. L- j, K5 f4 ~& d% q7 O
MyGATE struct
;门结构类型定义
) r* \5 v" }, b) g. t& t2 }2 [( @% U
OFFSETL
WORD
?
;32位偏移的低16位
- |0 x+ n2 S9 k \" b; d
SELECTOR
WORd
?
;选择子
0 v. w m/ G9 C: Z5 j/ K
DCOUNT
BYTE
?
;双字计数字段
: Z0 ]& D' O0 }. {/ u' A
GTYPE
BYTE
?
;类型
: H ]/ ]* a# t1 ^1 F
OFFSETH
WORD
?
;32位偏移的高16位
6 Y' t Z* M; `8 @- c5 p
MyGATE
ends
! a3 l8 H9 l" ^4 R- Y8 N9 c
$ Z, O3 J4 D$ G- c4 d1 G
IDEINFO struct
, D+ l8 r ^! j2 @: U
wGenConfig
dw
?
! P4 Q* T& S5 X' u! C& l
wNumCyls
dw
?
;拄面数
; d& I+ {' O# D0 _ l4 o
wReserved
dw
?
6 E7 ]8 P7 w2 } \. _0 b2 L! n) L
wNumHeads
dw
?
;磁头数
6 E( P2 C2 n8 D: C8 U- Q9 w8 U$ y
wBytesPerTrack
dw
?
;每道字节数
" R" V$ d' d& n6 i
wBytesPerSector
dw
?
;每扇区字节数
* y, V2 r0 E$ }: v! B9 z0 F( i1 d/ [
wSectorsPerTrack
dw
?
;每道山区数
7 c3 n- `+ ^/ P! V% ~- z
wVendorUnique
dw
3 dup (?)
* I7 \6 I$ ~. `( Y: W, P
sSerialNumber
db
20 dup (?)
;硬盘序列号
+ S( E ?* |5 f7 ~$ P( ?1 j: t
wBufferType
dw
?
;
! e& u" p+ H1 E6 x# q, R
wBufferSize
dw
?
; ;n * 512
0 t* c5 T! a ?# F; j
wECCSize
dw
?
- L) R7 o4 m6 o
sFirmwareRev
db
8 dup (?)
;
' C' d; Z( p9 w( e+ X
sModelNumber
db
40 dup (?)
- v* [$ `3 F) P$ q
wMoreVendorUnique
dw
?
$ ~' p' c0 O: H+ N- E
wDoubleWordIO
dw
?
7 J, R2 P' V( J6 `8 F
wCapabilities
dw
?
3 x( Z' _1 c' a; |+ C
wReserved1
dw
?
( k& x$ r d3 M7 L3 W U* @
wPIOTiming
dw
?
;
( p% |/ J9 o7 A
wDMATiming
dw
?
;
/ I2 I" B, m5 P0 _9 T1 c
wBS
dw
?
8 E8 r1 p( O( y7 \3 r) Q8 k& ]
wNumCurrentCyls
dw
?
;
4 c) K. W! E8 y6 }9 V- \9 e
wNumCurrentHeads
dw
?
;
6 p5 F2 k& R: n1 g A+ _
wNumCurrentSectorsPerTrack
dw
?
;
( j/ m8 p9 Q- t* {6 J |+ A
dwCurrentSectorCapacity
dd
?
;
+ D+ j! s: |# |
wMultSectorStuff
dw
?
;
' F" P6 |5 R) k) V1 A: v
dwTotalAddressableSectors
dd
?
;
( s/ Q# f8 p3 i2 K M# i- {
wSingleWordDMA
dw
?
;
# F5 n/ _! C- B( l" S
wMultiWordDMA
dw
?
;
- D/ `3 {) |! e" s9 v+ |! u
bReserved
db
128 dup (?)
$ s( X% ?5 G: `* X" T8 \
IDEINFO
ends
3 g2 x9 o/ `& B
0 s9 R3 H! [- V3 U# L9 k
/ x. }% g! M q# U! v
SetPhyscialMemorySectionCanBeWrited
proto
:
dword
+ i3 I( S" M' C( v
MiniMmGetPhysicalAddress
proto
:
dword
9 L$ A! `% J1 N. h- }8 P) R) H6 B7 r! D
, w' J; H$ _" ^8 C% z" ]; p
ENTERRING0
macro
8 G: ~% c" k! q+ Z \0 Q
pushad
4 t) [, v8 }3 Z
pushfd
- ~# w/ i: X5 V- W4 ?7 D! F0 F
cli
: w9 P5 W$ W# Y: G# {3 |! L3 K. @0 J
mov
eax
,
cr0
;get rid off readonly protect
0 w0 `! P# m9 T
and
eax
,0fffeffffh
5 z1 h, ~$ ^2 T. H# n. ]
mov
cr0
,
eax
2 D: C+ g- s5 W6 Y- S# T: c# j; P
endm
* C8 C, `9 m" Q' l7 i+ @
- h/ U K$ A: Z$ i: l: }
LEAVERING0
macro
# P8 O: n% G! }3 T3 V
mov
eax
,
cr0
;restore readonly protect
& K$ N" V6 O, e% Y& N
or
eax
,10000h
8 Z/ b7 {! k% Y0 P- s6 i
mov
cr0
,
eax
4 {' @( u2 p! o4 p M8 a( F3 B
sti
: S% w5 l* Z/ n2 t
popfd
; J5 H7 R2 Y5 \. d: v5 ~* e# k
popad
7 A' \- L) h2 o% ] W7 Z* { s
retf
9 K, b+ X/ N$ W. ?& W( s, W
endm
: X5 f. e- S3 M' L* X1 `# L
: y. z R C! i
9 k8 `8 O8 ` x
UNICODE_STR
macro
str
* a7 q; I3 U$ }6 m/ S1 L( D
irpc _c,<
str
>
" _8 U# m# Q: f# A, [. |
db
'&_c'
' b) k: n4 s" a2 n
db
0
: k5 o p1 g% O8 v- L
endm
) }8 ~/ S9 z { Z- w9 c
endm
, k5 X1 }; J; k, }/ t
0 }" g r' `; b, A# ?3 [9 Q
.data?
; Q {! x, h: l" y; ^, h [ ^
GdtLimit
dw
?
' k7 x# D! ~( g( f: i+ ^8 `
GdtAddr
dd
?
0 _2 }- I3 i2 q, ]7 f. p4 W
# D( T+ |9 W- g' {
mapAddr
dd
?
% Y. C) } _) u! b, s, I! G
OldEsp
dd
?
) U1 V# _7 S4 |, B- X- i- S
% q, z$ c% q) L! l- o& G5 L
readed
dw
?
4 v$ P, w# J; C6 ?
buffer
db
512 dup(?)
9 i' }' u/ ^2 d& t6 R( p
ShowText
db
512*3 dup (?)
* I& y7 c& ?1 a# a$ a$ l! h# \
9 Q- a8 D7 U: K0 `; d2 c0 O4 @+ N4 N
szBuffer
db
1024 dup (?)
4 N6 m) Z- A* l1 [9 u1 Y
szModelNumber
db
41 dup (?)
9 _8 E; D6 b: z) v' I
szSerialNumber
db
21 dup (?)
" d+ z1 [1 e* ]$ Z, f+ p
szFirmwareRev
db
9 dup (?)
* w) [: _8 y8 U `; t- K
- y2 R2 U4 J9 {* A2 Y. [
stIDEINFO IDEINFO >
. X6 a$ @2 H. t! k
! X% N B5 R' S. i
.data
% N% R5 u8 [ t
align 4
" O6 @2 x! J# s$ ?5 K
objname
dw
objnamestr_size,objnamestr_size+2
( _3 p# w& Z9 Q/ X j' F5 U
objnameptr
dd
0
) C0 }1 }& {7 p( Q J5 N4 ~
objnamestr
equ
this
byte
8 x8 s- t: x2 f! `. w* p O
UNICODE_STR <\Device\PhysicalMemory>
% B/ I" A- w7 _1 }, F1 g
objnamestr_size
equ
$-objnamestr
/ x( R3 o' C8 a3 s% G; f
5 F# d; K* X. D; W) r
szTitle
db
'IDE 硬盘信息',0
" G4 z6 V3 v* X; }
szErrInfo
db
'无法读取硬盘信息',0
: i8 T) d' ~ H+ v- F( a5 C
szIDEInfo
db
'柱面数 : %d',0dh,0ah
, e) {; k% N3 I* m. s0 ?
db
'磁头数 : %d',0dh,0ah
& K* F: i8 {. _5 M8 v7 {
db
'每道扇区数 : %d',0dh,0ah
' @+ U/ Z: d1 h1 v
db
'缓冲大小 : %d 扇区',0dh,0ah
& [+ H* I% t# c/ Y* Y6 ^
db
'硬盘型号 : %40s',0dh,0ah
. m/ [" J% N* B* `8 v4 F* w% y
db
'序列号 : %20s',0dh,0ah
! c, X& e7 D5 ?
db
'版本号 : %8s',0
* C+ V; [/ J# c4 B; y
' q( {$ }4 j4 H$ |
align 4
" C+ R+ g4 g& w( Y( t
ObjAttr
db
24 dup (0)
# D/ L7 g% m" e, }/ ?4 `) R
+ ?8 ~- l! E/ }/ z* f2 @
Callgt
dq
0
;call gate's sel
ff
; N# o3 d V) O- Z0 n
Caption
db
'Windows XP绝对磁盘读写',0
& U2 ?7 j; [/ H* v) o: M
Digit
db
'0123456789ABCDEF',0
" j$ M4 e; b9 `0 M% O' R8 n
.code
# K. v: C: m+ A0 M) z! r
_ShowBuffer
proc
;显示所读出的信息
7 ^4 k+ I5 U, M* F: B: A
;把数据转换成16进制的形式
( l# b/ k- W, e6 ^% k0 c9 z7 }; s
mov
[readed],512
. t# w& {* S4 Q7 m3 N3 n
mov
esi
,
offset
buffer
;数据
# k7 X* R$ E6 y, |" I$ e: K
mov
edi
,
offset
ShowText
;转换后的数据
9 q4 x4 O1 w$ ~* c0 A0 d
mov
ebx
,
offset
Digit
+ B' U( W2 O/ b: l2 D) N+ a& Q
xor
ecx
,
ecx
: g6 s+ ~% `9 w+ e3 K( c
xor
eax
,
eax
! [ i. ^# \ E: L. Q
computeAgain:
. M2 d: C+ p$ k6 p
cmp
[readed],0
# F# K4 v: D% `3 l4 K1 x: f
jz
endCompute
+ g6 ]8 U3 B* ]! v* ? C; w9 B& }2 }
dec
[readed]
, n! c" z- C$ V! C- D3 v8 t
lodsb
& J$ t5 {# D' N/ o% i3 _) `
push
eax
* |5 a6 M [5 f& |& V C# i
shr
eax
,4
;高4位
8 c$ R0 ^' w8 {( W- ?& h
xlatb
/ ]% X3 w E( H* X: G- Y
stosb
! w% ~% F% I7 _* @
pop
eax
3 ~8 @' ]. p- X
and
eax
,0fH
;低4位
) P5 |8 J/ C$ B3 _/ P' w
xlatb
: g) k r* X/ ^2 q& V
stosb
5 l: M0 q" k0 E1 j
mov
byte
ptr
[
edi
],' '
;空格
/ K" R0 ~2 u" F) C# M
inc
edi
, D/ Z9 a5 ~. f6 a, h o
inc
ecx
$ J. V( V( w% _! ]# {. N# ]7 n0 o
cmp
ecx
,16
H7 E6 ?2 o- e2 V$ g$ C
jnz
computeAgain
! H2 T% [$ @0 @: t9 I% S
xor
ecx
,
ecx
# L, g9 ?& C6 T4 r" ?
mov
byte
ptr
[
edi
-1],13
;回车
9 W* t$ S k& }5 R
jmp
computeAgain
6 S5 r8 p8 h3 B" ^% H- {- D
endCompute:
7 A9 K& A: ?' B9 E; {2 o
;显示
, i) c5 h- ]5 g5 \/ p" m6 @ W
invoke
MessageBoxA,NULL,
offset
ShowText,
offset
Caption,MB_OK
. p0 P$ X/ U+ n9 ~
ret
) A7 I, q" E2 m) A) A4 s O* V
_ShowBuffer
endp
4 h. |9 O4 G" h0 S6 A
( ?' S- M+ X5 M: T; o6 l
SetPhyscialMemorySectionCanBeWrited
proc
uses
ebx
esi
edi
hSection:HANDLE
- U. d8 S" Y3 J; U
local
pDacl: PACL
0 J8 k. N3 r* E4 ]+ O
local
pNewDacl
ACL
* B. @! E9 s5 T! ^
local
pSD
SECURITY_DESCRIPTOR
6 o% s @) B3 w& e- c5 N, o
local
dwRes:
DWORD
;
0 n" X8 _6 H! a
local
ea:EXPLICIT_ACCESS
;
5 V/ C5 m) J8 e4 g! a7 H
invoke
GetSecurityInfo,hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION, NULL,NULL,
addr
pDacl,NULL,
addr
pSD
6 }" r/ \. }# W
cmp
eax
,ERROR_SUCCESS
* w" Y0 X2 s5 d
jz
@f
- }' j; K% m" S- N! [
jmp
OutSet
: [! B, ^# D' N! ]
@@:
7 _* y k' S7 C9 ~, W! l
mov
dwRes,
eax
, O% j1 {* N$ J2 {5 V7 U# L
mov
ea.grfAccessPermissions ,SECTION_MAP_WRITE
;2
5 ?2 l# d$ s3 `4 k. t7 x! E
mov
ea.grfAccessMode ,GRANT_ACCESS
;1
2 ]2 _8 u3 }3 Q* |3 ~7 d4 Q! m
mov
ea.grfInheritance,NO_INHERITANCE
;0
5 a3 D5 ?- N; u, Z6 h
mov
ea.Trustee.pMultipleTrustee,0
+ n4 g1 A! L- K
mov
ea.Trustee.MultipleTrusteeOperation,0
0 G! _2 q; I4 V |
mov
ea.Trustee.TrusteeForm,TRUSTEE_IS_NAME
;1
5 O1 N+ ^; u _
mov
ea.Trustee.TrusteeType,TRUSTEE_IS_USER
;1
# M/ b8 Y7 H! |' n- V/ R5 [
call
@f
$ G* E" q7 a4 n- Z2 g- T
db
"CURRENT_USER"
,0
* n9 m) j& T! Z, ?2 @0 ]' b7 T
@@:
/ R4 E0 Z5 a9 r" r0 D" k
pop
edx
1 T9 X2 L- w7 a3 y4 V
mov
ea.Trustee.ptstrName,
edx
* b9 D f4 O3 U2 K
invoke
SetEntriesInAcl,1,
addr
ea,pDacl,
addr
pNewDacl
7 v1 Q: q' S$ g: ?! b
cmp
eax
,ERROR_SUCCESS
0 z! L/ ^- e+ O6 ]- T
jz
@f
% T1 j( @6 ]' z1 S: P
jmp
OutSet
. @' N# i9 B2 q6 h+ l6 R \
@@:
F( r- G3 s) L' s. x8 \& m
invoke
SetSecurityInfo,hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION, NULL,NULL,pNewDacl,NULL
8 |0 X) t1 h2 D6 B
OutSet:
8 e7 J7 k- P" J9 P( `- g7 ?4 E
cmp
pSD,0
2 `! I. \+ w4 l
jz
@f
1 S& C7 y. k v
invoke
LocalFree,pSD
+ ^' C0 @! T+ s
@@:
% [- s( H1 n5 O. `8 W
cmp
pNewDacl,0
) q7 p8 f) V; v- O0 k3 {
jz
@f
/ B/ p% C( C, c3 {, @; J/ t: Y
invoke
LocalFree,pNewDacl
* r; Y' D. V" z# j" I% w9 ?
@@:
k# p( R4 F0 T7 [- v
ret
/ G! j- l3 I# C3 A! |
SetPhyscialMemorySectionCanBeWrited
endp
- m3 u0 r$ F8 ~7 k; }
6 } z( u& [; |
MiniMmGetPhysicalAddress
proc
virtualaddress:
dword
* |5 S7 Z4 p5 O8 S* s3 M6 w
mov
eax
,virtualaddress
* F! t$ F7 x" O6 j2 ]0 w6 X
cmp
eax
,80000000h
. h& `/ [9 R8 q- Z
jb
@f
% w$ b. @( r. ~
cmp
eax
,0a0000000h
0 n; @) |) f& ]& W0 \
jae
@f
$ K/ O& _& i% j5 o
and
eax
,1FFFF000h
& b) P7 N" V& k6 P7 L' J
ret
, G' h1 W: y4 W# f* Z
@@:
5 X, Y8 X! K/ r. ?8 C
mov
eax
,0
0 l% F- V% Y( A
ret
* I3 o. j }+ A" W2 s
MiniMmGetPhysicalAddress
endp
( o3 t+ z+ F. ^+ w
7 a, H" d2 N2 t1 [
ExecRing0Proc
proc
: T" g5 q1 k- m; k
local
tmpSel:
dword
" @4 j; |( n7 o$ T- I3 @8 C
local
setcg:
dword
8 _ }% V$ g+ _* J
local
BaseAddress:
dword
) |, Z8 ]2 r, p& {- c
local
NtdllMod :
dword
( }/ z3 c3 Z% w
local
hSection:HANDLE
# {2 c& U( P* q8 g/ U9 t/ ]- a% {0 f
local
status:NTSTATUS
% K2 L- H! t1 ~! w0 K
local
objectAttributes:OBJECT_ATTRIBUTES
( z* W+ }7 ~/ N$ L
local
objName:UNICODE_STRING
& u$ j9 P* s: m: ]$ ]7 }
mov
status,STATUS_SUCCESS
;
; k. [, a9 w/ z; I( N% {
sgdt
GdtLimit
3 q' H6 z" S/ k8 o4 x) K6 K
invoke
MiniMmGetPhysicalAddress,GdtAddr
+ W; n+ L6 U* a
mov
mapAddr,
eax
# p' }/ |6 Z3 ^' M8 U
test
eax
,
eax
) C* m" S0 ~& d- F6 W3 F
jz
Exit1
i( |3 O2 _- W d. B) I6 I# P
call
@f
y' O" F2 K- e! S
db
"Ntdll.dll"
,0
B* H" g, W+ D. Z9 h6 X$ @# `2 G4 ?
@@:
3 N2 ]" ^$ U- P5 ]% ~
call
LoadLibraryA
, X6 {$ \. f& Q% ^ { y, Q
mov
NtdllMod,
eax
8 E' e0 F) P" v
" k1 J) G+ M" u. i
lea
edx
,objnamestr
1 G: j7 C: Y1 A u3 q
mov
objnameptr,
edx
& ]" [5 U) `3 r$ B# E7 y5 S, G
lea
edi
,ObjAttr
$ \; i* G7 t# ^
and
di
,0fffch
;align to 4 bytes,or ZwOpenSection will fail
% O! ]- C1 K6 W/ u$ H. {! v
push
edi
;edi->ObjAttr
: _- F9 [' \9 T3 l7 u4 s! }4 c( j
push
24
;length of <\Device\PhysicalMemory>
* U0 l8 G# j m7 I4 \7 P+ r1 L
pop
ecx
6 `. _ V9 Q3 _1 q3 v9 T
push
ecx
3 I/ j+ [2 e6 C7 o4 ~: v' ~
xor
eax
,
eax
0 i: o V3 g$ S1 R5 Q
rep
stosb
;put ObjAttr with 0
' d; u/ w& p0 x0 m% a1 e/ N- ?- U
pop
ecx
8 A4 g2 c: G* G. }
pop
edi
0 E. ?: x4 F1 E! Q
mov
esi
,
edi
6 n4 T. m% f( s, S3 X
stosd
+ c9 M5 E, M8 m! z/ b
mov
dword
ptr
[
esi
],
ecx
4 c1 A: S2 Y5 ]& b
stosd
# c0 g1 ^/ b3 R" ^& |
lea
eax
,[
edx
-8]
;eax->objname
/ q Q2 |( u# l( I) Q
stosd
;ObjAddr(18h,00,00,00,00,00,00,00,offset objname,40,02,00,00,dd 2 dup(0)
( P0 B; h+ o6 O
mov
dword
ptr
[
edi
],240h
( ] U; M. H3 h' o+ @' _
' a) s' R) m0 ]* q8 s
call
@f
3 b' V+ C! Q% j5 E* l {
db
"ZwOpenSection"
,0
% f' k( W: v+ M
@@:
& Z; o) X! I. J- Q3 F( w
push
NtdllMod
$ V4 B5 D+ U* q: N, [2 i1 k
call
GetProcAddress
- l" C- a! R6 v/ O* V7 a: N+ ^
mov
ebx
,
eax
;ebx=ZwOpenSection
$ b# |2 H; ?9 ?" e. T. ~
! I2 j0 L% c8 ~4 Q: p
push
esi
;esi->ObjAttr
* y5 v; g+ z& M8 [9 R: m) S
push
SECTION_MAP_READ
or
SECTION_MAP_WRITE
" s; t5 W- f/ t* x9 C6 c$ C* ?2 G
lea
edi
,hSection
/ t( d9 A4 p7 t& h3 O
push
edi
;edi->hSection
" U1 r- B& R0 t; V2 P
call
eax
;ZwOpenSection(&hSection,SECTION_MAP_READ or SECTION_MAP_WRITE,ObjAttr)
+ Z1 q- v) L$ C
: F+ R1 Y& B) x; S# t
mov
status,
eax
& B7 c$ I4 m/ s! C N
cmp
status,STATUS_ACCESS_DENIED
& R' ^- i; s4 J( l/ H
jnz
AccessPermit
) f# v3 [2 r9 i/ @: a3 a+ J
mov
eax
,
ebx
- N$ i) b. v) l d3 Y0 c7 }2 G/ _
$ }) D( c+ @. B. n: Q
push
esi
, y+ g& j; f" \5 Y# L8 a* g/ o
push
READ_CONTROL
or
WRITE_DAC
# C# c/ |- _% I- N: `0 i
push
edi
$ M4 u* d) P; `5 J
call
eax
. w5 p* O( Z( i4 K
$ j1 }, k6 A/ g' T* v
mov
status,
eax
' y1 G' Z) K8 ], {. N
invoke
SetPhyscialMemorySectionCanBeWrited,hSection
# Z. \8 A2 g9 a
5 [0 `2 @/ Y0 a9 u( x, d
call
@f
$ D, r1 Q M& L
db
"ZwClose"
,0
! W8 k2 ~% U- O
@@:
% s9 R! ?, h+ Y) N0 |" _
push
NtdllMod
( Z# q) l0 y: Y2 ^1 q4 x
call
GetProcAddress
* V6 L: F% P7 g% T$ C- G g' D
$ }6 |) v! q) r, h
push
hSection
$ L( b0 O5 y3 j; e4 s
call
eax
;zwClose hSection
' Z6 M I. f5 R. R$ N
3 O! {( K7 _( x m% [
mov
eax
,
ebx
% z% {$ J/ o# u# m) S" F2 u5 d
( ~6 Z+ w0 [ j4 K6 i1 Z: B
push
esi
1 }* B+ |! s8 l
push
SECTION_MAP_READ
or
SECTION_MAP_WRITE
! b; p% J( c1 @! ?- Q
lea
edi
,hSection
% l5 k2 w* b8 r7 c+ x
push
edi
4 ~: g. ~! }8 v% J
call
eax
$ L( S3 o$ O" h7 v
mov
status ,
eax
+ W) C8 |* ~" W4 @: E+ P
;status =ZwOpenSection(&hSection,SECTION_MAP_WRITE|SECTION_MAP_WRITE,&objectAttributes);
9 j, l" e9 r+ q' {' V( W0 }4 }/ M4 K
AccessPermit:
/ |5 E8 w9 O$ B( F
cmp
status ,STATUS_SUCCESS
2 ?* h+ m o q1 s
jz
@f
/ o+ _+ }; X5 z" s
;printf("Error Open PhysicalMemory Section Object,Status:%08X\n",status);
% j* }) c9 D* ]$ H
;return 0;
$ V# F" w2 R& \& p) H# ?
mov
eax
,0
3 p0 e6 [1 ^' Z) |
ret
* Q, H- b6 i. I; C x) h
@@:
0 ^+ ~" s) ~" v4 V" X0 Q9 Z# }3 P
movzx
eax
,
word
ptr
[GdtLimit]
. V% v6 q& j. r) K( r3 k
inc
eax
8 i9 ^* w9 G* s% C* H( _6 q, t* S) c
invoke
MapViewOfFile,hSection, FILE_MAP_READ
or
FILE_MAP_WRITE, 0, mapAddr,
eax
* |) i% G% N ] E( ?0 y; e) @. Y
mov
BaseAddress,
eax
5 t+ K8 E& L8 ], k0 z! d8 K( H
cmp
BaseAddress,0
" P! y% |' F/ j8 x9 U0 s. v& a
jnz
@f
5 k% P' \* t" m0 t4 Z4 o- h3 E
;printf("Error MapViewOffile:");
! K# i2 ^3 C1 D: y
rintWin32Error(GetLastError()); return 0;
9 {& u* y+ m; \
mov
eax
,0
$ B( B+ H% A- _/ q* g
ret
4 I- \3 R+ T7 h `5 `
@@:
6 d- J: s, S6 o6 E/ {/ T" F- w0 h
mov
esi
,
eax
;esi->gdt base
" }( L2 G- _& T0 V
mov
ecx
,3e0h
: M3 p/ F) E$ z2 n) ^) d8 t
mov
eax
,GdtAddr
1 N% P' l7 H2 E* B4 M9 ~1 o$ q
.if
dword
ptr
[
esi
+
ecx
+2]!=0ec0003e8h
: ~6 [0 u( M& Y5 X
mov
byte
ptr
[
esi
],0c3h
# D" a9 O L$ n
0 a8 N+ `! X& x/ u+ a
mov
word
ptr
[
esi
+
ecx
],
ax
( H* ^; }) ?* _1 Y( e2 Y5 i
shr
eax
,16
7 ^/ F3 b; U# r7 i
mov
word
ptr
[
esi
+
ecx
+6],
ax
' Y6 J, U* z% T0 J# |7 ?3 t2 {6 @( C) a
mov
dword
ptr
[
esi
+
ecx
+2],0ec0003e8h
4 o9 U( `* C) ?( J( Y
1 g) w2 y/ m( g K7 ?6 o
mov
dword
ptr
[
esi
+
ecx
+8],0000ffffh
9 {7 z$ ]! Y* x5 {. i: S
mov
dword
ptr
[
esi
+
ecx
+12],00cf9a00h
3 ~# p' [) u, E: K9 O
.endif
, \2 l/ e3 t' |0 K5 s/ A
, a! J- E4 l+ T7 \& V2 F; E
mov
setcg,
TRUE
5 Y7 A2 S2 i" }% w6 \* X0 j1 l$ u
cmp
setcg,0
0 Z/ \ w( U, X- D9 u* ~
jnz
ChangeOK
7 V* y6 A1 z+ L1 P9 {
call
@f
, P" T* S5 {# D7 O6 e
db
"ZwClose"
,0
2 B! C3 u# q7 B+ S; y. ^
@@:
3 a0 |2 C# y) @. U8 ]! B
push
NtdllMod
! H) `9 n: z6 C6 p/ @
call
GetProcAddress
- n! A/ l) R/ m. Z
push
hSection
- }! p3 D8 p, |
call
eax
+ X4 J! }* f: L. U6 A% g
xor
eax
,
eax
5 n5 b3 [3 w; }& }' a- h5 c
ret
2 |1 k1 Z, K( F X
ChangeOK:
* ?' Q" M+ }3 q8 g
and
dword
ptr
Callgt,0
* V7 e7 b j( [. ~
xor
eax
,
eax
" O: x6 K1 S- s; o
mov
ax
,3e0h
1 y; V7 [9 P0 q& g6 x
or
al
,3h
- a4 c6 F4 c! q
mov
word
ptr
[Callgt+4],
ax
/ O$ g; Q! D- {: k& ]& I
;farcall[2]=((short)((ULONG)cg-(ULONG)BaseAddress))|3; //Ring 3 callgate;
+ C; A. |0 t/ Q) {: N
lea
eax
,_Ring0Proc
9 h" M* |3 M4 [# c# J2 |
;invoke VirtualLock,eax,seglen
: X. Z% P, q' J+ J% \6 ~6 J2 ]
test
eax
,
eax
- P. K( P; E$ g9 N- R# f1 @
jnz
@f
0 k# s+ d$ C( n. J/ m
xor
eax
,
eax
& F2 c' z! p& m) q/ u
ret
) f8 H6 s# u1 }& e$ G* y
@@:
& B- y g' `# o+ e
invoke
GetCurrentThread
1 i2 _$ l& Y2 u) ^, O: H% R
invoke
SetThreadPriority,
eax
,THREAD_PRIORITY_TIME_CRITICAL
" ?+ \) [+ W& j* E1 g& M
& ~& z4 c6 ]: F. R, r
invoke
Sleep,0
, j/ P# S. W* J7 m) c
call
fword
ptr
[Callgt]
;use callgate to Ring0!
# L9 W, T' g$ v( h: W8 k
;_asm call fword ptr [farcall]
x7 ?+ G6 e( G; [3 }% w7 a
_Ring0Proc:
; Ring0 code here..
1 q8 N3 m) d+ G5 L
mov
eax
,
esp
;save ring0 esp
6 F2 A. o' c3 E4 `4 j: V6 d
mov
esp
,[
esp
+4]
;->ring3 esp
7 p6 p# r1 F; j$ b6 n% j
push
eax
& m1 J. q: Z3 X0 z) r
mov
ebx
,
offset
stIDEINFO
. M; h# C' K$ S" G
assume
ebx
:
ptr
IDEINFO
. k+ ? Q* i+ s# Q m( \
;********************************************************************
" Y d* Q0 `6 v
; 等待硬盘就绪
& p: A2 `+ c; g' _# a5 {5 h$ d
;********************************************************************
& R' x" f9 `$ P& u5 q P) B
mov
ecx
,10000h
3 D7 Z: W6 `% d9 O3 X$ }
mov
dx
,01f7h
7 G# v# q% Z2 z1 |: H
@@:
1 A# U" H8 `+ l/ x0 |. G5 N! m
in
al
,
dx
) n3 {: J/ H( }! D
cmp
al
,50h
5 y1 v7 v, d9 j0 J
jz
@F
1 s' s% g! @/ O
loop
@B
( r$ ?+ t# T8 W; F9 `; b; H
jmp
_II_TimeOut
: H5 b6 q, K! R& S5 s+ c+ j
@@:
) V. Z8 I4 e5 Y5 B
;********************************************************************
% R+ f I3 h) { e1 E8 L, O5 y, g
; 发送命令
7 r* w% Q; t+ Y+ H
; 如果向主控制发送命令,则端口为 1f0h-1f7h
3 S1 z) f. E; z3 D) @0 j
; 如果向副控制发送命令,则端口为 170h-177h
; i/ U) u5 S0 f4 ], R' _0 M/ P
; 1f6h 如果要检测的设备为该IDE接口的主(MASTER)设备,
b1 e# h5 `7 Y* p
; 那么发送 a0,如果为从那么发送 b0
0 f- B$ E4 T1 l% s8 o
; 1f7h 如果要检测的设备为 ATA 设备那么发送 ec
$ P6 ]' X' g5 I! N; }% p! Y
; 如果为 ATAPI 设备那么发送 a1
, q5 f% F2 a; C- r
;********************************************************************
( y! q! T0 H( V$ b* x
mov
al
,0a0h
;Drive 0,Head 0
0 F1 d, H( D' m, D
mov
dx
,01f6h
;Drive and head port
, M& i. E7 J0 Q9 ^- s# |
out
dx
,
al
2 @% \$ T1 A$ a# X, n6 o
) D$ f2 r+ F6 c& O n6 W
mov
al
,0ech
% V( G! k: |/ j+ n) c% D4 Y
inc
dx
;Command port
' _) O4 h% p0 w) b9 |7 h& b3 a, p- J
out
dx
,
al
/ y: `' u/ h3 [$ j- |8 e' h% i
;********************************************************************
" ]+ |( J2 j+ j1 e$ B+ g# |) e
; 等待硬盘就绪
2 I3 `3 [$ f. a. o! o1 `: b, l
;********************************************************************
3 l; w7 x+ C. H- `8 j. E0 T
mov
ecx
,10000h
+ w5 S( N* c* x" F0 s4 k6 f
@@:
/ C2 l' @( {7 W: u' n7 e" G! c
in
al
,
dx
;1f7 (r-status register)
/ E4 b. ~$ v7 V, u1 _0 V
cmp
al
,58h
;(driver is ready ,and seek complete)
2 Z. s8 D1 U0 v" }" d9 F/ y
jz
@F
* c$ R% Y, R2 l
loop
@B
9 {1 O$ K1 @" V
jmp
_II_TimeOut
$ s5 Z W/ f; d( q
@@:
4 i8 u7 ~1 i5 G$ m# D
;********************************************************************
- d, k' ?( D- ^& J: Z5 J6 Z
; 将返回信息读回
" W1 v8 {* Q8 Z/ T8 D- {% B
; 注意一定要读满 100h 个字长
& k7 W4 s/ I# [& w p% H
;********************************************************************
+ q. O2 F9 b+ H
cld
: P6 }( h9 s! g: {4 H4 g) e( C/ b
mov
edx
,01f0h
;data port - data comes in and out here
; F3 i( |; ~ X5 K1 M
mov
edi
,
ebx
1 y0 \+ a) T# g" g; D
mov
ecx
,0100h
5 j n" U. {7 p
rep
insw
) b- D# ?" L& L3 Y. E; Y5 V
;********************************************************************
) w1 S! L4 \1 Y
; 返回的信息中,型号、序列号、版本号为字形式
# H W d0 h; N, {. c- i8 B" v2 f
; 需要整理到字符串的形式
2 f9 J+ a u4 K5 Y) n: k
;********************************************************************
( @; }( R n, y u# _- R% X
lea
esi
,[
ebx
].sSerialNumber
& |* x( P% m+ K8 A" e
mov
edi
,
esi
) F+ ^! e& G$ F2 S+ O
mov
ecx
,10
8 M; N4 q8 @- [1 T) Q' \. A" W
@@:
% Q% g8 v- x4 s$ @
lodsw
5 r( p5 b2 i% ?1 S9 R" H2 Q
xchg
ah
,
al
2 N0 r# L2 s/ j4 c( N
stosw
1 Z4 w, D. z( y# D) x
loop
@B
/ K' ]2 e7 h/ h0 O; V! c. v
" u" `( d' B8 P O7 M: d' p
lea
esi
,[
ebx
].sFirmwareRev
, F$ u8 E8 a4 _% I0 y8 h4 {$ ~
mov
edi
,
esi
1 i1 p( }# m: o# Z- x+ P4 m$ E) ^6 U
mov
ecx
,24
s v; r, V/ s* m
@@:
1 l# S) l0 L2 e& Q! [3 a6 Q5 f6 {
lodsw
7 @9 Z+ u6 Y& N6 T" M
xchg
ah
,
al
. p0 i! e9 f, Q
stosw
. {9 f, b, v, Q8 t
loop
@B
0 h0 K8 V1 f: H, F: O0 x9 H
_II_TimeOut:
/ [# z- Y4 G- s; u( ^
assume
ebx
:nothing
; E# @% @+ o% g
# G9 z% q+ H8 [: M! T8 O/ [2 |8 w& f
pop
esp
;restore ring0 esp
G6 t+ O2 A0 L* x- _4 Z
push
offset
Ring3
' r' z( j' S6 `6 ]( @* w
retf
2 |6 p! Z& x6 w- I5 g
Ring0CodeLen=$-_Ring0Proc
) Y, |- e+ e: b" Q, C4 M$ D( r$ i, Y
, v4 C* ^( O8 n! O- t% ^
Ring3:
9 r$ I# R6 n+ C% e
invoke
GetCurrentThread
" s6 \) ?! o$ G" Q+ f
invoke
SetThreadPriority,
eax
,THREAD_PRIORITY_NORMAL
1 Y7 p6 _5 C6 l# ]# G7 G6 k
& x, Q5 ?$ i- H) R( A4 C4 [
;invoke VirtualUnlock,Entry,seglen
7 P: Y( o8 L; }
L% ~3 N1 B* ~- X8 V, }4 v# y5 o
call
@f
S0 ^7 s q: O5 Y. L9 w
db
"ZwClose"
,0
/ ^* e: j6 R/ p. l# C) O& ~# v; |
@@:
! a7 Z# G5 T% c% t4 ?
push
NtdllMod
* {4 M6 ]. h4 P2 c5 O [ |
call
GetProcAddress
: s5 m+ r# w; w/ d) q2 l- t
push
hSection
5 _( R* Y/ Z5 E7 [
call
eax
. T! `6 c, U& O
mov
eax
,
TRUE
5 Z( [+ U* F4 `- |1 H& t
ret
0 V: z' {) b/ |1 X6 I
ExecRing0Proc
endp
, a X% @$ ]0 N0 N, {& U
) h8 s* g, l" A. k" G' n# W; D
main:
7 @* l3 K- S0 y4 D0 c4 r3 m
assume
fs
:nothing
. Y/ g# n& x8 R Q
push
offset
MySEH
- F) f+ ?6 ^) |' [2 U6 T
push
fs
:[0]
" Q _$ p* s- m" D
mov
fs
:[0],
esp
* H6 q7 Z) t0 M
mov
OldEsp,
esp
! C/ S- {# u. E8 ~1 D; ]" W
mov
ax
,
ds
;if Win9x?
* @. u2 E# q1 [5 m4 v
test
ax
,4
2 e8 C( ?: R- u5 X* |
jnz
Exit1
4 w, f7 }9 r- c) T: m
invoke
ExecRing0Proc
# _4 T" j, l! D0 F) a
- _5 X# L% T7 }9 K6 g
.if
stIDEINFO.wNumCyls
- `2 \; S6 @# x- }
lea
esi
,stIDEINFO.sModelNumber
l2 A4 S% E# ^7 B
mov
edi
,
offset
szModelNumber
* L5 J. D; U0 q- I* U- o1 m
mov
ecx
,sizeof stIDEINFO.sModelNumber
0 e5 g9 d& z5 X O. U+ k
rep
movsb
# m4 C; C [1 W; T1 \5 t5 r
3 K# Z9 \) P, b. r9 @( B! h
lea
esi
,stIDEINFO.sSerialNumber
^; c. ^, o& z
mov
edi
,
offset
szSerialNumber
1 h }1 q# C/ M, ~+ E
mov
ecx
,sizeof stIDEINFO.sSerialNumber
/ H* k. b& k3 w
rep
movsb
) H1 t/ u+ Y" L6 o$ {$ p |- M
; |) ~# B8 w0 [8 W' L
lea
esi
,stIDEINFO.sFirmwareRev
5 p7 s) }0 G9 Y4 p5 ^* }5 `) }
mov
edi
,
offset
szFirmwareRev
: C& i1 i9 o" b# O5 h. N
mov
ecx
,sizeof stIDEINFO.sFirmwareRev
& H3 `# M6 G* D( n
rep
movsb
, j0 B% C$ a# l4 ?$ G! K6 m3 M P
, u+ g* [8 A1 l( _1 L0 k! I
movzx
eax
,stIDEINFO.wNumCyls
6 v. u8 i2 I0 m4 q
movzx
ebx
,stIDEINFO.wNumHeads
5 {/ K/ h% _( Q' _) i0 L& h
movzx
ecx
,stIDEINFO.wSectorsPerTrack
& E/ G" ?1 c8 w, k1 R
movzx
edx
,stIDEINFO.wBufferSize
9 ^5 V9 O" k* O, d- r
invoke
wsprintf,
addr
szBuffer,
addr
szIDEInfo,
eax
,
ebx
,
ecx
,
edx
,
addr
szModelNumber,
addr
szSerialNumber,
addr
szFirmwareRev
. s t, r+ P6 }) h) D2 |2 h8 t
mov
eax
,
offset
szBuffer
" d* s. @: Y) R% h# b2 {) o
.else
! ]& U4 \' o- ~, ~7 E! j, ^. h/ t
mov
eax
,
offset
szErrInfo
1 h; [1 r4 X; t1 J
.endif
' |' @* b% H" o! v# e8 y
@@:
2 w" U5 s" D# f1 H# i
invoke
MessageBox,NULL,
eax
,
addr
szTitle,MB_ICONINFORMATION
or
MB_OK
% ]# x) }+ `7 C$ S
Exit1:
3 _1 X7 Y2 K c
pop
fs
:[0]
8 Y; P7 y: U: n# u" E8 w
add
esp
,4
9 `6 ^9 G; E. o: \! O2 W
invoke
ExitProcess,0
5 k! h/ u+ x$ b" D# e3 K
) W. k5 J$ q a3 n; z: |9 ]) m
MySEH :
! t7 k4 n( e$ G7 F
mov
esp
,OldEsp
$ F" [. W5 A- }3 U7 A
pop
fs
:[0]
3 b" I' U+ V5 E% P* O Z6 p* I
add
esp
,4
. e) v }9 S7 D, M
invoke
ExitProcess,-1
& w8 ]. h; `2 ~: Q( N! p
end
main
4 n9 k+ ]/ Q- ~ T1 U" \
. G1 J6 J. m B" A/ x
[此贴子已经被作者于2003-11-2 18:14:02编辑过]
+ r' _5 I2 T- r- W7 P o6 K
作者:
bigfoot
时间:
2003-11-3 16:22
提示:
作者被禁止或删除 内容自动屏蔽
作者:
firelinux
时间:
2003-11-19 00:12
win32位汇编,真的很不错,业余的时间,全都投进去了
作者:
唐明
时间:
2003-11-26 19:36
要能有台机器试一下多好,学汇编还从没想过去ring0,也感觉没哪个必要。
8 }& Q) R2 @ O; e/ e! _1 s
现在闲着真相试试。这片文章我在家保存了有快一年了。不用感觉可惜了。一直停着不用,我都快忘了那些曾经那些依稀的记忆了。水能给我一台电脑,我力马高喊:有你这么富的吗?
作者:
fyer
时间:
2003-12-3 03:31
提示:
作者被禁止或删除 内容自动屏蔽
作者:
游侠无极限
时间:
2003-12-3 15:33
很久以前?
3 p' Q2 D/ P0 M K" ^5 Q* F
不是吧,这个是 轻描淡写 编程论坛的斑竹写的
作者:
fyer
时间:
2003-12-24 19:21
提示:
作者被禁止或删除 内容自动屏蔽
欢迎光临 下沙论坛 (http://bbs.xiasha.cn/)
Powered by Discuz! X3.3