namespace Wifi { static AutoPtr< ArrayOf<String> > InitStrings() { AutoPtr< ArrayOf<String> > strings = ArrayOf<String>::Alloc(3); (*strings)[0] = "NONE"; (*strings)[1] = "TKIP"; (*strings)[2] = "CCMP"; return strings; } const AutoPtr< ArrayOf<String> > CWifiConfigurationPairwiseCipher::sStrings = InitStrings(); ECode CWifiConfigurationPairwiseCipher::GetStrings( /* [out, callee] */ ArrayOf<String>** strings) { VALIDATE_NOT_NULL(strings); *strings = sStrings; REFCOUNT_ADD(*strings); return NOERROR; } ECode CWifiConfigurationPairwiseCipher::ToString( /* [in] */ Int32 index, /* [out] */ String* strValue) { VALIDATE_NOT_NULL(strValue); if (index < 0 || index > 2) return E_ILLEGAL_ARGUMENT_EXCEPTION; *strValue = (*sStrings)[index]; return NOERROR; } } // namespace Wifi
bool StaticStrings::Init() { // StaticStringData has no default constructor, because LitString // has const members, so we can't use 'new' here. Since we're going // to copy all the string data from a static instance anyway, it's // probably fine to use malloc/free for this member. data = reinterpret_cast<StaticStringData*>(malloc(sizeof(StaticStringData))); if (data == nullptr) return false; InitData(); InitStrings(); return true; }
/* Test u_vformatMessage() with various test patterns. */ static void TestMessageFormatWithValist( void ) { UChar *str; UChar* result; int32_t resultLengthOut,resultlength,i, patternlength; UErrorCode status = U_ZERO_ERROR; UDate d1=1000000000.0; ctest_setTimeZone(NULL, &status); str=(UChar*)malloc(sizeof(UChar) * 7); u_uastrcpy(str, "MyDisk"); resultlength=1; result=(UChar*)malloc(sizeof(UChar) * 1); log_verbose("Testing u_formatMessage90\n"); InitStrings(); for (i = 0; i < cnt_testCases; i++) { status=U_ZERO_ERROR; patternlength=u_strlen(testCasePatterns[i]); resultLengthOut=CallFormatMessage( "en_US",testCasePatterns[i], patternlength, result, resultlength, &status, 1, 3456.00, d1); if(status== U_BUFFER_OVERFLOW_ERROR) { status=U_ZERO_ERROR; resultlength=resultLengthOut+1; result=(UChar*)realloc(result,sizeof(UChar) * resultlength); CallFormatMessage( "en_US",testCasePatterns[i], patternlength, result, resultlength, &status, 1, 3456.00, d1); } if(U_FAILURE(status)){ log_data_err("ERROR: failure in message format on testcase %d: %s (Are you missing data?)\n", i, myErrorName(status) ); } else if(u_strcmp(result, testResultStrings[i])==0){ log_verbose("PASS: MessagFormat successful on testcase : %d\n", i); } else{ log_err("FAIL: Error in MessageFormat on testcase : %d\n GOT %s EXPECTED %s\n", i, austrdup(result), austrdup(testResultStrings[i]) ); } } free(result); free(str); FreeStrings(); ctest_resetTimeZone(); }
void hack::Initialize() { ::signal(SIGSEGV, &critical_error_handler); ::signal(SIGABRT, &critical_error_handler); time_injected = time(nullptr); /*passwd *pwd = getpwuid(getuid()); char *logname = strfmt("/tmp/cathook-game-stdout-%s-%u.log", pwd->pw_name, time_injected); freopen(logname, "w", stdout); free(logname); logname = strfmt("/tmp/cathook-game-stderr-%s-%u.log", pwd->pw_name, time_injected); freopen(logname, "w", stderr); free(logname);*/ // Essential files must always exist, except when the game is running in text // mode. #if ENABLE_VISUALS { std::vector<std::string> essential = { "fonts/tf2build.ttf" }; for (const auto &s : essential) { std::ifstream exists(DATA_PATH "/" + s, std::ios::in); if (not exists) { Error(("Missing essential file: " + s + "/%s\nYou MUST run install-data script to finish " "installation") .c_str(), s.c_str()); } } } #endif /* TEXTMODE */ logging::Info("Initializing..."); InitRandom(); sharedobj::LoadAllSharedObjects(); CreateInterfaces(); CDumper dumper; dumper.SaveDump(); logging::Info("Is TF2? %d", IsTF2()); logging::Info("Is TF2C? %d", IsTF2C()); logging::Info("Is HL2DM? %d", IsHL2DM()); logging::Info("Is CSS? %d", IsCSS()); logging::Info("Is TF? %d", IsTF()); InitClassTable(); BeginConVars(); g_Settings.Init(); EndConVars(); #if ENABLE_VISUALS draw::Initialize(); #if ENABLE_GUI // FIXME put gui here #endif #endif /* TEXTMODE */ gNetvars.init(); InitNetVars(); g_pLocalPlayer = new LocalPlayer(); g_pPlayerResource = new TFPlayerResource(); uintptr_t *clientMode = 0; // Bad way to get clientmode. // FIXME [MP]? while (!(clientMode = **(uintptr_t ***) ((uintptr_t)((*(void ***) g_IBaseClient)[10]) + 1))) { usleep(10000); } hooks::clientmode.Set((void *) clientMode); hooks::clientmode.HookMethod(HOOK_ARGS(CreateMove)); #if ENABLE_VISUALS hooks::clientmode.HookMethod(HOOK_ARGS(OverrideView)); #endif hooks::clientmode.HookMethod(HOOK_ARGS(LevelInit)); hooks::clientmode.HookMethod(HOOK_ARGS(LevelShutdown)); hooks::clientmode.Apply(); hooks::clientmode4.Set((void *) (clientMode), 4); hooks::clientmode4.HookMethod(HOOK_ARGS(FireGameEvent)); hooks::clientmode4.Apply(); hooks::client.Set(g_IBaseClient); hooks::client.HookMethod(HOOK_ARGS(DispatchUserMessage)); #if ENABLE_VISUALS hooks::client.HookMethod(HOOK_ARGS(FrameStageNotify)); hooks::client.HookMethod(HOOK_ARGS(IN_KeyEvent)); #endif hooks::client.Apply(); #if ENABLE_VISUALS hooks::vstd.Set((void *) g_pUniformStream); hooks::vstd.HookMethod(HOOK_ARGS(RandomInt)); hooks::vstd.Apply(); hooks::panel.Set(g_IPanel); hooks::panel.HookMethod(hooked_methods::methods::PaintTraverse, offsets::PaintTraverse(), &hooked_methods::original::PaintTraverse); hooks::panel.Apply(); #endif hooks::input.Set(g_IInput); hooks::input.HookMethod(HOOK_ARGS(GetUserCmd)); hooks::input.Apply(); #if ENABLE_VISUALS hooks::modelrender.Set(g_IVModelRender); hooks::modelrender.HookMethod(HOOK_ARGS(DrawModelExecute)); hooks::modelrender.Apply(); #endif hooks::enginevgui.Set(g_IEngineVGui); hooks::enginevgui.HookMethod(HOOK_ARGS(Paint)); hooks::enginevgui.Apply(); hooks::engine.Set(g_IEngine); hooks::engine.HookMethod(HOOK_ARGS(IsPlayingTimeDemo)); hooks::engine.Apply(); hooks::eventmanager2.Set(g_IEventManager2); hooks::eventmanager2.HookMethod(HOOK_ARGS(FireEvent)); hooks::eventmanager2.HookMethod(HOOK_ARGS(FireEventClientSide)); hooks::eventmanager2.Apply(); hooks::steamfriends.Set(g_ISteamFriends); hooks::steamfriends.HookMethod(HOOK_ARGS(GetFriendPersonaName)); hooks::steamfriends.Apply(); #if ENABLE_NULL_GRAPHICS g_IMaterialSystem->SetInStubMode(true); IF_GAME(IsTF2()) { logging::Info("Graphics Nullified"); logging::Info("The game will crash"); // TODO offsets::()? hooks::materialsystem.Set((void *) g_IMaterialSystem); uintptr_t base = *(uintptr_t *) (g_IMaterialSystem); hooks::materialsystem.HookMethod((void *) ReloadTextures_null_hook, 70); hooks::materialsystem.HookMethod((void *) ReloadMaterials_null_hook, 71); hooks::materialsystem.HookMethod((void *) FindMaterial_null_hook, 73); hooks::materialsystem.HookMethod((void *) FindTexture_null_hook, 81); hooks::materialsystem.HookMethod((void *) ReloadFilesInList_null_hook, 121); hooks::materialsystem.HookMethod((void *) FindMaterialEx_null_hook, 123); hooks::materialsystem.Apply(); // hooks::materialsystem.HookMethod(); } #endif // FIXME [MP] logging::Info("Hooked!"); velocity::Init(); playerlist::Load(); #if ENABLE_VISUALS InitStrings(); #ifndef FEATURE_EFFECTS_DISABLED if (g_ppScreenSpaceRegistrationHead && g_pScreenSpaceEffects) { effect_chams::g_pEffectChams = new CScreenSpaceEffectRegistration("_cathook_chams", &effect_chams::g_EffectChams); g_pScreenSpaceEffects->EnableScreenSpaceEffect("_cathook_chams"); effect_glow::g_pEffectGlow = new CScreenSpaceEffectRegistration("_cathook_glow", &effect_glow::g_EffectGlow); g_pScreenSpaceEffects->EnableScreenSpaceEffect("_cathook_glow"); } logging::Info("SSE enabled.."); #endif sdl_hooks::applySdlHooks(); logging::Info("SDL hooking done"); #endif /* TEXTMODE */ #if ENABLE_VISUALS #ifndef FEATURE_FIDGET_SPINNER_ENABLED InitSpinner(); logging::Info("Initialized Fidget Spinner"); #endif #endif logging::Info("Clearing initializer stack"); while (!init_stack().empty()) { init_stack().top()(); init_stack().pop(); } logging::Info("Initializer stack done"); #if not ENABLE_VISUALS hack::command_stack().push("exec cat_autoexec_textmode"); #endif hack::command_stack().push("exec cat_autoexec"); hack::command_stack().push("cat_killsay_reload"); hack::command_stack().push("cat_spam_reload"); hack::initialized = true; for (int i = 0; i < 12; i++) { re::ITFMatchGroupDescription *desc = re::GetMatchGroupDescription(i); if (!desc || desc->m_iID > 9) // ID's over 9 are invalid continue; if (desc->m_bForceCompetitiveSettings) { desc->m_bForceCompetitiveSettings = false; logging::Info("Bypassed force competitive cvars!"); } } }
/* Test u_formatMessage() with various test patterns() */ static void MessageFormatTest( void ) { UChar *str; UChar* result; int32_t resultLengthOut,resultlength,i, patternlength; UErrorCode status = U_ZERO_ERROR; UDate d1=1000000000.0; ctest_setTimeZone(NULL, &status); str=(UChar*)malloc(sizeof(UChar) * 7); u_uastrncpy(str, "MyDisk", 7); resultlength=1; result=(UChar*)malloc(sizeof(UChar) * 1); log_verbose("Testing u_formatMessage()\n"); InitStrings(); for (i = 0; i < cnt_testCases; i++) { status=U_ZERO_ERROR; patternlength=u_strlen(testCasePatterns[i]); resultLengthOut=u_formatMessage( "en_US",testCasePatterns[i], patternlength, result, resultlength, &status, 1, 3456.00, d1); if(status== U_BUFFER_OVERFLOW_ERROR) { status=U_ZERO_ERROR; resultlength=resultLengthOut+1; result=(UChar*)realloc(result,sizeof(UChar) * resultlength); u_formatMessage( "en_US",testCasePatterns[i], patternlength, result, resultlength, &status, 1, 3456.00, d1); } if(U_FAILURE(status)){ log_data_err("ERROR: failure in message format on testcase %d: %s (Are you missing data?)\n", i, myErrorName(status) ); continue; } if(u_strcmp(result, testResultStrings[i])==0){ log_verbose("PASS: MessagFormat successful on testcase : %d\n", i); } else{ log_err("FAIL: Error in MessageFormat on testcase : %d\n GOT %s EXPECTED %s\n", i, austrdup(result), austrdup(testResultStrings[i]) ); } } free(result); result = NULL; free(str); { for (i = 0; i < cnt_testCases; i++) { UParseError parseError; status=U_ZERO_ERROR; patternlength=u_strlen(testCasePatterns[i]); resultlength=0; resultLengthOut=u_formatMessageWithError( "en_US",testCasePatterns[i], patternlength, result, resultlength, &parseError,&status, 1, 3456.00, d1); if(status== U_BUFFER_OVERFLOW_ERROR) { status=U_ZERO_ERROR; resultlength=resultLengthOut+1; result=(UChar*)malloc(sizeof(UChar) * resultlength); u_formatMessage( "en_US",testCasePatterns[i], patternlength, result, resultlength, &status, 1, 3456.00, d1); } if(U_FAILURE(status)){ log_data_err("ERROR: failure in message format on testcase %d: %s (Are you missing data?)\n", i, myErrorName(status) ); continue; } if(u_strcmp(result, testResultStrings[i])==0){ log_verbose("PASS: MessagFormat successful on testcase : %d\n", i); } else{ log_err("FAIL: Error in MessageFormat on testcase : %d\n GOT %s EXPECTED %s\n", i, austrdup(result), austrdup(testResultStrings[i]) ); } free(result); result=NULL; } } { UErrorCode ec = U_ZERO_ERROR; int32_t patternLength = u_strlen(testCasePatterns[0]); UMessageFormat formatter = umsg_open(testCasePatterns[0],patternLength,"en_US",NULL,&ec); if(U_FAILURE(ec)){ log_data_err("umsg_open() failed for testCasePattens[%d]. -> %s (Are you missing data?)\n",i, u_errorName(ec)); return; } for(i = 0;i<cnt_testCases; i++){ UParseError parseError; int32_t resultLength =0,count=0; int32_t one=0; int32_t two=0; UDate d2=0; result=NULL; patternLength = u_strlen(testCasePatterns[i]); umsg_applyPattern(formatter,testCasePatterns[i],patternLength,&parseError,&ec); if(U_FAILURE(ec)){ log_err("umsg_applyPattern() failed for testCasePattens[%d].\n",i); return; } /* pre-flight */ resultLength = umsg_format(formatter,result,resultLength,&ec,1,3456.00,d1); if(ec==U_BUFFER_OVERFLOW_ERROR){ ec=U_ZERO_ERROR; result = (UChar*) malloc(U_SIZEOF_UCHAR*resultLength+2); resultLength = umsg_format(formatter,result,resultLength+2,&ec,1,3456.00,d1); if(U_FAILURE(ec)){ log_err("ERROR: failure in message format on testcase %d: %s\n", i, u_errorName(status) ); free(result); return; } if(u_strcmp(result, testResultStrings[i])==0){ log_verbose("PASS: MessagFormat successful on testcase : %d\n", i); } else{ log_err("FAIL: Error in MessageFormat on testcase : %d\n GOT %s EXPECTED %s\n", i, austrdup(result), austrdup(testResultStrings[i]) ); } if (returnsNullForType(1, (double)2.0)) { /* HP/UX and possibly other platforms don't properly check for this case. We pass in a UDate, but the function expects a UDate *. When va_arg is used, most compilers will return NULL, but HP-UX won't do that and will return 2 in this case. This is a platform dependent test. This relies upon "undefined" behavior, as indicated by C99 7.15.1.1 paragraph 2 */ umsg_parse(formatter,result,resultLength,&count,&ec,one,two,d2); if(ec!=U_ILLEGAL_ARGUMENT_ERROR){ log_err("FAIL: Did not get expected error for umsg_parse(). Expected: U_ILLEGAL_ARGUMENT_ERROR Got: %s \n",u_errorName(ec)); }else{ ec = U_ZERO_ERROR; } } else { log_verbose("Warning: Returning NULL for a mismatched va_arg type isn't supported on this platform.\n", i); } umsg_parse(formatter,result,resultLength,&count,&ec,&one,&two,&d2); if(U_FAILURE(ec)){ log_err("umsg_parse could not parse the pattern. Error: %s.\n",u_errorName(ec)); } free(result); }else{ log_err("FAIL: Expected U_BUFFER_OVERFLOW error while preflighting got: %s for testCasePatterns[%d]",u_errorName(ec),i); } } umsg_close(formatter); } FreeStrings(); ctest_resetTimeZone(); }
// Initialize internal variables of the compiler void initialize() { int i; ArmVersion=400; // default ARM version // variables for predefined types halfword_t IntegerTypeNode; halfword_t BooleanTypeNode; halfword_t RealTypeNode; halfword_t PointerTypeNode; // initialization of variables for (i=0;i<NB_FILES;i++) Files[i].f=NULL; iStackPtr=0; // declare that no input file is open HiPoolMin=POOL_SIZE; LoPoolMax=0; InitMem(); // memory initialization InitStrings(); InitHTable(); InitCode(); InitParse(); // read the time start_time=clock(); // initialize initial stack value initial_stack_value=get_stack_value(); // Predefined identifier initialisation NewSymbol("write",sWRITE,0); NewSymbol("writeln",sWRITE,1); NewSymbol("sizeof",sSIZEOF,0); NewConst("true",TBOOLEAN,1); NewConst("false",TBOOLEAN,0); NewConst("maxint",TINTEGER,0x7fffffff); // predefined types IntegerTypeNode=NewType("integer",TINTEGER); BooleanTypeNode=NewType("boolean",TBOOLEAN); RealTypeNode=NewType("real",TREAL); CharTypeNode=NewType("char",TCHAR); PointerTypeNode=NewType("pointer",TPOINTER); NewType("text",TTEXT); NewSymbol("ord", sORDF,0); NewSymbol("pred", sORDF,1); NewSymbol("succ", sORDF,2); NewSymbol("abs",sNUMF,0); NewSymbol("sqr",sNUMF,1); NewSymbol("chr",sCHR,0); NewSymbol("new",sNEW,0); NewSymbol("dispose",sNEW,1); // predefined inlines functions NewInline1("odd",IntegerTypeNode,BooleanTypeNode,-1,1,0xe2100001); NewInline1("sqrt",RealTypeNode,RealTypeNode,-2,2,0xE1A0E00F, // MOV lr,pc 0xE599F000+REALSQRT); NewInline1("round",RealTypeNode,IntegerTypeNode,-4,2,0xE1A0E00F,0xE599F000+REALROUND); NewInline1("trunc",RealTypeNode,IntegerTypeNode,-4,2,0xE1A0E00F,0xE599F000+REALTRUNC); NewInline1("ln",RealTypeNode,RealTypeNode,-4,2,0xE1A0E00F,0xE599F000+REALLN); NewInline1("exp",RealTypeNode,RealTypeNode,-4,2,0xE1A0E00F,0xE599F000+REALEXP); NewInline1("sin",RealTypeNode,RealTypeNode,-4,2,0xE1A0E00F,0xE599F000+REALSIN); NewInline1("cos",RealTypeNode,RealTypeNode,-4,2,0xE1A0E00F,0xE599F000+REALCOS); NewInline1("arctan",RealTypeNode,RealTypeNode,-4,2,0xE1A0E00F,0xE599F000+REALATAN); NewFunc1("halt",IntegerTypeNode,NADA,HALT); NewInlineProc("clrscr",-10,2,0xE1A0E00F,0xE599F000+CLRSCR); InputVar=NewVar("input", TTEXT, -36); OutputVar=NewVar("output", TTEXT, -24); NewSymbol("rewrite",sOPEN,1); NewSymbol("reset",sOPEN,0); NewSymbol("close",sFILEP,CLOSE); NewSymbol("get",sFILEP,GET); NewSymbol("put",sFILEP,PUT); // crt functions NewInline1("wherex",NADA,IntegerTypeNode,-4,2,0xE1A0E00F,0xE599F000+WHEREX); NewInline1("wherey",NADA,IntegerTypeNode,-4,2,0xE1A0E00F,0xE599F000+WHEREY); NewInline1("screenwidth",NADA,IntegerTypeNode,-4,2,0xE1A0E00F,0xE599F000+SCREENWIDTH); NewInline1("screenheight",NADA,IntegerTypeNode,-4,2,0xE1A0E00F,0xE599F000+SCREENHEIGHT); NewInline2("gotoxy",IntegerTypeNode, IntegerTypeNode, -4,2,0xE1A0E00F,0xE599F000+GOTOXY); NewSymbol("read",sREAD,0); NewSymbol("readln",sREAD,1); NewSymbol("eof",sEOF,0); NewSymbol("eoln",sEOF,1); NewFunc1("length",StringTypeNode,IntegerTypeNode,LENGTH); }