下沙论坛

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

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2003-11-2 18:09:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我可没这个水平! ?* L$ `9 U- u0 a \! |6 Q; ^ .686p! ^- A: Z# [* n, H2 x- |2 x2 G: f .model flat, stdcall- a% s. x) ^3 w+ g/ A option casemap :none ; case sensitive5 h, Y' I( \7 f ; #########################################################################3 e0 G) e/ W5 M. R: z include \masm32\include\windows.inc9 G7 W' i9 p% `% K. }6 O2 H2 y include \masm32\include\user32.inc 1 w* ^& K/ T" }' _% T3 vinclude \masm32\include\kernel32.inc % |+ m% F+ K2 Rinclude \masm32\include\advapi32.inc 2 [4 b$ h% t0 U, c7 I : G8 l$ y9 W1 _( W( [( kincludelib \masm32\lib\user32.lib / M7 X) [& v7 T# U' z$ M; Iincludelib \masm32\lib\kernel32.lib7 }, T- ?5 r: c# ]6 P includelib \masm32\lib\advapi32.lib2 e6 S. W' {! J# x; I: f DEBUG = TRUE! P0 L' ]1 o- E0 e2 x# M3 {; G- z' A : Q) o, j) T' Y$ ^" b* ^ HMODULE typedef dword 3 m4 C; j9 _; H; Y* f$ ^ @8 `3 yNTSTATUS typedef dword 5 |! f, i. l) C \2 cPACL typedef dword2 U0 g* X; ?* o. C) G- h* C PSECURITY_DESCRIPTOR typedef dword% u" T+ f! P5 h6 ~6 r( s / e8 |0 D& }3 j, k3 S- p OBJ_INHERIT=2 " S$ ^' S3 B' IOBJ_PERMANENT=10h * _+ x( V. t% `! gOBJ_EXCLUSIVE=20h 1 F5 [* K1 f4 } v0 J5 f OBJ_CASE_INSENSITIVE=40h E p& e7 }. c& r# @ OBJ_OPENIF=80h $ G* Z9 N; F6 ^7 L) P/ bOBJ_OPENLINK =100h ' u, i$ j4 O% L OBJ_KERNEL_HANDLE=200 , r8 E5 n. I0 w2 GOBJ_VALID_ATTRIBUTES=3F2h 2 w1 N( e2 C4 y( h* y" S8 e5 C6 [2 |5 F A4 s# x SE_KERNEL_OBJECT = 69 ^+ b# c- q6 {, I GRANT_ACCESS =1 1 C+ y- T" j1 y* Z" sNO_INHERITANCE =0+ e$ w# a& b3 c: P7 P( P TRUSTEE_IS_NAME=1 8 b3 d8 j- a/ r7 w% e( {TRUSTEE_IS_USER=1, `3 ^- D$ V: f2 u4 N1 V3 T STATUS_SUCCESS =0 # q% S( ?. m7 a g1 L+ KSTATUS_ACCESS_DENIED =0C0000022h ) u8 R8 h% s% O% `+ g8 W $ R1 {2 U) ]8 P3 lSTATUS_ACCESS_VIOLATION equ 0C0000005h9 E9 v ? C: P% p0 k- l STATUS_INFO_LENGTH_MISMATCH equ 0C0000004h 6 I! C* `7 E5 a/ W$ ESystemModuleInformation equ 11 / R" E: j# c" }! k/ R1 n MPVOID TYPEDEF DWORD+ L5 \; Y4 ~, o( M UNLONG TYPEDEF DWORD/ J) V9 g& ^4 W" M. N3 U8 G! j1 l9 W CHAR TYPEDEF BYTE 0 {) }# f* Z) n" X% z% t1 v# J H, h$ E$ T; l7 U UNICODE_STRING struct : H O9 i2 {% G) k# A4 ?3 p nLength word ? 8 C4 {8 p, m$ u* K8 v MaximumLength word ? + b/ w3 t0 g) X4 X Buffer dword ? 1 m- Y: [# |- M6 YUNICODE_STRING ends : D, M, l0 ~8 q; J5 X0 l, Y' M9 o0 k! _3 e9 m! T, b2 Q! P OBJECT_ATTRIBUTES struct , H" A# e! T9 u' V' F | nLength dword ? 8 }, v$ u) w- j S RootDirectory HANDLE ? 8 }1 v( ?% e) a1 _" Z ObjectName dword ?UNICODE_STRING 2 `; T, q+ @3 c; S- W% q Attributes dword ?; ' [: O) v6 w! }. e) ]0 T SecurityDescriptor dword ?; PVOID // Points to type SECURITY_DESCRIPTOR $ q, G0 G3 \5 N; h' V1 e; n, a SecurityQualityOfService dword ?VOID // Points to type SECURITY_QUALITY_OF_SERVICE 2 ^& h0 |. W, u8 ~ OBJECT_ATTRIBUTES ends / `' `# G) T' x& K: \5 n3 l6 J- j" m3 h' r( C, G - {4 }4 m* i1 l2 @* ~4 ]# Q, v1 Q TRUSTEE struct * a; X( n. W7 s" K) Q pMultipleTrustee dword ?TRUSTEE , R% A: ]) V' C, E MultipleTrusteeOperation dword ?; MULTIPLE_TRUSTEE_OPERATION . J. G* ?* h5 `* K. z" h! t( {( [7 k TrusteeForm dword ?;TRUSTEE_FORM2 d6 z4 J! [8 n, r TrusteeType dword ?;TRUSTEE_TYPE " n3 ?3 T' _! R4 @' h ptstrName dword ?;LPTSTR 3 `8 |; ^4 |& H7 s3 s! D/ d @TRUSTEE ends 4 A( ]8 j9 U( B5 w9 A% e: l* M3 X% W4 O- y( w1 \3 P " W% q$ m4 Z- o/ y. |+ S) ~ EXPLICIT_ACCESS struct . x* ^1 `9 r: E, S' [! Y# P grfAccessPermissions DWORD ? * A" ~* X. d5 g grfAccessMode dword ? ;ACCESS_MODE / j7 g( K+ D" L, b( ` F5 _% g$ s grfInheritance DWORD ? ;- w- B( L: {) ?4 t* U/ a Trustee TRUSTEE <> ;% p1 U) A5 h+ _& ` EXPLICIT_ACCESS ends " h- e$ H0 T# |! p9 J! b' z+ E5 o# G) F MyGATE struct ;门结构类型定义 + G2 x& ?( B9 I- F" B4 R OFFSETL WORD ? ;32位偏移的低16位9 p' `! C8 q# C9 I4 T SELECTOR WORd ? ;选择子! p9 K) D! r e( ]) H4 m DCOUNT BYTE ? ;双字计数字段 / {! ^8 ^! V: {! n: ?. A9 v GTYPE BYTE ? ;类型 # @ q; d+ g% H7 q OFFSETH WORD ? ;32位偏移的高16位+ y9 J+ ?# o' g' T% A$ y' ^! e MyGATE ends- R, O, Q) e y# i9 ^& O" T( \6 n 8 V& \, T K" {/ ^& c; F1 f4 S- s IDEINFO struct6 E/ _) q; N+ j% Z% [ wGenConfig dw ? * e" X5 w/ `' {6 rwNumCyls dw ?;拄面数 , D1 C- m5 ~& I$ n/ J" k8 {' IwReserved dw ?3 M s0 l% V5 T8 v( U: W" @ wNumHeads dw ?;磁头数) ?* k& d+ Z& t, v$ n wBytesPerTrack dw ?;每道字节数* w- w; a$ N9 p6 S wBytesPerSector dw ?;每扇区字节数 0 F# ]' m+ Q- s# i) \3 _+ iwSectorsPerTrack dw ?;每道山区数 3 K$ W( U4 i6 j4 X: ^wVendorUnique dw 3 dup (?)) h; O7 p4 @2 S! Y( K0 T sSerialNumber db 20 dup (?);硬盘序列号; `1 S8 T1 @9 i" K* b6 j* B wBufferType dw ?; * k" h! D9 ^2 c+ I! @wBufferSize dw ?; ;n * 5125 P3 ?/ S5 G+ R s4 |2 I. l wECCSize dw ? # r; T L/ `6 z0 [( J6 E# B6 |/ GsFirmwareRev db 8 dup (?); 4 q0 x9 n* ^! z9 QsModelNumber db 40 dup (?)2 s7 e& a+ a. M, ~! i wMoreVendorUnique dw ? ; E. ]- `( }" @% qwDoubleWordIO dw ? % ~' ?7 y& j1 u7 q& PwCapabilities dw ? Y) j i" J( [/ y* uwReserved1 dw ? . ~( D0 @3 h0 pwPIOTiming dw ?;* T' A. V' {6 \! L7 \8 j8 k+ k wDMATiming dw ?;) K! Q) G( I) }3 ]& o8 o$ { wBS dw ? 8 I7 \9 u2 H1 k3 AwNumCurrentCyls dw ?;8 v: C" x) I5 k! { wNumCurrentHeads dw ?;8 f; y$ M/ Y7 k5 B# u* w wNumCurrentSectorsPerTrack dw ?; + e! R5 ~* R3 F5 l2 g5 wdwCurrentSectorCapacity dd ?;+ c1 K# w3 c+ {/ x( i7 n$ ]. \ wMultSectorStuff dw ?;2 V$ Z+ r9 x) \ dwTotalAddressableSectors dd ?;- ?# Y; Y5 b' ]: ^ wSingleWordDMA dw ?;3 ?% [+ x+ Y; M, {5 z& x! u6 f: ] wMultiWordDMA dw ?;4 N, t& x/ A* b; ?2 {; |& Z5 f1 ~6 Y bReserved db 128 dup (?) 5 s% M, b1 `, C. T$ r, [2 G) m8 @IDEINFO ends % `: ?# |. Q/ N& g- E* M! E* N; ^1 T6 I 5 A8 W$ ?/ z/ o* O3 _ SetPhyscialMemorySectionCanBeWrited proto :dword( H' {, m- g9 h V4 Z* S+ ` MiniMmGetPhysicalAddress proto :dword/ t7 x; h* g9 S3 j* w4 x 2 g- W5 D; U/ j# d# A- j ENTERRING0 macro$ ?5 w4 J: F/ ]; |: E5 _2 t5 B$ \ pushad # u0 @* x! u, I6 {2 L- |$ { pushfd 8 X* R6 f! [$ `8 r$ M cli : t+ V! M. g7 x. A% j: L+ lmov eax,cr0 ;get rid off readonly protect $ y h: G% S& T( Sand eax,0fffeffffh . Y, l @# n p6 p0 \' x7 ^mov cr0,eax 3 {/ [$ U% d0 t$ J& Gendm" G8 |9 r9 U- c' \1 l 1 }7 E' ]& a" \* wLEAVERING0 macro 4 h: M9 B6 E" emov eax,cr0 ;restore readonly protect6 T2 ~8 P4 v/ Z" W or eax,10000h/ g# A# s4 S( I$ Z# Z8 J$ `# I mov cr0,eax5 i' {& I# q6 H8 C0 x0 J! B sti& M' c% v; G+ F' z6 M3 b2 | popfd 3 u8 N% f q$ d7 K& k popad * F6 w6 R6 Y% M$ B- j retf( e( S% l0 C; J endm6 {& g- P, t& R 1 F/ B; B3 q2 E- A+ @ 0 W* @- d& l# A7 J4 FUNICODE_STR macro str$ a9 q1 \9 V6 h% _8 g irpc _c,<str> j4 `* N$ q; {* r( G! Rdb '&_c'5 E5 K4 \; o) X5 U4 b1 U db 0 8 C! W8 H/ ~: g% ]endm; D5 F& f2 _% f; u! _6 F' @ endm . O" F% Y( Z. i2 C# _7 d# n5 `9 L1 Y. e .data?) s4 a% Y7 T, B/ B GdtLimit dw ? 4 A9 t3 S6 j* ?0 }0 r7 tGdtAddr dd ? + X7 V0 o; n$ \+ g5 ?* `4 O8 h& {# t# {/ T5 h: Y4 z mapAddr dd ?) o/ J0 q6 `5 T0 l6 J, V; F* ] OldEsp dd ? 6 `/ B/ f6 K5 \9 E; e 3 V$ O/ L! D4 x- g$ treaded dw ? 1 @! Y9 U8 Z! j, A6 A! @buffer db 512 dup(?) : r C! W: l4 E# P3 fShowText db 512*3 dup (?)8 s ~' o; g4 a$ d) t ' U& k+ b7 k3 ?szBuffer db 1024 dup (?)- H3 \5 r" y+ F5 `1 Q' f* T szModelNumber db 41 dup (?)- V+ q F* o* U) Z& G) t4 T, P' n+ S szSerialNumber db 21 dup (?) ( M" A) |$ F2 K, bszFirmwareRev db 9 dup (?); h( l( w8 o1 V2 ~4 p% T4 Z 8 H4 c& z9 d% d" {8 r$ g stIDEINFO IDEINFO 5 u/ f( w7 O5 u0 y$ P$ ~# K ; s0 N% I" M( o. r7 D/ A2 [/ R.data7 G( l! {) l' \* f3 I* _% N; `/ B align 4 h, f( j1 J" B4 \ objname dw objnamestr_size,objnamestr_size+2( d. o7 r2 r/ c7 }, J objnameptr dd 0) X3 S4 I T% b( q9 I objnamestr equ this byte$ O! `8 V1 A% m7 z( Z. a: d UNICODE_STR <\Device\PhysicalMemory> ! R" p" O- ]# I" S6 hobjnamestr_size equ $-objnamestr 8 k( X! ~- g$ k7 x/ @0 v% a ' A9 Q% b5 a' Y. a7 jszTitle db 'IDE 硬盘信息',0 $ n8 \ I" y% \2 P6 C# c1 ~szErrInfo db '无法读取硬盘信息',0$ F' K6 k1 U! ]0 E4 T' e) h szIDEInfo db '柱面数 : %d',0dh,0ah 2 r4 H/ f0 g- r9 ]: m- M db '磁头数 : %d',0dh,0ah 6 t! T2 M3 m: H; R; w3 s7 D db '每道扇区数 : %d',0dh,0ah( L, l3 X$ Q/ G/ h. | db '缓冲大小 : %d 扇区',0dh,0ah " u! j8 ]" |; E- ~ db '硬盘型号 : %40s',0dh,0ah : c; f' s, f. F db '序列号 : %20s',0dh,0ah , d3 Q8 T; q9 J/ Y db '版本号 : %8s',0 " | B$ D$ U+ p0 r1 B0 X& \: s , I4 r+ E% Z& kalign 4 2 a* x6 ^" D7 i, @. a5 ~( X. LObjAttr db 24 dup (0)8 L4 y. }, e; r- G' T. A1 k ) I0 q1 p3 j7 K/ r: v' [$ D Callgt dq 0 ;call gate's selff8 C* Q4 j7 r, q# s Caption db 'Windows XP绝对磁盘读写',0. @& c1 L1 L# m8 ] Digit db '0123456789ABCDEF',0 ! z# w/ U$ _$ [.code / C9 x8 V! n' [- e, B_ShowBuffer proc ;显示所读出的信息) W3 h! |" x- O( p x ;把数据转换成16进制的形式9 W; u, R+ T* s mov [readed],512 ! O/ s( w$ Q ], x# \% G' d* ^ mov esi,offset buffer ;数据7 U" q8 @7 u9 P3 K7 t mov edi,offset ShowText ;转换后的数据 ' ~3 U$ \" O$ L7 P mov ebx,offset Digit* _- l( J/ U; T6 @! R xor ecx,ecx " h3 b: |6 V- V8 }/ k- i xor eax,eax ' l$ _# [3 K mcomputeAgain: ' k+ s! J Z4 N1 c- ^; n! i0 B cmp [readed],07 L e0 J) V/ F) { F4 A: d jz endCompute ; `4 E+ Q7 ~1 Y; V' p3 m dec [readed] " E5 c: ^. W! E lodsb0 e2 z) h, Q# z+ k9 W% r7 U push eax/ }( ?& R! w# d: g shr eax,4 ;高4位9 ?/ f6 P8 {4 q" ^' S xlatb ?! B: v( J5 l6 D stosb, i% Z+ X9 K8 [0 q @* W pop eax& M& r5 ?0 l) @' O and eax,0fH ;低4位- ~- [0 T' U$ M3 a; [) Y F6 } xlatb* k# H4 o ?( k& K* j stosb, {4 r' j% r0 \0 S# [" H mov byte ptr[edi],' ' ;空格" W4 m1 U8 M) x* h inc edi5 p7 N9 v: `% D9 R# L, L! ^$ r. q" l inc ecx 0 |2 U; {/ R! }# h- z1 h* j cmp ecx,16 ) S! n6 v$ F3 k* H& p# y6 M jnz computeAgain4 e" K" E# W* |1 _) I7 ^; t! \ xor ecx,ecx - ]9 l" i. z6 a& X0 U8 V mov byte ptr[edi-1],13 ;回车 : I: b" O1 L7 m. u0 Z" n/ ~1 d jmp computeAgain" Q. X7 z8 R" N4 m- m$ @ endCompute:5 |7 Z2 r" Z R! f ;显示2 N b0 [! l& D0 x invoke MessageBoxA,NULL,offset ShowText,offset Caption,MB_OK8 P7 m+ c3 | C ret : ]4 s2 g* T6 |_ShowBuffer endp8 h2 D, C* }( y1 @; {/ @ # `% q1 y) O, w9 A) D' j2 h0 y' O; a SetPhyscialMemorySectionCanBeWrited proc uses ebx esi edi hSection:HANDLE 5 S5 D# p1 Z/ p0 R local pDacl: PACL 4 ^, ]7 H5 U) {, h& h local pNewDaclACL 4 H4 m8 S& w8 a/ C; t: p+ J+ N local pSD SECURITY_DESCRIPTOR 7 q4 `$ H4 l1 N0 H2 V; z! Rlocal dwRes:DWORD ; 5 d% o4 t# c* S( l* zlocal ea:EXPLICIT_ACCESS ;8 W q/ s9 m& i3 E: v4 W) w0 z0 b! b invoke GetSecurityInfo,hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION, NULL,NULL, addr pDacl,NULL, addr pSD2 w3 `: b0 w# u cmp eax,ERROR_SUCCESS ! [+ b! p" O) y+ B8 V6 o& n# Mjz @f 6 `6 w4 B4 C" w) N, H3 q3 z9 Vjmp OutSet ) t9 S3 ]; i/ C4 L, g) ]! {0 [ i, H@@: 5 z. ^$ v- V3 b: r$ n% Tmov dwRes,eax / q9 Y8 ~1 W2 y, smov ea.grfAccessPermissions ,SECTION_MAP_WRITE;2) f ]9 N/ G q) W# w. U# Q mov ea.grfAccessMode ,GRANT_ACCESS;1 ' Z! k; Y# S/ B0 `3 dmov ea.grfInheritance,NO_INHERITANCE;0 . \& y4 _ c# hmov ea.Trustee.pMultipleTrustee,0- T' i* n# y+ i( k' x mov ea.Trustee.MultipleTrusteeOperation,0 $ u. L0 v- e- ^' k/ p; q/ dmov ea.Trustee.TrusteeForm,TRUSTEE_IS_NAME;1 . n2 n1 J& x6 |4 lmov ea.Trustee.TrusteeType,TRUSTEE_IS_USER;1 ( c1 m' G! o7 y; Z7 P% @9 G! P0 Dcall @f ) j+ ?+ x# A9 k0 T j9 `db "CURRENT_USER",0- y7 ?8 y4 j7 m4 K& [ @@: & W$ m8 k" o- F+ M2 ^pop edx - E6 V! C5 n) T- y1 l u1 G; }mov ea.Trustee.ptstrName,edx) b% g! P( U' g4 S' N4 x invoke SetEntriesInAcl,1,addr ea,pDacl,addr pNewDacl 1 {7 w7 y5 m/ Acmp eax,ERROR_SUCCESS % | e4 s% u) T! G! fjz @f1 u# h% O1 U! s# @ jmp OutSet8 e, |, x3 I, A, J1 l @@: * y- r5 V6 E% x6 j! Sinvoke SetSecurityInfo,hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION, NULL,NULL,pNewDacl,NULL 8 X( e5 _! Q# f% P) J+ O* }, t. l! tOutSet:! G) X' w3 J/ h( E4 t$ M cmp pSD,0' Q' o7 g5 ^. d/ s; P# X: C jz @f 9 }1 X- h- Q" tinvoke LocalFree,pSD : S2 K" b2 f+ g/ c: P m) X@@: n+ y/ n8 J- s' b( D7 X9 f3 scmp pNewDacl,0- g/ w, L1 r. r5 d' K. A: r& P. ^ jz @f4 }& j" E( z7 }& x invoke LocalFree,pNewDacl , B; x, w3 a8 r5 U8 I( D6 X& o, O@@:" J7 T* j0 H7 {& R, B3 e- R ret5 v! p! {8 c" j6 N) Z0 P SetPhyscialMemorySectionCanBeWrited endp& b7 |6 b2 f% z6 t4 { 7 A6 K4 n% s) A8 sMiniMmGetPhysicalAddress proc virtualaddress:dword x, w) V# P$ a/ q: y mov eax,virtualaddress3 g& v9 S$ ^) T2 I cmp eax,80000000h: P0 J, L8 v# k/ ~" J jb @f3 m6 Z% W/ D' B% Y2 T cmp eax,0a0000000h 3 @. H8 Q5 d) S8 C, \9 C4 }* k4 W jae @f & F# l9 u/ l: o- N; s and eax,1FFFF000h5 A" I, F7 B5 m. u ret; X5 u4 R8 z" w5 M+ ?; H1 f5 F8 w @@: , U9 A" D! r+ Y+ q mov eax,09 F& M) k5 B9 `4 w8 \# v' P! L ret: y! H& y8 z" [ MiniMmGetPhysicalAddress endp2 x0 j3 V* n$ v+ i1 V 8 i5 d. `4 F1 H& k9 Q" k+ _8 mExecRing0Proc proc + g3 p& t# u _: C+ |+ {; l local tmpSel:dword 1 q0 m$ M% K+ E y: ?, `local setcg:dword" n4 {3 R! Y* h. R9 e0 }2 k+ V. a$ V local BaseAddress:dword - Q5 l8 P O( E1 F% e+ B: alocal NtdllMod :dword " ?9 a# y* e: n3 E Hlocal hSection:HANDLE 0 D, R/ X* f) Clocal status:NTSTATUS p! A& E% Y1 M local objectAttributes:OBJECT_ATTRIBUTES - \- M! y S/ plocal objName:UNICODE_STRING E" P$ g2 R3 o1 @, \/ _# b. r! Z mov status,STATUS_SUCCESS; " @# m8 n6 u# ?' w9 {% b" p0 O( y sgdt GdtLimit1 G9 L% g+ x" ~1 x; D- w- z invoke MiniMmGetPhysicalAddress,GdtAddr% ]1 j2 Z) P, `/ e1 i mov mapAddr,eax, ?# Z" j% P5 V test eax,eax & w: z/ @7 J1 V) s3 P/ zjz Exit1% A9 R# m7 j0 u& b) f+ K a. | call @f* j4 v% l8 _# o; ~+ R$ p% ? db "Ntdll.dll",0 / I- z6 |* B( I4 i. h! E@@: / \9 u2 W! L; Ncall LoadLibraryA ( b% {8 W' `" H. Xmov NtdllMod,eax / `6 P# C' ~# B5 U( r) d& S4 o6 f% P. U- \) Q* U7 c5 x lea edx,objnamestr3 {7 L7 a9 I. N mov objnameptr,edx1 ]( |8 B1 s: b3 c1 ~0 ?0 J lea edi,ObjAttr " l- ]& v8 Q6 U0 V5 b; Yand di,0fffch ;align to 4 bytes,or ZwOpenSection will fail& T, @ J( @& s. C4 o1 j push edi ;edi->ObjAttr1 k, p4 i, h. f8 ? push 24 ;length of <\Device\PhysicalMemory>! X* y, x# b, [( @6 p/ F pop ecx 9 P' j4 S* o3 L# X* O$ s0 O& x3 Y; mpush ecx 7 _3 Z. y, Q0 ^5 x x' ]xor eax,eax4 ?6 B2 `% D' l$ u; B8 | rep stosb ;put ObjAttr with 0 $ g6 W, P# n- g/ a4 _pop ecx6 I4 J. x* \( X& _5 j pop edi. P% y* K# x% p mov esi,edi 7 a/ I8 {! F R% S7 ]stosd 0 ^/ ?: r! Y+ J; w* E! smov dword ptr[esi],ecx ( [, ~* K; T8 [stosd 4 d+ L; n/ A: j( P- b4 E: k" k lea eax,[edx-8] ;eax->objname 5 v- s& g& v- a4 e' estosd ;ObjAddr(18h,00,00,00,00,00,00,00,offset objname,40,02,00,00,dd 2 dup(0)+ U9 Z) X' z# L) [* c mov dword ptr [edi],240h9 A. u4 P' N% U% f0 G+ k 3 O ~0 a) r5 K+ ~, ~$ bcall @f 0 ^, U S( y' c8 H, ?db "ZwOpenSection",03 ?8 s* O2 s9 t5 \% j% [ @@:' o* U$ `& G7 J4 i' ?% a8 ? push NtdllMod5 `+ x! l4 u* V$ ~# l call GetProcAddress + A2 Y9 K; U; y: [9 t) bmov ebx,eax ;ebx=ZwOpenSection - u9 v. G1 u' L# o) g+ d: F( v 0 w/ @, O" R% Spush esi ;esi->ObjAttr : S1 H, k8 d* k( Rpush SECTION_MAP_READ or SECTION_MAP_WRITE 1 n) B! v: d# K1 Z5 O5 u' C0 plea edi,hSection( U3 m! L& S4 P# J push edi ;edi->hSection; y& ?3 } @1 `7 Y$ D4 P1 L, Z call eax ;ZwOpenSection(&hSection,SECTION_MAP_READ or SECTION_MAP_WRITE,ObjAttr)- ~% M% _7 u. r: n0 p& _ * U( _- g7 }0 g' F7 |! emov status,eax ; ?0 g7 u: z, a. D9 S' e* b9 rcmp status,STATUS_ACCESS_DENIED ! N5 F' G: R% A c, G j% |( njnz AccessPermit - J0 @1 H* |: O! Y# U1 amov eax,ebx $ z8 q- g* G% b9 o6 t; u 0 o0 g( ?/ ~. E" b) i8 ?+ v) Vpush esi ; f- v9 A0 v# B3 w7 h% o3 opush READ_CONTROL or WRITE_DAC - {& p! C$ c0 O' H* o; d% H% @ push edi % s6 K% x1 C9 E/ O7 |4 U+ kcall eax $ \* _5 @3 O7 N$ P5 c: O$ P 7 |& k% F( z- r2 b0 Y. Imov status,eax 4 r) u; R0 L9 h( U+ minvoke SetPhyscialMemorySectionCanBeWrited,hSection ' R3 L' [2 l" s ; j* Y- ^/ A. A! @& Wcall @f/ Y; }( T8 Q; t. b8 g% @# u7 ^) y db "ZwClose",0 : ~# B) d2 q. W! ~. b! \@@:: ]- [* H& y `7 G: U% W push NtdllMod* J/ Q7 P9 g0 O! y+ q8 i, r call GetProcAddress) {% t( m% L$ U! ^/ Z3 D # K" c" s4 a! t. Y |push hSection * P: `9 c2 w3 r( Qcall eax ;zwClose hSection ' H% z/ x: g' `1 |* c4 k0 F0 \1 W mov eax,ebx; C# F& } y# q, Q+ y4 J . O6 U3 q' K+ b6 r lpush esi 8 K" O/ L6 ]" n4 u0 [1 U9 jpush SECTION_MAP_READ or SECTION_MAP_WRITE ( C, @# @+ e( X6 Qlea edi,hSection 3 Z" [6 T2 `* S( v( A4 Hpush edi 6 E M1 h1 C& j2 t' { call eax 0 D8 F: v9 G4 E4 J* U* [mov status ,eax / E3 m" p! ?* k;status =ZwOpenSection(&hSection,SECTION_MAP_WRITE|SECTION_MAP_WRITE,&objectAttributes); 3 A7 G# I! {$ z- N AccessPermit: , f( s+ [2 }. G) _, Y I, Kcmp status ,STATUS_SUCCESS 6 f( k4 j' z4 y8 ?+ { jz @f " A! L1 l. s* ~' H8 }2 \;printf("Error Open PhysicalMemory Section Object,Status:%08X\n",status); $ Q! i: _; o! r/ ?2 B/ I, C;return 0;( T$ D' e8 F, ^$ Z& Q/ g mov eax,0 / E3 n4 p1 j* v0 ?4 X2 Oret" K* E) A. t2 g: O8 Y @@: 9 J3 | i6 e1 p; ~ P movzx eax,word ptr[GdtLimit] 8 `) I9 U. b3 D" Kinc eax J5 C) [( B Y& d" w5 ]invoke MapViewOfFile,hSection, FILE_MAP_READ or FILE_MAP_WRITE, 0, mapAddr, eax ' l' ]0 h6 r# j) e3 j mov BaseAddress,eax' F8 ~0 ]0 f# X$ a( k cmp BaseAddress,0 . K% [9 }% u5 ^! _ Kjnz @f " L( A5 Y( b; k7 A9 X( ];printf("Error MapViewOffile:"); . `( B; `8 Z& d# C; Z. K2 [% urintWin32Error(GetLastError()); return 0; . \3 T' B9 ^ s9 { mov eax,08 @: q- a6 k# n& Y1 l ret * D6 o1 i; ?) |: N" l1 l@@: ( S" y. f6 k( g5 z g5 G$ q mov esi,eax ;esi->gdt base : d# A, \# u: s, [& a5 x4 Kmov ecx,3e0h ! ^- m1 J* i6 ^9 P0 j6 U7 emov eax,GdtAddr 9 p. }2 k$ H z# q* ]9 G: v/ t! b.if dword ptr [esi+ecx+2]!=0ec0003e8h 2 b4 V% H' H) d" q- {" ^mov byte ptr [esi],0c3h . |+ f0 ] W5 N0 O1 m/ O: A7 L 0 g, Z5 E, u) T% ^' Dmov word ptr [esi+ecx],ax ) x: }1 |* l3 |( ~# p! \shr eax,16 7 L2 c: {8 m* T Z% h, H; [mov word ptr [esi+ecx+6],ax & Z$ ^) G5 Z! q0 L5 Hmov dword ptr [esi+ecx+2],0ec0003e8h # n6 l D# ~% p' S0 a# @1 S* F: h V. g mov dword ptr [esi+ecx+8],0000ffffh% z: A* |' w. F/ y; i' A' } mov dword ptr [esi+ecx+12],00cf9a00h ) \# B [1 l& }5 f, _" W! y" ?.endif1 D# @& b) ^: g3 i* a3 J* f2 t" [ * b. F2 M. Q& ?" [8 g mov setcg,TRUE* V e( J$ x( ?% ^ V cmp setcg,0; n1 G. S& ^1 u7 ?' l jnz ChangeOK , @6 ?0 X" v3 V2 \1 p! y: F% M+ Wcall @f! P. C: M, Q& O db "ZwClose",0- @5 [1 u; ^& W$ a8 V% d: t @@: ( e( R0 w# M: Mpush NtdllMod 3 w" O/ W, g& @, o: d0 l Wcall GetProcAddress ) p3 b9 @5 E, x5 _1 Wpush hSection * h' q9 Z1 v1 F# ]call eax $ M0 a O2 d+ T* Vxor eax,eax7 _ k3 d: \6 T ret; l' J' V! g+ ^ ChangeOK:" l K$ j9 b- y2 p, p, d and dword ptr Callgt,0 , a- h$ b' O$ L8 L3 V7 i xor eax,eax }/ x; Y; G' ~& D: w) ]- O3 _2 `3 a1 j mov ax,3e0h5 w: B! B3 {1 u# v or al,3h ! @. u' r; [! h2 Smov word ptr [Callgt+4],ax . |5 C3 j( y3 W( M4 {5 { ;farcall[2]=((short)((ULONG)cg-(ULONG)BaseAddress))|3; //Ring 3 callgate; 0 F0 `6 n, u4 r: b lea eax,_Ring0Proc 0 c- {5 Q5 t# G( v9 e;invoke VirtualLock,eax,seglen 5 y6 y% N. s' Z: a" Etest eax,eax- N( G' }) c$ K# f! \, [5 L+ G: K jnz @f 5 k% t1 S+ c, V7 {xor eax,eax% Z3 ]. ` z3 O* V+ i+ o ret 5 @9 } `: ]7 i6 {2 y" s' e@@: , |$ N8 M, ]4 i9 C" k- s9 q7 I) iinvoke GetCurrentThread, N" s" @& e$ h, a invoke SetThreadPriority,eax,THREAD_PRIORITY_TIME_CRITICAL / u2 r" g. D+ k: l Y 0 ^/ K0 e6 _( H invoke Sleep,0 # q, @3 e- n* }& U% V+ lcall fword ptr [Callgt] ;use callgate to Ring0! # [; O% \/ O. h- R* D* q;_asm call fword ptr [farcall]" N$ w1 ~+ `% }2 k, `2 f _Ring0Proc: ; Ring0 code here.. % \9 N6 x6 b1 C) U: d9 h6 omov eax,esp ;save ring0 esp4 N/ b1 J2 h k) ]4 z# g$ V mov esp,[esp+4];->ring3 esp 4 R; G+ y# n* S8 ~- zpush eax # e7 Q7 E( o0 ~ mov ebx,offset stIDEINFO; m# C c# L6 l' h* f assume ebx:ptr IDEINFO $ a a( N# v6 _5 P;********************************************************************7 T9 T$ q; J9 R: {; @ ; 等待硬盘就绪1 q" C7 W$ v7 x: L- v' N+ K ;********************************************************************2 T! G/ {" p* n' }: E/ B7 f mov ecx,10000h 7 U4 M, {+ [7 H0 L0 J5 m; T: u r mov dx,01f7h4 d5 _/ K# c& j @@:1 B: X9 s0 E; N( _ in al,dx/ i \4 Y- o3 P9 g6 g6 X" v9 M cmp al,50h ' c" E) l# v2 p$ { jz @F - a% \/ G0 ?4 Q loop @B 1 H8 O# w' } b M) u jmp _II_TimeOut1 o+ a2 h, k7 S7 e3 h& `7 i( W @@:6 O) g; T$ w" g/ ?# }) T ;******************************************************************** * |2 l. H' O+ Q: u$ C; 发送命令 ' u( Q7 f+ w A; 如果向主控制发送命令,则端口为 1f0h-1f7h 2 p" M2 j# L# n3 C7 ?, l; 如果向副控制发送命令,则端口为 170h-177h . L ?) K: X" x4 ?; ?9 l$ E; 1f6h 如果要检测的设备为该IDE接口的主(MASTER)设备,% q8 @6 Y- j" ]# c ; 那么发送 a0,如果为从那么发送 b0/ T) _7 ~) H5 [) Q$ f ; 1f7h 如果要检测的设备为 ATA 设备那么发送 ec ; H1 ~' q1 j+ x; 如果为 ATAPI 设备那么发送 a1& F8 z9 M% F* j. D( I% Q$ t$ { ;********************************************************************& U% a h6 y4 C2 \ mov al,0a0h ;Drive 0,Head 0 B: c4 a! n7 c- ^, K7 w; h( M1 O5 X6 L mov dx,01f6h ;Drive and head port & J4 p" D5 H: u: {' \ out dx,al 4 |0 A3 F% s* x, _2 v* `: d$ I- f- W" H2 A' ~, w7 ]9 L mov al,0ech - d5 k6 `* u) U5 d/ R9 S2 d+ i% ? inc dx ;Command port* h* @& @4 r- W! _2 j out dx,al+ @! J% c8 Y+ c4 E; Q9 Y ;******************************************************************** % C8 |# q$ r% i' \5 ]: x$ o; 等待硬盘就绪3 @. r2 _8 X& v& u8 v1 S7 x- a/ h { ;******************************************************************** + T- j6 I4 S+ s1 ^* _ mov ecx,10000h ; e7 b' _& w1 a5 Z; K, i* o, ` @@: , I5 k; R$ g7 S in al,dx;1f7 (r-status register)' \* C4 M: B$ X3 q8 t! \+ j5 l cmp al,58h;(driver is ready ,and seek complete)' x; v. v& w' K# e# n/ j2 @0 [' T8 C jz @F 6 @6 F: H: L7 R8 j loop @B- U/ l! s& O% A jmp _II_TimeOut& ~# x2 Z/ \7 Q6 }+ l! ]; S& K8 `* S/ D' P @@:/ x& [3 `1 @3 ?0 J3 ^% B ;******************************************************************** / T: v2 [3 n6 R( ^& U2 a# n! t/ g3 @; 将返回信息读回 R2 w0 { n0 |& r0 l; 注意一定要读满 100h 个字长 - O; l I3 v" [;********************************************************************. P" k: |+ ]/ d2 Z. ?9 n! {% _ cld : }1 i4 I6 \# M8 E mov edx,01f0h;data port - data comes in and out here5 M" k( z0 ?- e mov edi,ebx / e7 D7 ?9 n1 X mov ecx,0100h 1 A; }' ?+ c$ V7 q# [ rep insw 9 Y d: o5 q3 W: `/ J;********************************************************************# T/ g- T) L9 _! ^6 x) Y ; 返回的信息中,型号、序列号、版本号为字形式' ]) v& e* w3 N K1 x ; 需要整理到字符串的形式' ~1 B6 H% ]* q6 T) h, e4 p( H ;********************************************************************: g2 I9 [+ C) L( }) F; V- _/ N lea esi,[ebx].sSerialNumber8 ^- t; P0 Y+ f. ? mov edi,esi . \: E7 p) Y7 ~9 l# Q/ U mov ecx,10 . o8 ^3 [& \; G8 L @@:) i+ }& h. @* }' t/ _& h K, g6 _ lodsw' B/ v0 A% ?2 A6 o xchg ah,al * V# F9 x- h; ^6 ?6 G stosw 4 a' A. j; T/ ~% Y. V) [ loop @B* ?6 D& q7 n( w$ T; H 6 t0 L" e0 p1 ] lea esi,[ebx].sFirmwareRev : C7 n7 |% {2 u9 Y: `" q C3 D mov edi,esi2 i! ]9 C) `" t mov ecx,241 B% @6 o8 l3 x4 B! X @@:' u$ r2 ~: @( X+ U7 P0 S+ y8 K3 [0 y lodsw 5 S) i. O( K. r xchg ah,al, q q8 S- i/ r2 e stosw9 r% Z2 u& t/ o1 `8 `# b% {, z r+ O# U loop @B 8 v4 \& d0 y% ?/ y l_II_TimeOut:+ |( `6 z0 ^$ O, `! r& E5 y9 @ d assume ebx:nothing 1 C, E5 b. O5 f) u- J ' |+ M, u R r9 w" c0 U: Ypop esp ;restore ring0 esp & p/ Z( ^; G1 o8 p% j1 Xpush offset Ring3 % P3 x @! I$ m A% n- x$ Uretf 0 f, Z: M% P+ ^$ SRing0CodeLen=$-_Ring0Proc3 A, j$ a# j0 | V) Z 3 G6 ?5 L" `" k% _ Ring3:! f; L" s& I0 t7 T3 k invoke GetCurrentThread4 M- w' J0 k9 J, Y, N invoke SetThreadPriority,eax,THREAD_PRIORITY_NORMAL 2 v* V; r* m5 b g, p 2 E, ~7 J/ J/ G; ~) O ;invoke VirtualUnlock,Entry,seglen 2 B- H1 z: k/ S; y 9 f/ d7 l* E: G! ~& zcall @f 6 l+ s" h n: {1 X6 X& k7 Sdb "ZwClose",0, ~3 [0 ?! P2 R2 a# \% V/ c; T, x @@:7 `9 h Q3 _ U7 o push NtdllMod$ L- w- @$ I- Z0 J# m' R9 o8 H call GetProcAddress % _7 R4 o9 v4 \3 U6 n @* ?push hSection7 F" b8 S# X- z: P; N call eax/ y; p' n% l; R' z3 w9 L mov eax,TRUE 7 _1 [# e8 n0 C% Z* d0 c7 h$ s: Tret) z1 p. W; }) {3 ~% u! Q ExecRing0Proc endp ; a4 M1 Q& j) y2 q. K- `& Y; U8 X! b: K; c/ d1 _ main:* ?7 X- I( ^1 t+ u3 Y assume fs:nothing/ W+ f* |1 z5 v/ e/ p push offset MySEH 9 e* N+ ?( U2 y5 C% rpush fs:[0]) ?1 g1 u# K" N e1 z mov fs:[0],esp3 z1 C: s7 l: j- D/ t+ w mov OldEsp,esp ) d* ~8 _; [' Wmov ax,ds ;if Win9x? 6 O$ @4 L* n2 H9 N9 k1 _6 itest ax,47 l7 f% T, L$ O/ m" I. @9 `) E+ h jnz Exit17 s% u+ h9 z4 N* M5 V7 i: u* l# g invoke ExecRing0Proc: R* O9 z$ Y6 w0 M ; l% a& T/ x; R& Z' `) Y% a2 n.if stIDEINFO.wNumCyls6 \+ m+ d+ y* L. K lea esi,stIDEINFO.sModelNumber2 N& B$ n9 Z" R7 {' b mov edi,offset szModelNumber ' a- _: P' } n- C( D* ^ mov ecx,sizeof stIDEINFO.sModelNumber. \" h) H8 X K+ m$ h rep movsb 0 n! G: t9 }3 v3 ~* v- G k% [# }0 a8 M/ J* s# \ lea esi,stIDEINFO.sSerialNumber2 L6 a# x+ M: F: v, m1 d mov edi,offset szSerialNumber- E; \. |6 W3 B9 U- m% X8 c) V mov ecx,sizeof stIDEINFO.sSerialNumber' O4 r8 H( k0 a% a rep movsb+ X5 o9 x' R% C8 @" {) p* q9 p % L% K9 B! f1 d2 P4 J, | lea esi,stIDEINFO.sFirmwareRev # [; J" c/ i3 D% T' |: h mov edi,offset szFirmwareRev " @0 w6 }$ ]- Z( p0 ~ mov ecx,sizeof stIDEINFO.sFirmwareRev5 @% _2 d& N# z( N' b/ |: E rep movsb$ B4 X5 g# j6 g) A, m6 Z' K+ y* L% s4 Y ; _+ X0 y3 `1 D/ z3 s movzx eax,stIDEINFO.wNumCyls; j$ v/ P& w2 U% w9 ~- I' k+ ] J4 Y movzx ebx,stIDEINFO.wNumHeads: ?& C" X" Y0 D+ H) O' s movzx ecx,stIDEINFO.wSectorsPerTrack 8 b/ ~* a8 e, a1 s movzx edx,stIDEINFO.wBufferSize 7 p0 p* d/ h( g invoke wsprintf,addr szBuffer,addr szIDEInfo, eax,ebx,ecx,edx, addr szModelNumber, addr szSerialNumber, addr szFirmwareRev : [: q% P2 R9 e2 ~! t" i mov eax,offset szBuffer$ V6 g0 ?; M: w& B0 T .else . A% L" c# q: ] mov eax,offset szErrInfo) h- J4 J! \8 D( I .endif) U# z9 V8 P. I2 o, Y7 c+ t @@: & @# |! V1 N1 ]7 \( Sinvoke MessageBox,NULL,eax,addr szTitle,MB_ICONINFORMATION or MB_OK5 [. N" W8 ^9 K7 h2 R Exit1:3 R" Z3 k% I. ]% B5 n0 d. @ pop fs:[0] ! y/ E- R) ^$ b; {, Q" hadd esp,44 l" b: |; b$ D$ ~ invoke ExitProcess,0* Q- H1 U0 @# ?6 p* d ]! m* o 7 }6 s+ ] Q6 M; Q MySEH : T8 F" }, v# m% A% I; ^# D: y5 Hmov esp,OldEsp / A4 \4 |' P1 z7 F/ W, I: d, d2 cpop fs:[0]8 p" i8 o/ L7 ^/ U add esp,4 s/ q9 L v9 _invoke ExitProcess,-17 l( t/ ]$ M& {* I end main 8 u: f' N; U/ C( ]8 { 6 _" ?8 q/ \: c
[此贴子已经被作者于2003-11-2 18:14:02编辑过]
) \+ J( M7 i& }+ C
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩
bigfoot 该用户已被删除
2
发表于 2003-11-3 16:22:00 | 只看该作者
呵呵,ExecRing0Proc 这段程序甚妙,先得到gdt,然后构造一个调用门call gate's ,使程序从用户模式(ring 3)进入内核模式(ring 0)。进入内核模式之后,就可以没有限制地对系统干任何勾当。这段程序确实为高手所为,在下佩服得紧。
! M/ d3 e2 l4 i5 l. w: v至于读硬盘序列号之类,只不过是在内核模式下的一个I/O应用罢了。  n  k# @5 k# j9 O! m8 V$ N* `
其实在NT/2000下读取硬盘序列号只要打开\\.\PhysicalDriveX(X:设备号0~26)设备,然后用DeviceIoControl()就可以读取了,不需要绕ring0这么一个大圈子5 d& c! ^  I) W% i2 p

