首页
社区
课程
招聘
[求助]关于双核cpu的监测
发表于: 2007-9-9 01:59 11479

[求助]关于双核cpu的监测

2007-9-9 01:59
11479

我手上有个软件(安装文件),在安装的时候 会监测cpu,提示不支持双核cpu,无法安装。
我想请问,这个cpu监测是怎么一个过程,我想是不是改动安装文件里的这个地方可以跳过这一步,
来安装这个软件。
请大家指教。


[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)

收藏
免费 7
支持
分享
最新回复 (19)
雪    币: 238
活跃值: (326)
能力值: ( LV12,RANK:450 )
在线值:
发帖
回帖
粉丝
2
有许多方法,我比较喜欢使用的是:
NtQuerySystemInformation函数,其中SystemBasicInformation(0号功能)返回的结果是一个SYSTEM_BASIC_INFORMATION结构,其中的域bKeNumberProcessors将返回系统CPU的个数。

下面是该函数的具体说明:
/×-------------------------------------------------------------
NtQuerySystemInformation is used to check some system informations
avaiable only in KernelMode (above 0x80000000).
All avaiable (or all known) information classes are described
in SYSTEM_INFORMATION_CLASS.
Requirements
Client: Requires Windows XP or Windows 2000 Professional.
Server: Requires Windows 2000 Server.
Header: Declared in Winternl.h.
DLL: Requires Ntdll.dll.
[NtQuerySystemInformation is available for use in Windows 2000 and
Windows XP. It may be altered or unavailable in subsequent versions.
Applications should use the alternate functions listed in this topic.]
*/

注:NtQuerySystemInformation底层使用中写为ZwQuerySystemInformation,两个函数完全相同,只是入口不同。

NTSYSAPI
NTSTATUS
NTAPI
NtQuerySystemInformation(

             //SystemInformationClass
             //[in] One of the values enumerated in SYSTEM_INFORMATION_CLASS,
             //indicating the kind of system information to be retrieved.
             IN SYSTEMINFOCLASS SystemInformationClass,

             // SystemInformation
             // [in, out] Points to a buffer where the requested information is
             // to be returned. The size and structure of this information varies
             // depending on the value of the SystemInformationClass parameter:
             OUT PVOID pSystemInformation,

             //  SystemInformationLength
             //  [in] Size of the buffer pointed to by the SystemInformation parameter,
             //  in bytes.
             IN ULONG uSystemInformationLength,

             //  ReturnLength
             //  [out, optional] Optional pointer to a location where the function
             //  writes the actual size of the information requested.
             //  If that size is less than or equal to the SystemInformationLength
             //  parameter, the function copies the information into the
             //  SystemInformation buffer; otherwise, it returns an NTSTATUS error code
             //  and returns in ReturnLength the size of buffer required to receive
             //  the requested information.
             OUT PULONG puReturnLength OPTIONAL
             );

//  Return Values
//  Returns an NTSTATUS success or error code.
//  The forms and significance of NTSTATUS error codes are listed
//  in the Ntstatus.h header file available in the Windows Device
//  Driver Kit (DDK), and are described in the DDK documentation
//  under Kernel-Mode Driver Architecture / Design Guide / Driver
//  Programming Techniques / Logging Errors.

typedef enum _SYSTEMINFOCLASS
{
    SystemBasicInformation, //0
    SystemProcessorInformation, // 1
    SystemPerformanceInformation, //2
    SystemTimeOfDayInformation, //3
    SystemPathInformation, //4 SystemNotImplemented1
    SystemProcessInformation, //5  per process SystemProcessesAndThreadsInformation
    SystemCallCountInformation, //6  SystemCallInformation
    SystemConfigurationInformation, //7    SystemDeviceInformation
    SystemProcessorPerformanceInformation, //8  per cpu SystemProcessorCounters
    SystemGlobalFlag, //SystemFlagsInformation
    SystemCallTimeInformation, //10
    SystemModuleInformation, //11
    SystemLockInformation, //12
    SystemStackTraceInformation, //13  SystemNotImplemented2
    SystemPagedPoolInformation, //14   checked build only
    SystemNonPagedPoolInformation, //15  checked build only
    SystemHandleInformation, //16
    SystemObjectInformation, //17   SystemObjectTypeInformation
    SystemPageFileInformation, //18  per page file
    SystemVdmInstemulInformation, //19  SystemVdmInstemulInformation
    SystemVdmBopInformation, //20
    SystemFileCacheInformation, //21
    SystemPoolTagInformation, //22
    SystemInterruptInformation, //23
    SystemDpcBehaviorInformation, //24
    SystemFullMemoryInformation, //25  checked build only
    SystemLoadGdiDriverInformation, //26  set mode only
    SystemUnloadGdiDriverInformation, //27  set mode only
    SystemTimeAdjustmentInformation, //28  writeable
    SystemSummaryMemoryInformation, //29  checked build only
    SystemNextEventIdInformation, //30  checked build only
    SystemEventIdsInformation, //31  checked build only
    SystemCrashDumpInformation, //32
    SystemExceptionInformation, //33
    SystemCrashDumpStateInformation, //34
    SystemKernelDebuggerInformation, //35
    SystemContextSwitchInformation, //36
    SystemRegistryQuotaInformation, //37
    SystemExtendServiceTableInformation, //38  set mode only  SystemAddDriver
    SystemPrioritySeperation, //39  set mode only    SystemPrioritySeparationInformation
    SystemPlugPlayBusInformation, //40  not implemented
    SystemDockInformation, //41  not implemented
    SystemPowerInformation, //42  XP only
    SystemProcessorSpeedInformation, //43  XP only
    SystemCurrentTimeZoneInformation, //44
    SystemLookasideInformation, //45
    SystemSetTimeSlipEvent, //46
    SystemCreateSession, // set mode only
    SystemDeleteSession, // set mode only
    SystemInvalidInfoClass1, // invalid info class
    SystemRangeStartInformation, // 0x0004 (fails if size != 4)
    SystemVerifierInformation,
    SystemAddVerifier,
    SystemSessionProcessesInformation, // checked build only
    MaxSystemInfoClass
} SYSTEMINFOCLASS, *PSYSTEMINFOCLASS;

typedef struct _SYSTEM_BASIC_INFORMATION
{
  DWORD dwUnknown1; // 0
  ULONG uKeMaximumIncrement; // x86: 0x0002625A or 0x00018730
  ULONG uPageSize; // bytes
  ULONG uMmNumberOfPhysicalPages;
  ULONG uMmLowestPhysicalPage;
  ULONG uMmHighestPhysicalPage;
  ULONG uAllocationGranularity; // bytes
  PVOID pLowestUserAddress;
  PVOID pMmHighestUserAddress;
  KAFFINITY uKeActiveProcessors;
  BYTE bKeNumberProcessors;
  BYTE bUnknown2;
  WORD wUnknown3;
} SYSTEM_BASIC_INFORMATION, *PSYSTEM_BASIC_INFORMATION;

typedef struct _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
{
  LARGE_INTEGER IdleTime;
  LARGE_INTEGER KernelTime;
  LARGE_INTEGER UserTime;
  LARGE_INTEGER DpcTime;
  LARGE_INTEGER InterruptTime;
  DWORD InterruptCount;
  DWORD dwUnknown1;
} SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION, *PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION

