static BOOL GetDeviceIdentifierAndVersion( __in int argc, __in TCHAR** argv, __out PNDAS_DEVICE_IDENTIFIER NdasDeviceIndentify, __out int * HardwareVersion, __out int * HardwareRevision ){ if(argc < 3) { _tprintf(_T("Error: NDAS Device Identifier is invalid.\n\n")); return FALSE; } // LU Device ID BOOL success = ParseNdasDeviceId(argv[0], NdasDeviceIndentify); if (!success) { _tprintf(_T("Error: NDAS Device Identifier is invalid.\n\n")); usage(); return FALSE; } // Hardware version and revision if( StrToIntEx(argv[1], STIF_DEFAULT, HardwareVersion) == FALSE) { _tprintf(_T("Error: Hardware version is invalid or not specified.\n\n")); usage(); return FALSE; } if( StrToIntEx(argv[2], STIF_DEFAULT, HardwareRevision) == FALSE) { _tprintf(_T("Error: Hardware revision is invalid or not specified.\n\n")); usage(); return FALSE; } #ifdef _DEBUG _tprintf(_T("%02X-%02X-%02X-%02X-%02X-%02X %d HwVer %d HwRev %d\n"), NdasDeviceIndentify->Identifier[0], NdasDeviceIndentify->Identifier[1], NdasDeviceIndentify->Identifier[2], NdasDeviceIndentify->Identifier[3], NdasDeviceIndentify->Identifier[4], NdasDeviceIndentify->Identifier[5], NdasDeviceIndentify->UnitNumber, *HardwareVersion, *HardwareRevision ); #endif return TRUE; }
BOOL CSZCommandLineEx::VerifyParam( LPCTSTR lpszParamName, CParamUsage& usage, CString* pstrErrorMessage) { assert(lpszParamName && *lpszParamName); if (!usage.m_bMustExist && !usage.m_bValueMustExist && !usage.m_bValueMustBeInt) return TRUE; CString strParamValue; if (!m_mapParams.Lookup(lpszParamName, strParamValue)) { if (usage.m_bMustExist) { if (pstrErrorMessage) { pstrErrorMessage->Format(_T("Parameter \"%s\" must be set!"), lpszParamName); } return FALSE; } } if (usage.m_bValueMustExist) { if (strParamValue.IsEmpty()) { if (pstrErrorMessage) { pstrErrorMessage->Format(_T("Parameter \"%s\" must not be empty!"), lpszParamName); } return FALSE; } } if (usage.m_bValueMustBeInt) { int nValue = 0; if (!StrToIntEx(strParamValue, STIF_DEFAULT, &nValue)) { if (pstrErrorMessage) { pstrErrorMessage->Format(_T("Parameter \"%s\" must be an integer!"), lpszParamName); } return FALSE; } } return TRUE; }
int __fastcall TThreadSubmitToDB::GetRowsForSQLLDR(const AnsiString & Text) { int Result = -1; if(Text.Pos(SQLLDR_KEY_WORD1) > 0) { Result = StrToIntEx(Text.SubString(strlen(SQLLDR_KEY_WORD1) + 1,Text.Length() - strlen(SQLLDR_KEY_WORD1) + 1).c_str()); } return Result; }
int __fastcall TThreadSubmitToDB::GetRowsForBCP(const AnsiString & Text) { int Result = -1; int pos = StrRScan(Text.c_str(),BCP_KEY_WORD1); if(pos > -1) { Result = StrToIntEx(Text.SubString(pos + strlen(BCP_KEY_WORD1) + 1, Text.Length() - pos - strlen(BCP_KEY_WORD1) - 1).c_str()); } return Result; }
UINT WINAPI GetShellIconSize(UINT uiDefault = ::GetSystemMetrics(SM_CXICON)) { HKEY hKey = (HKEY) INVALID_HANDLE_VALUE; LONG lResult = ::RegOpenKeyEx( HKEY_CURRENT_USER, _T("Control Panel\\Desktop\\WindowMetrics"), 0, KEY_READ, &hKey); if (ERROR_SUCCESS != lResult) { return uiDefault; } TCHAR szData[30] = {0}; DWORD cbData = sizeof(szData); DWORD regType; lResult = ::RegQueryValueEx( hKey, _T("Shell Icon Size"), NULL, ®Type, (BYTE*) szData, &cbData); if (ERROR_SUCCESS != lResult) { ::RegCloseKey(hKey); return uiDefault; } UINT uiValue = uiDefault; BOOL fSuccess = StrToIntEx(szData, STIF_DEFAULT, (int*)&uiValue); if (!fSuccess) { ::RegCloseKey(hKey); return uiDefault; } ::RegCloseKey(hKey); return uiValue; }
bool __fastcall TThreadSubmitToDB::SubmitToMySQL() { SECURITY_ATTRIBUTES se = {0}; se.nLength = sizeof(se); se.bInheritHandle = true; se.lpSecurityDescriptor = NULL; CreatePipe(&hReadPipe,&hWritePipe,&se,0); STARTUPINFO si = {0}; si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES; si.wShowWindow = SW_HIDE; si.hStdOutput = hWritePipe; si.hStdError = hWritePipe; memset(&pi,sizeof(pi),0); //AnsiString Text; //mysqlimport -prl --fields-enclosed-by= --fields-terminated-by=, // mysql --local c:\hdhd_test_bills1.tmp --user=root --port=3306 --password=root --host=127.0.0.1 AnsiString Command = ToolPath + " -prl --fields-enclosed-by= --fields-terminated-by=, " + DataBaseName + " --local " + TempFileName + " --user="******" --password="******" --host=" + DBServer + " --port=" + ServerPort; MessageTextList->Add("执行命令:" + ToolPath + " -prl --fields-enclosed-by= --fields-terminated-by=, " + DataBaseName + " --local " + TempFileName + " --user="******" --password=******* --host=" + DBServer + " --port=" + ServerPort); if(SlentMode) { printf("%s\n","执行命令:" + ToolPath + " -prl --fields-enclosed-by= --fields-terminated-by=, " + DataBaseName + " " + TempFileName + " --user="******" --password=******* --host=" + DBServer + " --port=" + ServerPort); } if(CreateProcess(NULL,Command.c_str(),&se,&se,true,NORMAL_PRIORITY_CLASS,NULL,WorkDir.c_str(),&si,&pi)) { bool bContinue = CloseHandle(hWritePipe); hWritePipe = NULL; char chBuffer[1025]; unsigned long Bytesread; AnsiString Text; MessageTextList->Add("MySQL批量复制进程已启动,请等待..."); while(bContinue) { bContinue = ReadFile(hReadPipe,&chBuffer[0],1024,&Bytesread,NULL); try { chBuffer[Bytesread] = 0; if(strlen(&chBuffer[0]) > 0) { Text = chBuffer; } if(Text != ""&&UpperCase(MessageTextList->Text).Pos("RECORDS") < 1) { MessageTextList->Add(Text); } } catch(...) { } chBuffer[0] = 0; } WaitForSingleObject(pi.hProcess,INFINITE); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); CloseHandle(hReadPipe); pi.hProcess = NULL; hReadPipe = NULL; if(UpperCase(MessageTextList->Text).Pos("RECORDS") < 1) { ErrorMessage = "提交数据失败,请查看状态窗口中的出错信息."; return false; } else { SendMessage(hWnd,MSG_SET_PROCESS_POS,TotalRecordCount,0); int k = 0; int n; for(int n = MessageTextList->Count - 1;n > -1;n--) { Text = MessageTextList->Strings[n]; int pos = Text.Pos("Records: "); if(pos > 0) { k = StrToIntEx(Text.SubString(pos + strlen("Records: "),Text.Length() - strlen("Records: ")).c_str()); if(TotalRecordCount - k > StrToInt(MaxError)) { ErrorMessage = "提交的数据行数与转换的行数不一致,且差异超出了允许的错误范围(最多" + MaxError + ").转换的数据行数为:" + IntToStr(TotalRecordCount) + ",实际提交的行数为:" + IntToStr(k) + "."; } break; } } if(n == -1) { ErrorMessage = "找不到MySQLImport关键字(Records).导入失败."; } //如果导入成功,则继续执行SQL语句 if(ErrorMessage == "" && SQLCommandList != NULL) { for(int n = 0;n < SQLCommandList->Count;n++) { try { if(SlentMode) { printf("正在执行语句:%s\n",SQLCommandList->Strings[n]); } MessageTextList->Add("正在执行语句:" + SQLCommandList->Strings[n]); ADOConnection->Execute(SQLCommandList->Strings[n]); } catch(...){} } } try { MessageTextList->Add("*********************************数据提交报告*********************************"); MessageTextList->Add("完成时间:" + FormatDateTime("yyyy-mm-dd hh:nn:ss",Now()) + "."); MessageTextList->Add("目标表:" + DestTableName); MessageTextList->Add("临时文件:" + TempFileName); MessageTextList->Add("共转换了" + IntToStr(TotalRecordCount) + "条记录,导入了" + IntToStr(k) + "条记录."); } catch(...) { } return true; } } else { CloseHandle(hWritePipe); CloseHandle(hReadPipe); ErrorMessage = "创建MySQLImport进程失败.请检查是否安装了MySQL客户端软件和ibill.ini中[ExternalTools]的MySQLImport是否配置正确."; return false; } }
//--------------------------------------------------------------------------- bool __fastcall TThreadSubmitToDB::SubmitToOracle() { SECURITY_ATTRIBUTES se = {0}; se.nLength = sizeof(se); se.bInheritHandle = true; se.lpSecurityDescriptor = NULL; CreatePipe(&hReadPipe,&hWritePipe,&se,0); STARTUPINFO si = {0}; si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES; si.wShowWindow = SW_HIDE; si.hStdOutput = hWritePipe; si.hStdError = hWritePipe; memset(&pi,sizeof(pi),0); if(CreateProcess(NULL,(ToolPath + " " + DBUserName + "/" + DBPassword + "@" + DBServer + " control=\"" + TempFileName + "\" errors=" + MaxError).c_str(),&se,&se,true,NORMAL_PRIORITY_CLASS,NULL,WorkDir.c_str(),&si,&pi)) { bool bContinue = CloseHandle(hWritePipe); hWritePipe = NULL; char chBuffer[2049]; unsigned long Bytesread; AnsiString Text; int pos = 0; while(bContinue) { bContinue = ReadFile(hReadPipe,&chBuffer[0],2048,&Bytesread,NULL); try { chBuffer[Bytesread] = 0; if(strlen(&chBuffer[0]) > 0) { Text = chBuffer; } //Text = AnsiReplaceStr(AnsiReplaceStr(Text,"\r",""),"\n",""); if(Text != "") { if(MessageTextList->Count > MaxMessageLine) MessageTextList->Clear(); if(SlentMode) { printf("%s\n",Text); } MessageTextList->Add(Text); } pos = GetRowsForSQLLDR(Text); if(pos > -1) { SendMessage(hWnd,MSG_SET_PROCESS_POS,pos,0); } } catch(...) { } } WaitForSingleObject(pi.hProcess,INFINITE); CloseHandle(pi.hProcess); pi.hProcess = NULL; CloseHandle(pi.hThread); CloseHandle(hReadPipe); hReadPipe = NULL; if(MessageTextList->Text.Pos("SQL*Loader-") > 0) { ErrorMessage = "提交数据失败,请查看状态窗口中的出错信息."; return false; } else { int n; AnsiString str;// = "逻辑记录计数"; /*for(n = MessageTextList->Count - 1;n > -1;n--) { Text = MessageTextList->Strings[n]; pos = Text.Pos(str); if(pos > 0) { pos = StrToIntEx(Text.SubString(pos + str.Length(),Text.Length() - str.Length() + 1).c_str()); SendMessage(hWnd,MSG_SET_PROCESS_POS,pos,0); if(pos != TotalRecordCount) { ErrorMessage = "提交的数据行数与转换的行数不一致.转换的数据行数为:" + IntToStr(TotalRecordCount) + ",实际提交的行数为:" + IntToStr(pos) + "."; } break; } } if(n == -1) { ErrorMessage = "找不到SQLLDR关键字.导入失败."; }*/ //分析日志文件 TStringList * LogFile = new TStringList; LogFile->LoadFromFile(ExtractFilePath(Application->ExeName) + DestTableName + ".log"); //if(LogFile->Pos(" str = "成功"; for(n = LogFile->Count - 1;n > -1;n--) { Text = LogFile->Strings[n]; int pos1 = Text.Pos(str); if(pos1 > 0) { pos1 = StrToIntEx(Text.c_str());//Text.SubString(pos1 + str.Length(),Text.Length() - str.Length() + 1).c_str()); if(TotalRecordCount - pos1 > StrToInt(MaxError)) { ErrorMessage = "共有" + IntToStr(TotalRecordCount) + "行需要导入,但实际上只载入了" + IntToStr(pos1) + "行."; } break; } } if(n == -1) { ErrorMessage = "找不到SQLLDR关键字,无法分析日志."; } delete LogFile; //如果导入成功,则继续执行SQL语句 if(ErrorMessage == "" && SQLCommandList != NULL) { for(int n = 0;n < SQLCommandList->Count;n++) { try { if(SlentMode) { printf("正在执行语句:%s\n",SQLCommandList->Strings[n]); } MessageTextList->Add("正在执行语句:" + SQLCommandList->Strings[n]); ADOConnection->Execute(SQLCommandList->Strings[n]); } catch(...){} } } //MessageTextList->Clear(); try { for(int n = 0;n < 10;n++) { try { MessageTextList->LoadFromFile(ExtractFilePath(Application->ExeName) + DestTableName + ".log"); break; } catch(...) { } } MessageTextList->Insert(0,"*********************************数据提交报告*********************************"); MessageTextList->Insert(1,"完成时间:" + FormatDateTime("yyyy-mm-dd hh:nn:ss",Now()) + "."); MessageTextList->Insert(2,"目标表:" + DestTableName); MessageTextList->Insert(3,"临时文件:" + TempFileName); MessageTextList->Insert(4,"共转换了" + IntToStr(TotalRecordCount) + "条记录,导入了" + IntToStr(pos) + "条记录."); MessageTextList->Insert(5,"以下是Oracle 的 SQLLDR 生成的报告:"); } catch(...) { } return true; } } else { CloseHandle(hWritePipe); CloseHandle(hReadPipe); ErrorMessage = "创建SQLLDR进程失败.请检查是否安装了Oracle客户端软件和ibill.ini中[ExternalTools]的sqlldrpath是否配置正确."; return false; } }
//--------------------------------------------------------------------------- bool __fastcall TThreadSubmitToDB::SubmitToSQLServer() { SECURITY_ATTRIBUTES se = {0}; se.nLength = sizeof(se); se.bInheritHandle = true; se.lpSecurityDescriptor = NULL; CreatePipe(&hReadPipe,&hWritePipe,&se,0); STARTUPINFO si = {0}; si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES; si.wShowWindow = SW_HIDE; si.hStdOutput = hWritePipe; si.hStdError = hWritePipe; memset(&pi,sizeof(pi),0); //AnsiString Text; //bcp pubs..hdhd_test_bills1 in c:\convert.tmp -Usa -Pwbzx9801 -S133.57.9.21 -fc:\convert.fmt AnsiString Command = ToolPath + " " + DataBaseName + ".." + DestTableName + " in " + TempFileName + " -U" + DBUserName + " -P" + DBPassword + " -S" + DBServer + " -f" + ExtractFilePath(TempFileName) + DestTableName + ".fmt" + " -m" + MaxError; MessageTextList->Add("执行命令:" + ToolPath + " " + DataBaseName + ".." + DestTableName + " in " + TempFileName + " -U" + DBUserName + " -P******** -S" + DBServer + " -f" + ExtractFilePath(TempFileName) + DestTableName + ".fmt" + " -m" + MaxError); if(SlentMode) { printf("%s\n","执行命令:" + ToolPath + " " + DataBaseName + ".." + DestTableName + " in " + TempFileName + " -U" + DBUserName + " -P******** -S" + DBServer + " -f" + ExtractFilePath(TempFileName) + DestTableName + ".fmt" + " -m" + MaxError); } if(CreateProcess(NULL,Command.c_str(),&se,&se,true,NORMAL_PRIORITY_CLASS,NULL,WorkDir.c_str(),&si,&pi)) { bool bContinue = CloseHandle(hWritePipe); hWritePipe = NULL; char chBuffer[2049]; unsigned long Bytesread; AnsiString Text; int pos = 0; while(bContinue) { bContinue = ReadFile(hReadPipe,&chBuffer[0],2048,&Bytesread,NULL); try { chBuffer[Bytesread] = 0; if(strlen(&chBuffer[0]) > 0) { Text = chBuffer; } //MessageBox(0,Text.c_str(),"",MB_OK); if(Text != "") { //if(MessageTextList->Count > MaxMessageLine) // MessageTextList->Clear(); if(SlentMode) printf("%s\n",Text); MessageTextList->Add(Text); } pos = GetRowsForBCP(Text); if(pos > -1) { SendMessage(hWnd,MSG_SET_PROCESS_POS,pos,0); } if(Text.Pos("时钟时间") > 0) break; } catch(...) { } chBuffer[0] = 0; } WaitForSingleObject(pi.hProcess,INFINITE); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); CloseHandle(hReadPipe); pi.hProcess = NULL; hReadPipe = NULL; if(UpperCase(MessageTextList->Text).Pos("ERROR") > 0) { ErrorMessage = "提交数据失败,请查看状态窗口中的出错信息."; return false; } else { SendMessage(hWnd,MSG_SET_PROCESS_POS,TotalRecordCount,0); int n; for(n = MessageTextList->Count - 1;n > -1;n--) { Text = MessageTextList->Strings[n]; pos = Text.Pos(BCP_KEY_WORD2); if(pos > 0) { pos = StrToIntEx(Text.SubString(pos + strlen(BCP_KEY_WORD2),Text.Length() - strlen(BCP_KEY_WORD2)).c_str()); if(TotalRecordCount - pos > StrToInt(MaxError)) { ErrorMessage = "提交的数据行数与转换的行数不一致,且差异超出了允许的错误范围(最多" + MaxError + ").转换的数据行数为:" + IntToStr(TotalRecordCount) + ",实际提交的行数为:" + IntToStr(pos) + "."; } break; } } if(n == -1) { ErrorMessage = "找不到BCP关键字,导入失败."; } //如果导入成功,则继续执行SQL语句 if(ErrorMessage == "" && SQLCommandList != NULL) { for(int n = 0;n < SQLCommandList->Count;n++) { try { if(SlentMode) { printf("正在执行语句:%s\n",SQLCommandList->Strings[n]); } MessageTextList->Add("正在执行语句:" + SQLCommandList->Strings[n]); ADOConnection->Execute(SQLCommandList->Strings[n]); } catch(...){} } } try { MessageTextList->Add("*********************************数据提交报告*********************************"); MessageTextList->Add("完成时间:" + FormatDateTime("yyyy-mm-dd hh:nn:ss",Now()) + "."); MessageTextList->Add("目标表:" + DestTableName); MessageTextList->Add("临时文件:" + TempFileName); MessageTextList->Add("共转换了" + IntToStr(TotalRecordCount) + "条记录,导入了" + IntToStr(pos) + "条记录."); } catch(...) { } return true; } } else { CloseHandle(hWritePipe); CloseHandle(hReadPipe); ErrorMessage = "创建BCP进程失败.请检查是否安装了SQLServer客户端软件和ibill.ini中[ExternalTools]的bcppath是否配置正确."; return false; } }
//-------------------------------------------------------------------------------------- int _tmain(int argc, _TCHAR* argv[]) { m_hInstance = (HINSTANCE)GetModuleHandle(NULL); if (argc >= 3) { m_lpFontPath = argv[2]; m_lpFontName = argv[1]; printf(__FUNCTION__"(): Using external font %ws \"%ws\"\n", m_lpFontName, m_lpFontPath); } else { printf("USAGE: MsFontsFuzz.exe <font_name> <font_file> [options]\n"); goto end; } _stprintf_s(m_TmpFontPath, _T("__TMP__%s"), _tGetNameFromFullPath(m_lpFontPath)); DbgMsg(__FILE__, __LINE__, "[+] Temporary font file is \"%ws\"\n", m_TmpFontPath); if (_tcslen(m_TmpFontPath) >= 4) { _tcslwr(m_TmpFontPath + _tcslen(m_TmpFontPath) - 4); if (!_tcscmp(m_TmpFontPath + _tcslen(m_TmpFontPath) - 4, _T(".otf"))) { m_dwFontType = FONT_TYPE_OTF; DbgMsg(__FILE__, __LINE__, "[+] Font type is .OTF\n"); } else if (!_tcscmp(m_TmpFontPath + _tcslen(m_TmpFontPath) - 4, _T(".ttf"))) { m_dwFontType = FONT_TYPE_TTF; DbgMsg(__FILE__, __LINE__, "[+] Font type is .TTF\n"); } } RemoveFontResource(m_TmpFontPath); #ifdef USE_BOADCAST_MESSAGES SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0); #endif char ch = 0; memset(m_szTable, '.', sizeof(m_szTable) - 1); for (int i = 0; i < sizeof(m_szTable); i++) { if (i != 0 && i % 16 == 0) { m_szTable[i] = '\n'; continue; } if (ch >= 0x20) { m_szTable[i] = ch; } if (ch == 0x7f) { m_szTable[i] = 0; break; } ch += 1; } if (argc > 3) { // enumerate additional parameters for (int i = 3; i < argc; i++) { if (!_tcscmp(argv[i], _T("--test"))) { // single launch mode m_bTest = TRUE; } else if (!_tcscmp(argv[i], _T("--resume"))) { // resume fuzzing in the new process m_bResume = TRUE; } else if (!_tcscmp(argv[i], _T("--noisy"))) { // show lot of output information m_bNoisy = TRUE; } else if (!_tcscmp(argv[i], _T("--text")) && argc - i > 1) { #ifdef UNICODE // use caller-specified text for display WideCharToMultiByte( CP_ACP, 0, argv[i + 1], -1, m_szTable, sizeof(m_szTable) - 1, NULL, NULL ); #else strcpy_s(m_szTable, argv[i + 1]); #endif i++; } else if (!_tcscmp(argv[i], _T("--fix-crcs"))) { // fix incorrect checksums for the original font file m_bFixCrcs = TRUE; } else if (argc - i > 1 && argv[i][0] == '-') { /** * Process data generation options. */ LPCTSTR lpParam = argv[i] + 1; DWORD dwValue = 0; BOOL bFound = FALSE; if (!StrToIntEx(argv[i + 1], STIF_SUPPORT_HEX, (int *)&dwValue)) { DbgMsg(__FILE__, __LINE__, "[!] ERROR: Invalid value for parameter \"%ws\"\n", argv[i]); continue; } for (int i_n = 0; i_n < sizeof(m_Params) / sizeof(ENGINE_PARAM); i_n++) { // search parameter by name if (!_tcscmp(m_Params[i_n].lpName, lpParam)) { *(m_Params[i_n].pdwValue) = dwValue; bFound = TRUE; break; } } if (!bFound) { DbgMsg(__FILE__, __LINE__, "[!] ERROR: Unknown parameter \"%ws\"\n", argv[i]); } i++; } } } DbgInit(LOG_FILE_NAME); // check block size and range if (BLOCK_SIZE == 1) { if (BLOCK_RANGE_START >= 0xFF) { DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_START value (it must be <0xFF)\n"); goto end; } if (BLOCK_RANGE_END > 0xFF) { DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_END value (it must be <=0xFF)\n"); goto end; } } else if (BLOCK_SIZE == 2) { if (BLOCK_RANGE_START >= 0xFFFF) { DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_START value (it must be <0xFFFF)\n"); goto end; } if (BLOCK_RANGE_END > 0xFFFF) { DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_END value (it must be <=0xFFFF)\n"); goto end; } } else if (BLOCK_SIZE == 4) { if (BLOCK_RANGE_START >= 0xFFFFFFFF) { DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_START value (it must be <0xFFFFFFFF)\n"); goto end; } if (BLOCK_RANGE_END > 0xFFFFFFFF) { DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_END value (it must be <=0xFFFFFFFF)\n"); goto end; } } else { DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_SIZE value (it must be 1, 2 or 4)\n"); goto end; } // check step size if (BLOCK_RANGE_N > BLOCK_RANGE_END) { DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_N value (it must be <=BLOCK_RANGE_END)\n"); goto end; } WNDCLASSEX wcex; ZeroMemory(&wcex, sizeof(wcex)); wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.hInstance = m_hInstance; wcex.lpszClassName = _T(WND_CLASS); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); m_hWndEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if (m_hWndEvent == NULL) { DbgMsg(__FILE__, __LINE__, "CreateEvent() ERROR %d\n", GetLastError()); goto end; } // register window class if (RegisterClassEx(&wcex) == NULL) { DbgMsg(__FILE__, __LINE__, "RegisterClassEx() ERROR %d\n", GetLastError()); goto end; } // init random number generator init_genrand(GetTickCount()); SetUnhandledExceptionFilter(UnhandledExceptionError); // read input file if (ReadFromFile(m_lpFontPath, &m_pData, &m_dwDataSize)) { if (FILE_RANGE_START >= m_dwDataSize) { DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid FILE_RANGE_START value (it must be <=FILE_SIZE)\n"); M_FREE(m_pData); return -1; } if (FILE_RANGE_END > m_dwDataSize) { DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid FILE_RANGE_END value (it must be <FILE_SIZE)\n"); M_FREE(m_pData); return -1; } if (FILE_RANGE_END == 0) { FILE_RANGE_END = m_dwDataSize; } if (FILE_RANGE_START >= FILE_RANGE_END) { DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid FILE_RANGE_START/FILE_RANGE_END values\n"); M_FREE(m_pData); return -1; } DbgMsg(__FILE__, __LINE__, "[+] %d bytes readed from \"%ws\"\n", m_dwDataSize, m_lpFontPath); if (!m_bResume && (m_dwFontType == FONT_TYPE_OTF || m_dwFontType == FONT_TYPE_TTF)) { OTF_TableByOffset(m_pData, (ULONG)-1); } if (m_bFixCrcs) { // write fixed checksums into the original file if (DumpToFile(m_lpFontPath, m_pData, m_dwDataSize)) { DbgMsg(__FILE__, __LINE__, "[+] Checksums has been fixed for font file \"%ws\"\n", m_lpFontPath); } } else if (m_bTest) { // single run with the unchanged font file if (DumpToFile(m_TmpFontPath, m_pData, m_dwDataSize)) { FuzzIteration(); } } else { DbgMsg(__FILE__, __LINE__, "[+] Fuzzing params:\n\n"); // print parameters values for (int i_n = 0; i_n < sizeof(m_Params) / sizeof(ENGINE_PARAM); i_n++) { DbgMsg(__FILE__, __LINE__, " %20ws = 0x%.8x\n", m_Params[i_n].lpName, *(m_Params[i_n].pdwValue)); } DbgMsg(__FILE__, __LINE__, "\n"); DbgMsg(__FILE__, __LINE__, "[+] Processing cases...\n\n"); // align buffer size by block size m_dwAlignedDataSize = XALIGN_UP(m_dwDataSize, BLOCK_SIZE); // allocate output buffer if (m_pAlignedData = M_ALLOC(m_dwAlignedDataSize)) { char *lpszBigBuff = (char *)M_ALLOC(BIG_BUFFER_LENGTH); if (lpszBigBuff) { FillMemory(lpszBigBuff, BIG_BUFFER_LENGTH, 'A'); } PVOID pBigData = M_ALLOC(m_dwDataSize + BIG_BUFFER_LENGTH); // for each byte/word/dword of input file... for (DWORD i = FILE_RANGE_START; i < FILE_RANGE_END; i += BLOCK_SIZE) { DbgMsg(__FILE__, __LINE__, "Offset=0x%.8x TotalSize=0x%.8x File=%.8x\n", i, m_dwDataSize, m_dwCasesProcessed); POTF_TABLE_HEADER Table = NULL; if (m_dwFontType == FONT_TYPE_OTF || m_dwFontType == FONT_TYPE_TTF) { Table = OTF_TableByOffset(m_pData, i); if (Table == NULL) { // skip OTF/TTF data outside the tables continue; } } if (BLOCK_RANGE_N > 0) { // fuze each value with the step size == BLOCK_RANGE_N for (DWORD n = XALIGN_DOWN(BLOCK_RANGE_START, BLOCK_RANGE_N); n < XALIGN_DOWN(BLOCK_RANGE_END, BLOCK_RANGE_N); n += BLOCK_RANGE_N) { // write plain value WriteVal(i, BLOCK_SIZE, n, n, n); if (BLOCK_SIZE > 1) { // write randomized value WriteVal(i, BLOCK_SIZE, n, n + getrand(0, BLOCK_RANGE_N - 1), n + getrand(0, BLOCK_RANGE_N - 1) ); } } } // zero-bytes stuff WriteVal(i, BLOCK_SIZE, 0x00, 0x0000, 0x00000000); // integer overflow stuff WriteVal(i, BLOCK_SIZE, 0xFF, 0xFFFF, 0xFFFFFFFF); // invalid user-mode pointers WriteVal(i, BLOCK_SIZE, 0x0D, 0x0D0D, 0x0D0D0D0D); if (lpszBigBuff && pBigData) { /** * Write big ASCI data after the each byte. */ memcpy(pBigData, m_pData, i); memcpy((PUCHAR)pBigData + i, lpszBigBuff, BIG_BUFFER_LENGTH); memcpy((PUCHAR)pBigData + i + BIG_BUFFER_LENGTH, (PUCHAR)m_pData + i, m_dwDataSize - i); if (m_dwFontType == FONT_TYPE_OTF || m_dwFontType == FONT_TYPE_TTF) { POTF_FILE_HEADER Hdr = (POTF_FILE_HEADER)pBigData; POTF_TABLE_HEADER Table = (POTF_TABLE_HEADER)((PUCHAR)pBigData + sizeof(OTF_FILE_HEADER)); POTF_TABLE_HEADER CurrentTable = NULL; for (USHORT t = 0; t < htons(Hdr->numTables); t++) { ULONG Offset = htonl(Table->offset), Length = htonl(Table->length); if (i >= Offset && i < Offset + Length) { // fix OTF/TTF table checksum and length ULONG Sum = OTF_CalcTableChecksum((ULONG *)((PUCHAR)pBigData + Offset), Length); Table->checkSum = htonl(Sum); Table->length = htonl(Length); CurrentTable = Table; break; } Table += 1; } if (CurrentTable) { Table = (POTF_TABLE_HEADER)((PUCHAR)pBigData + sizeof(OTF_FILE_HEADER)); for (USHORT t = 0; t < htons(Hdr->numTables); t++) { ULONG Offset = htonl(Table->offset), Length = htonl(Table->length); if (Offset > htonl(CurrentTable->offset)) { // fix offsets of the other tables Table->offset = htonl(Offset + BIG_BUFFER_LENGTH); } Table += 1; } } } if (DumpToFile(m_TmpFontPath, pBigData, m_dwDataSize + BIG_BUFFER_LENGTH)) { FuzzIteration(); m_dwCasesProcessed++; } } if (m_dwCasesProcessed > MAX_CASES_PER_PROCESS) { TCHAR szSelf[MAX_PATH], szCmdLine[MAX_PATH]; GetModuleFileName(GetModuleHandle(NULL), szSelf, MAX_PATH); _stprintf_s( szCmdLine, MAX_PATH, _T("\"%s\" \"%s\" \"%s\" -BLOCK_SIZE 0x%x -BLOCK_RANGE_START 0x%x -BLOCK_RANGE_END 0x%x -BLOCK_RANGE_N 0x%x -FILE_RANGE_START 0x%x --resume Y"), szSelf, m_lpFontName, m_lpFontPath, BLOCK_SIZE, BLOCK_RANGE_START, BLOCK_RANGE_END, BLOCK_RANGE_N, i ); if (m_bNoisy) { _tcscat(szCmdLine, _T(" --noisy Y")); } STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&pi, sizeof(pi)); ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); // create a new fuzzer instance if (!CreateProcess(NULL, szCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { MessageBox(0, _T("CreateProcess() fails"), _T("ERROR"), MB_ICONERROR); } ExitProcess(0); } } DbgMsg(__FILE__, __LINE__, "Done; %d cases processed\n", m_dwCasesProcessed); if (pBigData) { M_FREE(pBigData); } if (lpszBigBuff) { M_FREE(lpszBigBuff); } M_FREE(m_pAlignedData); } } M_FREE(m_pData); } else { DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Error while reading input file\n"); } end: if (m_hWndEvent) { CloseHandle(m_hWndEvent); } printf("Press any key to quit...\n"); _getch(); return 0; }
int Run(int argc, TCHAR** argv) { typedef enum _COMMAND_TYPE { CmdUnknown, CmdPlugIn, CmdEject, CmdUnplug } COMMAND_TYPE; if (argc < 3) { usage(); return 1; } COMMAND_TYPE commandType = CmdUnknown; if (0 == lstrcmpi(argv[1], _T("-p"))) { commandType = CmdPlugIn; } else if (0 == lstrcmpi(argv[1], _T("-e"))) { commandType = CmdEject; } else if (0 == lstrcmpi(argv[1], _T("-u"))) { commandType = CmdUnplug; } else { usage(); return 1; } NDAS_LOGICALUNIT_ADDRESS address = {0}; int value; BOOL success = StrToIntEx(argv[2], STIF_SUPPORT_HEX, &value); if (!success) { _tprintf(_T("Logical unit address is invalid.\n")); return 1; } // // Only TargetId can be used. // address.TargetId = static_cast<UCHAR>(value); address.PathId = 0; address.Lun = 0; if (CmdPlugIn == commandType) { success = ProcessPlugIn(address, argc - 3, argv + 3); return success ? 0 : 1; } XTL::AutoFileHandle handle = NdasPortCtlCreateControlDevice(GENERIC_READ | GENERIC_WRITE); if (handle.IsInvalid()) { ErrorHolder lastError; _tprintf(_T("Opening NDAS Port device file failed.\n")); _tprintf(_T("Error %u (0x%X): %hs\n"), lastError.GetCode(), lastError.GetCode(), lastError.GetDescriptionA()); return 1; } if (!NdasPortCtlGetPortNumber(handle, &address.PortNumber)) { ErrorHolder lastError; _tprintf(_T("Getting the port number failed.\n")); _tprintf(_T("Error %u (0x%X): %hs\n"), lastError.GetCode(), lastError.GetCode(), lastError.GetDescriptionA()); return 1; } success = TRUE; switch (commandType) { case CmdEject: success = NdasPortCtlEjectLogicalUnit(handle, address, 0); if (!success) { ErrorHolder lastError; _tprintf(_T("Eject failed.\n")); _tprintf(_T("Error %u (0x%X): %hs\n"), lastError.GetCode(), lastError.GetCode(), lastError.GetDescriptionA()); } break; case CmdUnplug: success = NdasPortCtlUnplugLogicalUnit(handle, address, 0); if (!success) { ErrorHolder lastError; _tprintf(_T("Unplug failed.\n")); _tprintf(_T("Error %u (0x%X): %hs\n"), lastError.GetCode(), lastError.GetCode(), lastError.GetDescriptionA()); } break; } return success ? 0 : 1; }
// Command: // [disk | aggr | stripe | mirror | odd | mo] <ro|rw> [ending address] [number of member disks] static PNDAS_LOGICALUNIT_DESCRIPTOR ProcessPlugIn_Dlu( NDAS_LOGICALUNIT_ADDRESS Address, int argc, TCHAR** argv ){ PNDAS_LOGICALUNIT_DESCRIPTOR logicalUnitDescriptor = NULL; INT memberCnt; LARGE_INTEGER endingAddress; NDASPORTCTL_NODE_INITDATA nodeInit; PNDASPORTCTL_NODE_INITDATA rootNodeInit = NULL; LARGE_INTEGER logicalBlockAddress; USHORT lurDevType; LURN_TYPE lurnType; BOOL bret; // // Reserve 2MB from the end // logicalBlockAddress.QuadPart = -2 * 1024 * 1024 / 512; if(argc < 1) { usage(); return NULL; } // Device type lurnType = ConvertStringToType(argv[0]); if(lurnType == LURN_NULL) { _tprintf(_T("Error: NDAS Device type is invalid.\n\n")); usage(); return NULL; } // Access mode NDAS_DEV_ACCESSMODE ndasDevAccessMode; if (0 == lstrcmpi(_T("ro"), argv[1])) { ndasDevAccessMode = DEVMODE_SHARED_READONLY; } else if (0 == lstrcmpi(_T("rw"), argv[1])) { ndasDevAccessMode = DEVMODE_SHARED_READWRITE; } else { _tprintf(_T("Error: Access mode is invalid or not specified.\n\n")); return NULL; } // Disk ending address endingAddress.QuadPart = 0; if( StrToIntEx(argv[2], STIF_DEFAULT, (INT *)&endingAddress.LowPart) == FALSE) { _tprintf(_T("Error: Ending address is invalid or not specified.\n\n")); usage(); return NULL; } // Member count memberCnt = 0; if( StrToIntEx(argv[3], STIF_DEFAULT, &memberCnt) == FALSE) { _tprintf(_T("Error: Member count is invalid or not specified.\n\n")); usage(); return NULL; } if(memberCnt == 0) { _tprintf(_T("Error: Member count is zero.\n\n")); return NULL; } #ifdef _DEBUG _tprintf(_T("(%d,%d,%d) %d Access %x Ending addr %I64u Member count %d\n"), Address.PathId, Address.TargetId, Address.Lun, lurnType, ndasDevAccessMode, endingAddress.QuadPart, memberCnt ); #endif // // Create the descriptor including a root node. // switch(lurnType) { case LURN_IDE_DISK: lurDevType = LUR_DEVTYPE_HDD; // We will initialize this root node later. Set NULL. rootNodeInit = NULL; memberCnt = 0; break; case LURN_IDE_ODD: lurDevType = LUR_DEVTYPE_ODD; // We will initialize this root node later. Set NULL. rootNodeInit = NULL; memberCnt = 0; break; case LURN_IDE_MO: lurDevType = LUR_DEVTYPE_MOD; // We will initialize this root node later. Set NULL. rootNodeInit = NULL; memberCnt = 0; break; case LURN_AGGREGATION: case LURN_RAID0: lurDevType = LUR_DEVTYPE_HDD; bret = NdasPortCtlGetRaidEndAddress( lurnType, endingAddress.QuadPart, memberCnt, &nodeInit.EndLogicalBlockAddress.QuadPart); if(bret == FALSE) { _tprintf(_T("Could not retreive RAID's end address.\n\n")); return NULL; } nodeInit.NodeType = lurnType; nodeInit.StartLogicalBlockAddress.QuadPart = 0; // RAID information is not needed. nodeInit.NodeSpecificData.Raid.SectorsPerBit = 0; nodeInit.NodeSpecificData.Raid.SpareDisks = 0; ZeroMemory(&nodeInit.NodeSpecificData.Raid.RaidSetId, sizeof(GUID)); ZeroMemory(&nodeInit.NodeSpecificData.Raid.ConfigSetId, sizeof(GUID)); rootNodeInit = &nodeInit; break; case LURN_RAID1R: case LURN_RAID4R: lurDevType = LUR_DEVTYPE_HDD; _tprintf(_T("Error: RAID1/4 not supported by this command line tool.\n")); return NULL; default: _tprintf(_T("Error: Invalid type!\n")); return NULL; } logicalUnitDescriptor = NdasPortCtlBuildNdasDluDeviceDescriptor( Address, 0, ndasDevAccessMode, lurDevType, &endingAddress, memberCnt, // Member count does not include the root node. 0, rootNodeInit); if(NULL == logicalUnitDescriptor){ _tprintf(_T("Error: Out of memory!\n")); return NULL; } // // Initialize child nodes for RAID // PNDAS_DLU_DESCRIPTOR dluDesc = (PNDAS_DLU_DESCRIPTOR)logicalUnitDescriptor; bret = InitializeLurNodes( argc - 4, argv + 4, dluDesc, rootNodeInit?TRUE:FALSE // Root node ); if(bret == FALSE) { HeapFree(GetProcessHeap(), 0, logicalUnitDescriptor); return NULL; } return logicalUnitDescriptor; }
bool ParseFID( char *FidName, AFSFileID *FID) { char *pchCell = NULL, *pchVolume = NULL, *pchVnode = NULL, *pchUnique = NULL; char *pchCurrentPos = FidName; char *pLocation = NULL; char chBuffer[ 50]; pchCell = pchCurrentPos; pLocation = strchr( pchCell, '.'); if( pLocation == NULL) { return false; } pLocation++; if( *pLocation == NULL) { return false; } pLocation--; *pLocation = NULL; pLocation++; pchVolume = pLocation; pLocation = strchr( pchVolume, '.'); if( pLocation == NULL) { return false; } pLocation++; if( *pLocation == NULL) { return false; } pLocation--; *pLocation = NULL; pLocation++; pchVnode = pLocation; pLocation = strchr( pchVnode, '.'); if( pLocation == NULL) { return false; } pLocation++; if( *pLocation == NULL) { return false; } pLocation--; *pLocation = NULL; pLocation++; pchUnique = pLocation; strcpy_s( chBuffer, 50, "0x"); strcat_s( &chBuffer[ 2], 48, pchCell); if( !StrToIntEx( chBuffer, STIF_SUPPORT_HEX, (int *)&FID->Cell)) { printf("AFSObjectStatus Failed to parse cell %s\n", chBuffer); return false; } strcpy_s( chBuffer, 50, "0x"); strcat_s( &chBuffer[ 2], 48, pchVolume); if( !StrToIntEx( chBuffer, STIF_SUPPORT_HEX, (int *)&FID->Volume)) { printf("AFSObjectStatus Failed to parse volume %s\n", chBuffer); return false; } strcpy_s( chBuffer, 50, "0x"); strcat_s( &chBuffer[ 2], 48, pchVnode); if( !StrToIntEx( chBuffer, STIF_SUPPORT_HEX, (int *)&FID->Vnode)) { printf("AFSObjectStatus Failed to parse vnode %s\n", chBuffer); return false; } strcpy_s( chBuffer, 50, "0x"); strcat_s( &chBuffer[ 2], 48, pchUnique); if( !StrToIntEx( chBuffer, STIF_SUPPORT_HEX, (int *)&FID->Unique)) { printf("AFSObjectStatus Failed to parse Unique %s\n", chBuffer); return false; } return true; }
INT_PTR CALLBACK ShellProc( _In_ HWND hwndDlg, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam ) { int idx; PWSTR exePath; wchar_t addrString[16]; DWORD address; switch (uMsg) { case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: { int ccnt=GetDlgItemText(hwndDlg,IDC_ADDRESS,addrString,15); if(ccnt==0) address=0; else if(!StrToIntEx(addrString,STIF_SUPPORT_HEX,(int*)&address)) { MessageBox(hwndDlg,L"Function address must be a hex number.",0,0); break; } int len=GetWindowTextLength(GetDlgItem(hwndDlg,IDC_EXEPATH)); if(len==0) { MessageBox(hwndDlg,L"Please select the exe file",0,0); break; } exePath=new wchar_t[len+1]; if(exePath==0) { delete[] exePath; MessageBox(hwndDlg,L"Not enough memory",0,0); break; } GetDlgItemText(hwndDlg,IDC_EXEPATH,exePath,len+1); STARTUPINFO si; memset1(&si,0,sizeof(si)); si.cb=sizeof(si); PROCESS_INFORMATION pi; if(!CreateProcess(0,exePath,0,0,FALSE,CREATE_SUSPENDED,0,0,&si,&pi)) { delete[] exePath; MessageBox(hwndDlg,L"Can't start exe!",0,0); break; } delete[] exePath; int pathLen=256; wchar_t* dllPath=new wchar_t[pathLen]; int retlen=GetModuleFileName(0,dllPath,pathLen); while(GetLastError()==ERROR_INSUFFICIENT_BUFFER) { delete[] dllPath; pathLen*=2; dllPath=new wchar_t[pathLen]; retlen=GetModuleFileName(0,dllPath,pathLen); }; wchar_t* p=dllPath+retlen; for(;p>dllPath;p--) if(*p==L'\\') break; *(p+1)=L'\0'; lstrcat(dllPath,L"extractor.dll"); int rslt=InjectToProcess(pi.hProcess,pi.hThread,dllPath,(DecoprFunc)address); delete[] dllPath; if(rslt<0) { MessageBox(hwndDlg,L"Failed to inject process",0,0); break; } wchar_t pipeName[30]; wsprintf(pipeName,PIPE_NAME,pi.dwProcessId); HANDLE pipe=CreateNamedPipe(pipeName,PIPE_ACCESS_DUPLEX,PIPE_TYPE_BYTE|PIPE_READMODE_BYTE|PIPE_WAIT, PIPE_UNLIMITED_INSTANCES,256,256,0,0); if(pipe==INVALID_HANDLE_VALUE) { MessageBox(hwndDlg,L"Faild to create pipe",0,0); TerminateProcess(pi.hProcess,0); break; } ResumeThread(pi.hThread); rslt=PipeComm(pipe,address); CloseHandle(pipe); if(rslt<0) { MessageBox(hwndDlg,L"Failed to communicated with sub process",0,0); break; } } // Fall through. case IDCANCEL: EndDialog(hwndDlg, wParam); return TRUE; case IDC_ADDRESS: if(HIWORD(wParam)==EN_CHANGE) { idx=SendDlgItemMessage(hwndDlg,IDC_GAMELIST,CB_GETCURSEL,0,0); if(idx<g_gameCount) { int cnt=GetDlgItemText(hwndDlg,IDC_ADDRESS,addrString,15); if(cnt==0) SendDlgItemMessage(hwndDlg,IDC_GAMELIST,CB_SETCURSEL,0,0); else if(idx!=CB_ERR && !(StrToIntEx(addrString,STIF_SUPPORT_HEX,(int*)&address) && address==g_gameList[idx].funcAddress)) SendDlgItemMessage(hwndDlg,IDC_GAMELIST,CB_SETCURSEL,-1,0); } } break; case IDC_GAMELIST: switch (HIWORD(wParam)) { case CBN_SELCHANGE: idx=SendDlgItemMessage(hwndDlg,IDC_GAMELIST,CB_GETCURSEL,0,0); if(idx==0) { SetDlgItemText(hwndDlg,IDC_ADDRESS,L""); } else if(idx!=CB_ERR && idx<g_gameCount) { wsprintf(addrString,L"0x%X",g_gameList[idx].funcAddress); SetDlgItemText(hwndDlg,IDC_ADDRESS,addrString); } break; } break; case IDC_BROWSE: if(SUCCEEDED(BasicFileOpen(&exePath))) { SetDlgItemText(hwndDlg,IDC_EXEPATH,exePath); CoTaskMemFree(exePath); } break; case IDC_ABOUT: MessageBox(hwndDlg,L"fxckBGI - an extractor for BGI engine.\n\tv" PRODUCT_VERSION L" by AmaF",L"About",MB_ICONINFORMATION); break; } break; case WM_INITDIALOG: g_hwnd=hwndDlg; HICON icon=LoadIcon(g_hInstance,(LPCWSTR)IDI_ICON1); SendMessage(hwndDlg,WM_SETICON,ICON_SMALL,(LPARAM)icon); for(int i=0;i<g_gameCount;i++) { SendDlgItemMessage(hwndDlg,IDC_GAMELIST,CB_ADDSTRING,0,(LPARAM)(g_gameList[i].gameName)); } SendDlgItemMessage(hwndDlg,IDC_GAMELIST,CB_SETCURSEL,0,0); return TRUE; } return FALSE; }
slide_show(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { EXDLL_INIT(); slide_abort(); // argument default values iHAlign = HALIGN_CENTER; iVAlign = VALIGN_CENTER; iFit = FIT_BOTH; g_hWnd = NULL; captionColor = RGB(255,255,255); int duration = 1000; // transition duration in ms (default = 1s) TCHAR caption[MAX_PATH]; caption[0] = '\0'; // parse arguments TCHAR arg[MAX_PATH]; LPTSTR argValue; while(!popstring(arg, sizeof arg) && *arg == '/' && (argValue = StrChr(arg, '=')) != NULL) { *argValue++ = '\0'; // replace '=' by '\0' if(lstrcmpi(arg, TEXT("/hwnd")) == 0) StrToIntEx(argValue, STIF_SUPPORT_HEX, (int*) &g_hWnd); else if(lstrcmpi(arg, TEXT("/fit")) == 0) { if(lstrcmpi(argValue, TEXT("height")) == 0) iFit = FIT_HEIGHT; else if(lstrcmpi(argValue, TEXT("width")) == 0) iFit = FIT_WIDTH; else if(lstrcmpi(argValue, TEXT("stretch")) == 0) iFit = FIT_STRETCH; } else if(lstrcmpi(arg, TEXT("/halign")) == 0) { if(lstrcmpi(argValue, TEXT("left")) == 0) iHAlign = HALIGN_LEFT; else if(lstrcmpi(argValue, TEXT("right")) == 0) iHAlign = HALIGN_RIGHT; } else if(lstrcmpi(arg, TEXT("/valign")) == 0) { if(lstrcmpi(argValue, TEXT("top")) == 0) iVAlign = VALIGN_TOP; else if(lstrcmpi(argValue, TEXT("bottom")) == 0) iVAlign = VALIGN_BOTTOM; } else if(lstrcmpi(arg, TEXT("/duration")) == 0) StrToIntEx(argValue, STIF_SUPPORT_HEX, &duration); else if(lstrcmpi(arg, TEXT("/caption")) == 0) lstrcpy(caption, argValue); else if(lstrcmpi(arg, TEXT("/ccolor")) == 0) StrToIntEx(argValue, STIF_SUPPORT_HEX, (int*) &captionColor); else if(lstrcmpi(arg, TEXT("/auto")) == 0) { lstrcpy(g_autoPath, argValue); PathRemoveFileSpec(g_autoPath); HGLOBAL hMem = GlobalAlloc(GMEM_FIXED, 32767*sizeof(TCHAR)); DWORD count = GetPrivateProfileSection(getuservariable(INST_LANG), LPTSTR(hMem), 32767, argValue); if (count == 0) { count = GetPrivateProfileSection(TEXT("1033"), LPTSTR(hMem), 32767, argValue); if (count == 0) count = GetPrivateProfileSection(TEXT("0"), LPTSTR(hMem), 32767, argValue); } if (count) { g_autoBuffer = LPTSTR(GlobalReAlloc(hMem, (count+1)*sizeof(TCHAR), 0)); g_autoNext = g_autoBuffer; } else GlobalFree(hMem); } } // if target window not defined we'll search for default (the details listview) if (g_hWnd == NULL) { g_hWnd = FindWindowEx(hwndParent, NULL, TEXT("#32770"), NULL); if (g_hWnd == NULL) return; hwndParent = FindWindowEx(hwndParent, g_hWnd, TEXT("#32770"), NULL); if (hwndParent != NULL && !IsWindowVisible(hwndParent)) g_hWnd = hwndParent; if (g_hWnd == NULL) return; HWND hWnd = GetDlgItem(g_hWnd, 1016); GetWindowRect(hWnd, &rDest); ScreenToClient(g_hWnd, (LPPOINT) &rDest.left); ScreenToClient(g_hWnd, (LPPOINT) &rDest.right); } else GetClientRect(g_hWnd, &rDest); // load new image if (arg[0] == '\0') return; // stop here if no filename if (g_autoNext != NULL) slide_NextAuto(); else slide_NewImage(arg, caption, duration); }