📄 hgeneric.h
字号:
// HGeneric.h: interface for the CHGeneric class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_HGENERIC_H__0C5C8C14_E4DD_48E1_960F_98E9D9E86743__INCLUDED_)
#define AFX_HGENERIC_H__0C5C8C14_E4DD_48E1_960F_98E9D9E86743__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include "HLib32.h"
#include "Base64coding.h"
#include "HFile.h"
#include "classldr.h"
#define ADDRESS_ROOT 0
#define ADDRESS_PROVINCE 1
#define ADDRESS_CITY 2
#define ADDRESS_DISTRICT 3
#define ADDRESS_NETBAR 4
#define ADDRESS_CLIENT 5
#define XBKR_FILE_PLAIN 0
#define XBKR_FILE_HZIP 1
typedef unsigned int SOCKET;
//监听模式
#define XBKR_LISTEN_ASYN 0//收到数据后,发送给窗体,不等待窗体处理完成
#define XBKR_LISTEN_SYN 1//收到数据后,发送给窗体,不等待窗体处理完成,然后继续
class AFX_EXT_CLASS CListenThreadParam
{
public:
CListenThreadParam(){
m_wPort=9431;
m_hWnd=NULL;
m_pskt=NULL;
m_nMode=0;
}
CListenThreadParam(WORD wPort,HWND hWnd,SOCKET *pskt=NULL,int nMode=XBKR_LISTEN_ASYN){
m_wPort=wPort;
m_hWnd=hWnd;
m_pskt=pskt;
m_nMode=nMode;
}
CListenThreadParam(CListenThreadParam& other){
(*this)=other;
};
~CListenThreadParam(){};
CListenThreadParam& operator=(CListenThreadParam& other){
m_wPort=other.m_wPort;
m_hWnd=other.m_hWnd;
m_pskt=other.m_pskt;
m_nMode=other.m_nMode;
return other;
}
public:
WORD m_wPort;
HWND m_hWnd;
SOCKET *m_pskt;
int m_nMode;
};
#define RCV_DATA_LEN 4*1024
class AFX_EXT_CLASS CHReceiveThreadParm
{
public:
CHReceiveThreadParm(){
m_skt=0;
m_hWnd=NULL;
m_dwHerIP=0;
m_wPort=0;
m_nMode=XBKR_LISTEN_ASYN;
}
CHReceiveThreadParm(SOCKET skt,HWND hWnd,DWORD dwHerIP,WORD wPort,int nMode=XBKR_LISTEN_ASYN){
m_skt=skt;
m_hWnd=hWnd;
m_dwHerIP=dwHerIP;
m_wPort=wPort;
m_nMode=nMode;
}
CHReceiveThreadParm(CHReceiveThreadParm& other){
(*this)=other;
};
~CHReceiveThreadParm(){};
CHReceiveThreadParm& operator=(CHReceiveThreadParm& other){
m_skt=other.m_skt;
m_hWnd=other.m_hWnd;
m_dwHerIP=other.m_dwHerIP;
m_wPort=other.m_wPort;
m_nMode=other.m_nMode;
return other;
}
public:
SOCKET m_skt;
HWND m_hWnd;
DWORD m_dwHerIP;
WORD m_wPort;
int m_nMode;
};
class AFX_EXT_CLASS CHReceiveInfo
{
public:
CHReceiveInfo(){
m_bufRcv=NULL;
m_nlenRcv=0;
m_dwHerIP=0;
m_wPort=0;
m_skt=0;
}
CHReceiveInfo(BYTE *bufRcv,int nLen,DWORD dwHerIP,WORD wPort,int skt=0){
m_bufRcv=bufRcv;//注意!!!用后手工销毁此缓冲区
m_nlenRcv=nLen;
m_dwHerIP=dwHerIP;
m_wPort=wPort;
m_skt=skt;
}
CHReceiveInfo(CHReceiveInfo& other){
(*this)=other;
};
~CHReceiveInfo(){};
CHReceiveInfo& operator=(CHReceiveInfo& other){
m_bufRcv=other.m_bufRcv;
m_nlenRcv=other.m_nlenRcv;
m_dwHerIP=other.m_dwHerIP;
m_wPort=other.m_wPort;
m_skt=other.m_skt;
return other;
}
public:
BYTE *m_bufRcv;
int m_nlenRcv;
DWORD m_dwHerIP;
WORD m_wPort;
int m_skt;
};
class AFX_EXT_CLASS CHGeneric
{
class AFX_EXT_CLASS CHPlayMusicInfo//奏乐线程入口参数
{
public:
CHPlayMusicInfo(int nMusic=0,int nFre=5,int nTime=5){
m_nMusic=nMusic;
m_nFre=nFre;
m_nTime=nTime;
};
~CHPlayMusicInfo(){};
CHPlayMusicInfo& operator =(CHPlayMusicInfo& other){
m_nMusic=other.m_nMusic;
m_nFre=other.m_nFre;
m_nTime=other.m_nTime;
return *this;
}
int m_nMusic;
int m_nFre;
int m_nTime;
};
public:
CHGeneric();
virtual ~CHGeneric();
public:
static int EncodePWD(char* str,char bufRet[256]);
static int DecodePWD(char* str,char bufRet[128]);
// static CHString RegGetVal(CHString strRegSubBranch,CHString strRegSubKey,HKEY hRootKey=HKEY_LOCAL_MACHINE,DWORD dwType=REG_SZ);
static HKEY MatchKEY(CHString strKey);
static CHString RegGetVal(CHString strRegKey,DWORD dwType=REG_SZ);
static int SendData2Net(BYTE *bufSend,int nLen,DWORD dwIP,int nPort);
static BOOL HZipFile(CHString strFile,CHString strZipFile);
static BOOL HUnZipFile(CHString strZipFile,CHString strFile);
static DWORD MakeTimes(DWORD dw,int nMod=16);
static DWORD MakeTimes(DWORD *pDW,int nMod=16);
static void PathNameShort2Long(char *szShortPathName,char szLongPathName[MAX_PATH]);
static BOOL ExecuteProcess(PROCESS_INFORMATION *pProcessInfo,char *szExe,char *szParam,UINT wWaitTime=0);
static BOOL CallProcess(char *szExe,char *szParam);
static BOOL IsFileExist(char *strURL);
static UINT AfxMakeSureBox(const char *format, ...);
static UINT AfxChoiseBox(const char *format, ...);
static UINT AfxWarningBox(const char *format, ...);
static UINT AfxPromptBox(const char *format, ...);
static UINT AfxDBGBox(const char *format, ...);
static UINT AfxMakeSureTitleBox(CHString strText,CHString strTitle="");
static UINT AfxChoiseTitleBox(CHString strText,CHString strTitle="");
static UINT AfxWarningTitleBox(CHString strWarning,CHString strTitle="");
static UINT AfxPromptTitleBox(CHString strPrompt,CHString strTitle="");
static DWORD Crc32(BYTE *buf,long nLen,BOOL bTailIt=TRUE);
static BOOL Crc32Verify(BYTE *buf,long nLen);
static WORD Crc(BYTE *buf,long nLen,BOOL bTailIt=TRUE);
static BOOL CrcVerify(BYTE *buf,long nLen);
static BOOL RandCheckIndependence(BYTE *lpbuffer);
static int l_bufchr(BYTE* bufBegin,int nLen,BYTE c);
static int r_bufchr(BYTE* bufEnd,int nLen,BYTE c);
//Base64(PEM)编码
static long EnBase64(char *bufBin, long lLenBin, char *buf64);
//Base64(PEM)解码
static long DeBase64(char *buf64, long lLen64, char *bufBin);
static bool IsPEM(BYTE * buf,int nLen);
static bool IsPEMChar(char c);
static void MsgBox(BOOL bDbg,char * str);
static int WriteLog(BOOL bWriteTime,BOOL bShowBox,char *strFile,const char *format, ...);
static int WriteLogDBG(BOOL bDbg,BOOL bShowBox,char *strFile,const char *format, ...);
static int StoreBuf2File(BYTE *buf,int nLen,CHString strFile);
//从内存中加载动态库______________________________________
#define FORCE_LOAD_NEW_IMAGE 0x00000400
#define SIZE_OF_PARAMETER_BLOCK 4096
#define REBIND_IMAGE_IMPORTS 0x00000100
#define RWX_PERMISSIONS 0x00000200
#define DLL_ATTACH 0
#define DLL_DETACH 1
#define NTSIGNATURE(ptr) ((LPVOID)((BYTE *)(ptr) + ((PIMAGE_DOS_HEADER)(ptr))->e_lfanew))
#define SIZE_OF_NT_SIGNATURE (sizeof(DWORD))
#define PEFHDROFFSET(ptr) ((LPVOID)((BYTE *)(ptr)+((PIMAGE_DOS_HEADER)(ptr))->e_lfanew+SIZE_OF_NT_SIGNATURE))
#define OPTHDROFFSET(ptr) ((LPVOID)((BYTE *)(ptr)+((PIMAGE_DOS_HEADER)(ptr))->e_lfanew+SIZE_OF_NT_SIGNATURE+sizeof(IMAGE_FILE_HEADER)))
#define SECHDROFFSET(ptr) ((LPVOID)((BYTE *)(ptr)+((PIMAGE_DOS_HEADER)(ptr))->e_lfanew+SIZE_OF_NT_SIGNATURE+sizeof(IMAGE_FILE_HEADER)+sizeof(IMAGE_OPTIONAL_HEADER)))
#define RVATOVA(base,offset) ((LPVOID)((DWORD)(base)+(DWORD)(offset)))
typedef struct __imageparameters {
void *pMemBase;
char svName[MAX_PATH];
DWORD dwFlags;
int nLockCount;
struct __imageparameters *next;
} IMAGE_PARAMETERS;
typedef struct {
DWORD dwPageRVA;
DWORD dwBlockSize;
} IMAGE_FIXUP_BLOCK, *PIMAGE_FIXUP_BLOCK;
typedef struct {
WORD offset:12;
WORD type:4;
} IMAGE_FIXUP_ENTRY, *PIMAGE_FIXUP_ENTRY;
typedef BOOL (WINAPI *DLLMAIN_T)(HMODULE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
static void InitializeDLLLoad();
static void ExitLoad();
static HMODULE Load(LPCTSTR lpFileName);
static HMODULE LoadFromMem(void *pFileMem, char *svMappingName, DWORD dwFlags);
static BOOL Free(HMODULE hModule);
static FARPROC GetProcAdd(HMODULE hModule, LPCSTR lpProcName);
static BOOL GetOSVersion(OSVERSIONINFO &osvi);
static DWORD GetLocalIP(char szIP[16],BOOL bRevers=FALSE,BOOL bFormat=0);
private:
static HMODULE LoadEx(LPCTSTR lpFileName, HANDLE hFile, DWORD dwFlags);
static HMODULE GetHandle(char *svName);
static BOOL MapFromMem(void *pFileMem, void *pMem);
static BOOL PrepareMem(void *pMem, DWORD dwIMemSize, BOOL bResolve, BOOL bRebind);
static int RemoveReference(void *pMemBase, char *svName, DWORD *pdwFlags);
static BOOL RunMain(void *pMemBase, DWORD dwIMemSize, BOOL bDetach);
static BOOL ProtectMem(void *pMem, BOOL bRWX);
static int AddDLLReference(void *pMemBase, char *svName, DWORD dwFlags);
//从内存中加载动态库______________________________________
public:
static BOOL IsNum(BYTE *buf,int nLen);
static BOOL IsNum(BYTE b);
static unsigned _int64 GetInstructionPeriod();
//注册特定设备变动消息
static HANDLE RegDeviceNotification(HANDLE hWnd,GUID giDevice);
static BOOL UnRegDeviceNotification(HANDLE hNotifyDevNode);
static int Ping(DWORD dwIP,int nTimeOutms=1000);//返回Ping通的时间(ms)
static int Ping(char *szIP,int nTimeOutms=1000);//返回Ping通的时间(ms)
static BOOL IsOSVersionNT();
static CHString AnalysisAddress(CHString strPath,int nFlag=ADDRESS_ROOT);
static CHString GetFileName(CHString strFileURL);
static CHString GetFileMainName(CHString strFileURL);
static CHString GetFilePath(CHString strFileURL);
static CHString GetFileExtName(CHString strURL);
static CHString GetLongPathName(CHString strShortPathName);
static void PlayMusic(int nMusic=0,int nFre=5,int nTime=5);
static void PlayMusic(LPVOID lp);
static CHString GetWinPath();
static CHString GetSysPath();
static CHString GetCurPath();
static CHString WC2MC( PWSTR wbuf,int nLenWC=255);
static int MC2WC( unsigned char *mbuf, int nLenMC, WCHAR *wbuf);
static BOOL ExecuteProcess(PROCESS_INFORMATION *pProcessInfo,
CHString strExe,
CHString strParam,
UINT wWaitTime=0);
static int CallDllFun(CHString strDllFun,void *pParam=NULL);
static int CallDllFun(CHString strDll,CHString strFun,void *pParam=NULL);
static BOOL CallProcess(CHString strExe,CHString strParam);
static CHString Int2HexString(int n);
static CHString Int2String(int n);
static CHString Long2String(long l);
static CHString Float2String(float f);
static CHString Buf2Hex(unsigned char *buf,int nLen);
static int Hex2Buf(CHString str, unsigned char *buf);
static CHString Buf2Hex2(unsigned char *buf,int nLen);
static CHString Buf2PEM(unsigned char *buf,int nLen);
static int Hex2Buf2(CHString str, unsigned char *buf);
static char Hex2Bin(CHString str);
static void IP2Buf(CHString strIP,unsigned char bufIP[16]);
static void IPStrTo4Byte(CHString strIP,unsigned char bufIP[4],BOOL bReverse=0);
static CHString IPDW2Str(unsigned long lgIPAsDec,BOOL bReverse=0,BOOL bFormat=0);
static DWORD IPStr2DW(CHString strIP,BOOL bReverse=0);
static DWORD HostName2IP(BYTE *szHostName,BOOL bReverse=0);
static DWORD IPReverse(DWORD dwIP);
static void IPDW2Buf(DWORD lgIPAsDec, unsigned char buf[4]);
static char* CifrIDDW2Str(DWORD dwCKID,BOOL bReverse=0);
static DWORD CifrIDStr2DW(char szCKID[],BOOL bReverse=0);
static BOOL IsAlreadyRun(CHString strApplicationName);
static BOOL IsFileExist(CHString strURL);
static CHString SeekFileByExtName(CHString strPath,CHString strExtName);
static CHString GetModuleFilePathName(HINSTANCE hInstance);
static CHString GetModuleFileExtName(HINSTANCE hInstance);
static CHString GetModuleFilePath(HINSTANCE hInstance);
static CHString GetModuleFileMainName(HINSTANCE hInstance);
static CHString GetAppProfile(HINSTANCE hIns);
static void GetDateTimeInBCD(char *buf);
static char* GetDateTimeInBCD();
static int GetDateTime(char *buf);
static char* GetDateTime();
static CHString GetStringValFromPrivateProfile(CHString strFileName,
CHString strSection,
CHString strKey,
CHString strDefault="");
//解析.xbkr配置文件_______________________________
static int GetXBKrFileSections(CHString strFile,CHString &strSections,int nFileType=XBKR_FILE_PLAIN);
static int WriteXBKrFileContent(CHString strContent,CHString strFile,int nFileType=XBKR_FILE_PLAIN);
static CHString ReadXBKrFileContent(CHString strFile,int nFileType=XBKR_FILE_PLAIN);
static CHString GetXBKrFileKeyVal(CHString strFile,CHString strSection,CHString strKey,CHString strDef="",int nFileType=XBKR_FILE_PLAIN);
static CHString GetKeyValFromXBKrFileContent(CHString strContent,CHString strSection,CHString strKey,CHString strDef);
static int SetXBKrFileKeyVal(CHString strFile,CHString strSection,CHString strKey,int nVal,int nFileType=XBKR_FILE_PLAIN);
static CHString SetXBKrFileKeyVal(CHString strFile,CHString strSection,CHString strKey,CHString strVal,int nFileType=XBKR_FILE_PLAIN);
static CHString GetStringValFromXBKrFile(CHString strFile,
CHString strSection,
CHString strKey,
CHString strDef="",
int nFileType=-1);
static CHString GetStringValFromXBKrFileContent(CHString strContent,
CHString strSection,
CHString strKey,
CHString strDef="");
static int GetIntValFromXBKrFile(CHString strFile,
CHString strSection,
CHString strKey,
int nDef=0,
int nFileType=-1);
static int GetIntValFromXBKrFileContent(CHString strContent,
CHString strSection,
CHString strKey,
int nDef=0);
//解析.xbkr配置文件_______________________________
};
#endif // !defined(AFX_HGENERIC_H__0C5C8C14_E4DD_48E1_960F_98E9D9E86743__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -