64,654
社区成员
发帖
与我相关
我的任务
分享
extern "C" {
#ifndef LPLONGLONG
#define LPLONGLONG LONGLONG*
#endif
int __stdcall WHX_Init(
int APIVersion = 1
);
bool WINAPI WHX_Done(
);
bool WINAPI WHX_Open(
LPCSTR lpResName
);
bool WINAPI WHX_Create(
LPCSTR lpPathName,
int Size
);
bool WINAPI WHX_Close(
);
bool WINAPI WHX_CloseAll(
);
bool WINAPI WHX_NextObj(
);
bool WINAPI WHX_Save(
);
bool WINAPI WHX_SaveAs(
LPCSTR lpNewFileName
);
bool WINAPI WHX_SaveAll(
);
bool WINAPI WHX_OpenEx(
LPCSTR lpResName,
int Param
);
bool WINAPI WHX_Read(
LPVOID lpBuffer,
int Bytes
);
bool WINAPI WHX_Write(
LPVOID lpBuffer,
int Bytes
);
bool WINAPI WHX_GetSize(
LPLONGLONG lpSize
);
bool WINAPI WHX_Goto(
LONGLONG Ofs
);
bool WINAPI WHX_Move(
LONGLONG Distance
);
bool WINAPI WHX_CurrentPos(
LPLONGLONG lpOfs
);
bool WINAPI WHX_SetBlock(
LONGLONG Ofs1,
LONGLONG Ofs2
);
bool WINAPI WHX_Copy(
);
bool WINAPI WHX_CopyIntoNewFile(
LPCSTR lpNewFileName
);
bool WINAPI WHX_Cut(
);
bool WINAPI WHX_Remove(
);
bool WINAPI WHX_Paste(
);
bool WINAPI WHX_WriteClipboard(
);
bool WINAPI WHX_Find(
LPCSTR lpData,
LPCSTR lpOptions
);
bool WINAPI WHX_Replace(
LPCSTR lpData1,
LPCSTR lpData2,
LPCSTR lpOptions
);
bool WINAPI WHX_WasFound(
);
int WINAPI WHX_WasFoundEx(
);
bool WINAPI WHX_Convert(
LPCSTR lpSrcFormat,
LPCSTR lpDstFormat
);
bool WINAPI WHX_Encrypt(
LPCSTR lpKey,
int Algorithm
);
bool WINAPI WHX_Decrypt(
LPCSTR lpKey,
int Algorithm
);
bool WINAPI WHX_GetCurObjName(
LPCSTR lpObjName
);
bool WINAPI WHX_SetFeedbackLevel(
int Level
);
bool WINAPI WHX_GetErrorMsg(
LPCSTR lpErrorMsg
);
bool WINAPI WHX_SetErrorMsg(
LPCSTR lpErrorMsg
);
bool WINAPI WHX_GetStatus(
LPCSTR lpInstPath,
LPLONG lpWHXVersion,
LPLONG lpWHXSubVersion,
LPLONG lpReserved
);
}
///////////////////////////////////////////////////////////////////////////////
// WinHex C sample
// Copyright 2004 X_ways Software Technology AG
///////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <iostream>
//#include <Winsock2.h>
using namespace std;
#include "whxapi.h"
void DumpBuf (char* buf, int count)
{
const char HexChars[] = "0123456789abcdef";
const int ValuesPerLine = 16;
const int AddressChars = 4;
int i, j;
for (i = 0; i * ValuesPerLine < count; i++) {
for (j = AddressChars-2; j >= 0; j--)
cout << HexChars[(i >> (j*4)) & 15];
cout << "0: ";
//cout << HexChars[(i>>4) & 15] << HexChars[i & 15] << "0: ";
for (j = 0; j < ValuesPerLine; j++) {
if (i * ValuesPerLine + j < count) {
unsigned char c = buf[i * ValuesPerLine + j];
cout << HexChars[(c>>4) & 15] << HexChars[c & 15] << " ";
} else
cout << " ";
}
for (j = 0; j < ValuesPerLine; j++) {
if (i * ValuesPerLine + j < count) {
unsigned char c = max (buf[i * ValuesPerLine + j], 32);
cout << c;
} else
cout << " ";
}
cout << endl;
}
}
///////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv)
{
// Open a file in read-only mode (flag 0x1).
// You can also open an image file with the contents of a disk and interpret
// it as such by specifying another flag (0x4).
if (argc < 2) {
cout << "Please give a file name" << endl;
return 1;
}
// Initialize the WinHex API, so that it is ready for use
int initRes = WHX_Init(1);
if (initRes <= 0) {
cout << "Could not initialize WinHexAPI.dll, error" << initRes << endl;
WHX_Done();
return 1;
} else if (initRes == 2) {
cout << "Opened WinHex API, evaluation version" << endl;
}
if (! WHX_OpenEx(argv[1], 0x00000001)) {
cout << "Error opening " << argv[1] << endl;
WHX_Done();
return 1;
}
//WHX_Goto(SomeOffset);
char buf[256];
WHX_Read(buf, sizeof(buf));
DumpBuf(buf, sizeof(buf));
// Close the file
WHX_Close();
// Properly free all allocated resources and release the WinHex API
WHX_Done();
return 0;
}