typedef struct _SYSTEM_PERFORMANCE_INFORMATION
{
  LARGE_INTEGER liIdleTime;
  LARGE_INTEGER IoReadTransferCount;
  LARGE_INTEGER IoWriteTransferCount;
  LARGE_INTEGER IoOtherTransferCount;
  ULONG IoReadOperationCount;
  ULONG IoWriteOperationCount;
  ULONG IoOtherOperationCount;
  ULONG AvailablePages;
  ULONG CommittedPages;
  ULONG CommitLimit;
  ULONG PeakCommitment;
  ULONG PageFaultCount;
  ULONG CopyOnWriteCount;
  ULONG TransitionCount;
  ULONG CacheTransitionCount;
  ULONG DemandZeroCount;
  ULONG PageReadCount;
  ULONG PageReadIoCount;
  ULONG CacheReadCount;
  ULONG CacheIoCount;
  ULONG DirtyPagesWriteCount;
  ULONG DirtyWriteIoCount;
  ULONG MappedPagesWriteCount;
  ULONG MappedWriteIoCount;
  ULONG PagedPoolPages;
  ULONG NonPagedPoolPages;
  ULONG PagedPoolAllocs;
  ULONG PagedPoolFrees;
  ULONG NonPagedPoolAllocs;
  ULONG NonPagedPoolFrees;
  ULONG FreeSystemPtes;
  ULONG ResidentSystemCodePage;
  ULONG TotalSystemDriverPages;
  ULONG TotalSystemCodePages;
  ULONG NonPagedPoolLookasideHits;
  ULONG PagedPoolLookasideHits;
  ULONG Spare3Count;
  ULONG ResidentSystemCachePage;
  ULONG ResidentPagedPoolPage;
  ULONG ResidentSystemDriverPage;
  ULONG CcFastReadNoWait;
  ULONG CcFastReadWait;
  ULONG CcFastReadResourceMiss;
  ULONG CcFastReadNotPossible;
  ULONG CcFastMdlReadNoWait;
  ULONG CcFastMdlReadWait;
  ULONG CcFastMdlReadResourceMiss;
  ULONG CcFastMdlReadNotPossible;
  ULONG CcMapDataNoWait;
  ULONG CcMapDataWait;
  ULONG CcMapDataNoWaitMiss;
  ULONG CcMapDataWaitMiss;
  ULONG CcPinMappedDataCount;
  ULONG CcPinReadNoWait;
  ULONG CcPinReadWait;
  ULONG CcPinReadNoWaitMiss;
  ULONG CcPinReadWaitMiss;
  ULONG CcCopyReadNoWait;
  ULONG CcCopyReadWait;
  ULONG CcCopyReadNoWaitMiss;
  ULONG CcCopyReadWaitMiss;
  ULONG CcMdlReadNoWait;
  ULONG CcMdlReadWait;
  ULONG CcMdlReadNoWaitMiss;
  ULONG CcMdlReadWaitMiss;
  ULONG CcReadAheadIos;
  ULONG CcLazyWriteIos;
  ULONG CcLazyWritePages;
  ULONG CcDataFlushes;
  ULONG CcDataPages;
  ULONG ContextSwitches;
  ULONG FirstLevelTbFills;
  ULONG SecondLevelTbFills;
  ULONG SystemCalls;
}

我们在任务管理器中所见到的所有信息只使用了下面5个调用:
0    SystemBasicInformation
2    SystemPerformanceInformation
5    SystemProcessInformation
8    SystemProcessorPerformanceInformation
21   SystemFileCacheInformation

