读书人

从Entry Point到main函数调用(二):

发布时间: 2012-12-24 10:43:13 作者: rapoo

从Entry Point到main函数调用(2):GetVersion

之前(1)篇中大致介绍了mainCRTStartup,但是其中一些调用到的函数并未深究,现打算逐一剖析它们。

?

GetVersion

GetVersion函数是kernel32.dll中提供的API,用于获取当前Win平台的版本。准确的说,GetVersion可以获得3个信息:

1. OSPlatformId

2. OSBuildNumber

3. OSMinorVersion

4. OSMajorVersion

其中比较诡异的是OSPlatformId,在GetVersion的过程当中它被获得过,但是返回的时候又没了...所以只剩下2、3、4

?

可以用OD来跟进GetVersion:

mov     eax, dword ptr fs:[18]mov     ecx, dword ptr [eax+30]mov     eax, dword ptr [ecx+B0]        // 获取 OSPlatformIdmovzx   edx, word ptr [ecx+AC]         // 获取 OSBuildNumber xor     eax, FFFFFFFEshl     eax, 0E                        // 几次左移,把OSPlatformId的信息给移没了...or      eax, edxshl     eax, 8or      eax, dword ptr [ecx+A8]        // 获取 OSMinorVersionshl     eax, 8or      eax, dword ptr [ecx+A4]        // 获取 OSMajorVersionretn

GetVersion主要是去PEB(Process Environment Block)结构中访问当前的OS信息,每个进程都会有自己独立的PEB。想要获取当前进程的PEB地址,首先要先访问TEB(Thread Environment Block)结构。因为TEB结构的30偏移量处中存放了PEB结构的指针。FS寄存器指向了当前活动线程的TEB结构,其中偏移位置18表示了FS段寄存器在内存中的镜像地址。

Operating systemVersion numberdwMajorVersiondwMinorVersionWindows?76.161Windows Server?2008?R26.161Windows Server?20086.060Windows?Vista6.060Windows Server?2003 R25.252Windows Home Server5.252Windows Server?20035.252Windows?XP Professional x64 Edition5.252Windows?XP5.151Windows?20005.050

?

?

?

?

?

读书人网 >网络基础

热点推荐