Initial commit

This commit is contained in:
2026-06-12 23:18:12 +08:00
commit 424bde1b02
249 changed files with 40338 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "BaseThread.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
__fastcall TBaseThread::TBaseThread()
: TThread(true)
{
m_bWaiting = false;
m_hHaltSema = CreateSemaphore( NULL, 0, 1, NULL );
}
//---------------------------------------------------------------------------
__fastcall TBaseThread::~TBaseThread()
{
if( m_hHaltSema ){
CloseHandle( m_hHaltSema );
m_hHaltSema = NULL;
}
}
//---------------------------------------------------------------------------
bool __fastcall TBaseThread::Halt( DWORD dwMS )
{
if( int(dwMS)>0 ){
// m_bWaiting = true;
WaitForSingleObject( m_hHaltSema, dwMS );
// m_bWaiting = false;
}
return !Terminated;
}
//---------------------------------------------------------------------------
void __fastcall TBaseThread::Cancel(void)
{
Terminate();
Suspended = false;
ReleaseSemaphore( m_hHaltSema, 1, NULL );
}
//---------------------------------------------------------------------------
+23
View File
@@ -0,0 +1,23 @@
//---------------------------------------------------------------------------
#ifndef BaseThreadH
#define BaseThreadH
//---------------------------------------------------------------------------
///////////////////////////////
//
// Ïß³Ì
//
class TBaseThread : public TThread
{
protected:
HANDLE m_hHaltSema;
bool m_bWaiting;
bool __fastcall Halt( DWORD dwMS );
public:
__fastcall TBaseThread();
__fastcall ~TBaseThread();
virtual void __fastcall Cancel();
};
#endif
+72
View File
@@ -0,0 +1,72 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "CommonV8Handler.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma comment(lib, "CEF4DelphiVCLRTL")
//---------------------------------------------------------------------------
TV8Handler* u_pV8handler = NULL;
bool __fastcall TV8Handler::Execute(const ustring name, const _di_ICefv8Value obj,
const TCefv8ValueArray arguments, _di_ICefv8Value &retval, ustring &exception)
{
if( arguments.Length>0 ){
_di_ICefProcessMessage msg = TCefProcessMessageRef::New(name);
for( int i=0; i<arguments.Length; i++ ){
// if( arguments[i]->IsString() )
if( arguments[i]->IsInt() )
msg->ArgumentList->SetString(i, IntToStr(arguments[i]->GetIntValue()) );
else if( arguments[i]->IsDouble() )
msg->ArgumentList->SetString(i, FloatToStr(arguments[i]->GetDoubleValue()) );
else
msg->ArgumentList->SetString(i, arguments[i]->GetStringValue() );
}
TCefv8ContextRef::Current()->Browser->MainFrame->SendProcessMessage(PID_BROWSER, msg);
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
void __fastcall TWebKitInitializeEvent::Invoke()
{
String app_code =
"var cefApp;"
"if(!cefApp)"
"cefApp={};"
"(function(){"
"cefApp.ReturnJQValue = function(){"
"native function ReturnJQValue();"
"return ReturnJQValue.apply(null,arguments);"
"};"
"cefApp.GetUserInfo=function(){"
"native function GetUserInfo();"
"return GetUserInfo.apply(null,arguments);"
"};"
"cefApp.GetRegInfo=function(){"
"native function GetRegInfo();"
"return GetRegInfo.apply(null,arguments);"
"};"
"cefApp.GetPageCode=function(){"
"native function GetPageCode();"
"return GetPageCode.apply(null,arguments);"
"};"
"cefApp.OnJSMessage = function(){"
"native function OnJSMessage();"
"return OnJSMessage.apply(null,arguments);"
"};"
"})();";
if( !u_pV8handler )
u_pV8handler = new TV8Handler;
CefRegisterExtension("v8/cefApp", app_code, *u_pV8handler);
}
////////////////////////////////////////////////////////////////////////////////
+24
View File
@@ -0,0 +1,24 @@
//---------------------------------------------------------------------------
#ifndef CommonV8HandlerH
#define CommonV8HandlerH
#include "CEF4DelphiVCLRTL.hpp"
//---------------------------------------------------------------------------
class TV8Handler : public TCefv8HandlerOwn
{
protected:
virtual bool __fastcall Execute(const ustring name, const _di_ICefv8Value obj,
const TCefv8ValueArray arguments, _di_ICefv8Value &retval, ustring &exception);
};
class TWebKitInitializeEvent : public TCppInterfacedObject<TOnWebKitInitializedEvent>
{
public:
INTFOBJECT_IMPL_IUNKNOWN(TInterfacedObject);
void __fastcall Invoke();
};
#endif
+150
View File
@@ -0,0 +1,150 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#include <stdio.h>
#include <stdarg.h>
#include <tchar.h>
#include <time.h>
#include "GlobalUnit.h"
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
// 全局变量
HINSTANCE g_hPMDll = NULL;
PM_PARAMENCODE PM_ParamEncode = NULL;
char g_AppPath[256] = ""; //应用程序路径
bool g_bTesting = false, //是否测试模式
g_bPassLogin = false, //是否绕过登录验证
g_bRestart = false; //是否重复执行同一目录下的exe
UINT g_xDpi=96, g_yDpi=96;
unsigned g_uid = 0; //用户号
char g_sWebUN[32] = ""; //用户名
//char g_sAgentDomain[32] = ""; //代理域名
char g_sWebID[16] = ""; //用户编号
#if defined(_PKH_)
char g_strWebsite[256] = "http:\/\/x76.fut168.com";
#elif defined(_SX_) || defined(_SSCSX_)
char g_strWebsite[256] = "http:\/\/x76.fut168.com";
#elif defined(_GD_)
char g_strWebsite[256] = "http:\/\/hkh360.com";
#elif defined(_CJ_)
char g_strWebsite[256] = "http:\/\/ww165421.gh.qy63.com";
#elif defined(_HKCHB_)
char g_strWebsite[256] = "http:\/\/www.vin211.com";
#elif defined(_TYSSC_)
char g_strWebsite[256] = "https:\/\/www.vip66606.com";
#elif defined(_XBSSC_)
char g_strWebsite[256] = "http:\/\/103.31.220.87";
//#elif defined(_ABG_)
// char g_strWebsite[256] = "https:\/\/www.abg7777.net";
#else
char g_strWebsite[256] = "";
#endif
#if defined(_PKH_)
char g_strWebsiteHdg[256] = "https:\/\/www.sg909.com"; // "www.vin211.com"
#elif defined(_HKCHDG_)
char g_strWebsiteHdg[256] = "http:\/\/ww165421.gh.qy63.com";
#elif defined(_HDG_)
char g_strWebsiteHdg[256] = "";
#endif
#if defined(_PKH_) || defined(_HKCHDG_)
// char g_sWebUNHdg[32] = ""; //对冲用户名
// char g_sAgentDomainHdg[32] = "";
#endif
//---------------------------------------------------------------------------
//全局函数
void DebugPrint(const char * fmt, ...)
{
#ifdef _DEBUG
char sDebug[10240];
sDebug[0] = '\0';
char tbuffer[9];
_strtime(tbuffer);
sprintf(sDebug, "[%s] ", tbuffer);
va_list vaParams;
va_start(vaParams, fmt);
vsprintf(sDebug + strlen(sDebug), fmt, vaParams);
OutputDebugStringA(sDebug);
#endif
}
//---------------------------------------------------------------------------
#include <System.DateUtils.hpp>
unsigned __fastcall GetCompileTime()
{
char sMon[4] = {0};
int year, mon, day, hour, min, sec;
sscanf(__TIME__, "%d:%d:%d", &hour, &min, &sec);
sscanf(__DATE__, "%3s %d %d", sMon, &day, &year);
if(sMon[0]=='J'){
if(sMon[1]=='a') mon = 1; //Jan
else if(sMon[2]=='n') mon = 6; //Jun
else mon = 7; //Jul
}
else if(sMon[0]=='F') mon = 2; //Feb
else if(sMon[0]=='M'){
if(sMon[2]=='r') mon = 3; //Mar
else mon = 5; //May
}
else if(sMon[0]=='A'){
if(sMon[1]=='p') mon = 4; //Apr
else mon = 8; //Aug
}
else if(sMon[0]=='S') mon = 9; //Sep
else if(sMon[0]=='O') mon = 10; //Oct
else if(sMon[0]=='N') mon = 11; //Nov
else mon = 12; //Dec
TDateTime dt;
TryEncodeDateTime(year, mon, day, hour, min, sec, 0, dt);
return DateTimeToUnix(dt, false);
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//TLog
TLog u_Log;
//---------------------------------------------------------------------------
HANDLE TLog::m_hLogSema = CreateSemaphore( NULL, 1, 1, NULL );
__fastcall TLog::~TLog()
{
if( m_hLogSema )
CloseHandle(m_hLogSema);
}
//---------------------------------------------------------------------------
void __fastcall TLog::WriteLog( String msg )
{
SYSTEMTIME st;
GetLocalTime(&st);
char szLogFile[256];
sprintf( szLogFile, "%s%s%04d%02d%02d.log", g_AppPath, APPABBR, st.wYear, st.wMonth, st.wDay);
WaitForSingleObject( m_hLogSema, 1000 );
FILE* fp = fopen( szLogFile, "a+" );
if( fp ){
fprintf( fp, "[%02d:%02d:%02d] ", st.wHour, st.wMinute, st.wSecond );
fprintf( fp, "%s\n" , ((AnsiString)msg).c_str() );
fclose( fp );
}
ReleaseSemaphore( m_hLogSema, 1, NULL );
}
//---------------------------------------------------------------------------
+413
View File
@@ -0,0 +1,413 @@
//---------------------------------------------------------------------------
#ifndef GlobalUnitH
#define GlobalUnitH
//---------------------------------------------------------------------------
// 自定义消息
#define UM_VCCOMPLETE WM_USER+0x1000
#define UM_WEBLOADED WM_USER+0x1001
#define UM_VALUEVISIT WM_USER+0x1002
#define UM_IMAGELODED WM_USER+0x1003
#define UM_AUTOBETEND WM_USER+0x1004
#define UM_STATUS WM_USER+0x1005
#define UM_DATALOADED WM_USER+0x1006
#define UM_RESTORE WM_USER+0x1007
#define UM_INITGAME WM_USER+0x1008
#define UM_WEBLOGIN WM_USER+0x1009
#define UM_HTTPRETURN WM_USER+0x100A
#define UM_WEBREFRESH WM_USER+0x100B
#define UM_WEBREGISTER WM_USER+0x100C
#define UM_USERCONFIRM WM_USER+0x100D
#define UM_MEMBERCLOSE WM_USER+0x100E
#define UM_RENEWCREDIT WM_USER+0x100F
#define UM_STATISTICS WM_USER+0x1010
#define UM_SETSIMMODE WM_USER+0x1011
#define UM_URLRETURN WM_USER+0x1012
#define UM_JSHANDLED WM_USER+0x1013
#define UM_BETFAILED WM_USER+0x1014
#define UM_SHOWBETPAGE WM_USER+0x1015
#define UM_EXPIRED WM_USER+0x1016
#define UM_REFRESHTAB WM_USER+0x1017
#define UM_XHRLOADED WM_USER+0x1018
#define UM_SHOWDATA WM_USER+0x1019
#define UM_LOADCONFIG WM_USER+0x101A
#define UM_VELOCITY WM_USER+0x101B
#define UM_REDIRECT WM_USER+0x101C
#define UM_CHRMREADY WM_USER+0x101D
#define UM_SETBET WM_USER+0x101E
#define UM_SETTRIAL WM_USER+0x101F
#define UM_SHOWEXPIRE WM_USER+0x1020
#define UM_CHECKCEF WM_USER+0x1021
#define UM_SUBFORMSHOWN WM_USER+0x1022
#define UM_SUBFORMCLOSED WM_USER+0x1023
#define UM_ENTERGAME WM_USER+0x1024
#define UM_ONLINEDATA WM_USER+0x1025
#define UM_ADDTABLE WM_USER+0x1026
#define UM_WEBDEAD WM_USER+0x1027
#define UM_POLICYCHANGED WM_USER+0x1028
#define UM_IDLE WM_USER+0x1029
#define UM_OPENMAUAL WM_USER+0x102A
#if defined(_LOTFIN_)
// #define APPNAME L"彩票理财软件\0"
// #define APPABBR "ltfn"
// #define SOFTWARE_ID 0 //软件类型
// #define SORTWARE_VER 200 //软件版本
//#elif defined(_XBZK_)
// #define APPNAME L"小百自控软件\0"
// #define APPABBR "xbzk"
// #define SOFTWARE_ID 1 //软件类型
// #define SORTWARE_VER 204 //软件版本
// #define REGKEY_CODES L"{5189B25C-5758-4BF2-BCA4-289B01BD29E2}"
//#elif defined(_XINH_)
// #define APPNAME L"鑫海数字彩\0"
// #define APPABBR "xhszc"
// #define SOFTWARE_ID 2 //软件类型
// #define SORTWARE_VER 104 //软件版本
// #define REGKEY_CODES L"{89B01BD2-BC57-F24B-58A4-295189B25CE2}"
//#elif defined(_SBBAC_)
// #define APPNAME L"申博百家乐\0"
// #define APPABBR "snbt"
// #define SOFTWARE_ID 3 //软件类型
// #define SORTWARE_VER 1008 //软件版本
// #define REGKEY_CODES L"{389B25C5-7584-BF2B-CA42-89B01BD29E25}"
//#elif defined(_KLHDSSC_)
// #define APPNAME L"凯利打hd时时彩\0"
// #define APPABBR "klhdssc"
// #define SOFTWARE_ID 4 //软件类型
// #define SORTWARE_VER 100 //软件版本
// #define REGKEY_CODES L"{49B25C57-584B-F2BC-A428-9B01BD29E251}"
//#elif defined(_XINH2_)
// #define APPNAME L"博顿智打数字彩\0"
// #define APPABBR "xhlmp"
// #define SOFTWARE_ID 5 //软件类型
// #define SORTWARE_VER 102 //软件版本
// #define REGKEY_CODES L"{53BBEE32-1710-4F5C-B8F0-523BABB6C153}"
//#elif defined(_BOSS2_)
// #define APPNAME L"BOSS小神通\0"
// #define APPABBR "bsxst"
// #define SOFTWARE_ID 6 //软件类型
// #define SORTWARE_VER 105 //软件版本
// #define REGKEY_CODES L"{62b81249-4ebc-49bb-a9b6-9c1f65d5f575}"
//#elif defined(_XINHXST_)
// #define APPNAME L"鑫海小神通\0"
// #define APPABBR "xhxst"
// #define SOFTWARE_ID 7 //软件类型
// #define SORTWARE_VER 105 //软件版本
// #define REGKEY_CODES L"{71EE56D8-EE30-4F0D-AE56-2E647BDA28AE}"
//#elif defined(_BDHDXYDW_)
// #define APPNAME L"博顿打幸运定位\0"
// #define APPABBR "bdhgxydw"
// #define SOFTWARE_ID 8 //软件类型
// #define SORTWARE_VER 100 //软件版本
// #define REGKEY_CODES L"{8CE3AE4F-C8D2-4BEB-9EE8-11854615F645}"
//#elif defined(_KKWBAC_)
// #define APPNAME L"博顿百家乐\0"
// #define APPABBR "bdbac"
// #define SOFTWARE_ID 9 //软件类型
// #define SORTWARE_VER 104 //软件版本
// #define REGKEY_CODES L"{9C59B808-BAA7-4AD0-848F-0FDC9C3D612A}"
//#elif defined(_KKWLMP_)
// #define APPNAME L"博顿智打两面盘\0"
// #define APPABBR "bdlmp"
// #define SOFTWARE_ID 10 //软件类型
// #define SORTWARE_VER 100 //软件版本
// #define REGKEY_CODES L"{ADA91D42-5A88-4530-80EF-3F83C0F67DE0}"
//#elif defined(_KLJMSB_)
// #define APPNAME L"凯利解码申博\0"
// #define APPABBR "kljmsb"
// #define SOFTWARE_ID 11 //软件类型
// #define SORTWARE_VER 104 //软件版本
// #define REGKEY_CODES L"{B124B325-2DAF-46B4-B2BE-EAE31F9BD593}"
//#elif defined(_BDYXXB_)
// #define APPNAME L"博顿游戏小百\0"
// #define APPABBR "bdyxxb"
// #define SOFTWARE_ID 12 //软件类型
// #define SORTWARE_VER 106 //软件版本
// #define REGKEY_CODES L"{CEE9C31C-7124-4266-947C-FCFF6CE63D71}"
//#elif defined(_KLZJSB_)
// #define APPNAME L"凯利阻击申博\0"
// #define APPABBR "klzjsb"
// #define SOFTWARE_ID 13 //软件类型
// #define SORTWARE_VER 101 //软件版本
// #define REGKEY_CODES L"{DE814441-BEEA-4F20-99FB-4E219506AFC8}"
//#elif defined(_XYFTHDG_)
// #define APPNAME L"博顿幸运对冲软件\0"
// #define APPABBR "bdxyfthdg"
// #define SOFTWARE_ID 0 //软件类型
// #define SORTWARE_VER 101 //软件版本
//#elif defined(_TOWEST_)
// #define APPNAME L"一路向西\0"
// #define APPABBR "twst"
// #define SOFTWARE_ID 0 //软件类型
// #define SORTWARE_VER 200 //软件版本
//#elif defined(_SBHDG_)
// #define APPNAME L"百家乐对冲软件\0"
// #define APPABBR "snbthdg"
// #define SOFTWARE_ID 0 //软件类型
// #define SORTWARE_VER 100 //软件版本
//#elif defined(_TWOPASS_)
// #define APPNAME L"百家乐闯两关\0"
// #define APPABBR "bacctp"
// #define SOFTWARE_ID 0 //软件类型
// #define SORTWARE_VER 100 //软件版本
//#elif defined(_AL5P_)
// #define APPNAME L"澳洲幸运5预测软件\0"
// #define APPABBR "al5p"
// #define SOFTWARE_ID 0 //软件类型
// #define SORTWARE_VER 100 //软件版本
//#elif defined(_AL5P3_)
// #define APPNAME L"澳洲幸运5过关预测软件\0"
// #define APPABBR "al5p3"
// #define SOFTWARE_ID 1 //软件类型
// #define SORTWARE_VER 103 //软件版本
//#elif defined(_BACPASS_)
// #define APPNAME L"百家乐过关预测软件\0"
// #define APPABBR "bacpass"
// #define SOFTWARE_ID 1 //软件类型
// #define SORTWARE_VER 100 //软件版本
//#elif defined(_TYKKW_)
// #define APPNAME L"天亿KKW自动下注软件\0"
// #define APPABBR "tykkw"
// #define SOFTWARE_ID 2 //软件类型
// #define SORTWARE_VER 100
//#elif defined(_TYBAC_)
// #define APPNAME L"百家乐自动下注软件\0"
// #define APPABBR "tybac"
// #define SOFTWARE_ID 1 //软件类型
// #define SORTWARE_VER 104 //软件版本
#elif defined(_TYWYZ_)
#define APPNAME L"网鱼者\0"
#define APPABBR "tywyz"
#define SOFTWARE_ID 0 //软件类型
#define SORTWARE_VER 100
#elif defined(_ABG_)
#define APPNAME L"天花板\0"
#define APPABBR "abgthb"
#define SOFTWARE_ID 18 //软件类型
#define SORTWARE_VER 310
#elif defined(_RBM_)
#define APPNAME L"红蓝大师\0"
#define APPABBR "rbmaster"
#define SOFTWARE_ID 23 //软件类型
#define SINGLE_INSTANCE 1 //唯一实例
#elif defined(_RBMabc_)
#define APPNAME L"红蓝大师ABC\0"
#define APPABBR "rbabc"
#define SOFTWARE_ID 24 //软件类型
#define SINGLE_INSTANCE 1 //唯一实例
//#elif defined(_HEATV_)
// #define APPNAME L"99度V\0"
// #define APPABBR "htv"
// #define SOFTWARE_ID 0 //软件类型
// #define SORTWARE_VER 100 //软件版本
//#elif defined(_HEAT_)
// #define APPNAME L"99度\0"
// #define APPABBR "ht"
// #define SOFTWARE_ID 0 //软件类型
// #define SORTWARE_VER 200 //软件版本
//#elif defined(_HOTSPOT_)
// #define APPNAME L"热度\0"
// #define APPABBR "htsp"
// #define SOFTWARE_ID 0 //软件类型
// #define SORTWARE_VER 101 //软件版本
#elif defined(_SPTHDG_)
#define APPNAME "竞彩对冲工具\0"
#define APPABBR "spth"
#define SOFTWARE_ID 13 //软件类型 13=竞彩对冲工具
#define SORTWARE_VER 320 //软件版本
#define SINGLE_INSTANCE 1 //唯一实例
#elif defined(_TGOAL_)
#define APPNAME "总进球数对比软件\0"
#define APPABBR "tgoal"
#define SOFTWARE_ID 14 //软件类型 13=竞彩对冲工具
#define SORTWARE_VER 111 //软件版本
#define SINGLE_INSTANCE 1 //唯一实例
#elif defined(_GOALS_)
#define APPNAME "进球数分析软件\0"
#define APPABBR "goals"
#define SOFTWARE_ID 14 //软件类型 13=竞彩对冲工具
#define SORTWARE_VER 101 //软件版本
#define SINGLE_INSTANCE 1 //唯一实例
//#elif defined(_TGDEMO_)
// #define APPNAME "总进球数据软件\0"
// #define APPABBR "tgdemo"
// #define SOFTWARE_ID 14 //软件类型 13=竞彩对冲工具
// #define SORTWARE_VER 100 //软件版本
// #define SINGLE_INSTANCE 1 //唯一实例
//#elif defined(_XBSSC_)
// #define APPNAME "环球时时彩理财软件-追号\0"
// #define APPABBR "xbss"
// #define REGKEY_SOFTWARE L"SOFTWARE\\DataTao\\HQFSSCXB\\"
// #define SOFTWARE_ID 12 //软件类型 12=时时彩新宝
// #define SORTWARE_VER 101 //软件版本
//#elif defined(_SLHDG_)
// #define APPCLASS L"DataTao::SLHedging"
#define APPNAME "足球对冲工具\0"
#define APPABBR "slhdg"
// #define REGKEY_SOFTWARE L"SOFTWARE\\DataTao\\SLHedging\\"
#define SOFTWARE_ID 11 //软件类型 11=足球对冲工具
#define SORTWARE_VER 501 //软件版本
#define SINGLE_INSTANCE 1 //唯一实例
#elif defined(_RBHDG_)
#define APPNAME "江球对冲\0"
#define APPABBR "rbhdg"
#define SOFTWARE_ID 16 //软件类型 16=江球对冲
#define SORTWARE_VER 105 //软件版本
#elif defined(_OUHLP_)
#define APPNAME "大小球助手\0"
#define APPABBR "ouhlp"
#define SOFTWARE_ID 19 //软件类型 19=大小球助手 19=新版本
#define SORTWARE_VER 300 //软件版本
#elif defined(_OUBTR_)
#define APPNAME "大小球注手\0"
#define APPABBR "oubtr"
#define SOFTWARE_ID 20 //软件类型 20=大小球注手
#define SORTWARE_VER 204 //软件版本
#elif defined(_WJODD_)
#define APPNAME "无极预测单双\0"
#define APPABBR "wjodd"
#define SOFTWARE_ID 21 //软件类型 21=无极预测单双
#define SORTWARE_VER 302 //软件版本
#elif defined(_WJROLL_)
#define APPNAME "无极滚球预测\0"
#define APPABBR "wjroll"
#define SOFTWARE_ID 22 //软件类型 22=无极滚球预测
#define SORTWARE_VER 100 //软件版本
#elif defined(_SCRTRDR_)
#define APPNAME "足球交易软件\0"
#define APPABBR "scrtrdr"
#define SOFTWARE_ID 12 //软件类型 12=足球交易软件
#define SORTWARE_VER 103 //软件版本
//#elif defined(_SSCSX_)
// #define APPNAME "环球时时彩智胜庄家(福胜)\0"
// #define REGKEY_SOFTWARE L"SOFTWARE\\DataTao\\SSCSX\\"
// #define SOFTWARE_ID 10 //软件类型 10=时时彩福胜
// #define SORTWARE_VER 102 //软件版本
//#elif defined(_HKCHB_)
// #define APPNAME "环球香港彩(浩博)\0"
// #define REGKEY_SOFTWARE L"SOFTWARE\\HQWin\\HKCHB\\"
// #define SOFTWARE_ID 9 //软件类型 9=香港彩浩博
// #define SORTWARE_VER 106 //软件版本
//#elif defined(_HKCHDG_)
// #define APPNAME "环球香港彩(对冲)\0"
// #define REGKEY_SOFTWARE L"SOFTWARE\\HQWin\\HKCHedge\\"
// #define SOFTWARE_ID 8 //软件类型 8=香港彩对冲
// #define SORTWARE_VER 101 //软件版本
//#elif defined(_PKH_)
// #define APPNAME "数之道北京赛车对冲软件\0"
// #define REGKEY_SOFTWARE L"SOFTWARE\\DataTao\\PK10Hedge\\"
// #define SOFTWARE_ID 7 //软件类型 7=PK10对冲
// #define SORTWARE_VER 203 //软件版本
//#elif defined(_HKCCJ_)
// #define APPNAME "环球香港彩(长江)\0"
// #define REGKEY_SOFTWARE L"SOFTWARE\\HQWin\\HKCCJ\\"
// #define SOFTWARE_ID 6 //软件类型 6=环球香港彩长江
// #define SORTWARE_VER 100 //软件版本
//#elif defined(_HQ_)
// #define APPNAME "环球北京赛车智胜庄家\0"
// #define REGKEY_SOFTWARE L"SOFTWARE\\HQWin\\HQPK10\\"
// #define SOFTWARE_ID 5 //软件类型 5=环球
// #define SORTWARE_VER 100 //软件版本
//#elif defined(_HB_)
// #define APPNAME "数之道北京赛车自动打单系统(浩博)\0"
// #define REGKEY_SOFTWARE L"SOFTWARE\\DataTao\\PK10HB\\"
// #define SOFTWARE_ID 2 //软件类型 2=浩博版
// #define SORTWARE_VER 204 //软件版本
//#elif defined(_SX_)
// #define APPNAME "数之道北京赛车自动打单系统(福胜)\0"
// #define REGKEY_SOFTWARE L"SOFTWARE\\DataTao\\PK10SX\\"
// #define SOFTWARE_ID 3 //软件类型 3=福胜版
// #define SORTWARE_VER 208 //软件版本
//#elif defined(_KH_)
// #define APPNAME "数之道北京赛车自动打单系统(尚银)\0"
// #define REGKEY_SOFTWARE L"SOFTWARE\\DataTao\\PK10KH\\"
// #define SOFTWARE_ID 4 //软件类型 4=尚银版
// #define SORTWARE_VER 206 //软件版本
#else
// #define APPNAME "数之道北京赛车自动打单系统(内测)\0"
// #define REGKEY_SOFTWARE L"SOFTWARE\\DataTao\\BJCars\\"
// #define SOFTWARE_ID 1 //软件类型 1=内部测试集合版
#endif
#if defined(_HENLY_)
#define GLOBAL_VAR_FILE "hlglbvrf.cnf"
#elif defined(_SPTHDG_)
#define GLOBAL_VAR_FILE "sptgvf.cnf"
#elif defined(_SLHDG_)
#define GLOBAL_VAR_FILE "slhglbvrf.cnf"
#elif defined(_SCRTRDR_)
#define GLOBAL_VAR_FILE "stglbvrf.cnf"
#elif defined(_ABG_)
#define GLOBAL_VAR_FILE "abgglbvrf.cnf"
#else
#define GLOBAL_VAR_FILE "glbvrf.cnf"
#endif
#define UPDATE_APP_NAME "AppUpgrade.exe"
#define MD5_FILE_NAME "filemd5.lst"
#define GLOBAL_VAR_VERSION 0x03
#define ID_ABOUT_MENU 101
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
#define DPIX(x) (MulDiv(x,g_xDpi,96))
#define DPIY(y) (MulDiv(y,g_yDpi,96))
typedef struct tGVFHeader{
char head[4];
WORD idSoftware;
WORD iUpdate;
tGVFHeader(){
head[0] = 'G';
head[1] = 'V';
head[2] = 'F';
head[3] = GLOBAL_VAR_VERSION;
idSoftware = SOFTWARE_ID;
iUpdate = 0;
}
} TGVFHEADER;
// 全局变量
extern HINSTANCE g_hPMDll;
typedef int (*PM_PARAMENCODE)( char* strEncode, int* len, char (*arrMap)[2][256], int num );
extern PM_PARAMENCODE PM_ParamEncode;
extern char g_AppPath[];
extern bool g_bTesting, g_bRestart, g_bPassLogin;
extern UINT g_xDpi, g_yDpi;
extern char g_strWebsite[];
extern unsigned g_uid; //用户号
extern char g_sWebUN[]; //用户名
//extern char g_sAgentDomain[]; //代理域名
extern char g_sWebID[]; //用户编号
#if defined(_PKH_) || defined(_HKCHDG_) || defined(_HDG_)
extern char g_strWebsiteHdg[];
extern char g_sWebUNHdg[]; //对冲用户名
// extern char g_sAgentDomainHdg[];
#endif
// 全局函数
void DebugPrint(const char * fmt, ...);
unsigned __fastcall GetCompileTime();
class TLog
{
private:
static HANDLE m_hLogSema;
public:
__fastcall ~TLog();
static void __fastcall WriteLog(String msg);
};
#endif
+588
View File
@@ -0,0 +1,588 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#include <Wininet.h>
#include <tchar.h>
#include <stdio.h>
#include <vector>
//#include <System.DateUtils.hpp>
#pragma hdrstop
#include "HttpThread.h"
#include "GlobalUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma comment(lib, "wininet")
//---------------------------------------------------------------------------
DWORD WINAPI HttpProc(LPVOID args)
{
THttpParam* param = (THttpParam*)args;
TCHAR hdrsStream[] = _T("Content-Type: application/octet-stream\r\n"),
hdrsXForm[] = _T("Content-Type: application/x-www-form-urlencoded\r\n"),
*hdrs = param->iMode==0 ? hdrsStream : hdrsXForm;
LPCTSTR lpszAccept[] = { _T("text/html"), NULL };//{ _T("application/json"), NULL };//
char szBuffer[1024];
DWORD dwFlags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE,
dwByteRead = 0,
dwAllBytes = 0,
dwSize = 4;
int pos = 0;
bool bSent = false;
// char srvAddr[256];
//Open internet connection
param->hSession = InternetOpen( L"HttpPost/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
if( !param->hSession ){
param->errCode = ERROR_INTERNET_OPEN;
return 0;
}
char addr[80];
int port = 80;
char* p = strstr( param->server, ":" );
if( p ){
memcpy( addr, param->server, p - param->server );
addr[p - param->server] = 0;
sscanf( p+1, "%d", &port );
}
else
strcpy( addr, param->server );
param->hConnect = InternetConnect(param->hSession,
(String(addr)).w_str(),
port,//INTERNET_DEFAULT_HTTP_PORT,
NULL,
NULL,
INTERNET_SERVICE_HTTP,
0,
1);
if( param->hConnect ){
if( port==INTERNET_DEFAULT_HTTPS_PORT )
dwFlags |= INTERNET_FLAG_SECURE;
param->hRequest = HttpOpenRequest(param->hConnect,
_T("POST"),
((String)param->api).c_str(),
NULL,
NULL,
NULL,//lpszAccept,//
dwFlags,
1);
if( param->hRequest ){
if( port==INTERNET_DEFAULT_HTTPS_PORT ){
DWORD flags = 0;
DWORD bufflen = sizeof(flags);
InternetQueryOption(param->hRequest, INTERNET_OPTION_SECURITY_FLAGS,
(LPVOID)&flags, &bufflen);
flags |= SECURITY_FLAG_IGNORE_REVOCATION;
InternetSetOption(param->hRequest, INTERNET_OPTION_SECURITY_FLAGS,
(LPVOID)&flags, sizeof(flags));
}
if( HttpSendRequest( param->hRequest, hdrs, wcslen(hdrs),
param->dataIn, param->sizeIn) ){
bSent = true;
}
else{
param->errCode = GetLastError();
}
}
else{
param->errCode = GetLastError();
}
}
else{
param->errCode = GetLastError();
}
if( !param->hConnect ){
param->errCode = ERROR_INTERNET_CONN;
return 0;
}
if( !param->hRequest ){
param->errCode = ERROR_INTERNET_REQ;
return 0;
}
if( !bSent ){
param->errCode = ERROR_INTERNET_SEND;
return 0;
}
// if( param->bGetDT ){
// SYSTEMTIME sysTime;
// SecureZeroMemory(&sysTime, sizeof(SYSTEMTIME));
// DWORD dwSize = sizeof(SYSTEMTIME);
// if( HttpQueryInfo( param->hRequest, HTTP_QUERY_DATE|HTTP_QUERY_FLAG_SYSTEMTIME,
// &sysTime, &dwSize, NULL ) ){
// TDateTime dt = SystemTimeToDateTime(sysTime);
// param->dwDateTime = DateTimeToUnix(dt);
// }
// else
// param->dwDateTime = 0;
// }
if( !HttpQueryInfo( param->hRequest, HTTP_QUERY_CONTENT_LENGTH|HTTP_QUERY_FLAG_NUMBER,
&dwAllBytes, &dwSize, NULL ) ){
dwAllBytes = 0;
}
// 防止乱码的方法就是建立完变量立即清空
ZeroMemory(szBuffer, sizeof(szBuffer));
ZeroMemory(param->dataOut, param->sizeOut);
// 循环读取缓冲区内容直到结束
while( param->hRequest && InternetReadFile(param->hRequest, szBuffer, sizeof(szBuffer),
&dwByteRead) && dwByteRead > 0 ){
if( pos + dwByteRead > param->sizeOut ){
param->errCode = ERROR_SIZE;
return 0;
}
// 复制输出数据
memcpy( param->dataOut+pos, szBuffer, dwByteRead );
pos += dwByteRead;
// 清空缓冲区以备下一次读取
ZeroMemory(szBuffer, sizeof(szBuffer));
}
if( !param->hRequest ){
param->errCode = ERROR_INTERNET_REQ;
}
else if( dwAllBytes>0 && pos!=dwAllBytes ){
param->errCode = ERROR_SIZE;
}
else{
param->dataOut[pos] = 0;
param->sizeOut = pos;
}
return 0;
}
//---------------------------------------------------------------------------
DWORD WINAPI VeloProc(LPVOID args)
{
TVeloParam* param = (TVeloParam*)args;
TCHAR hdrs[] = _T("Content-Type: application/x-www-form-urlencoded\r\n");
// TCHAR hdrs[] = _T("Content-Type: text/html\r\n");
LPCTSTR lpszAccept[] = { _T("*/*"), NULL };
// char srvAddr[256];
//Open internet connection
param->hSession = InternetOpen(L"Velocity",INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if( !param->hSession ){
param->errCode = ERROR_INTERNET_OPEN;
return 0;
}
param->hConnect = InternetConnect(param->hSession,
(String(param->addr)).w_str(),
param->port,
NULL,
NULL,
INTERNET_SERVICE_HTTP,
0,
0);
if( !param->hConnect ){
param->errCode = ERROR_INTERNET_CONN;
return 0;
}
param->hRequest = HttpOpenRequest(param->hConnect,
_T("GET"),
((String)param->api).c_str(),
_T("HTTP/1.1"),
NULL,
NULL,//lpszAccept,
param->flag,
0);
if( !param->hRequest ){
//param->errCode = ERROR_INTERNET_REQ;
return 0;
}
if( param->port==INTERNET_DEFAULT_HTTPS_PORT ){
DWORD flags = 0;
DWORD bufflen = sizeof(flags);
InternetQueryOption(param->hRequest, INTERNET_OPTION_SECURITY_FLAGS,
(LPVOID)&flags, &bufflen);
flags |= SECURITY_FLAG_IGNORE_REVOCATION | SECURITY_FLAG_IGNORE_UNKNOWN_CA | SECURITY_FLAG_IGNORE_CERT_CN_INVALID;
InternetSetOption(param->hRequest, INTERNET_OPTION_SECURITY_FLAGS,
(LPVOID)&flags, sizeof(flags));
}
if( !HttpSendRequest( param->hRequest, hdrs, wcslen(hdrs), NULL, 0) ){
//param->errCode = ERROR_INTERNET_SEND;
int err = GetLastError();
return 0;
}
DWORD dwCode = 0,
dwSize = sizeof(DWORD);
if( HttpQueryInfo( param->hRequest, HTTP_QUERY_STATUS_CODE |HTTP_QUERY_FLAG_NUMBER,
&dwCode, &dwSize, NULL ) ){
if( dwCode<HTTP_STATUS_SERVER_ERROR ){
param->errCode = 1;
ReleaseSemaphore( param->hSema, 1, NULL );
}
}
return 0;
}
//---------------------------------------------------------------------------
DWORD WINAPI ProbProc(LPVOID args)
{
TProbParam* param = (TProbParam*)args;
param->hSession = InternetOpen( L"RookIE/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
if( param->hSession ){
String api = L"http://" + (String)param->server + L"/Api/chkServer";
param->hRequest = InternetOpenUrl( param->hSession, api.c_str(), NULL, 0,
INTERNET_FLAG_DONT_CACHE|INTERNET_FLAG_RELOAD|INTERNET_FLAG_PRAGMA_NOCACHE, 0 );
if( param->hRequest ){
DWORD dwByteRead = 0;
char szBuffer[1024];
ZeroMemory(szBuffer, sizeof(szBuffer));
InternetReadFile(param->hRequest, szBuffer, sizeof(szBuffer), &dwByteRead);
if( dwByteRead==2 && szBuffer[0]=='o' && szBuffer[1]=='k' ){
param->errCode = 1;
ReleaseSemaphore( param->hSema, 1, NULL );
}
}
else
param->errCode = ERROR_INTERNET_REQ;
}
else
param->errCode = ERROR_INTERNET_OPEN;
return 0;
}
//---------------------------------------------------------------------------
DWORD WINAPI UrlProc(LPVOID args)
{
TUrlParam* param = (TUrlParam*)args;
param->hSession = InternetOpen( L"RookIE/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
if( param->hSession ){
param->hRequest = InternetOpenUrl( param->hSession, param->url.c_str(), param->header.c_str(), 0,
INTERNET_FLAG_DONT_CACHE|INTERNET_FLAG_RELOAD|INTERNET_FLAG_PRAGMA_NOCACHE, 0 );
if( param->hRequest ){
int pos = 0;
DWORD dwByteRead = 0;
char szBuffer[10240];
ZeroMemory(szBuffer, sizeof(szBuffer));
ZeroMemory(param->dataOut, param->sizeOut);
// 循环读取缓冲区内容直到结束
while( param->hRequest && InternetReadFile(param->hRequest, szBuffer, 10240, &dwByteRead)
&& dwByteRead > 0){
if( pos + dwByteRead > param->sizeOut ){
param->errCode = ERROR_SIZE;
break;
}
// 复制输出数据
memcpy( param->dataOut+pos, szBuffer, dwByteRead );
pos += dwByteRead;
// 清空缓冲区以备下一次读取
ZeroMemory(szBuffer, 10240);
}
param->dataOut[pos] = 0;
param->sizeOut = pos;
if( param->hRequest )
return 0;
}
param->errCode = ERROR_INTERNET_REQ;
}
else
param->errCode = ERROR_INTERNET_OPEN;
return 0;
}
//---------------------------------------------------------------------------
bool IsPureUrl(String url)
{
bool bPure = false;
int num = 0;
int len = url.Length();
for( int i=1; i<=len && num<5; i++ ){
if( url[i]=='/' ){
num++;
}
}
if( num<3 )
bPure = true;
else if( num==3 && url[len]=='/' )
bPure = true;
return bPure;
}
/////////////////////////////////////////////////////////////////////////////
// TBaseWebThread
__fastcall TBaseWebThread::TBaseWebThread( HWND handle )
: TThread(true)
{
m_hWnd = handle;
m_hSema = CreateSemaphore( NULL, 0, 1, NULL );
}
//---------------------------------------------------------------------------
__fastcall TBaseWebThread::~TBaseWebThread()
{
if( m_hSema )
CloseHandle( m_hSema );
}
//---------------------------------------------------------------------------
void __fastcall TBaseWebThread::Cancel()
{
Terminate();
ReleaseSemaphore( m_hSema, 1, NULL );
}
//---------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
// TAsynHttpThread
__fastcall TAsynHttpThread::TAsynHttpThread( HWND handle, char* server, String api,
char* dataIn, int sizeIn, int op, int mode )
: TBaseWebThread( handle )
{
memcpy( m_dataIn, dataIn, sizeIn );
m_dataIn[sizeIn] = 0;
m_sizeIn = sizeIn;
memset( m_dataOut, 0, sizeof(m_dataOut) );
m_sizeOut = 0;
strcpy( m_server, server );
m_api = api;
m_iOp = op;
m_iMode = mode;
}
//---------------------------------------------------------------------------
void __fastcall TAsynHttpThread::Execute()
{
char szReturn[10240];
int errCode = 0;
THttpParam param;
param.iMode = m_iMode;
param.sizeIn = m_sizeIn;
param.dataIn = m_dataIn;
param.sizeOut = 10240;
param.dataOut = szReturn;
strcpy( param.server, m_server );
strcpy( param.api, ((AnsiString)m_api).c_str() );
DWORD id;
HANDLE hThread = CreateThread( NULL, 0, HttpProc, &param, 0, &id );
if( hThread ){
HANDLE aHandle[2] = { m_hSema, hThread };
DWORD dwRet = WaitForMultipleObjects( 2, aHandle, FALSE, 15000 );
if( param.hRequest )
InternetCloseHandle( param.hRequest );
if( param.hConnect )
InternetCloseHandle( param.hConnect );
if( param.hSession )
InternetCloseHandle( param.hSession );
param.hSession = param.hConnect = param.hRequest = NULL;
WaitForSingleObject( hThread, 200 );
CloseHandle( hThread );
if( dwRet==WAIT_OBJECT_0 ){ //用户退出
return;//errCode = ERROR_INTERNET_CANCEL;
}
else if( dwRet==WAIT_OBJECT_0+1 && param.errCode==0 ){ //线程正常退出
m_sizeOut = param.sizeOut;
memcpy( m_dataOut, szReturn, m_sizeOut );
m_dataOut[m_sizeOut] = 0;
}
else if( dwRet==WAIT_TIMEOUT ) //超时
errCode = ERROR_INTERNET_TMOUT;
else if( param.errCode==0 )//出错了
errCode = ERROR_INTERNET_UNKNOWN;
}
else
errCode = ERROR_INTERNET_UNKNOWN;
if( m_hWnd )
PostMessage( m_hWnd, UM_HTTPRETURN, errCode, m_iOp );
}
//---------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
// TAsynUrlThread
__fastcall TAsynUrlThread::TAsynUrlThread( HWND handle, String api, char* pzOut, int& szOut, int op, String header )
: TBaseWebThread( handle ), m_szOut(szOut)
{
m_url = api;
m_pzOut = pzOut;
m_iOp = op;
m_header = header;
}
//---------------------------------------------------------------------------
void __fastcall TAsynUrlThread::Execute()
{
int errCode = 0;
TUrlParam param;
param.url = m_url;
param.header = m_header;
param.dataOut = m_pzOut;
param.sizeOut = m_szOut;
DWORD id;
HANDLE hThread = CreateThread( NULL, 0, UrlProc, &param, 0, &id );
if( hThread ){
HANDLE aHandle[2] = { m_hSema, hThread };
DWORD dwRet = WaitForMultipleObjects( 2, aHandle, FALSE, 15000 );
if( param.hRequest )
InternetCloseHandle( param.hRequest );
if( param.hSession )
InternetCloseHandle( param.hSession );
param.hSession = param.hRequest = NULL;
WaitForSingleObject( hThread, 200 );
CloseHandle( hThread );
if( dwRet==WAIT_OBJECT_0 ){ //用户退出
return;
}
else if( dwRet==WAIT_OBJECT_0+1 ){ //线程正常退出
m_szOut = param.sizeOut;
errCode = param.errCode;
}
else if( dwRet==WAIT_TIMEOUT ) //超时
errCode = ERROR_INTERNET_TMOUT;
else if( param.errCode==0 )//出错了
errCode = ERROR_INTERNET_UNKNOWN;
}
else
errCode = ERROR_INTERNET_UNKNOWN;
if( m_hWnd )
PostMessage( m_hWnd, UM_URLRETURN, errCode, m_iOp );
}
//---------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
// TVeloThread
__fastcall TVeloThread::TVeloThread( HWND handle, int nWS, char* websites[],
int ports[], char* api, int msWait )
: TBaseWebThread( handle )
{
m_nWS = nWS;
m_websites = websites;
m_ports = ports;
m_msWait = msWait;
strcpy(m_sApi, api);
}
//---------------------------------------------------------------------------
void __fastcall TVeloThread::Execute()
{
HANDLE *aHandle = new HANDLE[m_nWS];
TVeloParam* aParam = new TVeloParam[m_nWS];
HANDLE hWaitSema = CreateSemaphore( NULL, 0, m_nWS>1 ? 2 : 1, NULL );
DWORD id;
for( int i=0; i<m_nWS; i++ ){
if(m_sWebsite.Length()>0 && m_sWebsite.Pos(m_websites[i])){
aHandle[i] = NULL;
}
else{
aParam[i].hSema = hWaitSema;
aParam[i].port = m_ports ? m_ports[i] : INTERNET_DEFAULT_HTTPS_PORT;
aParam[i].flag = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
if( aParam[i].port==INTERNET_DEFAULT_HTTPS_PORT )
aParam[i].flag |= INTERNET_FLAG_SECURE;
strcpy( aParam[i].addr, m_websites[i] );
strcpy( aParam[i].api, m_sApi );
//aParam[i].api[0] = 0;
aHandle[i] = CreateThread( NULL, 0, VeloProc, &aParam[i], CREATE_SUSPENDED, &id );
ResumeThread(aHandle[i]);
}
}
DWORD dwRet = WaitForSingleObject( hWaitSema, m_msWait );
int sel = -1;
for( int i=0; i<m_nWS; i++ ){
if( aHandle[i] ){
if( aParam[i].hRequest )
InternetCloseHandle( aParam[i].hRequest );
if( aParam[i].hConnect )
InternetCloseHandle( aParam[i].hConnect );
if( aParam[i].hSession )
InternetCloseHandle( aParam[i].hSession );
aParam[i].hSession = aParam[i].hConnect = aParam[i].hRequest = NULL;
WaitForSingleObject( aHandle[i], 800 );
CloseHandle( aHandle[i] );
if( aParam[i].errCode==1 && sel<0 )
sel = i;
}
}
if( sel<0 ){ //线程非正常退出
sel = GetTickCount() % m_nWS;
if( m_sWebsite.Pos( m_websites[sel] ) )
sel = (sel+1) % m_nWS;
}
if( !m_ports || m_ports[sel]==INTERNET_DEFAULT_HTTPS_PORT )
m_sWebsite = Format( "https://%s", ARRAYOFCONST((m_websites[sel])) );
else if( m_ports[sel]==INTERNET_DEFAULT_HTTP_PORT )
m_sWebsite = Format( "http://%s", ARRAYOFCONST((m_websites[sel])) );
else
m_sWebsite = Format( "http://%s:%d", ARRAYOFCONST((m_websites[sel], m_ports[sel])) );
CloseHandle( hWaitSema );
delete[] aHandle;
delete[] aParam;
if( !Terminated )
PostMessage( m_hWnd, UM_VELOCITY, sel, (LPARAM)this );
}
//---------------------------------------------------------------------------
+179
View File
@@ -0,0 +1,179 @@
//---------------------------------------------------------------------------
#ifndef HttpThreadH
#define HttpThreadH
//---------------------------------------------------------------------------
#define ERROR_OPEN_FILE 10
#define ERROR_MEMORY 11
#define ERROR_SIZE 12
#define ERROR_INTERNET_OPEN 13
#define ERROR_INTERNET_CONN 14
#define ERROR_INTERNET_REQ 15
#define ERROR_INTERNET_SEND 16
#define ERROR_INTERNET_TMOUT 17
#define ERROR_INTERNET_UNKNOWN 18
#define ERROR_INTERNET_FORMAT 19
#define ERROR_INTERNET_CANCEL 20
#define ERROR_VCODE_NORET 21
#define ERROR_VCODE_INVLEN 22
#define ERROR_VCODE_INVDATA 23
#define ERROR_VCODE_NOFUNC 24
#define ERROR_VCODE_RCGFAIL 25
//#define MAX_KEY_NUM 32
//#define MAX_STR_LEN 256
#define OP_VCODE 1
#define OP_USERREG 2
#define OP_USERLOG 3
#define OP_HKCCHK 4
#define OP_VCODEHDG 5
#define OP_GETUSER 6
#define OP_GETPROXY 7
#define OP_SETWHITE 8
#define OP_GETPROXYAPI 9
#define OP_GETWHITEAPI 10
typedef struct tBaseParam
{
int errCode;
HINTERNET hSession,
hRequest;
tBaseParam(){
memset( this, 0, sizeof(tBaseParam) );
};
} TBaseParam;
typedef struct tVeloParam : public TBaseParam
{
char api[32];
char addr[256];
int port;
DWORD flag;
HANDLE hSema;
HINTERNET hConnect;
tVeloParam(){
memset( this, 0, sizeof(tVeloParam) );
};
} TVeloParam;
typedef struct tHttpParam : public TBaseParam
{
char server[256];
char api[32];
int iMode;
HINTERNET hConnect;
DWORD sizeIn, sizeOut;
char *dataIn, *dataOut;
// bool bGetDT;
// DWORD dwDateTime;
tHttpParam(){
memset( this, 0, sizeof(tHttpParam) );
};
} THttpParam;
typedef struct tProbParam : public TBaseParam
{
char server[256];
HANDLE hSema;
tProbParam(){
memset( this, 0, sizeof(tProbParam) );
};
} TProbParam;
typedef struct tUrlParam : public TBaseParam
{
String url;
String header;
int sizeOut;
char* dataOut;
tUrlParam(){
memset( this, 0, sizeof(tUrlParam) );
};
} TUrlParam;
///////////////////////////////////////////////////////////////
class TBaseWebThread : public TThread
{
protected:
HWND m_hWnd;
HANDLE m_hSema;
virtual void __fastcall Execute()=0;
public:
__fastcall TBaseWebThread(HWND handle );
__fastcall ~TBaseWebThread();
void __fastcall Cancel();
};
class TAsynHttpThread : public TBaseWebThread //异步HTTP线程
{
private:
char m_dataIn[10240];
int m_sizeIn;
char m_server[256];
String m_api;
int m_iOp;
int m_iMode;
protected:
virtual void __fastcall Execute();
public:
__fastcall TAsynHttpThread(HWND handle, char* server, String api, char* dataIn, int sizeIn, int op=0, int mode=0 );
char m_dataOut[10240];
int m_sizeOut;
};
class TAsynUrlThread : public TBaseWebThread //异步URL访问线程
{
private:
String m_url;
String m_header;
int& m_szOut;
char* m_pzOut;
int m_iOp;
protected:
virtual void __fastcall Execute();
public:
__fastcall TAsynUrlThread(HWND handle, String url, char* pzOut, int& szOut, int op=0, String header="");
};
class TVeloThread : public TBaseWebThread //服务器选择线程
{
private:
int m_nWS;
char** m_websites;
int* m_ports;
int m_msWait;
char m_sApi[128];
protected:
virtual void __fastcall Execute();
public:
String m_sWebsite;
__fastcall TVeloThread(HWND handle, int nWS, char* websites[], int ports[]=NULL, char* api="", int msWait=10000 );
};
DWORD WINAPI ProbProc(LPVOID args); //服务器探测函数
DWORD WINAPI HttpProc(LPVOID args); //同步线程函数
DWORD WINAPI VeloProc(LPVOID args); //测速线程函数
DWORD WINAPI UrlProc(LPVOID args); //URL访问函数
bool IsPureUrl(String url); //url检查函数
#endif
+106
View File
@@ -0,0 +1,106 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ResourceHandler.h"
//#include "GlobalUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
__fastcall TResHandler::TResHandler(const _di_ICefBrowser browser, const _di_ICefFrame frame,
const _di_ICefRequest request, HWND wnd, int msg)
: TCefResourceHandlerOwn( browser, frame, "ImgHandler", request )
{
_size = _offset = 0;
_callback = NULL;
_response = NULL;
_wnd = wnd;
_msg = msg;
}
//---------------------------------------------------------------------------
bool __fastcall TResHandler::ProcessRequest(const _di_ICefRequest request, const _di_ICefCallback callback)
{
_offset = 0;
_callback = callback;
TCefUrlRequestFlags flags = request->GetFlags();
flags << UR_FLAG_ALLOW_CACHED_CREDENTIALS << UR_FLAG_SKIP_CACHE;
request->SetFlags( flags );
TResRequestClient* client = new TResRequestClient( this );
TCefUrlRequestRef::New( request, *client, NULL/*callback*/ );
return true;
}
//---------------------------------------------------------------------------
void __fastcall TResHandler::GetResponseHeaders(const _di_ICefResponse response, /* out */ __int64 &responseLength, /* out */ ustring &redirectUrl)
{
if( _response ){
_di_ICefStringMultimap map = *(new TCefStringMultimapOwn());
_response->GetHeaderMap( map );
response->SetHeaderMap( map );
response->SetMimeType( _response->GetMimeType() );
response->SetStatus( _response->GetStatus() );
response->SetStatusText( _response->GetStatusText() );
}
responseLength = _size;
}
//---------------------------------------------------------------------------
bool __fastcall TResHandler::ReadResponse(const void * dataOut, int bytesToRead, int &bytesRead, const _di_ICefCallback callback)
{
if( _offset < _size ){
bytesRead = _size - _offset;
if( bytesRead > bytesToRead )
bytesRead = bytesToRead;
char* pData = (char*)dataOut;
memcpy( pData, _data + _offset, bytesRead );
_offset += bytesRead;
return true;
}
return false;
}
//---------------------------------------------------------------------------
__fastcall TResRequestClient::TResRequestClient(TResHandler* handler)
{
_resHandler = handler;
}
//---------------------------------------------------------------------------
void __fastcall TResRequestClient::OnRequestComplete(const _di_ICefUrlRequest request)
{
_resHandler->_response = request->GetResponse();
TCefResourceType type = request->GetRequest()->GetResourceType();
// String str = _imgHandler->_response->GetMimeType();
// if( str.Pos("image") )
if( type==RT_IMAGE || type==RT_XHR )
SendMessage( _resHandler->_wnd, _resHandler->_msg,
_resHandler->_size, (int)_resHandler->_data );
if( _resHandler->_callback )
_resHandler->_callback->Cont();
}
//---------------------------------------------------------------------------
void __fastcall TResRequestClient::OnDownloadData(const _di_ICefUrlRequest request, void * data, NativeUInt dataLength)
{
char* pData = _resHandler->_data;
int& nSize = _resHandler->_size;
memcpy( pData + nSize, data, dataLength );
nSize += dataLength;
}
//---------------------------------------------------------------------------
+46
View File
@@ -0,0 +1,46 @@
//---------------------------------------------------------------------------
#ifndef ResourceHandlerH
#define ResourceHandlerH
#include "ceflib.hpp"
//---------------------------------------------------------------------------
class TResHandler : public TCefResourceHandlerOwn
{
public:
HWND _wnd;
int _msg;
char _data[10240];
int _size, _offset;
_di_ICefCallback _callback;
_di_ICefResponse _response;
virtual bool __fastcall ProcessRequest(const _di_ICefRequest request, const _di_ICefCallback callback);
virtual void __fastcall GetResponseHeaders(const _di_ICefResponse response, /* out */ __int64 &responseLength, /* out */ ustring &redirectUrl);
virtual bool __fastcall ReadResponse(const void * dataOut, int bytesToRead, int &bytesRead, const _di_ICefCallback callback);
virtual bool __fastcall CanGetCookie(const PCefCookie cookie){return true;};
virtual bool __fastcall CanSetCookie(const PCefCookie cookie){return true;};
virtual void __fastcall Cancel(void){};
__fastcall TResHandler(const _di_ICefBrowser browser, const _di_ICefFrame frame,
const _di_ICefRequest request, HWND wnd, int msg);
};
class TResRequestClient : public TCefUrlrequestClientOwn
{
public:
TResHandler* _resHandler;
virtual void __fastcall OnRequestComplete(const _di_ICefUrlRequest request);
virtual void __fastcall OnDownloadData(const _di_ICefUrlRequest request, void * data, NativeUInt dataLength);
virtual void __fastcall OnUploadProgress(const _di_ICefUrlRequest request,
__int64 current, __int64 total){};
virtual void __fastcall OnDownloadProgress(const _di_ICefUrlRequest request,
__int64 current, __int64 total){};
bool __fastcall OnGetAuthCredentials(bool isProxy, const ustring host, int port,
const ustring realm, const ustring scheme,
const _di_ICefAuthCallback callback){return true;};
__fastcall TResRequestClient(TResHandler* handler);
};
#endif
+327
View File
@@ -0,0 +1,327 @@
/*
* FIPS-180-2 compliant SHA-256 implementation
*
* Copyright (C) 2006-2007 Christophe Devine
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* The SHA-256 Secure Hash Standard was published by NIST in 2002.
*
* http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
*/
//#include "StdAfx.h"
#include "sha2.h"
#include <memory.h>
#include <string.h>
#include <stdio.h>
/*
* 32-bit integer manipulation macros (big endian)
*/
#ifndef GET_ULONG_BE
#define GET_ULONG_BE(n,b,i) \
{ \
(n) = ( (unsigned long) (b)[(i) ] << 24 ) \
| ( (unsigned long) (b)[(i) + 1] << 16 ) \
| ( (unsigned long) (b)[(i) + 2] << 8 ) \
| ( (unsigned long) (b)[(i) + 3] ); \
}
#endif
#ifndef PUT_ULONG_BE
#define PUT_ULONG_BE(n,b,i) \
{ \
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
(b)[(i) + 3] = (unsigned char) ( (n) ); \
}
#endif
static const unsigned char sha2_padding[64] =
{
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
/*
* SHA-256 context setup
*/
void sha2_starts( sha2_context *ctx, int is224 )
{
ctx->total[0] = 0;
ctx->total[1] = 0;
if( is224 == 0 )
{
/* SHA-256 */
ctx->state[0] = 0x6A09E667;
ctx->state[1] = 0xBB67AE85;
ctx->state[2] = 0x3C6EF372;
ctx->state[3] = 0xA54FF53A;
ctx->state[4] = 0x510E527F;
ctx->state[5] = 0x9B05688C;
ctx->state[6] = 0x1F83D9AB;
ctx->state[7] = 0x5BE0CD19;
}
else
{
/* SHA-224 */
ctx->state[0] = 0xC1059ED8;
ctx->state[1] = 0x367CD507;
ctx->state[2] = 0x3070DD17;
ctx->state[3] = 0xF70E5939;
ctx->state[4] = 0xFFC00B31;
ctx->state[5] = 0x68581511;
ctx->state[6] = 0x64F98FA7;
ctx->state[7] = 0xBEFA4FA4;
}
ctx->is224 = is224;
}
static void sha2_process( sha2_context *ctx, unsigned char data[64] )
{
unsigned long temp1, temp2, W[64];
unsigned long A, B, C, D, E, F, G, H;
GET_ULONG_BE( W[ 0], data, 0 );
GET_ULONG_BE( W[ 1], data, 4 );
GET_ULONG_BE( W[ 2], data, 8 );
GET_ULONG_BE( W[ 3], data, 12 );
GET_ULONG_BE( W[ 4], data, 16 );
GET_ULONG_BE( W[ 5], data, 20 );
GET_ULONG_BE( W[ 6], data, 24 );
GET_ULONG_BE( W[ 7], data, 28 );
GET_ULONG_BE( W[ 8], data, 32 );
GET_ULONG_BE( W[ 9], data, 36 );
GET_ULONG_BE( W[10], data, 40 );
GET_ULONG_BE( W[11], data, 44 );
GET_ULONG_BE( W[12], data, 48 );
GET_ULONG_BE( W[13], data, 52 );
GET_ULONG_BE( W[14], data, 56 );
GET_ULONG_BE( W[15], data, 60 );
#define SHR(x,n) ((x & 0xFFFFFFFF) >> n)
#define ROTR(x,n) (SHR(x,n) | (x << (32 - n)))
#define S0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3))
#define S1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10))
#define S2(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22))
#define S3(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25))
#define F0(x,y,z) ((x & y) | (z & (x | y)))
#define F1(x,y,z) (z ^ (x & (y ^ z)))
#define R(t) \
( \
W[t] = S1(W[t - 2]) + W[t - 7] + \
S0(W[t - 15]) + W[t - 16] \
)
#define P(a,b,c,d,e,f,g,h,x,K) \
{ \
temp1 = h + S3(e) + F1(e,f,g) + K + x; \
temp2 = S2(a) + F0(a,b,c); \
d += temp1; h = temp1 + temp2; \
}
A = ctx->state[0];
B = ctx->state[1];
C = ctx->state[2];
D = ctx->state[3];
E = ctx->state[4];
F = ctx->state[5];
G = ctx->state[6];
H = ctx->state[7];
P( A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98 );
P( H, A, B, C, D, E, F, G, W[ 1], 0x71374491 );
P( G, H, A, B, C, D, E, F, W[ 2], 0xB5C0FBCF );
P( F, G, H, A, B, C, D, E, W[ 3], 0xE9B5DBA5 );
P( E, F, G, H, A, B, C, D, W[ 4], 0x3956C25B );
P( D, E, F, G, H, A, B, C, W[ 5], 0x59F111F1 );
P( C, D, E, F, G, H, A, B, W[ 6], 0x923F82A4 );
P( B, C, D, E, F, G, H, A, W[ 7], 0xAB1C5ED5 );
P( A, B, C, D, E, F, G, H, W[ 8], 0xD807AA98 );
P( H, A, B, C, D, E, F, G, W[ 9], 0x12835B01 );
P( G, H, A, B, C, D, E, F, W[10], 0x243185BE );
P( F, G, H, A, B, C, D, E, W[11], 0x550C7DC3 );
P( E, F, G, H, A, B, C, D, W[12], 0x72BE5D74 );
P( D, E, F, G, H, A, B, C, W[13], 0x80DEB1FE );
P( C, D, E, F, G, H, A, B, W[14], 0x9BDC06A7 );
P( B, C, D, E, F, G, H, A, W[15], 0xC19BF174 );
P( A, B, C, D, E, F, G, H, R(16), 0xE49B69C1 );
P( H, A, B, C, D, E, F, G, R(17), 0xEFBE4786 );
P( G, H, A, B, C, D, E, F, R(18), 0x0FC19DC6 );
P( F, G, H, A, B, C, D, E, R(19), 0x240CA1CC );
P( E, F, G, H, A, B, C, D, R(20), 0x2DE92C6F );
P( D, E, F, G, H, A, B, C, R(21), 0x4A7484AA );
P( C, D, E, F, G, H, A, B, R(22), 0x5CB0A9DC );
P( B, C, D, E, F, G, H, A, R(23), 0x76F988DA );
P( A, B, C, D, E, F, G, H, R(24), 0x983E5152 );
P( H, A, B, C, D, E, F, G, R(25), 0xA831C66D );
P( G, H, A, B, C, D, E, F, R(26), 0xB00327C8 );
P( F, G, H, A, B, C, D, E, R(27), 0xBF597FC7 );
P( E, F, G, H, A, B, C, D, R(28), 0xC6E00BF3 );
P( D, E, F, G, H, A, B, C, R(29), 0xD5A79147 );
P( C, D, E, F, G, H, A, B, R(30), 0x06CA6351 );
P( B, C, D, E, F, G, H, A, R(31), 0x14292967 );
P( A, B, C, D, E, F, G, H, R(32), 0x27B70A85 );
P( H, A, B, C, D, E, F, G, R(33), 0x2E1B2138 );
P( G, H, A, B, C, D, E, F, R(34), 0x4D2C6DFC );
P( F, G, H, A, B, C, D, E, R(35), 0x53380D13 );
P( E, F, G, H, A, B, C, D, R(36), 0x650A7354 );
P( D, E, F, G, H, A, B, C, R(37), 0x766A0ABB );
P( C, D, E, F, G, H, A, B, R(38), 0x81C2C92E );
P( B, C, D, E, F, G, H, A, R(39), 0x92722C85 );
P( A, B, C, D, E, F, G, H, R(40), 0xA2BFE8A1 );
P( H, A, B, C, D, E, F, G, R(41), 0xA81A664B );
P( G, H, A, B, C, D, E, F, R(42), 0xC24B8B70 );
P( F, G, H, A, B, C, D, E, R(43), 0xC76C51A3 );
P( E, F, G, H, A, B, C, D, R(44), 0xD192E819 );
P( D, E, F, G, H, A, B, C, R(45), 0xD6990624 );
P( C, D, E, F, G, H, A, B, R(46), 0xF40E3585 );
P( B, C, D, E, F, G, H, A, R(47), 0x106AA070 );
P( A, B, C, D, E, F, G, H, R(48), 0x19A4C116 );
P( H, A, B, C, D, E, F, G, R(49), 0x1E376C08 );
P( G, H, A, B, C, D, E, F, R(50), 0x2748774C );
P( F, G, H, A, B, C, D, E, R(51), 0x34B0BCB5 );
P( E, F, G, H, A, B, C, D, R(52), 0x391C0CB3 );
P( D, E, F, G, H, A, B, C, R(53), 0x4ED8AA4A );
P( C, D, E, F, G, H, A, B, R(54), 0x5B9CCA4F );
P( B, C, D, E, F, G, H, A, R(55), 0x682E6FF3 );
P( A, B, C, D, E, F, G, H, R(56), 0x748F82EE );
P( H, A, B, C, D, E, F, G, R(57), 0x78A5636F );
P( G, H, A, B, C, D, E, F, R(58), 0x84C87814 );
P( F, G, H, A, B, C, D, E, R(59), 0x8CC70208 );
P( E, F, G, H, A, B, C, D, R(60), 0x90BEFFFA );
P( D, E, F, G, H, A, B, C, R(61), 0xA4506CEB );
P( C, D, E, F, G, H, A, B, R(62), 0xBEF9A3F7 );
P( B, C, D, E, F, G, H, A, R(63), 0xC67178F2 );
ctx->state[0] += A;
ctx->state[1] += B;
ctx->state[2] += C;
ctx->state[3] += D;
ctx->state[4] += E;
ctx->state[5] += F;
ctx->state[6] += G;
ctx->state[7] += H;
}
/*
* SHA-256 process buffer
*/
void sha2_update( sha2_context *ctx, unsigned char *input, int ilen )
{
int fill;
unsigned long left;
if( ilen <= 0 )
return;
left = ctx->total[0] & 0x3F;
fill = 64 - left;
ctx->total[0] += ilen;
ctx->total[0] &= 0xFFFFFFFF;
if( ctx->total[0] < (unsigned long) ilen )
ctx->total[1]++;
if( left && ilen >= fill )
{
memcpy( (void *) (ctx->buffer + left),
(void *) input, fill );
sha2_process( ctx, ctx->buffer );
input += fill;
ilen -= fill;
left = 0;
}
while( ilen >= 64 )
{
sha2_process( ctx, input );
input += 64;
ilen -= 64;
}
if( ilen > 0 )
{
memcpy( (void *) (ctx->buffer + left),
(void *) input, ilen );
}
}
/*
* SHA-256 final digest
*/
void sha2_finish( sha2_context *ctx, unsigned char output[32] )
{
unsigned long last, padn;
unsigned long high, low;
unsigned char msglen[8];
high = ( ctx->total[0] >> 29 )
| ( ctx->total[1] << 3 );
low = ( ctx->total[0] << 3 );
PUT_ULONG_BE( high, msglen, 0 );
PUT_ULONG_BE( low, msglen, 4 );
last = ctx->total[0] & 0x3F;
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
sha2_update( ctx, (unsigned char *) sha2_padding, padn );
sha2_update( ctx, msglen, 8 );
PUT_ULONG_BE( ctx->state[0], output, 0 );
PUT_ULONG_BE( ctx->state[1], output, 4 );
PUT_ULONG_BE( ctx->state[2], output, 8 );
PUT_ULONG_BE( ctx->state[3], output, 12 );
PUT_ULONG_BE( ctx->state[4], output, 16 );
PUT_ULONG_BE( ctx->state[5], output, 20 );
PUT_ULONG_BE( ctx->state[6], output, 24 );
if( ctx->is224 == 0 )
PUT_ULONG_BE( ctx->state[7], output, 28 );
}
int MD5_Get_SHA256( char *chIn, char* chOut )
{
sha2_context m_Context2;
unsigned char result[32] = { 0 };
sha2_starts( &m_Context2, 0 );
sha2_update( &m_Context2, (unsigned char*)chIn, strlen(chIn) );
sha2_finish( &m_Context2, result );
chOut[0] = 0;
for(int i = 0; i < 32; i++)
{
char temp[3];
sprintf( temp, "%02x", result[i] );
strcat( chOut, temp );
}
return 0;
}
+55
View File
@@ -0,0 +1,55 @@
/**
* file sha2.h
*/
#ifndef _SHA2_H
#define _SHA2_H
/**
* brief SHA-256 context structure
*/
typedef struct
{
unsigned long total[2]; /*!< number of bytes processed */
unsigned long state[8]; /*!< intermediate digest state */
unsigned char buffer[64]; /*!< data block being processed */
unsigned char ipad[64]; /*!< HMAC: inner padding */
unsigned char opad[64]; /*!< HMAC: outer padding */
int is224; /*!< 0 => SHA-256, else SHA-224 */
}
sha2_context;
#ifdef __cplusplus
extern "C" {
#endif
/**
* brief SHA-256 context setup
* param ctx context to be initialized
* param is224 0 = use SHA256, 1 = use SHA224
*/
void sha2_starts( sha2_context *ctx, int is224 );
/**
* brief SHA-256 process buffer
* param ctx SHA-256 context
* param input buffer holding the data
* param ilen length of the input data
*/
void sha2_update( sha2_context *ctx, unsigned char *input, int ilen );
/**
* brief SHA-256 final digest
* param ctx SHA-256 context
* param output SHA-224/256 checksum result
*/
void sha2_finish( sha2_context *ctx, unsigned char output[32] );
int MD5_Get_SHA256(char *chIn, char* chOut);
#ifdef __cplusplus
}
#endif
#endif /* sha2.h */
+88
View File
@@ -0,0 +1,88 @@
#include <windows.h>
//#include <process.h>
#include <stdio.h>
#include "SimpleMutex.h"
//#include "GlobalUnit.h"
////////////////////////////////////////////////////////////////////
//CSema
CSema::CSema(const char *sName, unsigned int nInit, bool bCreate)
{
m_bCreate = bCreate;
if (!m_bCreate)
return;
m_hSema = CreateSemaphore(NULL,nInit,0xffff,NULL);
if (!m_hSema){
char txt[256];
sprintf(txt, "Create semaphore error, errno=%d\n", errno);
OutputDebugStringA( txt );
}
}
CSema::~CSema()
{
if (!m_bCreate)
return;
if( !CloseHandle(m_hSema) ){
char txt[256];
sprintf(txt, "Close semaphore error, errno=%d\n", errno);
OutputDebugStringA( txt );
}
}
int CSema::ActP(DWORD dwTimeout)
{
if (!m_bCreate)
return -1;
int ret = WaitForSingleObject(m_hSema, dwTimeout);
if( ret==WAIT_TIMEOUT ){
OutputDebugStringA("WaitforSingleObject timeout!\n");
return 1;
}
else if( ret!=0 ){
char txt[256];
sprintf(txt, "sema wait error, errno=%d\n", errno);
OutputDebugStringA( txt );
}
return ret;
}
void CSema::ActV()
{
if (!m_bCreate)
return;
if (!ReleaseSemaphore(m_hSema,1,NULL)){
char txt[256];
sprintf(txt, "sema release error, errno=%d\n", errno);
OutputDebugStringA( txt );
}
}
////////////////////////////////////////////////////////////////////
//CMutextLock
CMutexLock::CMutexLock(bool bCreate)
{
m_psmMut = new CSema( NULL, 1, bCreate );
m_psmMut->ActP();
}
CMutexLock::CMutexLock(CSema * pSema, DWORD dwTimeOut)
{
m_psmMut = pSema;
m_psmMut->ActP(dwTimeOut);
}
CMutexLock::~CMutexLock()
{
if( m_psmMut!=NULL )
m_psmMut->ActV();
}
////////////////////////////////////////////////////////////////////
+41
View File
@@ -0,0 +1,41 @@
#ifndef SimpleMutexH
#define SimpleMutexH
#include <windows.h>
#ifndef INFINITE
#define INFINITE 0x7FFFFFFF
#endif
//////////////////////////////
//
// 信号量
//
class CSema
{
protected:
bool m_bCreate;// 用来控制是否生成信号量,缺省情况下生成。
HANDLE m_hSema;
public:
CSema(const char *sName, unsigned int nInit, bool bCreate=true);
~CSema();
int ActP(DWORD dwTimeOut = INFINITE); // 等待状态
void ActV(); // 非等待状态
};
///////////////////////////////
//
// 互斥量
//
class CMutexLock
{
protected:
CSema * m_psmMut;
public:
CMutexLock(bool bCreate=true);
CMutexLock(CSema * pSema, DWORD dwTimeOut = INFINITE);
~CMutexLock();
};
#endif //SimpleMutexH