初始化部分使用了其中的3个调用(0、2、8),这里给出的是任务管理器的初始化部分:
010058D6 InitPerfInfo proc near
010058D6
010058D6 SYSPROCPERFINFO= SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION ptr -76Ch
010058D6 SYSPERFINFO= SYSTEM_PERFORMANCE_INFORMATION ptr -16Ch
010058D6 SYSBASICINFO= SYSTEM_BASIC_INFORMATION ptr -34h
010058D6 pBuf= dword ptr -8
010058D6 i   = dword ptr -4
010058D6
010058D6     push ebp
010058D7     mov ebp, esp
010058D9     sub esp, 76Ch
010058DF     push ebx
010058E0     push esi
010058E1     xor ebx, ebx
010058E3     push edi
010058E4     push ebx                ; puReturnLength
010058E5     lea eax, [ebp+SYSBASICINFO]
010058E8     push 2Ch                ; SizeOf(SYSTEM_BASIC_INFORMATION)
010058EA     push eax                ; pSystemInformation
010058EB     push ebx                ; ebx = 0  SystemBasicInformation
010058EC     call ds:NtQuerySystemInformation
010058F2     cmp eax, ebx
010058F4     jl  Err_CpuNumAbove32
010058FA     mov eax, [ebp+SYSBASICINFO.uPageSize]
010058FD     mov g_PageSize, eax     ; 页面大小
01005902     mov al, [ebp+SYSBASICINFO.bKeNumberProcessors]
01005905     cmp al, 32              ; 32位Windows操作系统最多允许系统有32个CPU
01005907     mov g_cProcessors, al   ; CPU的个数
0100590C     ja  Err_CpuNumAbove32
01005912     mov esi, ds:LocalAlloc
01005918     mov edi, 1F40h
0100591D     test al, al
0100591F     jbe short CpuNumEquOne
01005921
01005921 Loop_for_AllocMem:
01005921     push edi
01005922     push LMEM_ZEROINIT
01005924     call esi ; LocalAlloc
01005926     test eax, eax
01005928     mov g_pCPUHistory[ebx*4], eax
0100592F     jz  Err_CpuNumAbove32
01005935     push edi
01005936     push LMEM_ZEROINIT
01005938     call esi ; LocalAlloc
0100593A     test eax, eax
0100593C     mov g_pKernelHistory[ebx*4], eax
01005943     jz  Err_CpuNumAbove32
01005949     movzx eax, g_cProcessors
01005950     inc ebx
01005951     cmp ebx, eax
01005953     jl  short Loop_for_AllocMem
01005955
01005955 CpuNumEquOne:
01005955     push edi
01005956     push LMEM_ZEROINIT
01005958     call esi ; LocalAlloc
0100595A     test eax, eax
0100595C     mov g_pMEMHistory, eax
01005961     jz  Err_CpuNumAbove32
01005967     push 0                  ; puReturnLength
01005969     lea eax, [ebp+SYSPROCPERFINFO]
0100596F     push 600h               ; 为32个CPU准备空间
0100596F                             ; SizeOf(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)*32
01005974     push eax                ; pSystemInformation
01005975     push SystemProcessorPerformanceInformation ; SystemInformationClass
01005977     call ds:NtQuerySystemInformation
0100597D     test eax, eax
0100597F     jl  Err_CpuNumAbove32
01005985     movzx eax, g_cProcessors
0100598C     and [ebp+i], 0
01005990     test eax, eax
01005992     jle short CpuNumEquOne_1
01005994     lea eax, [ebp+SYSPROCPERFINFO.KernelTime]
0100599A     mov [ebp+pBuf], offset PreviousCPUKernelTime
010059A1
010059A1 Loop_IniCpuAllTime:
010059A1     mov ecx, [ebp+i]
010059A4     mov edx, [eax-8]        ; edx = IdleTime.LowPart
010059A7     mov edi, [eax+8]        ; edi = UserTime.LowPart
010059AA     mov esi, [eax+4]        ; esi = KernelTime.HighPart
010059AD     shl ecx, 3              ; ecx = i X 8
010059B0     mov ebx, [eax+0Ch]      ; ebx = UserTime.HighPart
010059B3     mov dword ptr PreviousCPUIdleTime.LowPart[ecx], edx
010059B9     mov edx, [eax-4]        ; edx = IdleTime.HighPart
010059BC     mov PreviousCPUIdleTime.HighPart[ecx], edx
010059C2     mov edx, [eax]          ; KernelTime.LowPart
010059C4     add edi, edx            ; edi = UserTime.LowPart + KernelTime.LowPart
010059C6     adc ebx, esi            ; 带进位加
010059C6                             ; ebx = UserTime.HighPart + KernelTime.HighPart
010059C8     add edx, [eax-8]        ; edx = KernelTime.LowPart + IdleTime.LowPart
010059CB     mov dword ptr PreviousCPUTotalTime.LowPart[ecx], edi
010059D1     mov PreviousCPUTotalTime.HighPart[ecx], ebx
010059D7     mov ecx, [ebp+pBuf]     ; PreviousCPUKernelTime的指针
010059DA     adc esi, [eax-4]        ; 带进位加
010059DA                             ; esi = KernelTime.HighPart + IdleTime.HighPart
010059DD     add eax, 30h            ; 取下一个CPU的相关数据
010059DD                             ; SizeOf(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)
010059E0     inc [ebp+i]
010059E3     mov [ecx], edx          ; PreviousCPUTotalTime.LowPart = KernelTime.LowPart + IdleTime.LowPart
010059E5     mov [ecx+4], esi        ; PreviousCPUTotalTime.HighPart = KernelTime.HighPart + IdleTime.HighPart
010059E8     add ecx, 8              ; 移动PreviousCPUKernelTime的指针
010059EB     mov [ebp+pBuf], ecx     ; 保存PreviousCPUKernelTime的指针
010059EE     movzx ecx, g_cProcessors
010059F5     cmp [ebp+i], ecx        ; 和Cpu的个数比较
010059F8     jl  short Loop_IniCpuAllTime
010059FA
010059FA CpuNumEquOne_1:             ; puReturnLength
010059FA     push 0
010059FC     lea eax, [ebp+SYSPERFINFO]
01005A02     push 138h               ; SizeOf(SYSTEM_PERFORMANCE_INFORMATION)
01005A07     push eax                ; pSystemInformation
01005A08     push SystemPerformanceInformation ; SystemInformationClass
01005A0A     call ds:NtQuerySystemInformation
01005A10     test eax, eax
01005A12     jge short Init_Exit
01005A14
01005A14 Err_CpuNumAbove32:          ; 如果出错返回 0
01005A14     xor al, al
01005A16     jmp short Exit
01005A18
01005A18 Init_Exit:
01005A18     mov eax, g_PageSize
01005A1D     shr eax, 10
01005A20     imul eax, [ebp+SYSPERFINFO.CommitLimit]
01005A27     mov g_MEMMax, eax
01005A2C     mov al, g_cProcessors   ; 返回Cpu的个数
01005A31
01005A31 Exit:
01005A31     pop edi
01005A32     pop esi
01005A33     pop ebx
01005A34     leave
01005A35     retn
01005A35 InitPerfInfo endp
01005A35