; r4 P- ^3 C9 q这个程序也可以C语言实现,不过中间必须嵌入几条汇编的指令,如sgdt GdtLimit% B6 V" y0 Q% h
但还是用c来写更方便,例如:
- Q, h. n: A2 W  n* H5 u- bcall @f
' H3 O4 B, T) S/ s7 i9 ~6 H4 Ddb "ZwOpenSection",0' x0 Z0 b) ^4 f: H: l) K
@@:) A) @/ x7 N6 d* s! ~# W- Y
push NtdllMod
: i6 _) M0 Y' z; Vcall GetProcAddress  \  \( H$ j" w7 D
mov ebx,eax ;ebx=ZwOpenSection( L5 N& ^( s6 P) N; m
push esi ;esi->ObjAttr% R) [3 g5 I4 P1 b) p( f6 Q7 W( X3 D
push SECTION_MAP_READ or SECTION_MAP_WRITE7 s7 ^+ J) {; ?
lea edi,hSection5 ?# F/ a8 i. w& s9 e
push edi ;edi->hSection
9 g! x/ r0 m: @6 Z  g& z! \9 ecall eax ;
- m3 p5 S5 T- ~6 p# z# ^& \4 j) Y# B8 a9 U, s' N" V
用c的话只要一句就可以了3 ~9 Y7 `+ j0 h. q+ G( G
ZwOpenSection(&hSection,SECTION_MAP_READ or SECTION_MAP_WRITE,ObjAttr);( j" ]6 R( m% f+ t. J  x2 T
因此懂汇编,然后用C/C++编程,是成为高手的捷径  @  _- l3 E$ K! X+ @
% n; ^! K% j* m' L
[此贴子已经被作者于2003-11-3 16:46:50编辑过]

! N* m: \4 l& r$ V5 k4 \6 X9 |* {

该用户从未签到

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

该用户从未签到

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

该用户从未签到

6
 楼主| 发表于 2003-12-3 15:33:00 | 只看该作者
很久以前?
* }/ B* @1 h7 p1 ?不是吧,这个是 轻描淡写 编程论坛的斑竹写的
fyer 该用户已被删除
7
发表于 2003-12-24 19:21:00 | 只看该作者
看到过的。

本版积分规则

关闭

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

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