下沙论坛

 找回密码
 注册论坛(EC通行证)

QQ登录

QQ登录

下沙大学生网QQ群8(千人群)
群号:6490324 ,验证:下沙大学生网。
用手机发布本地信息严禁群发,各种宣传贴请发表在下沙信息版块有问必答,欢迎提问 提升会员等级,助你宣传
新会员必读 大学生的论坛下沙新生必读下沙币获得方法及使用
查看: 5564|回复: 6
打印 上一主题 下一主题

[转帖]2000/xp下读硬盘序列号[汇编]

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2003-11-2 18:09:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我可没这个水平 ) M7 D; V/ a. J) Y.686p ) s! v( K. l0 k8 y$ H, {$ { P.model flat, stdcall7 `" A( K& b J. w" k, W option casemap :none ; case sensitive 7 Y8 k; a4 C7 b; \) ?4 `1 C* \' a# X; #########################################################################& w& R7 D+ X {, A* M; L( r% B include \masm32\include\windows.inc% h$ h& E# \0 s1 [1 F1 X include \masm32\include\user32.inc/ M$ C7 F" X( ~' w7 ]# G include \masm32\include\kernel32.inc8 V2 V( l8 P) _, i8 Q) f/ u" n include \masm32\include\advapi32.inc q+ b5 R: M+ o) }; b- d , t2 B; ` E5 f2 o; j9 P- Zincludelib \masm32\lib\user32.lib 3 n; L0 }- g. a5 m' W6 Eincludelib \masm32\lib\kernel32.lib# a, e6 o; k9 L5 f. k3 G# L- a& r includelib \masm32\lib\advapi32.lib9 Q( u- |6 ^) X9 [7 e; W1 N9 d" a DEBUG = TRUE + v: c) W2 @$ S$ x- N3 q; F/ I/ K0 Q. H8 z HMODULE typedef dword ) C7 n9 V# j$ Y, V- {: aNTSTATUS typedef dword % ~; y7 e% H: lPACL typedef dword " U7 P' c/ x3 R$ `6 lPSECURITY_DESCRIPTOR typedef dword + G- j. F5 I/ h. Y1 d' a" L. R OBJ_INHERIT=2 3 g8 X7 C \ J& F+ E$ K# D OBJ_PERMANENT=10h % u5 S# U9 f3 g* ?/ E& h! T% p* ^4 uOBJ_EXCLUSIVE=20h 8 a8 V+ |; G% l% E) O5 yOBJ_CASE_INSENSITIVE=40h + J% d$ C5 x% s% A; _. {/ N. z OBJ_OPENIF=80h 0 x7 B; }$ M4 T. V d; BOBJ_OPENLINK =100h 7 l# U+ R5 {; L OBJ_KERNEL_HANDLE=200 " p/ S, l& w3 ]+ vOBJ_VALID_ATTRIBUTES=3F2h - m- o3 E6 v) d2 \* D* ~ # j$ k8 g( P3 k+ J! t8 e% jSE_KERNEL_OBJECT = 69 E, O& U, X, I; c8 q3 {' Z* D7 P GRANT_ACCESS =1- h, ?. \& l: T/ Y- n NO_INHERITANCE =07 J1 o1 U) ^9 i, D+ ] TRUSTEE_IS_NAME=1) R/ ?: N0 Q* }5 ^: _ TRUSTEE_IS_USER=1 + V$ ~( K$ e" |# E7 b7 ?" v" Z4 ISTATUS_SUCCESS =0 3 \6 C- s+ w/ c5 ZSTATUS_ACCESS_DENIED =0C0000022h6 C8 L9 ?( q- g i & p: X/ d/ c+ A1 V STATUS_ACCESS_VIOLATION equ 0C0000005h : _9 `1 G$ \& {STATUS_INFO_LENGTH_MISMATCH equ 0C0000004h: h7 V' v( ]7 n' N$ Q SystemModuleInformation equ 11! L* P% |' i5 r5 ]; H6 S PVOID TYPEDEF DWORD ! [3 z) ]0 K. P$ _3 d" {; a, g; qUNLONG TYPEDEF DWORD 4 F$ _/ c6 d: ^9 a3 M; o2 KCHAR TYPEDEF BYTE " [* @4 W! ? v7 h$ D- @; X n6 k# \/ E W1 z2 g/ ^; y# u UNICODE_STRING struct + h4 Z5 n5 r/ ~4 G; n* c nLength word ? ) T9 \! |9 D9 H# w; V# G% t MaximumLength word ? ' ?( M9 `2 y: q2 j Buffer dword ? 9 F- _- S# |. x( ^* G; v3 @4 Q' HUNICODE_STRING ends B4 h& ~) X4 ]; V- G" v* K2 y5 v% N" ]2 j: x. P5 ]/ r* M3 B& ~ OBJECT_ATTRIBUTES struct 6 I; N8 e a1 b: a nLength dword ? ' F6 i1 M( ]# A" ~* A9 U RootDirectory HANDLE ? 1 Y8 |& }' _, Q$ y ObjectName dword ?UNICODE_STRING + o$ ~1 t1 p. M' \ Attributes dword ?; 0 _$ w Q) p( ?! Y SecurityDescriptor dword ?; PVOID // Points to type SECURITY_DESCRIPTOR # [ X! j- P0 Z: _) L, H k: ? SecurityQualityOfService dword ?VOID // Points to type SECURITY_QUALITY_OF_SERVICE ; J) q' p8 v$ ]OBJECT_ATTRIBUTES ends , X9 I& h8 c& ^8 K+ S. z* ~( `( [! |, y+ r 3 J t: _2 t3 R% f+ _5 [# }TRUSTEE struct & Y: N3 P6 M X1 t" S, | pMultipleTrustee dword ?TRUSTEE . M: [/ e+ y- p: ? MultipleTrusteeOperation dword ?; MULTIPLE_TRUSTEE_OPERATION ' }8 i. y* `6 y! u" } j TrusteeForm dword ?;TRUSTEE_FORM% P) P; T% t9 B* k+ N TrusteeType dword ?;TRUSTEE_TYPE 5 H& }; O3 g9 R ptstrName dword ?;LPTSTR ) j8 S# j* d5 g1 H TRUSTEE ends) ~6 m5 U% B3 f: K% V 4 g2 k8 C1 k" Q. Y4 g% n( G8 f; Z B# O- J! W1 P3 ?: b) ~ EXPLICIT_ACCESS struct " b7 ~0 x) M8 H) u grfAccessPermissions DWORD ? , u9 w+ g. s# l8 v. g grfAccessMode dword ? ;ACCESS_MODE 8 _/ b+ |0 p6 r2 m grfInheritance DWORD ? ;3 k* j( h3 t( j* I/ j! Y( t Trustee TRUSTEE <> ; 0 j' I8 P: r2 u7 S6 h, e. |EXPLICIT_ACCESS ends ! L) _* e/ b4 I2 t1 @, r* g( q# F7 q) ~# f, F8 F) Y8 l; b MyGATE struct ;门结构类型定义 ' X/ A' f9 Q& u9 a7 I. m& i OFFSETL WORD ? ;32位偏移的低16位 6 b6 i8 [( m/ }& j1 R" ~ SELECTOR WORd ? ;选择子 x" D& @- c& V b `7 Z2 @ DCOUNT BYTE ? ;双字计数字段! T7 ~4 J# ]0 M# T6 s GTYPE BYTE ? ;类型 m' ?) p1 d- X- D" K( l OFFSETH WORD ? ;32位偏移的高16位: u7 a' @4 L# @$ ^3 g MyGATE ends : l2 O; Z) {. @4 D2 M. g; H f( r& F' h0 x9 x: X IDEINFO struct! Z+ T! f" x# i! {9 ~7 h) G L wGenConfig dw ? * v9 j k w }; F' i7 k6 FwNumCyls dw ?;拄面数- b( Q( t1 E! @- |% w" z wReserved dw ? % W2 K, e( E, M9 SwNumHeads dw ?;磁头数& _5 s- C+ [9 E wBytesPerTrack dw ?;每道字节数 8 g( V( i+ K# n$ CwBytesPerSector dw ?;每扇区字节数 : w3 q/ l I' X6 w" CwSectorsPerTrack dw ?;每道山区数' { u% e/ X5 ?( d" J" G wVendorUnique dw 3 dup (?)% J7 @8 }8 k( C& \" v! U2 t" X sSerialNumber db 20 dup (?);硬盘序列号- {! R: X) D- U. R( v% K0 j wBufferType dw ?; + D4 Y7 ?9 O! K/ }/ h* z2 L3 xwBufferSize dw ?; ;n * 512% l& M% y1 d* A$ Q5 m2 _3 d wECCSize dw ? c9 X- l- z7 j# M, n/ S+ x# N sFirmwareRev db 8 dup (?); 8 B- S0 N+ `4 F, u! f. t7 Q6 I9 [% \sModelNumber db 40 dup (?)1 Q* K, l" |* n2 D wMoreVendorUnique dw ? 5 c* s6 s/ G1 m4 ^1 \! ZwDoubleWordIO dw ?& K3 @; S7 g: N* L* f: y1 X, ? wCapabilities dw ?- E0 e+ W3 o |' x f2 G8 Z- | wReserved1 dw ?2 I) _" {/ @# U7 O" b% P6 I; @4 e wPIOTiming dw ?;( o9 s& ]: |2 e& e, X+ d wDMATiming dw ?; 2 A0 m" b- z; TwBS dw ? 9 J3 Q% b; K% f0 i! x. q) SwNumCurrentCyls dw ?;9 T5 r% w2 G; K4 }9 t wNumCurrentHeads dw ?; 3 {% v# X& D% ]: s9 V. ~- b( WwNumCurrentSectorsPerTrack dw ?; / J: n: p5 H0 gdwCurrentSectorCapacity dd ?; $ E1 I& l1 c& Y% Y: o) f' ^wMultSectorStuff dw ?;& Z$ k3 n ~" M+ t- C dwTotalAddressableSectors dd ?;( u( k! g0 s" B wSingleWordDMA dw ?; 0 \$ j4 N. D6 |0 X, MwMultiWordDMA dw ?;/ S6 O! X, @2 Q( a3 s4 F bReserved db 128 dup (?) : f- d& ^+ I/ o: YIDEINFO ends8 t0 N5 y+ D1 z; s3 [ ?/ ~ - G$ B* _3 L. l. y: ?- Q 4 q8 Z' i$ D3 {/ KSetPhyscialMemorySectionCanBeWrited proto :dword . o* G/ |' [5 O7 h; d4 EMiniMmGetPhysicalAddress proto :dword . t1 J, e# m' J4 N! g! t + l2 q6 {6 A3 W3 n3 P3 G$ M! F, A( YENTERRING0 macro ! v) L/ p4 r' i7 n8 ]pushad + J, ~% H8 d p pushfd % g3 @) ^4 E$ L/ H cli: W9 v$ c9 b x. d, p. m mov eax,cr0 ;get rid off readonly protect 7 K' s2 T% J \and eax,0fffeffffh , D# n) i; l. \/ o1 o1 Gmov cr0,eax( Y, S( L5 G* E endm$ p k/ [5 T, A; N' q , O7 x- U0 t" _8 I8 y4 F LEAVERING0 macro* ]% E- q( ~5 B0 W7 \! ? mov eax,cr0 ;restore readonly protect 1 S* o- N6 o) W z0 Aor eax,10000h ! S# |6 D+ C0 \- w9 {! Xmov cr0,eax" G* j9 a& X5 z# n& s" @) X7 X sti ! [& A( _7 F% F% z. S7 Vpopfd 7 D4 e2 N6 |8 E3 M& t- F popad / T# L& U" F g7 B `retf- J: ?: ?* @- _4 @; p, B; l+ ~ endm' t# }9 ^: [3 @+ E 7 H1 x' @6 j/ |1 N2 a8 G8 |7 k% ]+ k3 m UNICODE_STR macro str ' s4 R6 l# l' D9 L: o$ r" D2 sirpc _c,<str>. h6 A) ` M* V& h& k db '&_c' 3 m, _; y! _: q3 `+ bdb 0, x1 l ]% G% X2 h' b% J9 j endm 4 M* O. c, ? _) z7 dendm ) v: J8 _: ]! G' M, }$ L# F* E4 k+ z/ S% }7 X .data?# k/ F2 j5 k, G, Z* B0 F3 b: S& p- a* l GdtLimit dw ?0 w; Z9 n4 e: r" O8 {% z GdtAddr dd ?3 n. J: ]# w l M ) W4 Q" D. E3 U7 }. p+ n2 lmapAddr dd ? 1 W: {' R: h9 m$ DOldEsp dd ?/ y2 {0 m o) R$ I' a / Q: T6 f4 m" r/ H- u0 yreaded dw ?9 v( ]5 O& D2 r' o buffer db 512 dup(?)1 W( j k; S5 j- p9 Z: @$ N! r ShowText db 512*3 dup (?)+ J9 [; T; B* L3 A $ }/ q! m6 D* u$ k) G szBuffer db 1024 dup (?)7 j! s u: C$ h2 q; m2 ] szModelNumber db 41 dup (?)5 {0 b' \+ \' q szSerialNumber db 21 dup (?) 6 n3 J# u x5 C' ?szFirmwareRev db 9 dup (?) 0 v! x, S1 t- k% f$ u7 M2 { ) C+ c3 S: X3 P( r. D. }- ?$ ^stIDEINFO IDEINFO 5 m' U! ` X, u/ F ) D0 U: q2 t: l$ I! {0 }.data : {6 j6 q7 v5 n/ b8 R4 o/ I/ q+ nalign 4) e4 p, U( ?! @4 a objname dw objnamestr_size,objnamestr_size+2 $ [% `% q. V+ v6 Tobjnameptr dd 03 h5 o( |+ \ H5 O: S/ @ objnamestr equ this byte% R! }, W( T3 f8 g( W UNICODE_STR <\Device\PhysicalMemory>) m' R$ D" N4 D- x objnamestr_size equ $-objnamestr ) t0 _& c: O; ?; r 2 }9 u( w2 \" _szTitle db 'IDE 硬盘信息',00 ]. r+ t. |% @ szErrInfo db '无法读取硬盘信息',02 C, s2 P1 j7 D szIDEInfo db '柱面数 : %d',0dh,0ah- x* a; Q2 V1 S$ C% _. G, k db '磁头数 : %d',0dh,0ah$ A* p3 s) U8 ? [$ W% m db '每道扇区数 : %d',0dh,0ah & N, B8 J3 w" L; h* I+ x! J db '缓冲大小 : %d 扇区',0dh,0ah 5 b* f; B) `6 \# U0 { db '硬盘型号 : %40s',0dh,0ah# B8 z! z$ ]! p db '序列号 : %20s',0dh,0ah / O0 W+ \: T: q) H- @% m1 V: o8 ^ db '版本号 : %8s',0, _* `( ?1 |1 h; e g , A1 r2 O/ _) M7 l2 I; ?7 galign 49 z1 {( r$ b: ?* u3 b; B ObjAttr db 24 dup (0) - \; d$ \: W( h* F d! y( F; r: ~4 q' h" G/ d Callgt dq 0 ;call gate's selff! q9 W) }' a: O4 O3 } Caption db 'Windows XP绝对磁盘读写',0 , d3 a8 P! i, e7 Z; Q5 yDigit db '0123456789ABCDEF',0 ( k' r" E: O/ L2 V* D.code % d5 G' v0 h4 y$ H4 `; I_ShowBuffer proc ;显示所读出的信息 9 t1 x' \! D e7 a8 I/ z4 O- P ;把数据转换成16进制的形式 2 J6 Z8 N+ P. O mov [readed],512: c R: J$ `* x' p7 Q mov esi,offset buffer ;数据( K& ~7 ^; f/ o7 s mov edi,offset ShowText ;转换后的数据( m' X' [- S" @6 J+ l' }/ j3 d7 V- [ mov ebx,offset Digit & X! P7 _6 Z( V$ ^ _0 c xor ecx,ecx 1 H4 U3 N. x% t* O xor eax,eax 9 s. l1 }4 p" E1 CcomputeAgain: 4 P7 ~8 R5 f- L- D cmp [readed],01 m* {: b F4 V) a: c& L jz endCompute3 S' p1 n) U) h9 r) D Z5 i dec [readed]/ x. l1 H7 w% Z1 u3 V/ ^; N lodsb 4 y+ {$ B3 Q# Y' K6 ` push eax1 H8 s8 {- m8 L/ Y% [: R shr eax,4 ;高4位# `5 |3 O# @( x xlatb 8 y- M- x4 z" X: a+ X( w. i, ` stosb# N" n2 ?. g+ T" z! x) Q pop eax 3 L- u% B+ x# h/ i. j6 ?+ L and eax,0fH ;低4位 % }8 B; R1 z$ ~2 p5 R0 n xlatb1 \: C* @' n8 P' u' Y) N7 A stosb; B. |+ d, b: i' Z5 n0 Q mov byte ptr[edi],' ' ;空格 6 g' @* V% u! h+ u1 O inc edi - J! ^/ Y9 H/ Q7 s inc ecx 4 P' r9 k7 D2 `3 A/ T cmp ecx,16+ z4 v; j' a% e6 | jnz computeAgain ) H& t; x6 z8 ?: A- K xor ecx,ecx) R& X5 b& F8 E4 e6 g9 {# Y6 U7 `" K mov byte ptr[edi-1],13 ;回车 : a x1 O5 g2 @. d3 M( _8 G0 c7 I3 W jmp computeAgain! e5 ^) Y! x% G! y- S endCompute:1 k- _1 l4 E4 v } ;显示 - y# `$ K7 ~0 ?) I1 r' W: w" @ invoke MessageBoxA,NULL,offset ShowText,offset Caption,MB_OK ! t% D3 ]- l3 C3 [0 ?* V7 Q ret : L4 N8 w/ p* ^ I4 j! D. s( c& __ShowBuffer endp6 y- Y2 i6 z1 P" ~' C+ r- D- @) D 4 _. b; E+ s! Z SetPhyscialMemorySectionCanBeWrited proc uses ebx esi edi hSection:HANDLE $ U& p! j0 ]6 g8 x" X local pDacl: PACL - q2 `8 p X# r: G+ Z. D- V( dlocal pNewDaclACL 5 x: Q: l# ^5 v! d, I4 E# w local pSD SECURITY_DESCRIPTOR & n5 I% @' l- j7 E: }2 c$ P( R+ O local dwRes:DWORD ;' @ O1 K+ i) R* |( h+ g5 U local ea:EXPLICIT_ACCESS ;& `( P% K. z' \0 h' J3 t5 T invoke GetSecurityInfo,hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION, NULL,NULL, addr pDacl,NULL, addr pSD 4 _2 r. Y' h* E, q# ocmp eax,ERROR_SUCCESS( D ~* I" u2 s8 M/ F jz @f2 f9 `( [: j2 k6 o' ]" o jmp OutSet) V* @& l8 I6 E6 D# _ @@:5 u& q, ]0 l& }3 Y! I mov dwRes,eax9 E$ I. G9 Z m- [' S; P mov ea.grfAccessPermissions ,SECTION_MAP_WRITE;2 - x. ?! u7 o$ ^) Y* ]+ tmov ea.grfAccessMode ,GRANT_ACCESS;10 y3 P. V6 J+ q" r: U; ^0 M mov ea.grfInheritance,NO_INHERITANCE;02 @* Q1 S/ Q# B mov ea.Trustee.pMultipleTrustee,0 1 m7 X% v* ^8 O Q& v0 L' `3 E* Kmov ea.Trustee.MultipleTrusteeOperation,0 0 `8 d6 ~2 a9 d# q' umov ea.Trustee.TrusteeForm,TRUSTEE_IS_NAME;1 % D! I+ F3 r% a3 k4 E; N2 wmov ea.Trustee.TrusteeType,TRUSTEE_IS_USER;19 }: y- v8 H y! c% { call @f2 g% |( K3 m- k3 a( e db "CURRENT_USER",06 @' }3 I* n0 x5 X3 i! o3 A4 }! g @@: 3 p, O0 g% {( h$ |- E7 }pop edx 4 v' @/ w. Q1 e. }" Umov ea.Trustee.ptstrName,edx : G: k$ t8 A' p% B) e/ `invoke SetEntriesInAcl,1,addr ea,pDacl,addr pNewDacl( Q- P; Y+ ?: x; {# U1 i cmp eax,ERROR_SUCCESS . w' y5 C1 K, O y. E: H3 m; N. L% Ajz @f + J# P8 p$ [$ _% W* Xjmp OutSet ; ^' H J v- j@@:% n/ S( S% p h B0 _ invoke SetSecurityInfo,hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION, NULL,NULL,pNewDacl,NULL 6 g9 f* S+ ]- xOutSet:3 L( a3 g9 A' B( g cmp pSD,0 / y) t- u; h* a& s, x4 ijz @f m! Z: L7 z" j# t* P) Ninvoke LocalFree,pSD3 U+ L! W! y* q7 u @@:6 [" g% F" p% y0 ?, _7 f cmp pNewDacl,0- \: I E. v( \( ^% d jz @f M, {$ o/ |* ?7 h( w5 o invoke LocalFree,pNewDacl: i( }. {2 S+ b: |' \3 X @@: 0 C( S1 Q6 B5 k1 z9 M8 S" sret7 Y. W8 y1 J; L$ E8 H& \ SetPhyscialMemorySectionCanBeWrited endp$ h- u. v' L4 S X4 z' |6 p+ R6 P8 ~* X MiniMmGetPhysicalAddress proc virtualaddress:dword ' [! ?/ _2 ~1 G% Q% U: d O F Y mov eax,virtualaddress6 d% W$ o1 J' Q' ~ cmp eax,80000000h% r9 \* b" B) \/ R jb @f0 s- K( e7 a/ Z, g5 T/ W cmp eax,0a0000000h # r, w7 t! L# c/ N. t6 Y jae @f i8 U( O2 B3 u: Y and eax,1FFFF000h/ I# X( O' Y$ v# x+ K! [ ret $ ?. i% d+ n! c, k/ } @@: 9 e) L* X* c/ c% p. o, G, j$ Y mov eax,0 ' j3 e# }4 ]+ f2 k, n2 v ret 6 t, J3 U, L) v" P. _% fMiniMmGetPhysicalAddress endp2 A+ W4 i' u" N " F1 W$ D) h2 A# sExecRing0Proc proc ! H/ n! Y. Z6 g: c0 m f* t local tmpSel:dword/ O( q1 N/ |' o0 E9 M+ t1 X- O local setcg:dword ) [: H* s( U& i, O- \* wlocal BaseAddress:dword , _6 n g; K; s0 flocal NtdllMod :dword' S9 z! f! N6 [9 V$ x local hSection:HANDLE # L& z4 M0 H0 g5 \! S+ N- {; B local status:NTSTATUS( h! T. z4 F- ]* |3 q local objectAttributes:OBJECT_ATTRIBUTES : T, O; H; p1 N' }& n, n local objName:UNICODE_STRING ! f1 d9 w Z# x( d/ @mov status,STATUS_SUCCESS; * L3 d {$ ] I. z6 Y( p9 O+ P sgdt GdtLimit" @( q- A, I: m6 [6 } invoke MiniMmGetPhysicalAddress,GdtAddr 6 n& x0 {! t- Ymov mapAddr,eax1 \/ {5 k% V( b/ C, t test eax,eax1 ~5 q7 R/ e1 r9 ]7 L9 P, F jz Exit15 g6 l( O7 x9 _& T8 h6 L call @f4 w* _) g" J% j( s4 {( y0 S db "Ntdll.dll",06 g+ f) E- v$ q/ i @@: 6 H) c: p; I! A3 kcall LoadLibraryA! }2 P& ^! I$ D. ?8 S9 t; b1 z: A mov NtdllMod,eax. W6 t$ Y* G8 I1 ?- j9 C* l 7 K( J! Q6 N" X: W% ~; Jlea edx,objnamestr$ U! C N* T+ p; m6 b) G5 c a! @2 G ] mov objnameptr,edx' {, h2 j4 p; z6 e: Z/ } lea edi,ObjAttr % Q" q3 i7 F+ \% `8 z) vand di,0fffch ;align to 4 bytes,or ZwOpenSection will fail 5 U: O! C1 W( ]" M# c y& vpush edi ;edi->ObjAttr % r1 m0 e; o7 t6 Jpush 24 ;length of <\Device\PhysicalMemory>' ?8 c6 V' @2 w$ z pop ecx ; ]! h8 k0 r: l' N8 D9 ypush ecx / e6 f* o3 P+ @- r# exor eax,eax, \( ?3 Q. Y9 F! W( E' V rep stosb ;put ObjAttr with 0 3 y) ?! q/ M( apop ecx' J9 g0 i, K9 Q n1 U6 Z pop edi . F/ A# O" u* d, G3 lmov esi,edi 6 B& D# I% b) Gstosd3 A: ?! F& v1 V( s mov dword ptr[esi],ecx4 C9 {2 L& Y; F) D$ u stosd : ?+ s3 {8 f( v! }$ S& h: M: plea eax,[edx-8] ;eax->objname - k$ l/ y1 T% ~0 O& Nstosd ;ObjAddr(18h,00,00,00,00,00,00,00,offset objname,40,02,00,00,dd 2 dup(0) # y5 e3 @: l3 emov dword ptr [edi],240h a1 x) R* S9 D$ `$ B$ a $ V% E ^0 _" W9 ~call @f: f1 j; i% ^" a3 c db "ZwOpenSection",0 9 \$ h1 [3 l9 y, Q- X, v@@: . N/ a, d5 z; ]/ n; d; h, k. } ^/ Epush NtdllMod0 p$ T3 W a! s% _! W call GetProcAddress & z9 w( p+ u5 l4 B& g$ F: vmov ebx,eax ;ebx=ZwOpenSection0 M. i7 i8 q# N, ~ 8 f' I* P; _* r Y1 N a# ?, E) v+ o push esi ;esi->ObjAttr 6 _& w. R! q4 G! T5 ]1 epush SECTION_MAP_READ or SECTION_MAP_WRITE 0 m( l- U0 v5 k! x0 flea edi,hSection$ J( v! m1 K7 \ push edi ;edi->hSection 9 b7 t+ q' g: ^call eax ;ZwOpenSection(&hSection,SECTION_MAP_READ or SECTION_MAP_WRITE,ObjAttr) 5 G8 x4 r& K& O2 p2 d& A! H9 @: u O9 n/ F$ _6 d mov status,eax # [" |$ O3 l! _. U/ Z: gcmp status,STATUS_ACCESS_DENIED6 c1 j* i9 a* R jnz AccessPermit 8 d1 D" J: }' L) G3 e1 X9 g! V. @mov eax,ebx7 k! {) b3 Q! I( z( e 1 b1 O' i/ \/ ^! x- Zpush esi * ~7 K: q9 o2 x1 {" W) u% g push READ_CONTROL or WRITE_DAC 5 C/ R y9 W! L4 I7 Ypush edi + c3 ^# s/ M- x5 K& m! V* r" acall eax & F+ x& ~$ }; G" z! `; n4 n+ ]1 G$ c. N+ T" d) E mov status,eax8 Q3 F/ k# I9 l# p4 ?1 F# z invoke SetPhyscialMemorySectionCanBeWrited,hSection : [% Q) A2 d5 N+ R% c: I$ H 6 a, R- |1 \- F* Z4 t- r0 ~call @f/ f9 p; A( H/ _# D3 g db "ZwClose",0 + }0 N7 B% [9 t5 ~( Y& f7 ~@@: / S" D# u4 b3 X9 ?; ?push NtdllMod2 ~' F! L3 z$ `, b9 F) u$ K call GetProcAddress* _' d. R2 V1 [1 G/ c- K ! j; q, v3 n) y0 t# dpush hSection- Q i0 g+ D, A/ n call eax ;zwClose hSection " Z. j& h; n6 F" w9 P3 S; ^8 [. E$ V& { mov eax,ebx * B) f. D: m& V8 Q : `" h6 P7 w! H$ rpush esi r! t2 b& P. H, c% ~ push SECTION_MAP_READ or SECTION_MAP_WRITE 3 }8 y' I% |) s9 O) E; N- n. Llea edi,hSection+ Y1 _8 ^" L' T6 S push edi $ G7 } K) r R7 }2 h; a call eax/ U& @' j( j ]' ~+ {1 C mov status ,eax+ r |& c' G: E, ` k4 N- J ;status =ZwOpenSection(&hSection,SECTION_MAP_WRITE|SECTION_MAP_WRITE,&objectAttributes); 1 W1 k8 m1 _5 f5 i- Q AccessPermit:$ z4 F) f, v; G6 x cmp status ,STATUS_SUCCESS 7 l; t! z* b% A" i jz @f3 c. [" g1 u8 t) l ;printf("Error Open PhysicalMemory Section Object,Status:%08X\n",status); " ]6 J$ f& Q$ G5 J- r- n" q: F+ S3 d ;return 0;) {% ?% S- I( D mov eax,0 # l% t) d3 J) F+ Fret 1 }) ]0 A7 |" ~0 [$ x@@: - J% r/ g% l- G3 j4 i ~) mmovzx eax,word ptr[GdtLimit] 3 O8 B4 n' l8 Q7 z' y6 linc eax% } P" _0 H* W3 t invoke MapViewOfFile,hSection, FILE_MAP_READ or FILE_MAP_WRITE, 0, mapAddr, eax ! n8 v' b- y8 ?! r! `% q' \( o mov BaseAddress,eax ; r) a: d0 c$ J A' D! z! {# K+ {cmp BaseAddress,0 ; @0 i# D7 r- d7 njnz @f4 L0 N, `$ o! Z& }- ? ;printf("Error MapViewOffile:"); - W7 F) F" @! a- N7 h1 VrintWin32Error(GetLastError()); return 0; % _7 I# B5 l- [8 S- j mov eax,0 7 y- s3 f+ G" n3 iret% z! {4 s) V8 P" @ @@: : U0 f& q& M# ~& I mov esi,eax ;esi->gdt base: {$ W" l5 Z; z! O' U mov ecx,3e0h ! @- e. @+ D, lmov eax,GdtAddr4 c% m! ~. v$ Y: W5 {+ ]3 P .if dword ptr [esi+ecx+2]!=0ec0003e8h$ F5 c: N8 _, Z( @; v: e1 B' I mov byte ptr [esi],0c3h+ p7 z/ j) }: Y @& ^. _7 }: Z8 K |; p& A6 q/ D; i% m! i7 g1 F- q mov word ptr [esi+ecx],ax * \4 Y0 |. o1 b( X, |* Tshr eax,16 9 S6 k [/ c, F; nmov word ptr [esi+ecx+6],ax - {! E# |8 d7 I( L! x5 Tmov dword ptr [esi+ecx+2],0ec0003e8h. P o: x7 t& G; M( Z 9 j% U) {/ `& l4 ~ mov dword ptr [esi+ecx+8],0000ffffh ~( S, {7 f$ G mov dword ptr [esi+ecx+12],00cf9a00h; Z* a5 h+ Y$ D7 G .endif 5 c. q6 b) d8 f! v% [1 M7 s, J2 I) C: I0 v( z" a0 o" S3 y+ C mov setcg,TRUE % X; q1 V! e( Y" Ycmp setcg,0 . n# u" o; q/ {, J$ r" j* vjnz ChangeOK# P3 Y4 f# g4 _% A% u call @f. y2 k) B) a1 X n0 V) m db "ZwClose",0+ S9 W, F3 k4 H* B3 L- m) |0 S+ \ @@:2 X# ` x; t. e1 O7 A8 `/ P1 z push NtdllMod + c& J3 |" t) K I: t9 Scall GetProcAddress : `; j3 U# h4 d& w Xpush hSection B* M: f. B) h* t K! C& h call eax / e3 C! G- b8 H* j& J- u: Jxor eax,eax ' X% z U' s! J8 H7 e0 yret& [. E, U. @; w# o+ ]1 P0 c2 X ChangeOK: 6 r4 K. j/ N1 ] ?# Y: ~( t# b' B. Sand dword ptr Callgt,0 R% n8 s! @) C% b$ v xor eax,eax, l& T& E' T! O mov ax,3e0h* s0 e O! m/ G5 q. l or al,3h9 l8 O' ^$ v9 [% D1 m! l4 X mov word ptr [Callgt+4],ax / |" r3 i7 s A- H ;farcall[2]=((short)((ULONG)cg-(ULONG)BaseAddress))|3; //Ring 3 callgate; 5 f y4 {) Z4 T" l2 z8 M }% L k lea eax,_Ring0Proc8 q7 y& h9 B% F ;invoke VirtualLock,eax,seglen 9 Y# Y8 O. g: h; `# z) y test eax,eax , ` o5 B$ G; W/ J& A6 n) Njnz @f$ A8 a$ F. ~' `1 i1 a0 P3 u xor eax,eax 9 N# D4 p) S' G$ {! `& ] uret8 j3 g9 `' M$ j/ n1 Z0 ? @@: ! b' w9 L( {# \5 A: T$ Tinvoke GetCurrentThread7 n, P( p9 R# y( F7 } invoke SetThreadPriority,eax,THREAD_PRIORITY_TIME_CRITICAL & A. @" A" w2 V- N s' |" h; G9 S) O6 l ! {8 j c( I. S$ O+ u( ~% [invoke Sleep,0 ) G, u6 A% n% A G: B2 k, g- h) r0 Z call fword ptr [Callgt] ;use callgate to Ring0! G, e' b o+ {/ G;_asm call fword ptr [farcall]7 R" v- p1 V+ ~ P. \. |, t _Ring0Proc: ; Ring0 code here.. ( M) V9 |, s; u. c: e! }mov eax,esp ;save ring0 esp / Q& ~) D/ _ qmov esp,[esp+4];->ring3 esp- Q" h2 K$ Q, O' M2 P7 K2 P; A push eax; n0 I# w. A+ r( V) P" x mov ebx,offset stIDEINFO 1 b2 M7 C6 y2 g9 I0 j U+ Q assume ebx:ptr IDEINFO 7 I- d. G) ?/ f9 B6 D% D;******************************************************************** : K9 c, R, r9 v0 z* Y" |" y- {' [; 等待硬盘就绪 / f! t2 V4 S) K& H( i9 s5 u6 Y- };********************************************************************+ M3 x2 |3 U& p! } mov ecx,10000h & G% o4 U% z5 o4 e mov dx,01f7h + g+ r; ]# C1 s4 z4 B/ `$ A, Z @@: ( I# Q) w7 M- }# i; e7 ]3 } in al,dx ) e2 z" i; p9 D7 |, l cmp al,50h6 n" k! D0 M4 V7 G jz @F/ ?9 V$ ?; {6 G# j2 u loop @B+ O1 T3 s* @( a8 j jmp _II_TimeOut : Z! U: a; |7 }2 B/ y4 B @@:( _) ^5 ?& Z) K! {9 t ;********************************************************************0 J, y0 N- k$ z7 z$ r: h5 H' l( Z ; 发送命令 0 Q6 P6 ]* A" u$ L; 如果向主控制发送命令,则端口为 1f0h-1f7h8 I# H+ A: D( c ; 如果向副控制发送命令,则端口为 170h-177h ! Z/ O4 {+ J5 ?0 K; 1f6h 如果要检测的设备为该IDE接口的主(MASTER)设备,/ p7 J4 a+ P& g5 D9 A* W) b2 ` ; 那么发送 a0,如果为从那么发送 b0* o( T; N4 L; Y. T* X ; 1f7h 如果要检测的设备为 ATA 设备那么发送 ec1 q6 c0 e' g3 ?' r; ^& ? ; 如果为 ATAPI 设备那么发送 a1 ! w% ~6 C8 s9 ~) i3 `;********************************************************************6 \- K' {4 M, \5 v; [ mov al,0a0h ;Drive 0,Head 0 7 \0 b7 X" b2 o" E" M mov dx,01f6h ;Drive and head port6 W, g0 U4 I1 C3 ^8 m out dx,al2 {7 ~9 g: e0 D" z+ o ' B0 n9 n2 {8 a3 x; l mov al,0ech & x3 q" a, L m* |9 A5 ^: u: a' E inc dx ;Command port 7 @$ u6 ?$ U; E& g' C; `3 Z out dx,al ( _. A, b2 t* }8 u; \;******************************************************************** " g3 N c4 d9 c B, Y; 等待硬盘就绪0 Z4 Y, j$ T1 ]$ `" }2 s ;******************************************************************** # h% ?( C% P( g+ Q. v+ c mov ecx,10000h% ~6 ~7 z- E; m% _# X @@: ; T. Q5 O% } J$ Z0 @' t in al,dx;1f7 (r-status register)9 D1 `( v7 m) ^5 L8 z cmp al,58h;(driver is ready ,and seek complete)9 i9 l; h1 o6 T W jz @F / j4 V, \% g! Z loop @B 0 E+ Y* g0 r( [/ D( H9 x jmp _II_TimeOut ' x# E* g0 F( R. O! W/ Z @@:, B$ H+ L. U6 ?- S- r9 n8 S4 R0 H ;********************************************************************- c" C& O2 H4 E ; 将返回信息读回 " B6 g# I/ K$ c; 注意一定要读满 100h 个字长' i! d5 a) Y, K1 Q' } ;********************************************************************2 K& \' H M, Z) i% ? cld$ }# P+ ^% j: O+ r7 Y; V) \ mov edx,01f0h;data port - data comes in and out here) F T, \5 Q4 Y' t0 g$ W! J3 ]+ V! Y mov edi,ebx : e W4 |, M# `0 G( ] mov ecx,0100h% U2 U) c6 m5 h, {0 }, L rep insw# [/ Q7 W$ Q @ ;******************************************************************** " A% y+ W* `* E! V; 返回的信息中,型号、序列号、版本号为字形式 + E: m- z( ^# {4 c; 需要整理到字符串的形式5 {6 t/ I0 O: _& j- c/ ` ;********************************************************************) ~: I! v5 u4 y7 s1 M6 M8 v3 N, Q lea esi,[ebx].sSerialNumber) z5 L7 x2 D9 v" k8 _) _% d W mov edi,esi b2 P- z, C& ]( P3 _: b mov ecx,10& `8 d6 e5 \& x% j4 A @@: / V8 b' j* Q+ \ lodsw' f, [. B( D0 y. f' S/ A% t) K/ K ?$ I xchg ah,al w4 ]1 A; U. d L stosw ) U. G% }* h# C, l loop @B 7 C( r4 c5 W' v4 e; g$ w3 h , ^7 @3 k% V$ ^6 W# s# E) q& G lea esi,[ebx].sFirmwareRev - F! l. ~4 e9 j4 f% S: [8 N mov edi,esi ( k j! z- C9 W+ H8 d mov ecx,24 - X/ S+ ~+ j# \! [/ A* n5 X3 O$ _ @@: # S8 ]. P% A, k P lodsw . N: u& I& ^# O' F3 g: M xchg ah,al% e: [9 {+ Z# @2 B4 D9 J- u1 ? stosw 1 B. x; B5 D/ o& t, R& g loop @B , N, ?2 Q$ R2 \" b+ @: t, x' l$ c_II_TimeOut: 8 Z- z& Q( k, H$ T8 k3 xassume ebx:nothing L! B; W0 ^1 ?/ A8 Z9 a 1 N( Z. [5 M- Q9 ~- x# Rpop esp ;restore ring0 esp 6 b" _. U" Z A! W+ \, bpush offset Ring3 $ K. I W' T6 f% u9 y- K+ ?2 [retf1 h, M# k- j3 E, M* `9 j Ring0CodeLen=$-_Ring0Proc6 v! b+ O4 G# h: B- n4 r$ B: T( `9 [ 7 k t; _& m% e3 @- B7 z% t! kRing3: / j& e8 K1 v, Y J; O6 minvoke GetCurrentThread O" [8 h# F1 r% U& H4 cinvoke SetThreadPriority,eax,THREAD_PRIORITY_NORMAL 5 a; A' p6 z8 H* J, q& X8 w2 C' g7 D! L3 V0 b ;invoke VirtualUnlock,Entry,seglen ( J( M# g* D4 J' A% [7 n ; _8 \; T: J: k) {" @call @f& q0 H8 O# x7 r8 i/ e! K db "ZwClose",0. ^ ?! X' z# O' k/ t! }! w6 s @@:" l" S& G* S4 O% n5 d' x; H% O push NtdllMod; \+ D" b' {$ C' W" V- i) E5 L call GetProcAddress( I9 O* V8 g f' w, s: ? push hSection! c1 i9 g$ a; s6 b7 p$ F call eax+ @ L' @0 M7 _+ a6 B mov eax,TRUE ) T7 ^& A+ z$ c' X7 Cret ) u' m0 C3 c. X+ `% r; P; zExecRing0Proc endp & }: `% j W) u2 U, `; I ) }3 k$ |; P( D1 W6 I4 V7 e9 zmain:" C0 ~; R# V% c9 u# p* y2 r assume fs:nothing( S" @) A$ Q. f" h# F/ @. R# [+ N push offset MySEH% z: a* q2 D5 l& S: l push fs:[0]1 @; \7 x. P- J mov fs:[0],esp # N8 U1 i; }9 |- g6 K8 o) B$ Emov OldEsp,esp% `0 W6 F! a# K( g+ p mov ax,ds ;if Win9x? 4 g5 J K2 I: s6 n, j# P, c* B Jtest ax,44 B2 b) R y) J0 Y jnz Exit1, j- h, U0 k1 Q invoke ExecRing0Proc % r- \* o( N u: f4 ]( q# x! i & a- v7 w, k6 d.if stIDEINFO.wNumCyls$ s% ^9 a' R' l0 V: s- b2 |& k lea esi,stIDEINFO.sModelNumber # s- v/ O4 R/ |% l3 t mov edi,offset szModelNumber % L) f) L: `# u- E4 h mov ecx,sizeof stIDEINFO.sModelNumber & D6 D, @' g7 s5 i" b% V rep movsb * C" R ^# C3 h$ B: n& H5 x) ]( ^8 Q4 j# ~7 J" k lea esi,stIDEINFO.sSerialNumber; a, x; {- g' S- B; p, ? mov edi,offset szSerialNumber # t: M/ ]0 C, \' Q4 Y# x; Q mov ecx,sizeof stIDEINFO.sSerialNumber ) p7 W* g! g* _' p o2 q9 U& U rep movsb 4 i3 w1 q) R: |/ [5 H, N$ A0 Z6 W- ]4 e2 L! A lea esi,stIDEINFO.sFirmwareRev" G% l/ f& X2 W& B) b. x4 x mov edi,offset szFirmwareRev k! E4 e: C2 ~' a$ y mov ecx,sizeof stIDEINFO.sFirmwareRev" g7 a& M$ t& `' |- C rep movsb 0 Y4 A: e9 w- M' m$ a" @9 O. }; W; L/ r' |* n9 B4 l! ~5 j movzx eax,stIDEINFO.wNumCyls1 i* F8 q' ]# g4 I movzx ebx,stIDEINFO.wNumHeads6 f9 `/ ^) R% ?& l* ~ movzx ecx,stIDEINFO.wSectorsPerTrack4 G4 v: x3 F% l; L. A, p7 l$ f movzx edx,stIDEINFO.wBufferSize * B }$ j$ {8 t- a) X invoke wsprintf,addr szBuffer,addr szIDEInfo, eax,ebx,ecx,edx, addr szModelNumber, addr szSerialNumber, addr szFirmwareRev " M4 c+ M n" k3 v+ R5 ^7 G mov eax,offset szBuffer+ w, f& d/ R/ C; M' J .else$ g! t4 [% X# T: \5 m9 B) g mov eax,offset szErrInfo( w0 m7 B0 j2 v2 f# }( t0 ~ .endif# Z( H1 b2 |! C5 V" ~7 @ @@: 4 Q) }& \( }& ]4 k1 ]/ R; Yinvoke MessageBox,NULL,eax,addr szTitle,MB_ICONINFORMATION or MB_OK 5 R+ l! W& U8 F) W* ~Exit1:% s. Q) {6 B3 _$ q/ G pop fs:[0]/ A* r' q" X9 f. D2 l P+ K3 @ add esp,40 V# F/ f" v' P# H invoke ExitProcess,0 9 b# M5 w/ C, x6 S6 G. L; R: S# d, w/ S; m MySEH :) w4 H/ S/ {; c# `6 s mov esp,OldEsp7 ]) }! G! s) G" X$ `- M" s pop fs:[0] 0 \& \5 w: b6 q/ x' Yadd esp,4 & q& V$ [, _5 E- F7 J( q) s! ainvoke ExitProcess,-1 - k) u4 Q! r3 u4 D3 g* ]6 wend main8 |* T( z. h/ X8 G% F 9 @4 K) p* R* j0 y t
[此贴子已经被作者于2003-11-2 18:14:02编辑过]
( V' r9 x8 H+ ]0 i) r7 C* \
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩
bigfoot 该用户已被删除
2
发表于 2003-11-3 16:22:00 | 只看该作者
呵呵,ExecRing0Proc 这段程序甚妙,先得到gdt,然后构造一个调用门call gate's ,使程序从用户模式(ring 3)进入内核模式(ring 0)。进入内核模式之后,就可以没有限制地对系统干任何勾当。这段程序确实为高手所为,在下佩服得紧。* @) n- S2 A8 x$ k* s8 ?8 r3 h
至于读硬盘序列号之类,只不过是在内核模式下的一个I/O应用罢了。
2 M# S# @- t" O+ `. M$ W" Y- r7 z- H其实在NT/2000下读取硬盘序列号只要打开\\.\PhysicalDriveX(X:设备号0~26)设备,然后用DeviceIoControl()就可以读取了,不需要绕ring0这么一个大圈子
8 q2 t5 x4 t# |  E
7 P$ `) x& U3 a/ i/ n: B6 R这个程序也可以C语言实现,不过中间必须嵌入几条汇编的指令,如sgdt GdtLimit
4 L3 m3 v+ G$ U: c1 I但还是用c来写更方便,例如:
  y4 ?6 R& m2 M3 ccall @f, F1 o' R! m% C. v# S
db "ZwOpenSection",0+ ~4 m% j0 b: X4 x, P3 L; [
@@:* _) X- t) L  y/ h2 S" q# F# f/ ]
push NtdllMod1 Z) p1 Q, t5 U( P7 n
call GetProcAddress
. a; }4 b+ K) r6 @mov ebx,eax ;ebx=ZwOpenSection# }4 Z3 j0 p3 M5 _  X$ T
push esi ;esi->ObjAttr
0 j5 b6 ?/ N" t1 Gpush SECTION_MAP_READ or SECTION_MAP_WRITE! R* z& }4 S" M6 I. ]
lea edi,hSection7 ?  R0 J+ n9 [$ ]
push edi ;edi->hSection6 c& |+ z. G2 J. r1 }" ]$ k
call eax ;
  c2 }% B6 b8 B
0 Q! m+ O6 Y( j/ `# B8 C用c的话只要一句就可以了
( n' I4 ~* x( zZwOpenSection(&hSection,SECTION_MAP_READ or SECTION_MAP_WRITE,ObjAttr);- f. ]' I4 d, J
因此懂汇编,然后用C/C++编程,是成为高手的捷径& o, d4 C5 {" x& K$ `& l( Z$ {
* P( x5 Q: t/ Y# c9 f
[此贴子已经被作者于2003-11-3 16:46:50编辑过]
+ C+ i  f( o+ v4 E

该用户从未签到

3
发表于 2003-11-19 00:12:00 | 只看该作者
win32位汇编,真的很不错,业余的时间,全都投进去了

该用户从未签到

4
发表于 2003-11-26 19:36:00 | 只看该作者
要能有台机器试一下多好,学汇编还从没想过去ring0,也感觉没哪个必要。$ y' p5 K! ^8 p0 ?# W
现在闲着真相试试。这片文章我在家保存了有快一年了。不用感觉可惜了。一直停着不用,我都快忘了那些曾经那些依稀的记忆了。水能给我一台电脑,我力马高喊:有你这么富的吗?
fyer 该用户已被删除
5
发表于 2003-12-3 03:31:00 | 只看该作者
很久以前的一段代码

该用户从未签到

6
 楼主| 发表于 2003-12-3 15:33:00 | 只看该作者
很久以前?
" D6 b: K( D7 J5 ], P) D/ j$ x不是吧,这个是 轻描淡写 编程论坛的斑竹写的
fyer 该用户已被删除
7
发表于 2003-12-24 19:21:00 | 只看该作者
看到过的。

本版积分规则

关闭

下沙大学生网推荐上一条 /1 下一条

快速回复 返回顶部 返回列表