NtQuerySystemInformation非常复杂,其中的结构随着Windows的版本变化会发生变化,这里给出的结构是2K系统的。
2007-9-9 12:32
0
雪    币: 141
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
不一定哦!
还有一个方法:
右击“我的电脑” “属性” “高级” “环境变量” “系统变量” “NUMBER_OF_PROCESSORS”(xp,vista,2k Pro)
我的“双核” 显示为“2”
老婆的“本本”(单核)显示为“1”
只要引用系统变量即可看除出(前提:双核装驱动后)
2007-9-9 20:54
0
雪    币: 238
活跃值: (326)
能力值: ( LV12,RANK:450 )
在线值:
发帖
回帖
粉丝
4
概念不同,你是从设备属性的窗口获得,我们这里谈的是从程序中获得,你的意思是写个程序,然后运行,然后打开你的设备窗口,然后看到CPU的个数,然后将这个参数填入你运行的程序,I服了u。
我这里只不过讨论了如何通过NtQuerySystemInformation获得cpu个数的问题,并同时向对这个函数不是很了解的朋友介绍一下这个函数的功能,乘机卖弄一下,哈哈。
道不同不相为谋。
2007-9-9 21:07
0
雪    币: 141
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
用程序一样查到系统变量可以呀!你不知道吗?
=========asp.net========
<% @ Page Language="C#" %>
<% @ Import Namespace="System.Data" %>
<Script Language="C#" Runat="Server">
public void Page_Load(Object src,EventArgs e)
{
  //本程序用来取得所有环境变量的值    
}
</script>
<html>
<head>
<title></title>
</head>
<body>
下面是获得的环境变量列表(Show All Value Of ServerVariables):

