当前位置: 代码迷 >> 汇编语言 >> 非API函数检测操作系统类型!MASM解决方案
  详细解决方案

非API函数检测操作系统类型!MASM解决方案

热度:5050   发布时间:2013-02-26 00:00:00.0
非API函数检测操作系统类型!~~~~~MASM

得到一段汇编代码MASM,功能如题,   本人不懂汇编,   想测试代码运行效果,手头工具   VS2003、VC6.0   求高人帮忙指导


.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

.code

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


------解决方案--------------------------------------------------------
.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
  相关解决方案