void LoadConfig(SystemState *LCState) { HANDLE hr=NULL; buildTransDisp2ScanTable(); LoadString(NULL, IDS_APP_TITLE,AppName, MAX_LOADSTRING); GetModuleFileName(NULL,ExecDirectory,MAX_PATH); PathRemoveFileSpec(ExecDirectory); strcpy(CurrentConfig.PathtoExe,ExecDirectory); strcpy(IniFilePath,ExecDirectory); strcat(IniFilePath,"\\"); strcat(IniFilePath,IniFileName); LCState->ScanLines=0; NumberOfSoundCards=GetSoundCardList(SoundCards); ReadIniFile(); CurrentConfig.RebootNow=0; UpdateConfig(); RefreshJoystickStatus(); SoundInit(EmuState.WindowHandle,SoundCards[CurrentConfig.SndOutDev].Guid,CurrentConfig.AudioRate); hr=CreateFile(IniFilePath,NULL,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if (hr==INVALID_HANDLE_VALUE) //No Ini File go create it WriteIniFile(); else CloseHandle(hr); }
void GetAACdecSettings ( void ) { FILE* fp = NULL; char PathAndName [] = {INI_FILE}; // set default values iniSettings.window_x = 64; // default box position (x co-ord) iniSettings.window_y = 64; // default box position (y co-ord) iniSettings.always_on_top = 8; // default = on iniSettings.logerr = 0; // default = off iniSettings.decode_mode = 1; // default = 1 (decode to file) iniSettings.outputFormat = 1; // default = 1 (16 bit PCM) iniSettings.fileType = 1; // default = 1 (Microsoft WAV) iniSettings.object_type = 1; // default = 1 (Low Complexity) // Read INI_FILE if ( (fp = fopen (PathAndName, "r")) == NULL ) { // file does not exist: write it! WriteIniFile ( PathAndName ); } else { // file does exist: read it! ReadIniFile (fp); fclose (fp); } return; }
BasicWindow::BasicWindow(HINSTANCE appHandle, int showStyle) : mCaption("") { ReadIniFile(); // If window creation failed, show a message. if(!InitWindowsApp(appHandle, showStyle)) ShowMessage("Window was not created!"); }
CString CIniFile::GetFileString(CString Section, CString Item, CString Value) { ReadIniFile();//打开文件 if(m_bFileExist == FALSE || FileContainer.GetSize() < 0) return Value;//文件打开出错或文件为空,返回默认值 int i = 0; int iFileLines = FileContainer.GetSize(); CString strline,str; while(i<iFileLines) { strline = FileContainer.GetAt(i++); strline.TrimLeft(); if(strline.GetAt(0)=='[')//查找Section,第一个必须为[ { str=strline.Left(strline.Find(_T("]")));//去掉]右边 str=str.Right(str.GetLength()-str.Find(_T("["))-1);//去掉[左边 str.TrimLeft(); str.TrimRight(); if(Section == str)//找到Section { while(i<iFileLines) { strline = FileContainer.GetAt(i++); strline.TrimLeft(); if(strline.GetAt(0)=='[') return Value;//如果到达下一个[],即找不到,返回默认值 str = strline.Left(strline.Find(_T("=")));//去掉=右边 str.TrimLeft(); str.TrimRight(); if(Item == str)//找到Item { str=strline.Right(strline.GetLength()-strline.Find(_T("="))-1);//去掉=左边 str.TrimLeft(); str.TrimRight(); return str; } } return Value;//找不到,返回默认值 } } } return Value;//找不到,返回默认值 }
int main(void) { int val; ReadIniFile(); CheckIniFileContent(); GetWebPages(); if(!strcmp(ini.retieved_ip[0], ini.retieved_ip[1]) && !strcmp(ini.retieved_ip[1], ini.retieved_ip[2])) { // all match, all is good if(!strcmp(ini.retieved_ip[0], ini.last_ip)) // nothing has changed, nothing to do return 0; else { Notify(NOTIFY_NEW_IP, ini.retieved_ip[0]); // update ini file and we are done UpdateIni(ini.retieved_ip[0]); return 0; } } if(strcmp(ini.retieved_ip[0], ini.retieved_ip[1]) && strcmp(ini.retieved_ip[1], ini.retieved_ip[2]) && strcmp(ini.retieved_ip[0], ini.retieved_ip[1])) { // no server returns the same ip Notify(NOTIFY_PANIC, NULL); return 0; } // one server is returning an odd ip if(strcmp(ini.retieved_ip[0], ini.retieved_ip[1]) && strcmp(ini.retieved_ip[0], ini.retieved_ip[2])) // web[0] if the odd man out { val = 0; if(strcmp(ini.retieved_ip[2], ini.retieved_ip[1]) && strcmp(ini.retieved_ip[2], ini.retieved_ip[0])) // web[2] is the odd man out val = 2; else // by elimination web[1] is the odd man out val = 1; Notify(NOTIFY_BAD_SERVER, ini.web[val]); // update ini file and we are done ++val; // find a good ip to use if(val > 2) val = 0; Notify(NOTIFY_NEW_IP, ini.retieved_ip[val]); UpdateIni(ini.retieved_ip[val]); return 0; } return 0; }
BOOL CMakeFileListDlg::OnInitDialog() { CDialog::OnInitDialog(); SetIcon(m_hIcon, TRUE); // 大きいアイコンを設定 SetIcon(m_hIcon, FALSE); // 小さいアイコンを設定 ReadIniFile (); MakeHashList (); EndDialog (IDCANCEL); return TRUE; }
///----------------------------------------------------------------------------- bool CreateIniFile(void){ char APchar[255]; FILE *F; MainIniStruct = new(IniStruct); GetWindowsDirectory(APchar,255); sFile = (String)APchar + "\\Hammer.ini"; if(FileExists(sFile)){ Ini = new TIniFile(sFile); }else{ if((F = fopen(sFile.c_str(),"w+")) == NULL){ return(false); } fclose(F); Ini = new TIniFile(sFile); } ReadIniFile(); return(true); }
void CBaseCommand::Init(const char* pFileName) { ReadIniFile(pFileName); //m_objLSServer.Init(1, "127.0.0.1", 10080, m_pServerObject); m_objLSServer.Init(1, m_szLSIP, m_u4LSPort, m_pServerObject); vecControlInfo objControlInfo; m_pServerObject->GetControlListen()->ShowListen(objControlInfo); //自动得到当前开放的IP和端口,然后记录下来,发送给远端LS m_objLSServer.Set_LG_Info(objControlInfo[0].m_szListenIP, objControlInfo[0].m_u4Port, (uint32)m_pServerObject->GetControlListen()->GetServerID()); m_objLSServer.Connect(); ActiveTimer* pTimer = m_pServerObject->GetTimerManager(); m_u4TimeID = (uint32)pTimer->schedule(this, NULL, ACE_OS::gettimeofday() + ACE_Time_Value(MAX_TIMER_INTERVAL), ACE_Time_Value(MAX_TIMER_INTERVAL)); }
bool GenSurfInit(){ strcpy( gszVersion, "1.05" ); strcpy( gszCaption, "GtkGenSurf" ); if ( strlen( gszVersion ) ) { strcat( gszCaption, " v" ); strcat( gszCaption, gszVersion ); } strcpy( gszIni, g_FuncTable.m_pfnProfileGetDirectory() ); strcat( gszIni, "gensurf.ini" ); /*if (g_FuncTable.m_pfnReadProjectKey != NULL) { char *basepath; basepath = g_FuncTable.m_pfnReadProjectKey("basepath"); if (basepath) { strlwr (basepath); if (strstr(basepath,"baseq3")) Game = QUAKE3; else if (strstr (basepath,"baseq2")) Game = QUAKE2; else // Gotta have a game, might as well be Quake3 Game = QUAKE3; } else Game = QUAKE3; } else */ Game = QUAKE3; if ( g_pWnd == NULL ) { g_pWnd = create_main_dialog(); } ReadIniFile( gszIni ); return true; }
int main (int argc, char* argv[]){ SciInfo_t SciInfo; int i; if (argc != 2 ) { print_usage(argv[0]); exit(-1); } if(ReadIniFile(argv[1], &SciInfo) != ERR_SCIINFO_OK) { printf("The file %s was not found!\n",argv[1]); } else { for (i=0;i<SciInfo.NumAdapter;i++) { printf("Adapter%d SciId=%d, SciRing=%d\n", i, SciInfo.SciId[i], SciInfo.SciRing[i]); } } return 0; }
void OpenSetup( GtkWidget *parent, int UseDefaults ){ const char *name; char key[32], *text; float value,range,rate; int i, j; if ( UseDefaults ) { name = g_strdup( "plugins/defaults.srf" ); // dummy string } else{ name = g_FuncTable.m_pfnFileDialog( parent, true, "Open GenSurf Settings", g_FuncTable.m_pfnProfileGetDirectory(), "gtkgensurf", NULL ); } if ( name != NULL ) { ReadIniFile( name ); Decimate = g_FuncTable.m_pfnProfileLoadInt( name, OPTS_SECTION,"Decimate",0 ); Decimate = max( 0,min( Decimate,100 ) ); for ( i = 0; i <= NH; i++ ) { for ( j = 0; j <= NV; j++ ) { sprintf( key,"I%dJ%d",i,j ); text = g_FuncTable.m_pfnProfileLoadString( name, "FixedPoints", key, "" ); if ( strlen( text ) ) { xyz[i][j].fixed = 1; xyz[i][j].rate = 0.; sscanf( text,"%g %g %g",&value,&range,&rate ); xyz[i][j].fixed_value = value; xyz[i][j].range = range; xyz[i][j].rate = rate; } else{ xyz[i][j].fixed = 0; } } } } }
void SetRegKey(int argc,wchar_t* argv[]) { CString Branch; int i; for (i=1;i<argc;i++) { if (argv[i][0]==L'-' || argv[i][0]==L'/') { switch (argv[i][1]) { case L'X': if (argv[i][2]==L'\0') { if (i<argc-1) Branch=argv[++i]; } else Branch=(argv[i]+2); break; } } } g_szRegKey=ReadIniFile(&g_szRegFile,Branch.GetPData(),g_bFileIsReg); if (g_szRegKey!=NULL) { if (g_szRegFile!=NULL) LoadSettingsFromFile(g_szRegKey,g_szRegFile,g_bFileIsReg); } else { // Use default g_szRegKey=alloccopy("Software\\Update"); } }
void CPhoneBook::OnInBook() { CDlgPbookBrw dlg; dlg.DoModal(); if( CDlgPbookBrw::s_bOk ) { CResString str; str.LoadString(RES_BUTTON_IN); CResString str1; str1.LoadString(RES_BLUETOOTH_PHONEBOOK); CDlgConfirm dlg; CDlgConfirm::m_stTitle = str + str1; dlg.DoModal(); if( CDlgConfirm::s_bOk ) { ReadIniFile( CDlgPbookBrw::s_csPath ); PostMessage(WM_ACTIVATE); } } }
/* Reads files and initializes things. This is mostly from Tormod's main() ... */ Int4 ReadFiles(void) { char *pStr; char Buf[10]; Int4 NumOfLumps; Int4 DirOfs; Int4 LumpInx; Int4 NumLargeImg; Int4 UsefulEntries; Int4 NumWadType[NUM_TAG]; Int4 LargestImgEntry; pStr = Get_pSearchList(NULL); if (pStr != NULL) pStr = FindFile(IniFileName, pStr); if (pStr != NULL) { Message("Ini file \"%s\" found\n", pStr); ReadIniFile(pStr); if (Ext_WAV_Player[0] != '\0') Message("WAV : \"%s\"\n", Ext_WAV_Player); if (Ext_MUS_Player[0] != '\0') Message("MUS : \"%s\"\n", Ext_MUS_Player); if (Ext_PCX_Viewer[0] != '\0') Message("PCX : \"%s\"\n", Ext_PCX_Viewer); } else Message("Ini file \"%s\" NOT found\n", IniFileName); if ( pPalFileSpec ) { USER_rgb = malloc( 3*256 ); if ( !USER_rgb ) Abort("Can't get mem for palette...\n"); ReadPal(pPalFileSpec, USER_rgb); CopyRGB( DAC_Reg, USER_rgb ); Message("Palette file '%s' loaded successfully\n", pPalFileSpec); } else CopyRGB( DAC_Reg, doom_rgb); /* set doom palette as default */ CreateXpmPalette( DAC_Reg, keep_transparent_color); if ((WADfp = fopen(pWadFileSpec, "rb")) == NULL) Abort("unable to open input file \"%s\"", pWadFileSpec); fgetc(WADfp); /* Waste the I or P before WAD */ fread(Buf, sizeof(char), 3, WADfp); if (memcmp(Buf, "WAD", 3) != 0) Abort("the file \"%s\" is not a proper wad file", pWadFileSpec); fread(&NumOfLumps, sizeof(Int4), 1, WADfp); fread(&DirOfs, sizeof(Int4), 1, WADfp); Message("Number of wad entries: %d\nWad directory offset: 0x%x\n", NumOfLumps, DirOfs); fseek(WADfp, DirOfs, SEEK_SET); /* Let's be real careful... */ if ((NumOfLumps * sizeof(Directory)) > UINT_MAX) Abort("error, directory table too large," " cannot malloc more than (%u) bytes", UINT_MAX); if ((pDirEnt = malloc(NumOfLumps * sizeof(Directory))) == NULL) Abort("error, no memory for wad directory table"); if ((pEntryTag = calloc(NumOfLumps, sizeof(char))) == NULL) Abort("error, no memory for wad directory tag table"); if (fread(pDirEnt, sizeof(Directory), NumOfLumps, WADfp) != NumOfLumps) Abort("error reading wad directory"); BuildWadDir(WADfp, pDirEnt, pEntryTag, NumOfLumps); /* The WAD Directory contains many entries of no value to us, these entries forms "holes" in pDirEnt. We need a one-to-one correspondance between the line in the browser and the directory entry, so we build a "linear map" : The entries in the linear map are indices to pDirEnt (and pEntryTag), omitting the holes. */ LinearMap = BulidLinearMap(pDirEnt, pEntryTag, NumOfLumps, &UsefulEntries); if ( !LinearMap ) Abort("\nerror building wad directory linear map"); Message("\nUseful WAD Entries : %d\n", UsefulEntries); /* To make sure we find something */ memset(NumWadType, 0, sizeof(NumWadType)); LargestImgEntry = 0; /* The number of large images discarded because malloc can't handle * them */ NumLargeImg = 0; /* I want to count the number of each type in the wad file. Can't * use the TAG_FLAT and such directly since they are bitmasks */ for (LumpInx = 0; LumpInx < NumOfLumps; LumpInx++) { /* Is this image to large for malloc ? */ if ((pEntryTag[LumpInx] & TAG_GFX) && pDirEnt[LumpInx].size > MAX_IMG_SIZ) { pEntryTag[LumpInx] = TAG_NONE; NumLargeImg++; continue; } if (pEntryTag[LumpInx] != 0) NumWadType[MapBitMaskToInx(pEntryTag[LumpInx])]++; if ( (pEntryTag[LumpInx] & TAG_GFX) && pDirEnt[LumpInx].size > LargestImgEntry) LargestImgEntry = pDirEnt[LumpInx].size; } Message("\nMUS entries: %d\n", NumWadType[MapBitMaskToInx(TAG_MUS)]); Message("SFX entries: %d\n", NumWadType[MapBitMaskToInx(TAG_SFX)]); Message("FLAT entries: %d\n", NumWadType[MapBitMaskToInx(TAG_FLAT)]); Message("FULL entries: %d\n", NumWadType[MapBitMaskToInx(TAG_FULL)]); Message("IMAGE entries: %d\n", NumWadType[MapBitMaskToInx(TAG_IMG)]); Message("HIRES entries: %d\n", NumWadType[MapBitMaskToInx(TAG_HIRES)]); if ( !UsefulEntries ) Abort("There are no MUS, SFX, FLAT, FULL, IMAGE or HIRES" "entries in this wad"); if (LargestImgEntry != 0) { if ((pBitMap = calloc(LargestImgEntry, sizeof(char))) == NULL) Abort("error, no memory for image buffer"); } return UsefulEntries; }
/****************************************************************** * main * ******************************************************************/ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { BOOL fLogTime = FALSE; BOOL fCompile = TRUE; BOOL fInstall = TRUE; BOOL fSetup = FALSE; BOOL fQuiet = FALSE; char szPBuf[256]; char szEPBuf[256]; char szJPBuf[256]; char seps[] = " \t"; char *token; char *pt; HMODULE hModule; hInst = hInstance; memset( szMeadowVersion, 0, sizeof(szMeadowVersion) ); token = strtok( lpCmdLine, seps ); while ( token ){ if ( ! strcmp(token,"-cd") || ! strcmp(token,"-nc") ) fCompile = FALSE; /* install only (not compile) */ if ( ! strcmp(token,"-ni") ) fInstall = FALSE; /* compile only (not install) */ if ( ! strcmp(token,"-s") ) fSetup = TRUE; /* setup mode */ if ( ! strcmp(token,"-q") ) fQuiet = TRUE; /* quiet mode */ if ( ! strcmp(token,"-h") ){ ShowUsage(); return 0; } token = strtok( NULL, seps ); } /* while ( token ){ */ /* Setup log module * After this, OutputLog function could be used. */ SetupLog( LOGFILE_NAME, TRUE, TRUE, fLogTime, TRUE, 0, fQuiet ); /* Startup Log Message */ sprintf(szPBuf,"Mew installer for Win32 Version %s",MEWINST_VERSION); OutputLog(szPBuf); sprintf(szPBuf," Copyright (C) %s Shuichi Kitaguchi", COPYRIGHT_YEARS); OutputLog(szPBuf); OutputLog(""); /* Startup window */ if (!fQuiet && !DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_TITLE), 0, TitleDlgProc, 0)){ OutputLog("Installation is canceled or title window is failed to create."); return -1; } /* Ini file name */ hModule = GetModuleHandle(NULL); GetModuleFileName(hModule,szCurrentPath,sizeof(szCurrentPath)); if ( (pt = strrchr(szCurrentPath,'\\')) ) *pt = (char)0; sprintf(szIniFile,"%s\\%s",szCurrentPath,MEWINST_DEFAULT); #if 0 /* parent process's console? xxx */ AllocConsole(); hConsole = CreateConsoleScreenBuffer( GENERIC_READ|GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL ); if ( hConsole == INVALID_HANDLE_VALUE ) goto Error; if ( ! SetStdHandle( STD_OUTPUT_HANDLE, hConsole ) ){ OutputLog("SetStdhandle fails."); goto Error; } if ( ! SetConsoleActiveScreenBuffer( hConsole ) ){ OutputLog("SetConsoleActiveScreenBuffer fails."); goto Error; } #endif if ( ! GetEnvironments() ) goto Error; if ( ! ReadEnvironments() ) goto Error; PrintEnvironments(); if ( ! CheckFile(MEWINST_DEFAULT) ){ sprintf(szEPBuf,"[%s] is not found!",MEWINST_DEFAULT); sprintf(szJPBuf,"[%s] が見付かりません!",MEWINST_DEFAULT); BilErrorMessageBox( szEPBuf, szJPBuf ); goto Error; } /* if ( ! CheckFile("mew.dot.emacs") ){ BilErrorMessageBox( "Archive Extraction Error!\nCheck your archiver program(support long filename?).", "アーカイブの解凍に失敗しています\n解凍プログラムがロングファイルネームをサポートしているか、確認して下さい"); goto Error; } */ /* selecting Emacs type */ if ( CheckFile( szIniFile ) ){ GetPrivateProfileString("Make","EMACS","Default", szPBuf,sizeof(szPBuf), szIniFile); if ( !strcmp( szPBuf, "Default" ) && !fQuiet ){ if ( ! SelectEmacsen() ){ BilErrorMessageBox( "Any Emacsen cannot found!\nHas Emacs been installed correctly?", "Emacs が見付かりませんでした\nEmacs を正しくインストールしましたか?" ); goto Error; } } } /* if ( CheckFile( szIniFile ) ) */ if ( langId == LANGID_JAPANESE ){ OutputLog(">>INI ファイルを読み込んでいます..."); } else { OutputLog(">>Read INI File..."); } if ( ! ReadIniFile() ) goto Error; if ( langId == LANGID_JAPANESE ) strcpy(szPBuf,">>>Emacs は ["); else strcpy(szPBuf,">>>Emacs is ["); switch ( bEmacsType ){ case EMACS_MEADOW: strcat(szPBuf,"Meadow "); strcat(szPBuf,szMeadowVersion); break; case EMACS_EMACS: strcat(szPBuf,"Emacs"); break; case EMACS_XEMACS: strcat(szPBuf,"XEmacs"); break; default: strcat(szPBuf,"unknown"); break; } if ( langId == LANGID_JAPANESE ) strcat(szPBuf,"] です"); else strcat(szPBuf,"]"); OutputLog(szPBuf); #if 0 /* XXX: */ if ( fSetup ){ if ( langId == LANGID_JAPANESE ){ OutputLog(">>設定を生成しています..."); } else { OutputLog(">>Creating configuration..."); } if ( ! SetupMew() ) goto Error; BilInfoMessageBox( "Add configuration to your ~/.emacs file.\nPlease check it.", "~/.emacs ファイルに設定を追加しました\n確認して下さい"); return ( 0 ); } #endif if ( fCompile ){ if ( langId == LANGID_JAPANESE ){ OutputLog(">>ソースをコンパイルしています..."); } else { OutputLog(">>Compiling sources..."); } if ( ! CompileSources() ) goto Error; if ( langId == LANGID_JAPANESE ){ OutputLog(">>実行ファイルを作成しています..."); } else { OutputLog(">>Making Executables..."); } } /* if ( fCompile ){ */ if ( fInstall ){ if ( langId == LANGID_JAPANESE ){ OutputLog(">>el/elc/実行 ファイルをインストールしています..."); } else { OutputLog(">>Installing el/elc/executable Files..."); } if ( ! InstallMew() ) goto Error; if ( langId == LANGID_JAPANESE ){ OutputLog(">>画像ファイルをインストールしています..."); } else { OutputLog(">>Installing Image files..."); } if ( ! InstallImage() ) goto Error; if ( langId == LANGID_JAPANESE ){ OutputLog(">>Info ファイルをインストールしています..."); } else { OutputLog(">>Installing Info files..."); } if ( ! InstallInfo() ) goto Error; } /* if ( fInstall ){ */ #if 0 /* XXX: */ if ( fInstall && !fQuiet ){ if ( BilMessageBox( NULL, "Do you want to setup your ~/.emacs?", "~/.emacs の設定を行ないますか?", "Question", MB_YESNO ) == IDYES ){ if ( ! SetupMew() ) goto Error; BilInfoMessageBox( "Add configuration to your ~/.emacs file.\nPlease check it.", "~/.emacs ファイルに設定を追加しました\n確認して下さい"); } } #endif if ( fInstall ) BilInfoMessageBox( "Mew installation complete", "Mew のインストールが終了しました" ); if ( langId == LANGID_JAPANESE ){ OutputLog(">>Mew のインストールが終了しました"); } else { OutputLog(">>Mew installation complete."); } return ( 0 ); Error: BilErrorMessageBox( "Mew installation is NOT complete!\nCheck mew.log file", "Mew のインストールが正常に終了しませんでした。mew.logファイルをチェックしてください" ); return ( -1 ); }
void TestDistVersion() { printf("Starting distribution.ini version tests...\n"); int result = _mkdir("../distribution"); check(result == 0 || errno == EEXIST, "Failed to create distribution directory: %d\n", errno); FILE* f = NULL; for (unsigned int i = 0; i < NS_ARRAY_LENGTH(DIST_TEST_DATA); ++i) { fprintf(stdout, "======================================================\n"); fprintf(stdout, "Test case %u: old %s new %s expected %s\n", i, DIST_TEST_DATA[i].oldVersion, DIST_TEST_DATA[i].newVersion, DIST_TEST_DATA[i].shouldSucceed ? "yes" : "no"); // put in dummy application.ini files :/ f = fopen("../application.ini", "w"); check(f != NULL, "Failed to write old application.ini"); fprintf(f, "[app]\nbuildid=0\n"); fclose(f); f = fopen("application.ini", "w"); check(f != NULL, "Failed to write new application.ini"); fprintf(f, "[app]\nbuildid=0\n"); fclose(f); // write out the test data if (DIST_TEST_DATA[i].oldVersion) { f = fopen("../distribution/test.ini", "w"); check(f != NULL, "Failed to write old data file"); fprintf(f, "[global]\nversion=%s\nid=old\n", DIST_TEST_DATA[i].oldVersion); fclose(f); } else { // no old version _unlink("../distribution/test.ini"); } if (DIST_TEST_DATA[i].newVersion) { f = fopen("test.ini", "w"); check(f != NULL, "Failed to write new data file"); fprintf(f, "[global]\nversion=%s\nid=new\n", DIST_TEST_DATA[i].newVersion); fclose(f); } else { // no new version _unlink("test.ini"); } fflush(stdout); fflush(stderr); #ifdef XP_WIN result = system("..\\disthelper.exe test tests\\test.ini"); #else result = system("../disthelper test tests/test.ini"); #endif /* XP_WIN */ check(result != -1, "Failed to execute disthelper: %08x\n", errno); IniFile_t data; result = ReadIniFile(_T("../distribution/test.ini"), data); check(result == DH_ERROR_OK || (!DIST_TEST_DATA[i].shouldSucceed && (!DIST_TEST_DATA[i].oldVersion || !DIST_TEST_DATA[i].newVersion)), "Failed to read output (testcase #%i)", i); if (DIST_TEST_DATA[i].shouldSucceed) { check(data["global"]["version"].compare(DIST_TEST_DATA[i].newVersion) == 0 && data["global"]["id"].compare("new") == 0, "Unexpectedly did not copy new data: %s -> %s result %s (%s)", DIST_TEST_DATA[i].oldVersion, DIST_TEST_DATA[i].newVersion, data["global"]["version"].c_str(), data["global"]["id"].c_str()); } else if (DIST_TEST_DATA[i].oldVersion){ check(data["global"]["version"].compare(DIST_TEST_DATA[i].oldVersion) == 0 && data["global"]["id"].compare("old") == 0, "Unexpectedly overwrote old data: %s -> %s result %s (%s)", DIST_TEST_DATA[i].oldVersion, DIST_TEST_DATA[i].newVersion, data["global"]["version"].c_str(), data["global"]["id"].c_str()); } else { // the act of finding the strings for dumping causes the condition to change if (data["global"].find("version") != data["global"].end()) { check(data["global"].find("version") == data["global"].end(), "Unexpectedly overwrote missing data: (null) -> %s result %s (%s)", DIST_TEST_DATA[i].newVersion, data["global"]["version"].c_str(), data["global"]["id"].c_str()); } } } printf("TestDistVersion: PASS\n"); }
BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_INITDIALOG: { HWND p=GetParent(hwndDlg); if(p) { HICON ico=(HICON)SendMessageA(p, WM_GETICON, ICON_SMALL, 0); SendMessageA(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)ico); } EnableWindow(GetDlgItem(hwndDlg, IDC_EDT_TEMPLATE), 0); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_COPY_CODE), 0); if(!Initialize(hwndDlg)) { MessageBoxA(hwndDlg, "Something went wrong during the initialization of the plugin.\n\nMaybe the file you are loading is unsupported, please contact me\n(Mr. eXoDia) at [email protected], I can fix it...", "Error...", MB_ICONERROR); SendMessageA(hwndDlg, WM_CLOSE, 0, 0); } } return TRUE; case WM_CLOSE: { EndDialog(hwndDlg, 0); } return TRUE; case WM_DROPFILES: { DragQueryFileA((HDROP)wParam, NULL, ini_file, MAX_PATH); if(!strcmp(ini_file+(strlen(ini_file)-3), "akt")) ReadIniFile(hwndDlg, ini_file); else MessageBoxA(hwndDlg, "Please drop a valid file...", "Error!", MB_ICONERROR); } return TRUE; case WM_COMMAND: { switch(LOWORD(wParam)) { case IDC_CHK_PROJECTID: { projectid=IsDlgButtonChecked(hwndDlg, IDC_CHK_PROJECTID); char new_pub_text[100]=""; if(GetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_NEW, new_pub_text, 100)) SetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_NEW, new_pub_text); } return TRUE; case IDC_EDT_TEMPLATE: { char templ[256]=""; char base[256]=""; char x[256]=""; char y[256]=""; char pvt[256]=""; int old_len=strlen(cur_pub_text); if(GetDlgItemTextA(hwndDlg, IDC_EDT_TEMPLATE, templ, 256)) { GenerateEcdsaParameters(templ, pvt, base, x, y); sprintf(pvt, "%s,%s,%s", base, x, y); sprintf(base, "%X", strlen(pvt)); } int len=strlen(pvt); if(len==old_len) { SetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_NEW, pvt); SetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_NEW_LEN, base); } else { SetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_NEW, ""); SetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_NEW_LEN, ""); } } return TRUE; case IDC_LIST_CERTS: { switch(HIWORD(wParam)) { case CBN_SELCHANGE: { int current_selected=SendDlgItemMessageA(hwndDlg, IDC_LIST_CERTS, CB_GETCURSEL, 0, 0); if(ini_file_loaded) { char temp_name[10]=""; GetPrivateProfileStringA(cert_names[current_selected], "pub", "", cur_pub_text, 256, ini_file); GetPrivateProfileStringA(cert_names[current_selected], "diff", "", cur_dif_text, 10, ini_file); GetPrivateProfileStringA(cert_names[current_selected], "md5", "", cur_md5_text, 10, ini_file); //v9.60 support GetPrivateProfileStringA(cert_names[current_selected], "seed1", "", cur_seed1_text, 10, ini_file); GetPrivateProfileStringA(cert_names[current_selected], "seed2", "", cur_seed2_text, 10, ini_file); GetPrivateProfileStringA(cert_names[current_selected], "projectid_diff", "", cur_projectid_diff_text, 10, ini_file); SetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_OLD, cur_pub_text); sprintf(temp_name, "%X", strlen(cur_pub_text)); SetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_OLD_LEN, temp_name); //sprintf(base_code, base_code_format+1, register_used, cert_function_addr, register_used, md5_replace_addr, cur_md5_text); //SetDlgItemTextA(hwndDlg, IDC_EDT_CODE, base_code); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_COPY_CODE), 0); SetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_NEW, ""); } } return TRUE; } } return TRUE; case IDC_EDT_PUBVALS_NEW: { char new_pub[256]=""; char new_byte[10]=""; unsigned int rand_init=~GetTickCount(); BYTE bytes_gtc[4]= {0}; bytes_gtc[0]=rand_init>>24; bytes_gtc[1]=(rand_init<<8)>>24; bytes_gtc[2]=(rand_init<<12)>>24; bytes_gtc[3]=(rand_init<<16)>>24; BYTE final_byte=bytes_gtc[0]^bytes_gtc[1]^bytes_gtc[2]^bytes_gtc[3]; if(final_byte<0x20) final_byte+=0x20; else if(final_byte>0x7E) { final_byte-=0x81; if(final_byte<0x20) final_byte+=0x21; } //v9.60 support unsigned char xor_byte=0; if(cur_seed1_text[0] and cur_seed2_text[0]) { unsigned int seed1=0; sscanf(cur_seed1_text, "%X", &seed1); CT_a=seed1; unsigned int result=CT_NextRandomRange(256); memcpy(&xor_byte, &result, 1); } sprintf(new_byte, "%X", final_byte^xor_byte); int new_pub_len=GetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_NEW, new_pub, 256); if(new_pub_len) { char replaced_pub_string[1024]=""; unsigned int proj_diff=2; //v9.60 support if(cur_seed1_text[0] and cur_seed2_text[0]) { sscanf(cur_projectid_diff_text, "%X", &proj_diff); unsigned char cpy[256]=""; strcpy((char*)cpy, new_pub); unsigned int seed2=0; sscanf(cur_seed2_text, "%X", &seed2); unsigned char* rand=CT_GetCryptBytes(seed2, new_pub_len); for(int i=0,j=0; i<new_pub_len; i++) { cpy[i]^=rand[i]; j+=sprintf(replaced_pub_string+j, "\\x%.2X", cpy[i]); } } else strcpy(replaced_pub_string, new_pub); if(projectid) sprintf(repl_code, repl_code_format, first_dword_text, proj_diff, new_byte, cur_dif_text, replaced_pub_string, new_pub_len); else sprintf(repl_code, repl_code_format2, first_dword_text, cur_dif_text, replaced_pub_string, new_pub_len); if(md5_replace_addr) sprintf(base_code, base_code_format, register_used, cert_function_addr, repl_code, register_used, md5_replace_addr, cur_md5_text); else sprintf(base_code, base_code_format2, register_used, cert_function_addr, repl_code); //TODO: fix this SetDlgItemTextA(hwndDlg, IDC_EDT_CODE, base_code); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_COPY_CODE), 1); } else { SetDlgItemTextA(hwndDlg, IDC_EDT_CODE, ""); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_COPY_CODE), 0); } } return TRUE; case IDC_BTN_COPY_CODE: { CopyToClipboard(base_code); MessageBeep(MB_ICONINFORMATION); } return TRUE; case IDC_BTN_ABOUT: { MessageBoxA(hwndDlg, "This plugin is very simple... Just Drag&Drop a .akt file created by Armadillo Key Tool,\nselect the certificate you want to use and use the Generate button to create new\npublic vals.\n\nThe Base Code is supposed be copied after: \";PLACE YOU CODE AFTER THIS!!!\"\nThe Replace Code should be appended to your inline code...\n\nMr. eXoDia\[email protected]", "Armadillo ECDSA Public Parameter Replace Plugin v0.4", MB_ICONINFORMATION); } return TRUE; } } return TRUE; } return FALSE; }