1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include <iomanip>
#include <iostream>
#include <windows.h>
using namespace std;
int main ()
{
HANDLE hFile = CreateFileA ("C:/Buildsvn.txt",
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (INVALID_HANDLE_VALUE == hFile)
{
cout << "Unable to open the file, error code " << GetLastError();
return 0;
}
LARGE_INTEGER fSize;
if (!GetFileSizeEx (hFile, &fSize))
{
cout << "Unable to get the file size, error code " << GetLastError();
CloseHandle (hFile);
return 0;
}
HANDLE hMapping = CreateFileMappingA (hFile,
NULL,
PAGE_READONLY,
0,
0,
NULL);
if (NULL == hMapping)
{
cout << "Unable to create file mapping, error code " << GetLastError();
CloseHandle (hFile);
return 0;
}
void* pBuffer = MapViewOfFile( hMapping,
FILE_MAP_READ,
0,
0,
fSize.QuadPart);
if (NULL == pBuffer)
{
cout << "Unable to map the file, error code " << GetLastError();
CloseHandle (hMapping);
CloseHandle (hFile);
return 0;
}
unsigned char* pBuf = (unsigned char*)pBuffer;
for (size_t i = 0; i < fSize.QuadPart; i++)
{
cout << hex << uppercase << setfill ('0') << std::setw(2) << (unsigned short)(unsigned char)pBuf[i] << " ";
}
UnmapViewOfFile(pBuffer);
CloseHandle (hMapping);
CloseHandle (hFile);
return 0;
}
|