非API函数检测操作系统类型

.386
.model   flat,stdcall
option   casemap:none

include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib

.const

;--   return   values   from   OS_GetOS
OS_UNKNOWN   equ   -1
OS_WIN95   equ   1
OS_WIN98   equ   2
OS_WINME   equ   3
OS_WINNT   equ   4
OS_WIN2K   equ   5
OS_WINXP   equ   6
OS_WIN2K3   equ   7

.data
szCaption db 'xp ',0
;> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
;   代码段
;> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
.code
start:
call OS_GetOS
.if   eax==5                                                 ;   在此处加入多个判断,根据eax,得出系统类型
invoke   MessageBox,NULL,offset   szCaption,offset   szCaption,MB_OK
.endif
invoke ExitProcess,NULL

OS_GetOS   proc

    local   _theReturnValue:DWORD

    pushad   ;   store   all   registers
    mov   _theReturnValue,OS_UNKNOWN
    assume   fs:nothing
    mov   ebx,fs:[18h]   ;   get   self   pointer   from   TEB
    mov   eax,fs:[30h]   ;   get   pointer   to   PEB   /   database
    .if   eax==7FFDF000h   &&   ebx==7FFDE000h   ;   WinNT   based
  mov   ebx,[eax+0A8h]   ;   get   OSMinorVersion
  mov   eax,[eax+0A4h]   ;   get   OSMajorVersion
  .if   eax==5   &&   ebx==0   ;   is   it   Windows   2000?
    mov   _theReturnValue,OS_WIN2K
  .elseif   eax==5   &&   ebx==1   ;   is   it   Windows   XP?
    mov   _theReturnValue,OS_WINXP
  .elseif   eax==5   &&   ebx==2   ;   is   it   Windows   2003?
    mov   _theReturnValue,OS_WIN2K3
  .elseif   eax <=4   ;   is   it   Windows   NT?
    mov   _theReturnValue,OS_WINNT
  .endif

    .else   ;   Win9X   based

  mov   edx,00530000h   ;   the   magic   value   to   search
  mov   eax,fs:[18h]   ;   get   the   TEB   base   address
  mov   ebx,[eax+58h]   ;   TEB-base   +   58h   (W95)
  mov   ecx,[eax+7Ch]   ;   TEB-base   +   7Ch   (WME)
  mov   eax,[eax+54h]   ;   TEB-base   +   54h   (W98)

  .if   ebx==edx   ;   is   it   Windows   95?
    mov   _theReturnValue,OS_WIN95
  .elseif   eax==edx   ;   is   it   Windows   98?
    mov   _theReturnValue,OS_WIN98
  .elseif   ecx==edx   ;   is   it   Windows   ME?
    mov   _theReturnValue,OS_WINME
  .endif

    .endif   ;   of   base   check   NT/9X

    popad   ;   restore   all   registers
    mov   eax,_theReturnValue
    ret   ;   return   to   caller
OS_GetOS   endp

;> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >

end start  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值