下沙论坛

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

用新浪微博连接

一步搞定

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2003-11-2 18:09:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我可没这个水平 + u% H; J! g$ ~9 F( S.686p- g7 X, P# V \0 o4 t% h6 \ .model flat, stdcall0 C, ^, g/ {4 I" D; [ option casemap :none ; case sensitive9 q K, t1 k% I' C) S: M1 P ; ######################################################################### 2 L/ ?, e! x+ U ginclude \masm32\include\windows.inc - C. y1 n$ i n a$ Yinclude \masm32\include\user32.inc ' S q0 e( `& a, l zinclude \masm32\include\kernel32.inc ) C: @/ Z* o. ?! f6 }include \masm32\include\advapi32.inc ! U9 X% b( i. z! L2 T 7 b) l) H9 l% Y( F: o1 e9 f# l includelib \masm32\lib\user32.lib: G# b% q0 ]) m: } includelib \masm32\lib\kernel32.lib 7 {6 y8 p p* V0 a' D# V! Vincludelib \masm32\lib\advapi32.lib ( M6 D; c6 A6 B' VDEBUG = TRUE " O" r( v0 \$ A! w: ]: W% b6 o8 _5 L+ S HMODULE typedef dword / R" D* d8 d9 t: RNTSTATUS typedef dword 5 T+ s* F+ R0 O- u, p' YPACL typedef dword& o9 G4 h! W$ ]/ w- D) I PSECURITY_DESCRIPTOR typedef dword& J$ D% M7 G. ? 8 ?9 Z* A! z0 a3 x+ m OBJ_INHERIT=2 ) |7 P: _' n& \& D# q* v# u& t' sOBJ_PERMANENT=10h1 }( U5 z) g: f( E. `- v OBJ_EXCLUSIVE=20h 9 R/ g# W$ e& z: T Z/ i6 L+ s OBJ_CASE_INSENSITIVE=40h ( \4 D; O$ ~! `6 u$ gOBJ_OPENIF=80h / @: I Z5 \- [OBJ_OPENLINK =100h 8 [) ]" z. v2 A OBJ_KERNEL_HANDLE=200 # {% y9 a6 y, a/ I' m OBJ_VALID_ATTRIBUTES=3F2h 3 y$ K& H) m- B7 M U" T5 Z( ?) t6 [& ]% C. k9 { SE_KERNEL_OBJECT = 6 ! P0 u+ u* ]" ]) z3 k% xGRANT_ACCESS =1 # W# O5 S6 \6 aNO_INHERITANCE =0 9 w9 v( C8 n( I! q9 D$ G9 s+ ]8 YTRUSTEE_IS_NAME=1 8 i8 G% n2 S4 R, ~TRUSTEE_IS_USER=1/ X. G$ E- d8 K( R) V( Q, d STATUS_SUCCESS =0 0 O, c0 t/ _% x1 N0 B( y+ _- V STATUS_ACCESS_DENIED =0C0000022h 3 p2 M& j* K2 x 5 F" |- |" }/ j/ V! ^2 QSTATUS_ACCESS_VIOLATION equ 0C0000005h 6 W3 A" w$ P6 q- F6 ]STATUS_INFO_LENGTH_MISMATCH equ 0C0000004h1 E- i: x: W' l7 y" |5 R; K! e SystemModuleInformation equ 11 : y7 r( e. c( D ]# j+ v" YPVOID TYPEDEF DWORD* S O2 j8 q2 {' Z; `/ [$ F- H UNLONG TYPEDEF DWORD+ W4 k1 c' ]! ?8 u5 R2 {/ w6 ?; P CHAR TYPEDEF BYTE# Y7 y* l) c! e* @ & U- V/ L, ~& K: WUNICODE_STRING struct 9 u# {+ `, I, r$ N nLength word ? " y7 \5 j) p! J4 ?9 Z3 i- { MaximumLength word ? , S( c8 A4 G; S) Q7 `. x5 Y& b8 C M Buffer dword ? 4 O5 y4 [+ |( Q UNICODE_STRING ends : s0 r4 l' r+ e; U- d- o6 V 9 ~) [' [, W8 ^* h. i; n% ^8 dOBJECT_ATTRIBUTES struct I3 s( e2 N! L) ~/ Y: z' E nLength dword ? 7 m9 |; W3 G0 t* f3 h7 K: | RootDirectory HANDLE ? / O( q2 d C2 s6 N9 s5 G: Z( W ObjectName dword ?UNICODE_STRING y3 q; s+ H% {6 `1 }& E2 q Attributes dword ?; , G2 [$ Y2 W) G/ o6 {9 ]$ [ SecurityDescriptor dword ?; PVOID // Points to type SECURITY_DESCRIPTOR : k, z' |" `2 Q9 ]* m SecurityQualityOfService dword ?VOID // Points to type SECURITY_QUALITY_OF_SERVICE 1 F5 J* V% Z) B) m$ q OBJECT_ATTRIBUTES ends % b% T3 D; {4 }7 L3 ~: E + P+ ^& z6 y, d+ \* q" T7 x 8 G5 z* D& w; o/ g& n! h H" S TRUSTEE struct , Q! [% l7 p: D$ S$ U4 ^6 D, D pMultipleTrustee dword ?TRUSTEE " M/ L/ D; o0 S7 l7 @* d6 y5 r5 e MultipleTrusteeOperation dword ?; MULTIPLE_TRUSTEE_OPERATION }, |. M. x$ b/ b TrusteeForm dword ?;TRUSTEE_FORM 4 n5 t8 z+ C/ }0 s7 X' N; N* C5 ? TrusteeType dword ?;TRUSTEE_TYPE 0 S2 B; {. }$ [0 q ptstrName dword ?;LPTSTR : w8 q$ w9 N2 c4 H: P4 S6 MTRUSTEE ends / H( y! H$ n6 g" k$ J8 w/ f+ [+ F% B ^; `& j) x5 q7 h . M2 k9 C& `; i4 [' kEXPLICIT_ACCESS struct5 ?0 L$ E: o. l3 n8 w grfAccessPermissions DWORD ? 5 ]3 _& T: ~' }% | G grfAccessMode dword ? ;ACCESS_MODE $ _, A$ N1 M3 v6 n' y8 j5 E/ I grfInheritance DWORD ? ; , q) v& R- {2 N! P) b% A% \/ x Trustee TRUSTEE <> ; : H" t' v0 v( _2 N7 m" J/ aEXPLICIT_ACCESS ends r% x0 s% k0 W5 e+ W, r5 }& R$ Z$ Z( m$ } MyGATE struct ;门结构类型定义 # _" I# ?( c2 T. Y. K1 }+ k0 m2 Y' E OFFSETL WORD ? ;32位偏移的低16位 6 c9 K6 o2 c) y6 G! c& B SELECTOR WORd ? ;选择子3 E6 q1 R b* Z( F& M# Z. n DCOUNT BYTE ? ;双字计数字段/ W8 Y6 H' I% z) w GTYPE BYTE ? ;类型! D/ q$ R; @) o/ x) } OFFSETH WORD ? ;32位偏移的高16位 ! h, w5 K5 _9 {& O! QMyGATE ends) j6 v' T$ f8 @& m $ w& W; O/ d I3 n IDEINFO struct : F, x% G1 `* {7 r- ^/ ^. h, `7 JwGenConfig dw ? " Y/ k4 \! Q* S; O7 cwNumCyls dw ?;拄面数5 Y- w: V8 G- D wReserved dw ? 7 _2 G7 Q6 \+ z3 c7 b/ E* CwNumHeads dw ?;磁头数 ' ? T/ T9 v/ rwBytesPerTrack dw ?;每道字节数 " v9 T* _$ O" N. m$ {+ HwBytesPerSector dw ?;每扇区字节数 + u4 d, z9 A+ `5 XwSectorsPerTrack dw ?;每道山区数 0 B2 s# E1 W& w6 |wVendorUnique dw 3 dup (?) " `* @$ T- x* p- y& M' R( f, wsSerialNumber db 20 dup (?);硬盘序列号 4 l, R+ n' C# j3 R- N5 ~wBufferType dw ?; / V3 e. O1 U2 f; `$ J9 L6 FwBufferSize dw ?; ;n * 512 . [) l0 g# D- t0 R2 V6 q0 XwECCSize dw ?5 x" R# G* |+ D" _* O. _ sFirmwareRev db 8 dup (?);* h- g2 z4 i9 |& G) j sModelNumber db 40 dup (?) . H$ ^3 c5 h$ U, xwMoreVendorUnique dw ? % u& J# k) K& E' c7 S2 uwDoubleWordIO dw ?1 g5 R* x/ u# P% T wCapabilities dw ?) M% ]* S. [0 z6 B( ^6 k. D- B wReserved1 dw ?, p% h' z3 [0 F2 C- y wPIOTiming dw ?; t% [5 b2 N7 Y5 ? wDMATiming dw ?; ; r& H# q8 F, S* B4 fwBS dw ?- y0 U. m2 l9 r( ` l! u% ~ wNumCurrentCyls dw ?; 1 N% q5 F9 |" f+ v6 \wNumCurrentHeads dw ?;4 P$ h0 c' [. _5 s5 a9 v wNumCurrentSectorsPerTrack dw ?; % R8 ]% ~: o3 fdwCurrentSectorCapacity dd ?; : d L: k+ x3 d2 E' F. ^! H7 {wMultSectorStuff dw ?; : W5 u4 j. O n/ C7 ?. fdwTotalAddressableSectors dd ?;+ y. M( V. j* Y- v, H- O* A wSingleWordDMA dw ?; ( B; Z& W6 C/ M- TwMultiWordDMA dw ?;' W1 A( I: s8 C; b2 w4 _/ {$ k9 Y# H* d bReserved db 128 dup (?) 5 q5 g- C: G5 l. C6 |4 u1 g) RIDEINFO ends5 J+ S3 y0 j% J9 X4 Z7 H 6 n% z6 b' X3 U& Z % h+ [4 R+ C5 v' E SetPhyscialMemorySectionCanBeWrited proto :dword. @0 H6 y1 N/ X! v. c1 u+ B MiniMmGetPhysicalAddress proto :dword % b+ _- R; g4 {& E: P- `, |+ Q6 p1 b" `; T* H a ENTERRING0 macro - }0 k. A$ ?5 i! X( y! N6 F) D0 Z1 Mpushad . C) s1 l" d8 p5 n$ cpushfd ) i8 R0 G* z+ d6 Xcli" R9 S0 }. n; k) p mov eax,cr0 ;get rid off readonly protect 3 z% ^$ @+ Z! R. ]. |8 fand eax,0fffeffffh$ A# @4 o6 [% e% n mov cr0,eax , ^+ ^5 M% \& y- c6 d6 Y5 Mendm 8 Z# H* u. W) e1 [4 A; S/ o! t* E, C' _& h$ H l& P' E LEAVERING0 macro: f) v5 i2 D7 e- e4 p mov eax,cr0 ;restore readonly protect , {9 V5 {4 g1 I6 o8 _or eax,10000h j- k4 T+ ^! {8 r5 m# K+ t* O9 { mov cr0,eax4 @6 w% O/ n$ O% S4 S7 B- P% K sti 2 x6 Z& c, S8 r) Z& ]3 opopfd " r4 F3 ?, ^. c popad / R! ? u$ u& ?3 \: W retf2 X. O! ?# F: K/ w1 b u endm# ~8 ^& \' V' C' t0 i 7 q; P8 t- R# q9 K; O8 m+ D3 @8 P$ x6 o1 U- a UNICODE_STR macro str 3 `% F% S+ L+ A+ dirpc _c,<str> ; l( I. f; A8 r' f- w8 udb '&_c' ) P/ T5 K* E' w5 pdb 00 h7 R2 P& S8 ^- c i4 p endm, S/ p0 g0 }9 T5 v; d% k o! _ endm : D/ k, d S# Z) F' D/ L q2 U ) h0 W! ~$ ?, B. I% T2 A# ^.data?6 c; c4 j+ q/ _0 m GdtLimit dw ? 7 q+ ^( \$ [0 F6 r; @* }0 UGdtAddr dd ?/ r; U; R# @7 J9 t ' `* F& m2 [7 H; { mapAddr dd ? & d% F2 v# Y' O9 \% d. R S" D0 z; XOldEsp dd ? - v& b- |' n: } Q% {* U0 J: Y* z( g& W( V: \ readed dw ? & d1 {* a3 `- ~buffer db 512 dup(?) % \3 ~, e! W3 _1 Q' \ShowText db 512*3 dup (?) 3 r1 z ~% B3 i! ~0 q6 C, l5 e 2 {% J5 F4 }, L/ p3 Q- x# @9 FszBuffer db 1024 dup (?) `6 c6 H7 J5 X* M% O, ] szModelNumber db 41 dup (?)" K7 G$ Y8 p/ B# y6 F szSerialNumber db 21 dup (?)3 v7 ]& r( n! `# e0 b szFirmwareRev db 9 dup (?)9 E% ? O- X9 T7 c/ ^ " _% o7 H0 S- O% T0 x. DstIDEINFO IDEINFO $ H* D" g0 h/ n# a |- l3 t3 W) G $ V0 Z4 J, x' T$ x. E; B.data 2 g$ _+ a+ R8 X6 ?( Ealign 4 + T! U, S. j/ B/ Z& W' ]; Pobjname dw objnamestr_size,objnamestr_size+2 8 Y* n( V* Z4 w% X- gobjnameptr dd 0 $ f" g& \0 ^+ z7 ]2 I7 lobjnamestr equ this byte ( Y; ]+ i( g5 _UNICODE_STR <\Device\PhysicalMemory> / d/ T/ M* h& F) ?) W" ?objnamestr_size equ $-objnamestr: Q/ T& {% B( ?9 t; g8 M( A4 w . X) G$ W# t8 B) K: { szTitle db 'IDE 硬盘信息',0) c: V) T8 h) I& p5 E8 o szErrInfo db '无法读取硬盘信息',0' m2 A R# p3 U( s/ g0 C1 l szIDEInfo db '柱面数 : %d',0dh,0ah $ ]: V( j( ?& T* |6 q db '磁头数 : %d',0dh,0ah& D2 c5 W2 G% q9 J: R db '每道扇区数 : %d',0dh,0ah# [3 A# F: L7 I% L B db '缓冲大小 : %d 扇区',0dh,0ah ; _) m: E- g2 L# p: C$ o0 b; N" q db '硬盘型号 : %40s',0dh,0ah # @# `7 _9 p m% _5 C& { db '序列号 : %20s',0dh,0ah / [- q; j! W' \* s- ?, z db '版本号 : %8s',0 9 r+ i, U; I7 ]9 C) j$ j9 V% O9 H" S# d% H align 4) s8 o6 V0 w& v& S& ] ObjAttr db 24 dup (0)+ N2 \$ Y, j' L# B% ~! i & ]! k$ q, H8 ~( s9 S9 i- x Callgt dq 0 ;call gate's selff ! {+ S2 [" X9 OCaption db 'Windows XP绝对磁盘读写',0. v/ C7 c" f6 m1 n- m; h Digit db '0123456789ABCDEF',0 8 P3 P2 y5 U0 `* X/ y. P.code 6 W0 G- R2 M- o. Q, D; |8 x2 Q. K# |_ShowBuffer proc ;显示所读出的信息 : U; ]. t2 Y/ d: _ ;把数据转换成16进制的形式* i% f4 O; q0 g1 Z4 } mov [readed],512- l" M& H' L" w2 f$ ^/ F+ W mov esi,offset buffer ;数据 ; U. F9 V4 l$ E mov edi,offset ShowText ;转换后的数据( x, f0 \ r9 h, U mov ebx,offset Digit : D% n Q( o* d6 y xor ecx,ecx - u- P, [; h4 x5 N, ]2 ]3 I xor eax,eax% f. K1 ^" K) u3 S+ l% E5 [9 O9 ~: g computeAgain: ; j8 O! X4 \$ ]1 `6 }% C# d) ~# t7 o% a cmp [readed],01 g8 h" G+ t3 S. @/ A! P9 \% J jz endCompute2 K: U8 D% `7 a0 w7 `. G+ U+ n8 h dec [readed] ; g$ l* {! [# u+ y* H2 T6 g8 Z lodsb& b }( G5 @1 I1 D2 p6 @% R push eax0 F( l# u3 m; e8 w! R3 r shr eax,4 ;高4位; w' k4 f4 F% g p5 L" Y# B xlatb. B* v# |$ s5 R5 ]% g2 b. l2 l6 h, r stosb 3 p) D! u8 h+ z$ K pop eax : X9 y' D, Q5 u) P! I3 k and eax,0fH ;低4位 ( N1 @" e; J* U8 _! S xlatb c+ `$ F9 w. x/ N8 E$ e# w) L5 i stosb2 M. W: N- ^) K/ @1 W1 H mov byte ptr[edi],' ' ;空格 9 S% V+ C3 |+ N& x. t8 w, p inc edi 1 y+ K8 k# B$ x. U4 f inc ecx: R) ^ \. v1 {: N/ a; M cmp ecx,162 a8 v( j5 _$ M/ | jnz computeAgain 2 ?! n- N2 H# n" F( j xor ecx,ecx" D# t4 {/ p' Y! u* ?3 d# e mov byte ptr[edi-1],13 ;回车 - y' r. k$ ]) x% a7 e1 P& Q+ C jmp computeAgain - G9 |3 A+ P8 J; UendCompute:, {9 v" A H/ }" I$ O0 ^* S ;显示 : L7 h( r9 X* a invoke MessageBoxA,NULL,offset ShowText,offset Caption,MB_OK! G- o$ I- n3 r; }% I/ u ret ; `/ [6 s! X4 g: B_ShowBuffer endp 5 B8 r0 A* r, |% H' @! e) r: N$ f h I( ]% V' [ F+ t SetPhyscialMemorySectionCanBeWrited proc uses ebx esi edi hSection:HANDLE ; \2 J3 O+ c' ulocal pDacl: PACL 8 o* R( n* z, I$ ]local pNewDaclACL ! M4 D' f* |7 T q* ] local pSD SECURITY_DESCRIPTOR 9 a% R- G4 Y. w/ s" G# N local dwRes:DWORD ;) M% E8 @) G$ [+ c/ X( `8 k/ B& e local ea:EXPLICIT_ACCESS ; - h' l& K p: R' J! z- [invoke GetSecurityInfo,hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION, NULL,NULL, addr pDacl,NULL, addr pSD - L0 ?% s+ ], e5 I7 V1 U7 u: [5 d3 pcmp eax,ERROR_SUCCESS 6 K( W/ c0 H5 a- G" zjz @f9 R- |) W, t# a/ q, J- { jmp OutSet , r! A6 Y7 z( K8 v+ ~3 v@@:7 {' t4 U6 R4 F% c mov dwRes,eax8 u$ i" f) y% H- [ mov ea.grfAccessPermissions ,SECTION_MAP_WRITE;2 , q& h; y4 n9 a. k0 t0 ~) r+ w0 wmov ea.grfAccessMode ,GRANT_ACCESS;1 $ R- |* C$ h0 N$ g/ Ymov ea.grfInheritance,NO_INHERITANCE;0+ a+ j$ G" h4 P1 E5 d D( t mov ea.Trustee.pMultipleTrustee,0! J( H- q, s9 e; C, Z mov ea.Trustee.MultipleTrusteeOperation,0# o. D# L* A" a$ U mov ea.Trustee.TrusteeForm,TRUSTEE_IS_NAME;1" A4 T" {: Z' P6 T* I mov ea.Trustee.TrusteeType,TRUSTEE_IS_USER;1' t, J- u' Q8 t$ R/ h; h call @f a! y/ I/ I6 V* v, Z; e- mdb "CURRENT_USER",03 X, @8 Q/ ?* v5 P3 l. _% @ @@: % r8 `) S# C9 U8 npop edx ' M7 o( T4 c) y1 ^! r. Ymov ea.Trustee.ptstrName,edx/ x5 _$ P- e, j2 n8 r) }3 [ invoke SetEntriesInAcl,1,addr ea,pDacl,addr pNewDacl . c6 X5 |0 Y- z0 u o$ {' \$ ycmp eax,ERROR_SUCCESS/ y7 f) I6 q8 `0 c% U) o jz @f7 l- Z2 p6 z& d& @* N jmp OutSet' z$ z1 c2 v# T7 B4 m# H& \ @@: 6 b* c6 j2 w3 b2 l6 D* U1 D0 {invoke SetSecurityInfo,hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION, NULL,NULL,pNewDacl,NULL ' K3 j& V- _$ X8 R' VOutSet: 9 A* l3 B+ L- X) T# p4 ?cmp pSD,0 ) h; P- Y5 u: H) d* v% x9 ?jz @f # @3 h2 c3 u3 s- M f- |3 uinvoke LocalFree,pSD) |/ [& B. z. j9 z3 E' U8 i \ @@:& n1 G# N: x" a% ^$ ^% n cmp pNewDacl,0( t" z9 T; A3 n }1 N, f* ~/ @ jz @f & v* m1 G5 y9 z+ Z; ninvoke LocalFree,pNewDacl& U/ z+ x! C+ H5 c9 d3 [. a @@: b% Z- g, [6 `" r9 pret/ N( e( o4 K v: d& U1 u3 d/ W Y SetPhyscialMemorySectionCanBeWrited endp) [. s8 U- h& c 0 x( c% c0 ^& N0 c7 s% F% h7 ] MiniMmGetPhysicalAddress proc virtualaddress:dword/ Y8 w3 t' M f: X9 Q mov eax,virtualaddress+ r5 [/ `$ c q% S' k cmp eax,80000000h , T u) w9 d0 Y! @% \% B( ? jb @f % g( s+ c3 i7 r2 W0 k! A cmp eax,0a0000000h/ b& C A7 v; w! i/ {1 P2 H( y2 s jae @f % O/ q# n4 e4 D6 ^/ g) q5 M& M7 g) \9 O and eax,1FFFF000h ! {% o& j* y0 r# p% G ret % [& H# E$ C4 Y& K) w8 N# ` @@:5 L, S N0 G; B+ b7 A3 u mov eax,01 e6 o6 ^9 `3 Q# P; M' \7 P ret # Q' g5 [+ _ C% ?* wMiniMmGetPhysicalAddress endp4 {( q ~" o: t. Q6 H5 t* D& G 5 O: T$ h7 F4 U( Q A) qExecRing0Proc proc , S# E$ z+ f( f1 m6 I6 _0 {9 plocal tmpSel:dword$ G4 m5 ~7 [# U local setcg:dword 6 P6 X7 y n c0 S. ~5 J: Mlocal BaseAddress:dword/ m4 j$ D0 D- `: b local NtdllMod :dword$ e& i6 o/ u) A9 D9 ]) N2 q1 q local hSection:HANDLE ; t" t: g7 p4 rlocal status:NTSTATUS; R3 [$ ^; ]: q# ^1 C local objectAttributes:OBJECT_ATTRIBUTES ; G! [; ?( k7 x( D3 G9 }$ p" M local objName:UNICODE_STRING1 ?9 U. e7 }. F) m9 ^3 Y. y1 w mov status,STATUS_SUCCESS; 3 F1 w: k6 F0 H9 s" {sgdt GdtLimit 4 r2 y7 b$ [/ x9 [0 [8 ?invoke MiniMmGetPhysicalAddress,GdtAddr ) e" ]9 Q# F/ Q" s0 ]( Xmov mapAddr,eax % A( j& w1 x' ztest eax,eax3 c% i! U' d* W+ S9 X' I5 q4 R jz Exit1 C% s8 z& M. S( l" ?# n+ y call @f& z5 _" P' h1 c5 @7 p8 Q db "Ntdll.dll",0: a6 e% s! [; R! A @@: 1 E8 b" w4 @8 wcall LoadLibraryA ; |/ ~4 j/ v8 m/ X. b# F/ qmov NtdllMod,eax$ m" R! n/ w$ ]7 _4 e. O/ u . i# V. q; W- H( B m" O- c2 J lea edx,objnamestr 3 ]& j# ^9 y) _% jmov objnameptr,edx ' g. A- @9 D; u# S, @lea edi,ObjAttr e E) \9 ?5 |and di,0fffch ;align to 4 bytes,or ZwOpenSection will fail * ] p4 B9 ]0 U5 L5 E3 npush edi ;edi->ObjAttr4 ^9 `( F7 P2 W$ y) r3 P push 24 ;length of <\Device\PhysicalMemory> " k( [, v3 K8 Wpop ecx ' J2 W1 V( Y+ G; W; \, cpush ecx ! q P* ~$ o3 P% O3 k8 Wxor eax,eax. t& T8 j; g3 i0 V! Y rep stosb ;put ObjAttr with 0- h+ N. y; s& B1 H: c `3 y pop ecx 4 G, j6 {. ^6 U6 Bpop edi$ q- c8 _& A8 ]& F4 @ mov esi,edi j* I U1 h/ e; r' w9 G/ u stosd ; W l, t" l, l* _) ]$ z' Wmov dword ptr[esi],ecx# ~! h" v% D: G+ Y- G stosd ) Y/ v+ K/ c2 P4 ^9 ~1 e# B7 xlea eax,[edx-8] ;eax->objname p+ w& F- q% Z3 cstosd ;ObjAddr(18h,00,00,00,00,00,00,00,offset objname,40,02,00,00,dd 2 dup(0) 7 c4 G+ a( U2 _1 B8 a- q; kmov dword ptr [edi],240h4 M2 ^3 i0 K4 d" q4 x# D3 x 9 t- W) c! X' D( A ~3 r$ z# x( pcall @f * _# E* ^3 I; P3 z- _2 Y, Ndb "ZwOpenSection",0 8 z: m }$ s% l& X7 t@@:. O* F* s9 K" A1 g* ^ Q push NtdllMod " T$ t& j7 U: w8 I, d% X8 hcall GetProcAddress $ Z! I' n# a9 P* m4 d4 Nmov ebx,eax ;ebx=ZwOpenSection ' r5 k7 ^; Y, ?4 k/ x. _; O & y' x+ T6 J6 X5 Y) U9 m/ Apush esi ;esi->ObjAttr9 i1 |% P' a" X8 Y8 W0 C- S3 Q push SECTION_MAP_READ or SECTION_MAP_WRITE3 d; b1 o; q% j, S lea edi,hSection+ r2 X' w0 U1 z' P3 f' w/ \! j$ n push edi ;edi->hSection* B( L2 T% y5 y7 K5 C% c call eax ;ZwOpenSection(&hSection,SECTION_MAP_READ or SECTION_MAP_WRITE,ObjAttr)6 _- M. t- e9 y- k- J" L- u, a 2 D/ z p2 Y; _6 I0 _ mov status,eax * g0 B/ i* h' @! @# t5 ?cmp status,STATUS_ACCESS_DENIED 4 H4 H$ b, v8 ?8 ~4 y; E) y4 ejnz AccessPermit( b- I/ q& r8 Y- j0 i, t7 K. d mov eax,ebx2 [' h$ ]2 q( t3 G% U ' {6 F# j$ E1 N. b push esi T& `: s( D+ M push READ_CONTROL or WRITE_DAC 2 m: r* C: p& k' H1 s% S push edi $ ^$ A |4 Q% F& h: j5 h/ J call eax 7 N: k! K- x0 q ; }( x5 g5 Z/ k% Q {9 w8 X mov status,eax0 M' p- q+ w w# j invoke SetPhyscialMemorySectionCanBeWrited,hSection 3 c; o7 G% o# ~1 z" d 8 c3 l! ^. z( Q4 `call @f" ]. J; i8 ~. f/ M9 z9 [ db "ZwClose",0 . I3 Y# v2 `, _9 `. [) l9 v@@: ! i [; ?+ n. t, q- v+ jpush NtdllMod5 u' E* r5 U( Q, {) W call GetProcAddress% [) p# V) g7 `5 s ' R5 A& A9 X$ s! M$ m7 @push hSection9 X2 E$ @9 _8 H, ^ call eax ;zwClose hSection % J9 U* X3 ]9 B: n0 r% h7 ~: y5 J 9 m1 p) H/ M7 T( _0 F) t2 [% tmov eax,ebx 8 Q) y& R3 ?; [- a" a1 ^ . ^ ?' j+ |, @, i/ kpush esi ' f% O! a' J+ T O push SECTION_MAP_READ or SECTION_MAP_WRITE ' Q1 m7 {' c* L: A4 B2 ]lea edi,hSection2 s, t- D; y9 m* S- P" ^" G2 X3 _ push edi ; ~! i! j9 i( k5 z4 U/ \: U call eax/ y8 g: l; M6 P" C! g+ l& x mov status ,eax5 c6 j) }0 Z1 M$ O ;status =ZwOpenSection(&hSection,SECTION_MAP_WRITE|SECTION_MAP_WRITE,&objectAttributes); / |$ B: J& y* DAccessPermit:+ {- Q# }* {8 z; G. y- {; h cmp status ,STATUS_SUCCESS - f2 I& i) h! P9 n, V jz @f 9 r# F0 M- o, T3 y; W* A5 [;printf("Error Open PhysicalMemory Section Object,Status:%08X\n",status); 8 x4 B4 q! B- P u/ d! r;return 0;7 _1 p% b% |# ] S) J: ~ mov eax,0 + \- a8 ?$ v% F1 Tret9 S3 y: r/ N( Y9 ^ @@: / }3 v3 n6 ]8 ^movzx eax,word ptr[GdtLimit] ?% C. z4 C$ v8 y2 @inc eax6 m. P+ d4 j2 G. f4 ] invoke MapViewOfFile,hSection, FILE_MAP_READ or FILE_MAP_WRITE, 0, mapAddr, eax 5 i; d1 K. D( t& u1 V mov BaseAddress,eax& N) `& N) }# Q# u cmp BaseAddress,0: ?. W; n4 g( ]. k! l jnz @f/ m/ L: v3 m5 W# z1 ~ ;printf("Error MapViewOffile:"); 6 |& w) `0 E R. g7 [rintWin32Error(GetLastError()); return 0; # E8 N3 D* h; V, c$ a: Omov eax,0: V$ C) g$ K' o ret! I$ h+ `. j5 b9 h( \ @@: 8 a/ c* K& C6 I- emov esi,eax ;esi->gdt base 9 e" T% D- f+ Z& n* D! mmov ecx,3e0h ) |0 F3 u( @. R; lmov eax,GdtAddr & T/ {9 J( I* L2 t+ {.if dword ptr [esi+ecx+2]!=0ec0003e8h 4 h6 @) p7 [, Emov byte ptr [esi],0c3h) L* c/ e1 i1 z5 W3 }3 q $ J5 T, C2 n$ g5 z2 d mov word ptr [esi+ecx],ax& o& C# |( q6 H shr eax,16 5 ~7 b4 u1 K" T, nmov word ptr [esi+ecx+6],ax; \+ \) ^! k) K+ o$ a( w mov dword ptr [esi+ecx+2],0ec0003e8h" r/ `! u. T( p4 T& S; @% t0 X ) |/ \4 a4 H8 \/ \. Z+ @ mov dword ptr [esi+ecx+8],0000ffffh ( b4 w9 S0 Y+ a( o6 ymov dword ptr [esi+ecx+12],00cf9a00h( g6 R8 a- r% d* m2 d .endif + D; ^" } Q2 X) G: ]5 ^; m( r" D. {, x5 @' j: } mov setcg,TRUE& O6 N) h4 E U cmp setcg,0 1 F7 u! I6 v1 bjnz ChangeOK# x2 V. ?$ r& g0 F call @f 5 _7 k0 Z2 O6 Z: B# S# k* n. x9 p* ddb "ZwClose",0 ; ~( i" f' }2 `' j@@:3 I% ?+ Z2 x" x" B+ C: F+ E push NtdllMod7 k1 |) e2 m- j3 Y call GetProcAddress5 d5 I5 X, B( ?! S push hSection/ J; l: ?" p6 q- e% H call eax; O/ c) o/ ?$ e+ m5 d# q6 I xor eax,eax S+ M2 {0 E2 m2 v) `ret4 `( \9 C8 T6 y% d \$ ~ ChangeOK:- B/ M0 c; _; ]9 y$ d+ U and dword ptr Callgt,0 3 {2 y" T0 J* a xor eax,eax1 b. e- n* S8 W7 c mov ax,3e0h- [3 o$ w+ V6 a8 _ or al,3h6 X, v9 O& W$ Y" J9 a- B, V mov word ptr [Callgt+4],ax 4 ~* r- K1 I( L1 d( X/ T;farcall[2]=((short)((ULONG)cg-(ULONG)BaseAddress))|3; //Ring 3 callgate; 3 ^# O8 r$ w- Q) s lea eax,_Ring0Proc7 n! B; D7 z7 T2 Z0 n. D f ;invoke VirtualLock,eax,seglen $ @" g1 U6 r5 qtest eax,eax4 c5 ]0 d, _2 [ jnz @f8 y4 {7 b, x& n7 J8 Q9 A; ^ xor eax,eax 7 l& O5 {# x! X4 j9 l+ S1 Eret- ~4 q! A. ?) G P0 T# f8 \ @@: . M, W- d7 B/ K' _* {invoke GetCurrentThread 4 s, J- `; H1 J. Q& w9 R6 o/ Winvoke SetThreadPriority,eax,THREAD_PRIORITY_TIME_CRITICAL 4 ]% U( W7 R; u: H # Z* J# t; j) einvoke Sleep,0 2 j8 ~& P8 ?; Qcall fword ptr [Callgt] ;use callgate to Ring0!1 A. C1 Y. |# G& `: V ;_asm call fword ptr [farcall]( r/ [6 u. u" n0 w T _Ring0Proc: ; Ring0 code here.. 8 f3 B; Y% C1 v! k/ N mov eax,esp ;save ring0 esp ; P# Q* S ]( R F+ Q% P) Vmov esp,[esp+4];->ring3 esp: K- D6 K& c1 z/ O8 \/ O d push eax% i$ @8 a" t3 ~* e7 }; q/ r mov ebx,offset stIDEINFO& j+ T# h* T$ }( P assume ebx:ptr IDEINFO ' s; }5 N! }2 k* Z ;******************************************************************** \% i q7 ?, V3 y: Q. y8 N# `; 等待硬盘就绪4 L5 I6 u I5 d2 V* n ;******************************************************************** , @8 O4 H' b( @& w" y& i mov ecx,10000h b2 \+ ]3 ^$ k5 i0 `0 i mov dx,01f7h3 h% _* E8 o8 w0 q @@: 6 U% v% L. i2 b5 J1 y* i in al,dx ! r# s1 V1 T& I6 @0 d+ W cmp al,50h 7 v/ g2 b4 \7 O1 s jz @F3 C3 g: w6 X' T loop @B % `9 w W5 v0 y: ^7 u8 w jmp _II_TimeOut% B* V$ U$ j9 H. p% x2 A3 F @@: ' u- p$ C' z* Q8 G;******************************************************************** , Q9 x9 \1 h4 ?" U& r2 \; 发送命令 ) u7 C9 n% C$ L, |- x- M; 如果向主控制发送命令,则端口为 1f0h-1f7h9 k A7 g/ h7 j4 E6 L ; 如果向副控制发送命令,则端口为 170h-177h " n9 L) h+ Z$ ?1 m; 1f6h 如果要检测的设备为该IDE接口的主(MASTER)设备, ' }( ~% q8 b* R8 v" f4 ~; 那么发送 a0,如果为从那么发送 b0, J% r- `/ c" m7 h ; 1f7h 如果要检测的设备为 ATA 设备那么发送 ec g6 V; D1 X( F/ E ; 如果为 ATAPI 设备那么发送 a1( n9 |0 S; h: I; e ;******************************************************************** + Q( s/ U$ W& E3 k o) g }' I mov al,0a0h ;Drive 0,Head 03 |" m+ \3 W9 [( B& h mov dx,01f6h ;Drive and head port$ s; ?5 ?! n! w8 S8 } out dx,al ( N3 _4 N7 Q) s+ @* h8 H( M$ { # p( F+ L% S* s5 J8 O+ ^; e* i1 K" q: p mov al,0ech ) t; d( i. d) L/ V6 W/ { inc dx ;Command port/ i% U$ Y) k) R3 W8 a; e/ a5 e2 l out dx,al4 J$ H( }- J P+ o* U3 z5 C. \( R2 D ;******************************************************************** ; U+ X# y/ b x) O8 t0 H ~8 W$ u; 等待硬盘就绪' n$ D2 g8 X+ U5 u/ [! [! q ;********************************************************************# a7 j& U" `- P0 X6 G6 i* V, N$ w mov ecx,10000h; F5 w8 f4 o( P @@:* a' @; N! N$ c+ O6 Y, C: ] in al,dx;1f7 (r-status register)5 x$ Y+ T; r5 ?# L cmp al,58h;(driver is ready ,and seek complete): k( Y" z( `$ c% ]1 E jz @F, ]% H* f$ f* g" O. F7 \& [8 e$ a loop @B0 H" o9 u1 `: H: d; \* J jmp _II_TimeOut + K X0 w8 E/ H6 d @@:3 D# o! @9 e6 G* p6 q0 H ;********************************************************************+ H( @9 N" f! W" L4 w% G& R; ?5 p ; 将返回信息读回$ u. v+ j6 m9 t) E ; 注意一定要读满 100h 个字长 # b! t. U! _0 E% Y7 O1 l$ T! H;******************************************************************** 6 `- s1 H" y. Z+ s( W3 H- o7 z cld / {4 [" }" U3 a. G' F K mov edx,01f0h;data port - data comes in and out here 8 `/ x% D" S% x7 X6 D/ ^. J mov edi,ebx. i& A) w# r' B- a2 Z- p, e mov ecx,0100h & d5 q! X0 S8 D* F7 D: L rep insw& K, S3 H2 f {8 D5 C ;******************************************************************** 4 D( m. u' D, k3 A N; 返回的信息中,型号、序列号、版本号为字形式, l+ v6 \7 d* o9 l' p ; 需要整理到字符串的形式 : M/ ^: T2 Y7 E4 B7 m" C- x- r+ b3 |- b;********************************************************************; w" J- W d) K" V$ D0 s' T lea esi,[ebx].sSerialNumber / Z; a" j6 D! e& i. J mov edi,esi+ O$ k6 V; i& i Y/ R mov ecx,10 , C" K7 s% b$ e @@:3 y3 k; a, V3 @ lodsw - {# p" @4 [% z- d3 w" }: L xchg ah,al7 ^9 Y7 _" W+ i, ~! s$ F stosw % B: V& e1 I& c# M: ?9 v- i loop @B$ C4 ?+ L( y4 ? [9 B9 F$ J; i 9 q5 q' X( o2 W lea esi,[ebx].sFirmwareRev- Z v$ w F/ {& @3 p/ S8 Y mov edi,esi5 u( w( c+ X& b W# ~) @4 g. f X mov ecx,24 0 T" u; R; d$ K @@: + t# j. m2 S4 j1 C; g lodsw& _9 c+ w! k: `8 R9 x xchg ah,al + `5 B; @# i: E; d' u5 y) A stosw; f9 {# k& R6 _1 ^- ~7 n2 \ loop @B1 v6 F0 T; Y, K _II_TimeOut: \4 V' r# q! ]1 gassume ebx:nothing V8 {; q+ F- d' X# | $ U' R9 f$ P9 K+ g pop esp ;restore ring0 esp" E" a$ H" L/ G3 g" b( E push offset Ring3 ) A1 |2 i$ ^& W6 \; O$ \retf : \1 ]' B7 H. LRing0CodeLen=$-_Ring0Proc8 g, W7 R- ?6 t0 `; D5 d ' c8 W7 m: t- g4 U' ^' L Ring3:& H" Z8 F, |5 o& `4 `4 }1 t: w8 B invoke GetCurrentThread ! X2 B9 s% A5 M9 G3 b; ~invoke SetThreadPriority,eax,THREAD_PRIORITY_NORMAL $ \' R7 _! W4 ^ , O' `( ^, e- A& w;invoke VirtualUnlock,Entry,seglen - [' P- d4 `: n % W- n8 O$ [# r' ~, {% k call @f: \7 L2 N! I; \5 l- v: Y db "ZwClose",0 + Q+ p( `3 D5 u3 N9 P6 k2 {@@:; \8 u0 ?+ y0 E% c7 O7 t4 D( f push NtdllMod5 U4 d2 F" _" P3 F7 V call GetProcAddress: d0 g# K7 E. m* W; B, s push hSection0 _7 p' \# t3 K- G3 s7 h$ H call eax $ f& B% \, V9 a0 Emov eax,TRUE% z% J% \- ~ o+ s9 k ret) z/ b/ \* I( C# d0 O ExecRing0Proc endp 4 X( P8 l8 s, E3 ~! O4 m ) _: C. b5 w( ^- Omain: 0 l4 u% ~- L$ k6 ~assume fs:nothing ) _) c7 @5 z9 G$ y6 Zpush offset MySEH / `; `$ G( k$ ?$ d2 Dpush fs:[0] 1 H! x7 G' j+ J) ^9 A/ qmov fs:[0],esp# Y# }3 B2 y$ s0 b7 J, x mov OldEsp,esp5 j. }- }2 C. F9 q* } mov ax,ds ;if Win9x?7 i" y" F3 | M test ax,4: @- m6 m6 D% x" O$ \ jnz Exit1' ^: o3 l* e$ H5 |8 x& |9 Z2 V invoke ExecRing0Proc9 |% \% H: S. x% c ; ~' W# M9 B' y. }: u .if stIDEINFO.wNumCyls ) f2 J" h5 F1 r' h; W lea esi,stIDEINFO.sModelNumber; G! o+ d n" k9 x" b( X. t' X6 |; O mov edi,offset szModelNumber: D3 U4 w* R( L7 g+ D mov ecx,sizeof stIDEINFO.sModelNumber 8 k' y' b: B) h2 Z+ [6 j rep movsb % y; V3 Z* v+ C$ m. `5 L, B) {* r; B# ^- y+ S9 ^ lea esi,stIDEINFO.sSerialNumber 6 T+ u6 o3 B! r. Q$ T& N# R+ }! o mov edi,offset szSerialNumber 1 W3 l9 A C8 G1 V+ j8 F mov ecx,sizeof stIDEINFO.sSerialNumber+ e4 I, H* D7 h' s2 }1 a rep movsb; M! @" Y5 }* B- y4 T( l$ H) W" q . v6 }1 X ^7 p lea esi,stIDEINFO.sFirmwareRev & ?4 `" O+ [# U, y) K! Q mov edi,offset szFirmwareRev3 W$ c9 ^+ z1 L T mov ecx,sizeof stIDEINFO.sFirmwareRev8 F2 T$ }7 Y+ j rep movsb ) ~- c8 d6 h0 s! G% y' x% s : g4 z. H2 G2 A; M& U movzx eax,stIDEINFO.wNumCyls 3 k3 e. h7 Z+ P1 j% i& {" q movzx ebx,stIDEINFO.wNumHeads3 m x# C6 h; S8 G3 A movzx ecx,stIDEINFO.wSectorsPerTrack / G* q3 J: e$ ~9 u1 ~3 [" a8 W movzx edx,stIDEINFO.wBufferSize' O" K$ A( R9 ] invoke wsprintf,addr szBuffer,addr szIDEInfo, eax,ebx,ecx,edx, addr szModelNumber, addr szSerialNumber, addr szFirmwareRev . v$ |2 ]3 l- b' B7 P q mov eax,offset szBuffer 5 b `( ?: R6 }* k- u1 k |.else ) ?( [) l! f1 e2 c mov eax,offset szErrInfo ' ~. e$ U2 e5 G. N R! q( W7 w.endif; n- m. t% {" h @@: & w; ^7 s1 a O( [invoke MessageBox,NULL,eax,addr szTitle,MB_ICONINFORMATION or MB_OK9 y: G9 `4 n+ B Exit1:$ A5 }( {& K+ `; M! d pop fs:[0] / J1 d( a/ c+ Y. ?' madd esp,4 3 ?+ M q' r8 |. M. Qinvoke ExitProcess,0+ f2 _4 w: U) U: M7 S % Q* W( G% @' j- Y- F MySEH : ; I/ E4 O; m) X- L' F- [mov esp,OldEsp7 U5 k3 a3 B6 A4 }% K, ~ pop fs:[0]0 |# y8 b1 A6 t2 z/ R5 G" ^, M; y5 N add esp,4 % q, L4 _$ [4 n; f5 t7 H% C( \invoke ExitProcess,-1 & \4 _" I" v0 yend main- |; s# r' B1 d# P+ R: K # K3 w3 s6 g5 z6 q
[此贴子已经被作者于2003-11-2 18:14:02编辑过]
; y, N7 s3 C# i5 D! U. D
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩 转发到微博
bigfoot 该用户已被删除
2
发表于 2003-11-3 16:22:00 | 只看该作者
呵呵,ExecRing0Proc 这段程序甚妙,先得到gdt,然后构造一个调用门call gate's ,使程序从用户模式(ring 3)进入内核模式(ring 0)。进入内核模式之后,就可以没有限制地对系统干任何勾当。这段程序确实为高手所为,在下佩服得紧。, \1 d$ Y  S2 E, w; u& \
至于读硬盘序列号之类,只不过是在内核模式下的一个I/O应用罢了。
0 |. B3 N9 u7 K) e( y$ |2 g其实在NT/2000下读取硬盘序列号只要打开\\.\PhysicalDriveX(X:设备号0~26)设备,然后用DeviceIoControl()就可以读取了,不需要绕ring0这么一个大圈子
* k4 j5 g" \) A, e3 a6 j- H
: V& P2 T  P7 h3 N7 f' {这个程序也可以C语言实现,不过中间必须嵌入几条汇编的指令,如sgdt GdtLimit
0 o! Y% K& u7 o  a8 v, t2 w- ]但还是用c来写更方便,例如:# d# T  u& O% b
call @f# J0 D. O9 n( x* A, \7 i$ Z
db "ZwOpenSection",0# }! V/ W4 E) ]. v2 [4 v& a& o" ^; I
@@:
9 ^. {" [% S& D0 O2 P$ }/ cpush NtdllMod( ]8 |; p. j# q/ S$ z7 A9 e
call GetProcAddress
/ B) O  `) p$ n/ U2 U2 jmov ebx,eax ;ebx=ZwOpenSection
! \! b( B, H6 y% x4 S" K; Z1 g  vpush esi ;esi->ObjAttr
8 f, y5 h9 H1 B, ^. L# x+ x7 \  ypush SECTION_MAP_READ or SECTION_MAP_WRITE
0 w8 `" ?( \$ V+ ylea edi,hSection
' U' t$ R* K% |9 n: {: N  Ppush edi ;edi->hSection
1 ~. |0 X9 x' F; a) fcall eax ;
7 n5 y& P, Z$ `( e6 P2 D: G$ l8 ?( t- n7 |' G6 S$ u4 y* G+ }0 @/ k
用c的话只要一句就可以了
4 q# x1 g. D; S9 S6 V/ _ZwOpenSection(&hSection,SECTION_MAP_READ or SECTION_MAP_WRITE,ObjAttr);* p5 Z  Y4 x# h+ b
因此懂汇编,然后用C/C++编程,是成为高手的捷径
7 u6 ?/ k' I9 y6 J1 q6 R% {( r; H
! l  o! e. [# \, P" k) v( |: f
[此贴子已经被作者于2003-11-3 16:46:50编辑过]

& I! U1 w' V" I" V

该用户从未签到

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

该用户从未签到

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

该用户从未签到

6
 楼主| 发表于 2003-12-3 15:33:00 | 只看该作者
很久以前?' L; F0 q" K6 Y" \9 t" W3 O. ~' U
不是吧,这个是 轻描淡写 编程论坛的斑竹写的
fyer 该用户已被删除
7
发表于 2003-12-24 19:21:00 | 只看该作者
看到过的。

本版积分规则

关闭

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

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