我在一个MFC的工程里
调用这个文件Physmem.c//========================================================
//
// Physmem
//
//
// This program demonstrates how you can open and
// map physical memory. This is essentially the NT
// equivalent of the \dev\kmem device in UNIX.
//
//========================================================
#include <windows.h>
#include <stdio.h>
#include <memory.h>
#include <stdlib.h>
#include <string.h>
#include "native.h"//
// Number of bytes to print per line
//
#define BYTESPERLINE 16//
// Lines to print before pause
//
#define LINESPERSCREEN 25
//
// Functions in NTDLL that we dynamically locate
//NTSTATUS (__stdcall *NtUnmapViewOfSection)
(
IN HANDLE ProcessHandle,
IN PVOID BaseAddress
);NTSTATUS (__stdcall *NtOpenSection)
(
OUT PHANDLE SectionHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes
);NTSTATUS (__stdcall *NtMapViewOfSection)
(
IN HANDLE SectionHandle,
IN HANDLE ProcessHandle,
IN OUT PVOID *BaseAddress,
IN ULONG ZeroBits,
IN ULONG CommitSize,
IN OUT PLARGE_INTEGER SectionOffset, /* optional */
IN OUT PULONG ViewSize,
IN SECTION_INHERIT InheritDisposition,
IN ULONG AllocationType,
IN ULONG Protect
);VOID (__stdcall *RtlInitUnicodeString)
(
IN OUT PUNICODE_STRING DestinationString,
IN PCWSTR SourceString
);ULONG (__stdcall *RtlNtStatusToDosError)
(
IN NTSTATUS Status
);//----------------------------------------------------------------------
//
// PrintError
//
// Formats an error message for the last error
//
//----------------------------------------------------------------------
void PrintError( char *message, NTSTATUS status )
{
char *errMsg; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, RtlNtStatusToDosError( status ),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &errMsg, 0, NULL );
printf("%s: %s\n", message, errMsg );
LocalFree( errMsg );
}
//--------------------------------------------------------
//
// UnmapPhysicalMemory
//
// Maps a view of a section.
//
//--------------------------------------------------------
VOID UnmapPhysicalMemory( DWORD Address )
{
NTSTATUS status; status = NtUnmapViewOfSection( (HANDLE) -1, (PVOID) Address );
if( !NT_SUCCESS(status))
{
PrintError("Unable to unmap view", status );
}
}
//--------------------------------------------------------
//
// MapPhysicalMemory
//
// Maps a view of a section.
//
//--------------------------------------------------------
BOOLEAN MapPhysicalMemory( HANDLE PhysicalMemory,
PDWORD Address, PDWORD Length,
PDWORD VirtualAddress )
{
NTSTATUS ntStatus;
PHYSICAL_ADDRESS viewBase;
char error[256]; *VirtualAddress = 0;
viewBase.QuadPart = (ULONGLONG) (*Address);
ntStatus = NtMapViewOfSection (PhysicalMemory,
(HANDLE) -1,
(PVOID) VirtualAddress,
0L,
*Length,
&viewBase,
Length,
ViewShare,
0,
PAGE_READONLY ); if( !NT_SUCCESS( ntStatus ))
{
sprintf( error, "Could not map view of %X length %X",
*Address, *Length );
PrintError( error, ntStatus );
return FALSE;
} *Address = viewBase.LowPart;
return TRUE;
}
//--------------------------------------------------------
//
// OpensPhysicalMemory
//
// This function opens the physical memory device. It
// uses the native API since
//
//--------------------------------------------------------
HANDLE OpenPhysicalMemory()
{
NTSTATUS status;
HANDLE physmem;
UNICODE_STRING physmemString;
OBJECT_ATTRIBUTES attributes;
WCHAR physmemName[] = L"\\device\\physicalmemory"; RtlInitUnicodeString( &physmemString, physmemName ); InitializeObjectAttributes( &attributes, &physmemString,
OBJ_CASE_INSENSITIVE, NULL, NULL );
status = NtOpenSection( &physmem, SECTION_MAP_READ, &attributes ); if( !NT_SUCCESS( status ))
{
PrintError( "Could not open \\device\\physicalmemory", status );
return NULL;
} return physmem;
}
//--------------------------------------------------------
//
// LocateNtdllEntryPoints
//
// Finds the entry points for all the functions we
// need within NTDLL.DLL.
//
//--------------------------------------------------------
BOOLEAN LocateNtdllEntryPoints()
{
if( !(RtlInitUnicodeString = (void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"RtlInitUnicodeString" )) )
{
return FALSE;
} if( !(NtUnmapViewOfSection = (void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"NtUnmapViewOfSection" )) )
{
return FALSE;
} if( !(NtOpenSection = (void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"NtOpenSection" )) )
{
return FALSE;
} if( !(NtMapViewOfSection = (void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"NtMapViewOfSection" )) )
{
return FALSE;
} if( !(RtlNtStatusToDosError = (void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"RtlNtStatusToDosError" )) )
{
return FALSE;
}
return TRUE;
}/* My function------2001.9.29 zhouying */
/* search string in f000:0000-ffff */
ULONG FindBiosString(char* strTarget, int nLength)
{
HANDLE physmem;
DWORD vaddress, paddress, length;
BOOL bFind = 0;
int i;
void *pCur;
ULONG lSearchNum = 0 ; //
// Load NTDLL entry points
//
if( !LocateNtdllEntryPoints() )
{
//printf("Unable to locate NTDLL entry points.\n\n");
MessageBox(NULL,"Unable to locate NTDLL entry points.","error",MB_OK);
return -1;
} //
// Open physical memory
//
if( !(physmem = OpenPhysicalMemory()))
{
return -1;
}
paddress = 0xf0000;
length = 0xffff; //
// Map it
//
if( !MapPhysicalMemory( physmem, &paddress, &length, &vaddress ))
{
CloseHandle( physmem );
return FALSE;
} //here do the search
for (i = 0; i<(0xffff-nLength); i++)
{
pCur = (void*)(vaddress+i);
if (0 == memcmp(pCur, strTarget, nLength))
{
//bFind = 1;
lSearchNum ++ ;
//break;
}
} //
// Unmap
//
UnmapPhysicalMemory( vaddress ); //
// Close physical memory section
//
CloseHandle( physmem ); return lSearchNum;}我也加了头文件native.h 为什么编译总是出现这个错误
fatal error C1010: unexpected end of file while looking for precompiled header directive
而别人的提供的源代码 编译这个文件却可以通过???
调用这个文件Physmem.c//========================================================
//
// Physmem
//
//
// This program demonstrates how you can open and
// map physical memory. This is essentially the NT
// equivalent of the \dev\kmem device in UNIX.
//
//========================================================
#include <windows.h>
#include <stdio.h>
#include <memory.h>
#include <stdlib.h>
#include <string.h>
#include "native.h"//
// Number of bytes to print per line
//
#define BYTESPERLINE 16//
// Lines to print before pause
//
#define LINESPERSCREEN 25
//
// Functions in NTDLL that we dynamically locate
//NTSTATUS (__stdcall *NtUnmapViewOfSection)
(
IN HANDLE ProcessHandle,
IN PVOID BaseAddress
);NTSTATUS (__stdcall *NtOpenSection)
(
OUT PHANDLE SectionHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes
);NTSTATUS (__stdcall *NtMapViewOfSection)
(
IN HANDLE SectionHandle,
IN HANDLE ProcessHandle,
IN OUT PVOID *BaseAddress,
IN ULONG ZeroBits,
IN ULONG CommitSize,
IN OUT PLARGE_INTEGER SectionOffset, /* optional */
IN OUT PULONG ViewSize,
IN SECTION_INHERIT InheritDisposition,
IN ULONG AllocationType,
IN ULONG Protect
);VOID (__stdcall *RtlInitUnicodeString)
(
IN OUT PUNICODE_STRING DestinationString,
IN PCWSTR SourceString
);ULONG (__stdcall *RtlNtStatusToDosError)
(
IN NTSTATUS Status
);//----------------------------------------------------------------------
//
// PrintError
//
// Formats an error message for the last error
//
//----------------------------------------------------------------------
void PrintError( char *message, NTSTATUS status )
{
char *errMsg; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, RtlNtStatusToDosError( status ),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &errMsg, 0, NULL );
printf("%s: %s\n", message, errMsg );
LocalFree( errMsg );
}
//--------------------------------------------------------
//
// UnmapPhysicalMemory
//
// Maps a view of a section.
//
//--------------------------------------------------------
VOID UnmapPhysicalMemory( DWORD Address )
{
NTSTATUS status; status = NtUnmapViewOfSection( (HANDLE) -1, (PVOID) Address );
if( !NT_SUCCESS(status))
{
PrintError("Unable to unmap view", status );
}
}
//--------------------------------------------------------
//
// MapPhysicalMemory
//
// Maps a view of a section.
//
//--------------------------------------------------------
BOOLEAN MapPhysicalMemory( HANDLE PhysicalMemory,
PDWORD Address, PDWORD Length,
PDWORD VirtualAddress )
{
NTSTATUS ntStatus;
PHYSICAL_ADDRESS viewBase;
char error[256]; *VirtualAddress = 0;
viewBase.QuadPart = (ULONGLONG) (*Address);
ntStatus = NtMapViewOfSection (PhysicalMemory,
(HANDLE) -1,
(PVOID) VirtualAddress,
0L,
*Length,
&viewBase,
Length,
ViewShare,
0,
PAGE_READONLY ); if( !NT_SUCCESS( ntStatus ))
{
sprintf( error, "Could not map view of %X length %X",
*Address, *Length );
PrintError( error, ntStatus );
return FALSE;
} *Address = viewBase.LowPart;
return TRUE;
}
//--------------------------------------------------------
//
// OpensPhysicalMemory
//
// This function opens the physical memory device. It
// uses the native API since
//
//--------------------------------------------------------
HANDLE OpenPhysicalMemory()
{
NTSTATUS status;
HANDLE physmem;
UNICODE_STRING physmemString;
OBJECT_ATTRIBUTES attributes;
WCHAR physmemName[] = L"\\device\\physicalmemory"; RtlInitUnicodeString( &physmemString, physmemName ); InitializeObjectAttributes( &attributes, &physmemString,
OBJ_CASE_INSENSITIVE, NULL, NULL );
status = NtOpenSection( &physmem, SECTION_MAP_READ, &attributes ); if( !NT_SUCCESS( status ))
{
PrintError( "Could not open \\device\\physicalmemory", status );
return NULL;
} return physmem;
}
//--------------------------------------------------------
//
// LocateNtdllEntryPoints
//
// Finds the entry points for all the functions we
// need within NTDLL.DLL.
//
//--------------------------------------------------------
BOOLEAN LocateNtdllEntryPoints()
{
if( !(RtlInitUnicodeString = (void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"RtlInitUnicodeString" )) )
{
return FALSE;
} if( !(NtUnmapViewOfSection = (void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"NtUnmapViewOfSection" )) )
{
return FALSE;
} if( !(NtOpenSection = (void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"NtOpenSection" )) )
{
return FALSE;
} if( !(NtMapViewOfSection = (void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"NtMapViewOfSection" )) )
{
return FALSE;
} if( !(RtlNtStatusToDosError = (void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"RtlNtStatusToDosError" )) )
{
return FALSE;
}
return TRUE;
}/* My function------2001.9.29 zhouying */
/* search string in f000:0000-ffff */
ULONG FindBiosString(char* strTarget, int nLength)
{
HANDLE physmem;
DWORD vaddress, paddress, length;
BOOL bFind = 0;
int i;
void *pCur;
ULONG lSearchNum = 0 ; //
// Load NTDLL entry points
//
if( !LocateNtdllEntryPoints() )
{
//printf("Unable to locate NTDLL entry points.\n\n");
MessageBox(NULL,"Unable to locate NTDLL entry points.","error",MB_OK);
return -1;
} //
// Open physical memory
//
if( !(physmem = OpenPhysicalMemory()))
{
return -1;
}
paddress = 0xf0000;
length = 0xffff; //
// Map it
//
if( !MapPhysicalMemory( physmem, &paddress, &length, &vaddress ))
{
CloseHandle( physmem );
return FALSE;
} //here do the search
for (i = 0; i<(0xffff-nLength); i++)
{
pCur = (void*)(vaddress+i);
if (0 == memcmp(pCur, strTarget, nLength))
{
//bFind = 1;
lSearchNum ++ ;
//break;
}
} //
// Unmap
//
UnmapPhysicalMemory( vaddress ); //
// Close physical memory section
//
CloseHandle( physmem ); return lSearchNum;}我也加了头文件native.h 为什么编译总是出现这个错误
fatal error C1010: unexpected end of file while looking for precompiled header directive
而别人的提供的源代码 编译这个文件却可以通过???
解决方案 »
- MFC基于对话框,多线程 显示多画面
- 如何把任意一个字符串转换成一个32位的整数,不同字符串转换成不同整数,不要有重复!
- TreeCtrl上的节点,在其前边加了一个表示Checkbox的图片,然后又加了一个Icon,如果我想再增加一个Icon,应该怎么实现?
- 急,在线等!
- 高手请进:如何获取wlan和gprs的信号强度
- 原创 《读BitTorrent码日记》(9-30结分)
- 关于diret show的基本问题
- vs2008 *.exe.intermediate.manifest清单文件问题
- 关于JSONCPP的问题,大家帮我看看。
- 关于线程终止的问题?
- 请教一个关于多线程中显示图像的问题
- 怎样在两台机器之间实时的传输数据?
#include "stdafx.h"
Error executing cl.exe.不行啊
//
// Physmem
//
//
// This program demonstrates how you can open and
// map physical memory. This is essentially the NT
// equivalent of the \dev\kmem device in UNIX.
//
//========================================================
#include <windows.h>
#include <stdio.h>
#include <memory.h>
#include <stdlib.h>
#include <string.h>
#include "native.h"//
// Number of bytes to print per line
//
#define BYTESPERLINE 16//
// Lines to print before pause
//
#define LINESPERSCREEN 25
// 强制使用 C 语言方式编译
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
//下面是你的代码
...................
...................
...................
//到了你的代码的结束的地方
////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif // __cplusplus