<p>
<table border=1>
<tr><td>环境变量名(ServerVariable)</td><td>其值(Value)</td></tr>
<%
  
  NameValueCollection rsv=Request.ServerVariables;
  //获得环境变量的个数
  int rsvCount=rsv.Count;
  //用于取得Key值
  string strKey;

  for(int i=0;i<rsvCount;i++)
  {
    strKey=rsv.GetKey(i);
%>
  <tr>
    <td><% =strKey %></td>
    <td><% =rsv.Get(strKey) %></td>
  </tr>
<% } %>
</table>
</p>
看看所有的环境变量都出来了
</body>
</html>
=======================
(刚学asp.net是写的,垃圾代码较多。见谅。)
C++可以用GetEnvironmentVariable
C可以用Getenv

头文件:dir.h

  getenv()读取环境变量的当前值的函数

  原形:char *getenv(const char *name)

  用法:s=getenv("环境变量名");

  需先定义char *s;
2007-9-10 15:40
0
雪    币: 238
活跃值: (326)
能力值: ( LV12,RANK:450 )
在线值:
发帖
回帖
粉丝
6
有100种方法可以获得这些信息,直接读注册表也可以,好像不是什么神秘的东西,很奇怪你的想法,只要没有使用你的方法,就是不对的,奇怪了。
我只不过是介绍一下NtQuerySystemInformation函数,你要是不喜欢,大可不看。
2007-9-10 18:02
0
雪    币: 1017
活跃值: (1002)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
爆破它不就行了?
2007-9-11 23:25
0
雪    币: 141
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
一样呀!没用你的东西一样不对,我只不过是介绍一下其他方法,你要是不喜欢,大可不看。
2007-9-14 12:40
0
雪    币: 398
活跃值: (343)
能力值: (RANK:650 )
在线值:
发帖
回帖
粉丝
9
可以用GetSystemInfo

我只不过是介绍一下其他方法,大家要是不喜欢,大可不看。
2007-9-14 13:45
0
雪    币: 494
活跃值: (629)
能力值: ( LV9,RANK:1210 )
在线值:
发帖
回帖
粉丝
10
用WinDbg查KeNumberProcessors试试
2007-9-14 18:27
0
雪    币: 39
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
11
既然软件对CPU个数敏感,那么lz就是想办法跳过去了,程序安装了成功,也不一定能运行,运行可能会发生无法预料的后果,建议最好找双核版或者多核版
2007-9-14 19:17
0
雪    币: 267
活跃值: (16)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
12
能不能改一下Kernel,只使用一个CPU呢?
2007-9-14 19:44
0
雪    币: 209
活跃值: (10)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
13
直接跳过可能会发生不可预料的问题。。。
2007-9-14 20:13
0
雪    币: 141
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
14
内核变量KeNumberProcessors用于指明驱动程序运行的系统上拥有的活跃的CPU数目。在WindowsXP的     中该变量的定义已经从一个指针改成了一个变量。Windows2000上该变量的定义方式决定了它在使用时需要利用*号取出其内容(e.g.   *KeNumberProcessors)。而因为这一改变,WindowsXPsp1编译环境下的驱动程序不需要(也不能够)在变量前面加*号(e.g.   KeNumberProcessors)。   
          驱动程序如果不能正确使用KeNumberProcessors会得到一个   "illegal   indirection"编译时错误。   
   
          注意:不管它使用了什么声明,驱动程序只要根据其编译环境合适地引用KeNumberProcessors都能在Windows2000和WindowsXP上正常工作。因此,一个在windows2000上编译的正确引用了KeNumberProcessors的驱动程序,当它不管在Windows2000还是WindowsXP上运行的时候都能获得该变量的正确值。   

引自Google

