[原创]帮win8写了个简单命令行显示十六进制文件
64位win8不知道为什么没有debug了。动手写了个。
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
if (argc < 2)
{
_tprintf(_T("语法:cmdhex 文件名"));
return -1;
}
HANDLE hHexFile;
DWORD dwNumberOfBytesRead;
BYTE SectorBuffer[1024*10];
ULARGE_INTEGER dwFileSize = { 0 };
hHexFile = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL);
if (hHexFile == INVALID_HANDLE_VALUE)
{
_tprintf(_T("文件未找到!"));
return FALSE;
}
dwFileSize.LowPart = GetFileSize(hHexFile, &dwFileSize.HighPart );
ReadFile(hHexFile, SectorBuffer, dwFileSize.LowPart , &dwNumberOfBytesRead, NULL);
for (int i = 0; i < dwFileSize.LowPart ; ++i)
{
if (i % 8 == 0 )
{
_tprintf(_T(" "));
}
if (i % 16 == 0)
{
for (int n = 16; n >= 0; n--)
{
if (i == 0) break;
if (isgraph(SectorBuffer[i - n]))
{
_tprintf(_T("%c"), SectorBuffer[i - n]);
}
else
{
_tprintf(_T("."));
}
}
_tprintf(_T("\n"));
_tprintf(_T("%08X "), i);
}
_tprintf(_T("%02X "), SectorBuffer[i]);
}
CloseHandle(hHexFile);
// _getch();
return 0;
}
