// Asserts that the rest of the line is empty and moves to the next one. void SymFile::ExpectEmptyRestOfLine() { SkipWhitespace(); if (m_buffer[m_pos] == 0) { if (m_pos >= m_size) RaiseWarning("file doesn't end with newline"); else RaiseError("unexpected null character"); } else if (m_buffer[m_pos] == '\n') { m_pos++; m_lineStart = m_pos; m_lineNum++; } else if (m_buffer[m_pos] == '\r') { RaiseError("only Unix-style LF newlines are supported"); } else { RaiseError("junk at end of line"); } }
// S_OK : 성공 // S_FALSE : 데이터는 가져왔지만 Consumer가 원하는 데이터가 아님 // E_FAIL : 실패 static HRESULT FetchData(int hReq, CTablesInfoRow &tirData, int table_type) { char *value; int int_value; int ind, res; T_CCI_ERROR err_buf; res = cci_fetch(hReq, &err_buf); if(res<0) return RaiseError(E_FAIL, 1, __uuidof(IDBSchemaRowset), err_buf.err_msg); res = cci_get_data(hReq, 1, CCI_A_TYPE_STR, &value, &ind); if(res<0) return RaiseError(E_FAIL, 0, __uuidof(IDBSchemaRowset)); wcscpy(tirData.m_szTableName, CA2W(value)); res = cci_get_data(hReq, 2, CCI_A_TYPE_INT, &int_value, &ind); if(res<0) return RaiseError(E_FAIL, 0, __uuidof(IDBSchemaRowset)); if (table_type >= 0 && table_type != int_value) return S_FALSE; if (int_value == 2) wcscpy(tirData.m_szTableType, L"TABLE"); else if (int_value == 1) wcscpy(tirData.m_szTableType, L"VIEW"); else if (int_value == 0) wcscpy(tirData.m_szTableType, L"SYSTEM TABLE"); tirData.m_bBookmarks = ATL_VARIANT_TRUE; tirData.m_bBookmarkType = DBPROPVAL_BMK_NUMERIC; tirData.m_bBookmarkDatatype = DBTYPE_BYTES; tirData.m_bBookmarkMaximumLength = sizeof(DBROWCOUNT); return S_OK; }
bool TryToSelfElevate(HWND hwnd) { HRESULT hRes = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); if (hRes != S_OK) throw std::runtime_error("Cannot initialize COM library."); wchar_t szPath[MAX_PATH]; if (::GetModuleFileNameW(NULL, szPath, ARRAYSIZE(szPath)) == 0) RaiseError("TryToSelfElevate:\n"); SHELLEXECUTEINFOW sei = { sizeof(sei) }; sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_UNICODE | SEE_MASK_NOASYNC | SEE_MASK_NO_CONSOLE | /*SEE_MASK_NOCLOSEPROCESS |*/ SEE_MASK_HMONITOR; sei.lpVerb = L"runas"; sei.lpFile = szPath; sei.nShow = SW_SHOW; sei.hMonitor = ::MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY); if (!ShellExecuteExW(&sei)) { DWORD dwError = GetLastError(); if (dwError != ERROR_CANCELLED) RaiseError("TryToSelfElevate:\n"); // The user refused the elevation. return false; } //if (sei.hProcess == nullptr) // throw std::runtime_error("Cannot start new process."); //::WaitForSingleObject(sei.hProcess, INFINITE); return true; }
bool IsRunAsAdmin() { BOOL ret = TRUE; SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; PSID AdministratorsGroup; ret = ::AllocateAndInitializeSid( &NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup); if (!ret) RaiseError("Couldn't AllocateAndInitializeSid:\n"); BOOL check = FALSE; if (!::CheckTokenMembership(nullptr, AdministratorsGroup, &check)) { FreeSid(AdministratorsGroup); RaiseError("Couldn't CheckTokenMembership:\n"); } FreeSid(AdministratorsGroup); return (check ? true : false); }
void EnableDebugPrivileges() { HANDLE hToken; LUID SeDebugNameValue; TOKEN_PRIVILEGES TokenPrivileges; if (!::OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) RaiseError("Couldn't OpenProcessToken:\n"); if (!::LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &SeDebugNameValue)) { ::CloseHandle(hToken); RaiseError("Couldn't LookupPrivilegeValue:\n"); } TokenPrivileges.PrivilegeCount = 1; TokenPrivileges.Privileges[0].Luid = SeDebugNameValue; TokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if (!::AdjustTokenPrivileges(hToken, FALSE, &TokenPrivileges, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) { ::CloseHandle(hToken); RaiseError("Couldn't AdjustTokenPrivileges:\n"); } ::CloseHandle(hToken); }
QCMutex::QCMutex(): mLockCnt(0), mOwner(), mMutex() { int theErr; pthread_mutexattr_t theAttr; if ((theErr = pthread_mutexattr_init(&theAttr)) != 0) { RaiseError("QCMutex: pthread_mutex_attr_init", theErr); } if ((theErr = pthread_mutexattr_settype(&theAttr, PTHREAD_MUTEX_RECURSIVE)) != 0) { RaiseError("QCMutex: pthread_mutexattr_settype", theErr); } if ((theErr = pthread_mutex_init(&mMutex, &theAttr)) != 0) { RaiseError("QCMutex: pthread_mutex_init", theErr); } if ((theErr = pthread_mutexattr_destroy(&theAttr)) != 0) { RaiseError("QCMutex: pthread_mutexattr_destroy", theErr); } }
int ConnectHopHTTPSProxy(STREAM *S, const char *Proxy, const char *Destination) { char *Tempstr=NULL, *Token=NULL; char *Proto=NULL, *Host=NULL, *User=NULL, *Pass=NULL; const char *ptr=NULL; int result=FALSE, Port; ParseConnectDetails(Proxy, &Token, &Host, &Token, &User, &Pass, NULL); Port=atoi(Token); if (! (S->State & SS_INITIAL_CONNECT_DONE)) { if (Port==0) Port=443; S->in_fd=TCPConnect(Host,Port,0); S->out_fd=S->in_fd; if (S->in_fd == -1) { RaiseError(0, "ConnectHopHTTPSProxy", "failed to connect to proxy at %s:%d", Host, Port); return(FALSE); } } ptr=Destination; if (strncmp(ptr,"tcp:",4)==0) ptr+=4; Tempstr=FormatStr(Tempstr,"CONNECT %s HTTP/1.1\r\n\r\n",ptr); STREAMWriteLine(Tempstr,S); STREAMFlush(S); Tempstr=STREAMReadLine(Tempstr,S); if (Tempstr) { StripTrailingWhitespace(Tempstr); ptr=GetToken(Tempstr," ",&Token,0); ptr=GetToken(ptr," ",&Token,0); if (*Token=='2') result=TRUE; else RaiseError(0, "ConnectHopHTTPSProxy", "proxy request to %s:%d failed. %s", Host, Port, Tempstr); while (StrLen(Tempstr)) { Tempstr=STREAMReadLine(Tempstr,S); StripTrailingWhitespace(Tempstr); } } else RaiseError(0, "ConnectHopHTTPSProxy", "proxy request to %s:%d failed. Server Disconnectd.", Host, Port); DestroyString(Tempstr); DestroyString(Token); DestroyString(Host); DestroyString(User); DestroyString(Pass); return(result); }
void CCommandLineParser::ProcessCommand(const char* command_str) { const s_arg_entry* command; if (!FindArgument(command_str, false, &command)) RaiseError("unknown command"); if (this->command.id != kNone) RaiseError("unexpected command.. already got one."); this->command.SetID(command->id); ReadParams(command, this->command); }
void CCommandLineParser::ReadParams(const s_arg_entry* arg, CArgEntity& out) { for (size_t x = 0; x < arg->nargs; x++) { char* arg_str; if (!ReadString(&arg_str)) RaiseError("expected arg"); std::string str = arg_str; if (str.size() > 0){ if (str.at(0) == '-') RaiseError("expected arg"); out.Add(arg_str); } } }
// *cur_ == '{' JsonValue * JsonParser::ReadObject(JsonValue * parent) { std::auto_ptr<JsonObjectValue> object(new JsonObjectValue(parent)); std::string key; Advance(); SkipSpaces(); if (*cur_ == '}') { Advance(); return object.release(); } while (true) { if (*cur_ == '"') { ParseStringLiteral(key); } else { RaiseError("Unexpected symbol, while waiting key of object"); } SkipSpaces(); if (*cur_ != ':') { RaiseError("Colon expected"); } Advance(); SkipSpaces(); object->Set(key, ReadValue(parent)); SkipSpaces(); if (*cur_ == ',') { Advance(); SkipSpaces(); } else if (*cur_ == '}') { Advance(); return object.release(); } else { RaiseError("Comma or end of object expected"); } } }
ErrorState* ImportModule(const std::string& modulePath, ParseResult& parse) { ErrorState* errorState = new ErrorState(); FILE* f = fopen(modulePath.c_str(), "rb"); if (!f) { RaiseError(errorState, ERROR_MALFORMED_MODULE_INFO, modulePath.c_str(), "Couldn't open file"); return errorState; } #define CONSUME(byte)\ if (fgetc(f) != byte)\ {\ RaiseError(errorState, ERROR_MALFORMED_MODULE_INFO, modulePath.c_str(), "Format not followed");\ return errorState;\ } CONSUME(0x7F); CONSUME('R'); CONSUME('O'); CONSUME('O'); uint8_t version = Read<uint8_t>(f); uint32_t typeCount = Read<uint32_t>(f); uint32_t codeThingCount = Read<uint32_t>(f); if (version != ROO_MOD_VERSION) { RaiseError(errorState, ERROR_MALFORMED_MODULE_INFO, modulePath.c_str(), "Unsupported version"); return errorState; } for (size_t i = 0u; i < typeCount; i++) { parse.types.push_back(Read<TypeDef*>(f)); } for (size_t i = 0u; i < codeThingCount; i++) { parse.codeThings.push_back(Read<CodeThing*>(f)); } fclose(f); return errorState; }
// S_OK : 성공 // S_FALSE : 데이터는 가져왔지만 Consumer가 원하는 데이터가 아님 // E_FAIL : 실패 static HRESULT FetchData(int hReq, CStatisticsRow &tprData) { char *value; int ind, res; T_CCI_ERROR err_buf; res = cci_fetch(hReq, &err_buf); if(res<0) return RaiseError(E_FAIL, 1, __uuidof(IDBSchemaRowset), err_buf.err_msg); res = cci_get_data(hReq, 1, CCI_A_TYPE_STR, &value, &ind); if(res<0) return RaiseError(E_FAIL, 0, __uuidof(IDBSchemaRowset)); wcscpy(tprData.m_szTableName, CA2W(value)); return S_OK; }
// CLitMultiLock CLitMultiLock::CLitMultiLock(CLitSyncObject* pObjects[], DWORD dwCount, BOOL bInitialLock) { ATLASSERT(dwCount > 0 && dwCount <= MAXIMUM_WAIT_OBJECTS); ATLASSERT(pObjects != NULL); if(pObjects == NULL) { RaiseError(cstMTErrorCode,_T("argument error.")); } m_ppObjectArray = pObjects; m_dwCount = dwCount; // as an optimization, skip allocating array if // we can use a small, preallocated bunch of handles if (m_dwCount > _countof(m_hPreallocated)) { ATL::CAutoVectorPtr<HANDLE> spHandleArray(new HANDLE[m_dwCount]); ATL::CAutoVectorPtr<BOOL> spLockedArray(new BOOL[m_dwCount]); m_pHandleArray = spHandleArray.Detach(); m_bLockedArray = spLockedArray.Detach(); } else { m_pHandleArray = m_hPreallocated; m_bLockedArray = m_bPreallocated; } // get list of handles from array of objects passed for (DWORD i = 0; i <m_dwCount; i++) { if(pObjects[i] == NULL) { RaiseError(cstMTErrorCode,_T("argument error.")); } // can't wait for critical sections ATLASSERT(pObjects[i]->m_objectType != enmSyncObjectCriticalSection); m_pHandleArray[i] = pObjects[i]->m_hObject; m_bLockedArray[i] = FALSE; } if (bInitialLock) Lock(); }
MPI_Datatype MPITypeConv( Type_tag t, size_t tsize ) { /* Check arguments make sense */ if( t != TYPE_IFloat && t != TYPE_int ) RaiseError("SCUMPITypeConv: unknown data type!"); if( tsize <= 0 ) RaiseError("SCUMPITypeConv: size of data type is <= 0!"); MPI_Datatype int_types[N_INT_TYPES] = { MPI_CHAR, MPI_SHORT, MPI_INT, MPI_LONG }; MPI_Datatype IFloat_types[N_FLOAT_TYPES] = { MPI_FLOAT, MPI_DOUBLE, MPI_LONG_DOUBLE }; char err_str[STRING_MAX_LEN]; int i, mpisize; /* Go through int OR IFloat types */ if( t == TYPE_int ) { for( i=0; i < N_INT_TYPES; i++ ) { MPI_Type_size( int_types[i], &mpisize ); /* Get size of this MPI type */ if( tsize == mpisize ) // If we have a match return( int_types[i] ); // return the matched type. } /* if this executes, no suitable type has not been found, so raise an error */ sprintf(err_str,"SCUMPITypeConv: no suitable %i-byte int type among MPI primitive types",tsize); RaiseError(err_str); /* IFloat types */ } else if( t == TYPE_IFloat ) { for( i=0; i < N_FLOAT_TYPES; i++ ) { MPI_Type_size( IFloat_types[i], &mpisize ); /* Get size of this MPI type */ if( tsize == mpisize ) // If we have a match return( IFloat_types[i] ); // return the matched type. } /* if this executes, no suitable type has not been found, so raise an error */ sprintf(err_str,"no suitable %i-byte IFloat type among MPI primitive types",tsize); RaiseError(err_str); } /* This statement should never execute, however just to check, and keep the compiler happy, we shall say: */ RaiseError("SCUMPITypeConv: running unrunnable section of SCUMPITypeConv! Possible memory access problem?"); return(( MPI_Datatype)0 ); }
// *cur_ == '[' JsonValue * JsonParser::ReadArray(JsonValue * parent) { std::auto_ptr<JsonArrayValue> array(new JsonArrayValue(parent)); Advance(); SkipSpaces(); if (*cur_ == ']') { Advance(); return array.release(); } while (true) { array->PushBack(ReadValue(parent)); SkipSpaces(); if (*cur_ == ',') { Advance(); SkipSpaces(); continue; } else if (*cur_ == ']') { Advance(); return array.release(); } else { RaiseError("Comma or end of array expected"); } } }
CodeThing* Read<CodeThing*>(FILE* f) { CodeThing* thing; switch (Read<uint8_t>(f)) { case 0u: { thing = new FunctionThing(Read<std::string>(f)); } break; case 1u: { thing = new OperatorThing(static_cast<TokenType>(Read<uint32_t>(f))); } break; default: { // TODO: get the module info path from somewhere RaiseError(ERROR_MALFORMED_MODULE_INFO, "ModuleFileIdk", "CodeThing type encoding should be 0 or 1"); return nullptr; } break; } thing->params = Read<std::vector<VariableDef*>>(f); /* * Even if it is defined in Roo in the other module, we're linking against it here and so it should be considered * a prototype function, as if it were defined in C or assembly or whatever. */ thing->attribs.isPrototype = true; return thing; }
HSCRIPTFUNCTION CScriptSystem::GetFunctionPtr(const char* sTableName, const char* sFuncName) { HSCRIPTFUNCTION func; lua_getglobal(m_pLS, sTableName); if (!lua_istable(m_pLS, -1)) { RaiseError(m_pLS, "(GetFunctionPtr)Table %s: not found(check for syntax errors or if the file wasn't loaded)", sTableName); lua_pop(m_pLS, 1); return HSCRIPTFUNCTION(); } lua_pushstring(m_pLS, sFuncName); lua_gettable(m_pLS, - 2); lua_remove(m_pLS, - 2); // Remove table global. if (lua_isnil(m_pLS, -1) || (!lua_isfunction(m_pLS, -1))) { lua_pop(m_pLS, 1); return HSCRIPTFUNCTION(); } func = lua_ref(m_pLS, true); return func; }
int CScriptSystem::BeginCall(const char* sFuncName, const bool bRaiseError /* = true */) { ASSERT_MAIN_THREAD(); // Check for LUA stack corruption CheckStackOnBeginCall(); lua_getglobal(m_pLS, sFuncName); m_nTempArg = 0; #ifdef _DEBUG if (!lua_isfunction(m_pLS, -1)) { if (bRaiseError) { RaiseError(m_pLS, "Function %s not found(check for syntax errors or if the file wasn't loaded)", sFuncName); } m_nTempArg = -1; lua_pop(m_pLS, 1); m_CurrentDeep--; return 0; } #endif return 1; }
static Img_Info Img_Info_Con(Img_Info self, char *urn, TSK_IMG_TYPE_ENUM type) { if(urn[0]) { #ifdef TSK_VERSION_NUM self->img = (Extended_TSK_IMG_INFO *)tsk_img_open_utf8(1, (const char **)&urn, type, 0); #else self->img = (Extended_TSK_IMG_INFO *)tsk_img_open_utf8(1, (const char **)&urn, type); #endif } else { // Initialise the img struct with the correct callbacks: self->img = talloc_zero(self, Extended_TSK_IMG_INFO); self->img->container = self; self->img->base.read = IMG_INFO_read; self->img->base.close = IMG_INFO_close; self->img->base.size = CALL(self, get_size); #ifdef TSK_VERSION_NUM self->img->base.sector_size = 512; #endif self->img->base.itype = TSK_IMG_TYPE_RAW_SING; }; if(!self->img) { RaiseError(ERuntimeError, "Unable to open image: %s", tsk_error_get()); goto error; }; talloc_set_destructor((void *)self, Img_Info_dest); return self; error: talloc_free(self); return NULL; };
int SMTPSendMailFile(const char *Sender, const char *Recipient, const char *Path, int Flags) { char *Tempstr=NULL; STREAM *S, *F; int result=FALSE; F=STREAMOpen(Path, "r"); if (F) { S=SMTPConnect(Sender, Recipient, Flags); if (S) { STREAMSendFile(F, S, 0, SENDFILE_LOOP); STREAMWriteLine("\r\n.\r\n", S); SMTPInteract("", S); SMTPInteract("QUIT\r\n", S); result=TRUE; STREAMClose(S); } STREAMClose(F); } else RaiseError(0,"SMTPSendMailFile","Failed to open file for sending"); DestroyString(Tempstr); return(result); }
void CProfilerRecord::Start() { if (m_Started){ RaiseError(); } m_Count++; m_Started = true; m_StartTime = CEngine::GetSingleton().GetRealTimeSinceStartup(); }
void MachineCache::add(VarObjFactory* factory, std::shared_ptr<Exemplar> e1) { // Supplied exemplar might be used in many different machine contexts, // but MachineCache refers to a single context; it's fine to JIT a copy // of the exemplar per context, but not across machine contexts - // different engines might instantiate different libraries causing // different resolutions of function pointers. // std::unique_ptr<Exemplar> e(new Exemplar()); e->copy(e1.get()); std::shared_ptr<MachineCacheEntry> mce = std::make_shared<MachineCacheEntry>(std::move(e)); if (mce->exemplar->sharedVarCount > 0) { for (int i = 0; i < e->sharedVarCount; ++i) { const char* varType = &mce->exemplar->stringData[e->stringArray[mce->exemplar->sharedVarTypeIndex[i]]]; const char* varName = &mce->exemplar->stringData[e->stringArray[mce->exemplar->sharedVarNameIndex[i]]]; std::unique_ptr<VarObj> v = factory->make(varType, varName); if (!v) RaiseError(0, "Unknown variable type", varType); mce->sharedVars->add(std::shared_ptr<VarObj>(std::move(v))); } } cache.push_back(std::move(mce)); }
CBlob *CBlobResult::GetBlob(int indexblob) { if( indexblob < 0 || indexblob >= GetNumBlobs() ) RaiseError( EXCEPTION_BLOB_OUT_OF_BOUNDS ); return m_blobs[indexblob]; }
QCMutex::~QCMutex() { const int theErr = pthread_mutex_destroy(&mMutex); if (theErr != 0) { RaiseError("QCMutex::~QCMutex: pthread_mutex_destroy", theErr); } }
QCCondVar::~QCCondVar() { const int theErr = pthread_cond_destroy(&mCond); if (theErr) { RaiseError("QCCondVar::~QCCondVar: pthread_cond_destroy", theErr); } }
void CProfilerRecord::Stop() { if (!m_Started) { RaiseError(); } m_Started = false; float l_ElapsedTime = (CEngine::GetSingleton().GetRealTimeSinceStartup() - m_StartTime); m_AccumulatedTime += l_ElapsedTime; CEngine::GetSingleton().GetLogManager()->Log(m_Name + ". Time: " + std::to_string(m_AccumulatedTime)); }
QCCondVar::QCCondVar() : mCond() { const int theErr = pthread_cond_init(&mCond, 0); if (theErr) { RaiseError("QCCondVar::QCCondVar: pthread_cond_init", theErr); } }
bool IsCurrentProcessElevated() { HANDLE hToken = NULL; if (!::OpenProcessToken(::GetCurrentProcess( ), TOKEN_QUERY, &hToken)) RaiseError("Couldn't OpenProcessToken:\n"); TOKEN_ELEVATION Elevation; DWORD cbSize = 0; if (!::GetTokenInformation(hToken, TokenElevation, &Elevation, sizeof(Elevation), &cbSize)) { ::CloseHandle(hToken); RaiseError("Couldn't GetTokenInformation:\n"); } ::CloseHandle(hToken); return (Elevation.TokenIsElevated != 0); }
// CLitMutex CLitMutex::CLitMutex() : CLitSyncObject(NULL, enmSyncObjectMutex) { m_bUsedhandle = FALSE; m_hObject = ::CreateMutex(NULL, FALSE, NULL); if (m_hObject == NULL) { RaiseError(cstMTErrorCode,_T("create Mutex object failed.")); } }
bool QCMutex::Lock( QCMutex::Time inTimeoutNanoSec) { struct timespec theAbsTimeout; int theErr = GetAbsTimeout(inTimeoutNanoSec, theAbsTimeout); if (theErr != 0) { RaiseError("QCMutex::Lock: clock_gettime", theErr); } theErr = pthread_mutex_timedlock(&mMutex, &theAbsTimeout); if (theErr == ETIMEDOUT) { return false; } if (theErr != 0) { RaiseError("QCMutex::Lock: pthread_mutex_timedlock", theErr); } return true; }