??内核变量?????活跃的CPU数目 写驱动用的?
2007-9-15 13:17
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
15
是个什么样的软件居然要先测CPU的数目呢?如果不是内核级的软件应该CPU多了更好啊,如果软件作者这么注意CPU的数目,的确有必要担心直接跳过这个检测是否有问题.
2007-9-18 08:07
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
16
高兴  高兴
2007-9-18 08:57
0
雪    币: 1829
活跃值: (1377)
能力值: (RANK:50 )
在线值:
发帖
回帖
粉丝
17
cpuid也行,不过还是喜欢NtQuerySystemInformation
2007-9-18 08:59
0
雪    币: 238
活跃值: (326)
能力值: ( LV12,RANK:450 )
在线值:
发帖
回帖
粉丝
18
GetSystemInfo还是调用NtQuerySystemInformation
//kernel32.dll  GetSystemInfo   Ordial 375
77E87B10 ; void __stdcall GetSystemInfo(LPSYSTEM_INFO lpSystemInfo)
77E87B10           public _GetSystemInfo@4
77E87B10 _GetSystemInfo@4 proc near
77E87B10
77E87B10 SysBaseInfo= SYSTEM_BASIC_INFORMATION ptr -38h
77E87B10 SysProcInfo= SYSTEM_PROCESSOR_INFORMATION ptr -0Ch
77E87B10 lpSystemInfo= dword ptr  8
77E87B10
77E87B10     push  ebp
77E87B11     mov   ebp, esp
77E87B13     sub   esp, 38h
77E87B16     push  ebx
77E87B17     push  esi
77E87B18     mov   esi, [ebp+lpSystemInfo]
77E87B1B     push  edi
77E87B1C     push  9
77E87B1E     xor   eax, eax
77E87B20     pop   ecx
77E87B21     mov   edi, esi
77E87B23     xor   ebx, ebx
77E87B25     rep stosd
77E87B27     mov   edi, ds:__imp__NtQuerySystemInformation
77E87B2D     push  ebx
77E87B2E     lea   eax, [ebp+SysBaseInfo]
77E87B31     push  2Ch                         ; sizeof(SYSTEM_BASIC_INFORMATION)
77E87B33     push  eax
77E87B34     push  ebx                         ; SystemBasicInformation
77E87B35     call  edi                             ; NtQuerySystemInformation
77E87B37     cmp   eax, ebx
77E87B39     jl    loc_77E87C12
77E87B3F     push  ebx
77E87B40     lea   eax, [ebp+SysProcInfo]
77E87B43     push  0Ch                         ; sizeof(SYSTEM_PROCESSOR_INFORMATION)
77E87B45     push  eax
77E87B46     push  SystemProcessorInformation
77E87B48     call  edi                             ; NtQuerySystemInformation
77E87B4A     cmp   eax, ebx
77E87B4C     jl    loc_77E87C12
77E87B52     mov   ecx, [ebp+SysBaseInfo.uPageSize]
77E87B55     mov   ax, [ebp+SysProcInfo.wKeProcessorArchitecture]
77E87B59     mov   [esi+_SYSTEM_INFO.dwPageSize], ecx
77E87B5C     mov   ecx, [ebp+SysBaseInfo.pLowestUserAddress]
77E87B5F     mov   [esi+_SYSTEM_INFO.lpMinimumApplicationAddress], ecx
77E87B62     mov   ecx, [ebp+SysBaseInfo.pMmHighestUserAddress]
77E87B65     mov   [esi+_SYSTEM_INFO.lpMaximumApplicationAddress], ecx
77E87B68     mov   ecx, [ebp+SysBaseInfo.uKeActiveProcessors]
77E87B6B     mov   dx, [ebp+SysProcInfo.wKeProcessorRevision]
77E87B6F     mov   [esi+_SYSTEM_INFO.dwActiveProcessorMask], ecx
77E87B72     movsx ecx, [ebp+SysBaseInfo.bKeNumberProcessors]
77E87B76     mov   [esi+_SYSTEM_INFO.dwNumberOfProcessors], ecx
77E87B79     mov   cx, [ebp+SysProcInfo.wKeProcessorLevel]
77E87B7D     cmp   ax, bx
77E87B80     mov   [esi+_SYSTEM_INFO.wProcessorArchitecture], ax
77E87B83     mov   [esi+_SYSTEM_INFO.wReserved], bx
77E87B87     mov   [esi+_SYSTEM_INFO.wProcessorLevel], cx
77E87B8B     mov   [esi+_SYSTEM_INFO.wProcessorRevision], dx
77E87B8F     jnz   short loc_77E87BB8
77E87B91     cmp   cx, Intel_80386
77E87B95     jnz   short loc_77E87BA0
77E87B97     mov   [esi+_SYSTEM_INFO.dwProcessorType], PROCESSOR_INTEL_386
77E87B9E     jmp   short loc_77E87BF7
77E87BA0
77E87BA0 loc_77E87BA0:
77E87BA0     cmp   cx, Intel_80486
77E87BA4     jnz   short loc_77E87BAF
77E87BA6     mov   [esi+_SYSTEM_INFO.dwProcessorType], PROCESSOR_INTEL_486
77E87BAD     jmp   short loc_77E87BF7
77E87BAF
77E87BAF loc_77E87BAF:
77E87BAF     mov   [esi+_SYSTEM_INFO.dwProcessorType], PROCESSOR_INTEL_PENTIUM
77E87BB6     jmp   short loc_77E87BF7
77E87BB8
77E87BB8 loc_77E87BB8:
77E87BB8     cmp   ax, PROCESSOR_ARCHITECTURE_MIPS
77E87BBC     jnz   short loc_77E87BC7
77E87BBE     mov   [esi+_SYSTEM_INFO.dwProcessorType], PROCESSOR_MIPS_R4000
77E87BC5     jmp   short loc_77E87BF7
77E87BC7
77E87BC7 loc_77E87BC7:
77E87BC7     cmp   ax, PROCESSOR_ARCHITECTURE_ALPHA
77E87BCB     jnz   short loc_77E87BD6
77E87BCD     mov   [esi+_SYSTEM_INFO.dwProcessorType], PROCESSOR_ALPHA_21064
77E87BD4     jmp   short loc_77E87BF7
77E87BD6
77E87BD6 loc_77E87BD6:
77E87BD6     cmp   ax, PROCESSOR_ARCHITECTURE_PPC
77E87BDA     jnz   short loc_77E87BE5
77E87BDC     mov   [esi+_SYSTEM_INFO.dwProcessorType], PROCESSOR_PPC_604
77E87BE3     jmp   short loc_77E87BF7
77E87BE5
77E87BE5 loc_77E87BE5:
77E87BE5     cmp   ax, PROCESSOR_ARCHITECTURE_IA64
77E87BE9     jnz   short loc_77E87BF4
77E87BEB     mov   [esi+_SYSTEM_INFO.dwProcessorType], PROCESSOR_INTEL_IA64
77E87BF2     jmp   short loc_77E87BF7
77E87BF4
77E87BF4 loc_77E87BF4:
77E87BF4     mov   [esi+_SYSTEM_INFO.dwProcessorType], ebx
77E87BF7
77E87BF7 loc_77E87BF7:
77E87BF7     mov   eax, [ebp+SysBaseInfo.uAllocationGranularity]
77E87BFA     push  ebx                                    ; ProcessId
77E87BFB     mov   [esi+_SYSTEM_INFO.dwAllocationGranularity], eax
77E87BFE     call  _GetProcessVersion@4        ; GetProcessVersion(x)
77E87C03     cmp   eax, 30033h
77E87C08     jnb   short loc_77E87C12
77E87C0A     mov   [esi+_SYSTEM_INFO.wProcessorLevel], bx
77E87C0E     mov   [esi+_SYSTEM_INFO.wProcessorRevision], bx
77E87C12
77E87C12 loc_77E87C12:
77E87C12     pop   edi
77E87C13     pop   esi
77E87C14     pop   ebx
77E87C15     leave
77E87C16     retn  4
77E87C16 _GetSystemInfo@4 endp
2007-9-22 11:07
0
雪    币: 207
活跃值: (40)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
19
个人觉得,好的程序员不一定要什么方法都会,重要的是要懂得用有限的方法去实现目的。有时候,简单一点的做法可能还会提高运行效率。。。
2007-9-22 23:34
0
雪    币: 200
活跃值: (11)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
20
简单和有效是两码事情.
2007-9-22 23:47
0
游客
登录 | 注册 方可回帖
返回
//