/*! Used to play a 3d sound * * Note, if you call this on a file that has not been Loaded * (see icSoundDeviceAL::LoadSource), it will keep this audio * loaded in memory until you call UnloadSource or the device * is destroyed. * * @param szFile Audio file to play * @param soundParam How to play that audio * @param[out] ppStream Handle to the sound object * @returns ICRESULT Success/failure of playing audio **/ ICRESULT icSoundDeviceAL::Play3D(const char* szName, const icSoundParam& soundParams, icSoundI** ppSound) { icSoundI* sound = GetFreeSound(); if (!sound) return IC_FAIL_GEN; icSoundBuffer pBuf; if (ICEFAIL(FindSource(szName,pBuf))) LoadSource(szName); if (ICEFAIL(FindSource(szName,pBuf))) return IC_FAIL_GEN; icSoundAL* alSound = (icSoundAL*)sound; alSound->m_buf = pBuf; alSound->m_Params = soundParams; // assign the buffer to this source alSourcei(alSound->m_ALsource, AL_BUFFER, pBuf.buffID); alSound->Play3d(); *ppSound = sound; return IC_OK; }// END FUNCTION Play3D(const char* szName,
PangoVideo::PangoVideo(const std::string& filename, bool realtime) : reader(filename, realtime), frame_id(-1) { src_id = FindSource(); if(src_id == -1) { throw pangolin::VideoException("No appropriate video streams found in log."); } }
string DCppTemplate::GetUpdatedCodes(const char *fileName,DCodeMacro cm[], int macroNum) { string result; if (!CheckContain()) throw "Template is error , pls check it careful!"; vector<stc_Flag> codeBlockList = FindSource(); int seq = GetBlockSequenceByFile(fileName); result = GetUpdatedCodes(seq,cm,macroNum); return result; }
/*! Gets a handle to a sound for playing * * @param szFile Audio file to play * @param[out] ppStream Handle to the sound object * @returns ICRESULT Success/failure of playing audio **/ ICRESULT icSoundDeviceAL::GetSound(const char* szName, icSoundI** ppSound) { icSoundI* sound = GetFreeSound(); if (!sound) return IC_FAIL_GEN; icSoundBuffer pBuf; if (ICEFAIL(FindSource(szName,pBuf))) { if (ICEFAIL(LoadSource(szName))) { return IC_FAIL_GEN; } if (ICEFAIL(FindSource(szName,pBuf))) { return IC_FAIL_GEN; } } icSoundAL* alSound = (icSoundAL*)sound; alSound->m_buf = pBuf; // assign the buffer to this source alSourcei(alSound->m_ALsource, AL_BUFFER, pBuf.buffID); ALenum err = alGetError(); if (err != AL_NO_ERROR) return IC_FAIL_GEN; *ppSound = sound; return IC_OK; }// END FUNCTION GetSound(const char* szName, icSoundI** ppSound)
PangoVideo::PangoVideo(const std::string& filename, bool realtime) : reader(filename, realtime), filename(filename), realtime(realtime), is_pipe(pangolin::IsPipe(filename)), is_pipe_open(true), pipe_fd(-1) { // N.B. is_pipe_open can default to true since the reader opens the file and // reads header information from it, which means the pipe must be open and // filled with data. src_id = FindSource(); if(src_id == -1) { throw pangolin::VideoException("No appropriate video streams found in log."); } }
string DCppTemplate::GetUpdatedCodes(int srcBlockId, DCodeMacro cm[], int macroNum) { if (!CheckContain()) throw "Template is error , pls check it careful!"; vector<stc_Flag> codeBlockList = FindSource(); if (srcBlockId < 0 || srcBlockId >= codeBlockList.size()) throw "BlockId error !"; string source = codeBlockList[srcBlockId].Contain; stc_Flag fgTemp; for (int i = 0;i < macroNum; i++) { int j = 0; for (; j< source.length();) { fgTemp = FindMacroByName(source.c_str(),cm[i].GetName(),source.length(),j); if (fgTemp.beginPos < 0) break; source.insert(fgTemp.endPos,cm[i].GetValue()); j = fgTemp.endPos + cm[i].GetValue().length(); } } return source; // vector<stc_Flag> srcFlags; // srcFlags = FindFlags(source.c_str(),STR_CGFLAG_BEGIN.c_str(),STR_CGFLAG_END.c_str(),source.length(),STR_CGFLAG_END.length()+1); // vector<DCppTemplate::stc_Flag> macroFlag; // macroFlag = FindMacroFlag(srcFlags); // if (!CheckFlagSequence(macroFlag)) // return source; // int copyPos = 0; // for (auto tf : macroFlag) // { // for (int i = 0; i < macroNum; i++) // { // if (RemoveFlagTag(tf.Contain,STR_CGFLAG_FLAGTYPE_END.length()) == cm[i].GetName()) // { // result += source.substr(copyPos,tf.beginPos-copyPos); // result += cm[i].GetValue(); // copyPos = tf.endPos; // } // } // } // result += source.substr(copyPos,source.length() - copyPos); }
long ReopenSource(long index, int notExtern, long isrc) { long source, position; p_file *file; source = (isrc<0)? FindSource(index) : isrc; if (source<0) return -1; /* source of func unknown */ file= PushInclude(sourceTab.names[source], 0); if (!file) return -2; /* unable to open source file */ position= ScanForFunc(globalTable.names[index], notExtern); if (position<0 || p_fseek(file, position)) { if (ypIncludes[nYpIncludes-1].file) { p_fclose(file); ypIncludes[nYpIncludes-1].file= 0; } if (position<0) return -3; /* func no longer in source file */ else return -4; /* seek error */ } return position; }
/* ** Take a string which is supposed to be an executable address, ** and find out what that address is. */ ULONG FindExecAddr(char *label, char **brkDesc) { ULONG addr = 0; char *desc; char *dummy; ULONG lineNum; DebugModule *module; char funcName[MAX_FUNCNAME]; char sourceName[CCHMAXPATH]; /* ** If there is no label, give up the ghost! */ if(label == NULL) return 0; /* ** Find the address of the line given a line number. */ if(label[0] == '.') { module = FindModule(debugBuffer.MTE, NULL); FindSource(module, Linearize(debugBuffer.EIP, debugBuffer.CS), funcName, sourceName, &lineNum); /* Cannot find source module. */ if(strcmp(sourceName, "UNKNOWN") == 0) { return 0; } lineNum = strtol(&label[1], &dummy, 0); addr = FindSourceLine(module, lineNum, sourceName); /* ** Build a string which describes the breakpoint. */ desc = malloc(strlen(label) + strlen(sourceName) + 1); strcpy(desc, sourceName); strcat(desc, ":"); strcat(desc, &label[1]); *brkDesc = desc; return addr; } /* ** If we have a '!' in the string, then it is a compound ** filename/line number */ if(strchr(label, '!') != NULL) { char *line; line = strchr(label, '!'); *line = '\0'; module = FindModule(debugBuffer.MTE, NULL); FindSource(module, Linearize(debugBuffer.EIP, debugBuffer.CS), funcName, sourceName, &lineNum); /* Cannot find source module. */ if(strcmp(sourceName, "UNKNOWN") == 0) { return 0; } lineNum = strtol(&label[1], &dummy, 0); addr = FindSourceLine(module, lineNum, sourceName); /* ** Build a string which describes the breakpoint. */ desc = malloc(strlen(label) + strlen(sourceName) + 1); strcpy(desc, sourceName); strcat(desc, ":"); strcat(desc, &label[1]); *brkDesc = desc; return addr; } /* ** Try finding the name as a function */ if((addr = FindFuncAddr(NULL, label)) != 0) { desc = malloc(strlen(label) + 1); strcpy(desc, label); *brkDesc = desc; return addr; } /* ** If we could not find a function, try using the label as ** a hex offset to break at. */ addr = StrToAddr(label, TOADDR_CODE); desc = malloc(strlen(label) + 1); strcpy(desc, label); *brkDesc = desc; return addr; }
/* ** Do a single step to the next source instruction. */ int CommandStep(char **ptrs) { int i; ULONG addr; ULONG lineNum; Breakpoint *bp; DebugModule *module; char funcName[MAX_FUNCNAME]; char funcName2[MAX_FUNCNAME]; char sourceName[CCHMAXPATH]; /* ** Provide a reference to keep from getting a compile warning. */ ptrs; /* ** Find the address specified. */ module = FindModule(debugBuffer.MTE, NULL); FindSource(module, Linearize(debugBuffer.EIP, debugBuffer.CS), funcName, sourceName, &lineNum); for(i=0; i<100; i++) { lineNum++; addr = FindSourceLine(module, lineNum, sourceName); if(addr != 0) { FindSource(module, addr, funcName2, sourceName, &lineNum); if(strcmp(funcName2, funcName) == 0) break; fprintf(logFile, "Unable to find next line. Next function found!\n"); return -1; } } /* ** Did we find a line */ if(addr == 0) { fprintf(logFile, "Unable to find next line.\n"); return -1; } /* ** Set the breakpoint at the address specified. */ debugBuffer.Addr = addr; debugBuffer.Len = 1; debugBuffer.Index = 0; debugBuffer.Value = DBG_W_Local | DBG_W_Execute; DispatchCommand(DBG_C_SetWatch); /* ** Add the breakpoint to the list, and tag it as a 'go' ** breakpoint which will unconditionally be cleared the ** next time we get back from the debuggee. */ if(Breakpoints) { for(i=0, bp=Breakpoints; bp->next; i++, bp=bp->next) ; bp->next = malloc(sizeof(Breakpoint)); bp = bp->next; } else { i = 0; Breakpoints = bp = malloc(sizeof(Breakpoint)); } bp->id = debugBuffer.Index; bp->addr = addr; bp->next = NULL; bp->desc = NULL; bp->oneTimeFlag = 1; return DBG_C_Go; }
/* ** Dump the stack frame. */ void DumpStack(int threadID) { ULONG lineNum; struct { ULONG ebp; ULONG eip; } info; DebugModule *module; ULONG oldTid; ULONG objectNum; ULONG baseOffset; USHORT lastCS; char funcName[MAX_FUNCNAME]; char sourceName[CCHMAXPATH]; /* ** Find the base and then extract out the EIP. Follow the chain ** until EBP == 0 */ oldTid = debugBuffer.Tid; debugBuffer.Tid = threadID; DispatchCommand(DBG_C_ReadReg); lastCS = debugBuffer.CS; info.ebp = Linearize(debugBuffer.EBP, debugBuffer.SS); info.eip = Linearize(debugBuffer.EIP, debugBuffer.CS); while(1) { /* ** End of chain. */ if((info.ebp == 0) || (info.eip == 0)) { debugBuffer.Tid = oldTid; return; } /* ** Find the module. */ debugBuffer.Addr = info.eip; DispatchCommand(DBG_C_AddrToObject); module = FindModule(debugBuffer.MTE, NULL); if(module == NULL) { fprintf(logFile, "MODULE NOT FOUND!\n"); debugBuffer.Tid = oldTid; return; } /* ** Dump EBP:EIP of the current stack frame. */ baseOffset = debugBuffer.Buffer; fprintf(logFile, "EBP:\t%08x\tEIP:\t%08x\n", info.ebp, info.eip); fprintf(logFile, " Base:\t%08x\tRel:\t%08x\tLen:\t%08x\n", baseOffset, info.eip - baseOffset, debugBuffer.Len); /* ** Find the object number associated with the address. */ for(objectNum=1;;objectNum++) { debugBuffer.Value = (ULONG) objectNum; debugBuffer.MTE = module->MTE; if(DispatchCommand(DBG_C_NumToAddr) != DBG_N_Success) break; if(debugBuffer.Addr == baseOffset) break; } fprintf(logFile, " Object: %08x\n", objectNum); /* ** Dump the values. */ FindSource(module, info.eip, funcName, sourceName, &lineNum); if(lineNum != 0) fprintf(logFile, " Module: %s\n" " Size: %u\n" " Timestamp:%s\n" " Function: %s\n" " Source: %s\n" " Line: %d\n\n", module->name, module->fileSize, ctime(&module->fTimestamp), funcName, sourceName, lineNum); else fprintf(logFile, " Module: %s\n" " Size: %u\n" " Timestamp:%s\n" " Lo Function: %s\n" " Hi Function: %s\n\n", module->name, module->fileSize, ctime(&module->fTimestamp), funcName, sourceName); #ifdef SHERLOCK { DebugModule *module; char *mod; debugBuffer.Addr = info.eip; DispatchCommand(DBG_C_AddrToObject); if((debugBuffer.Cmd == DBG_N_Success) && (debugBuffer.Value & 0x10000000)) { module = FindModule(debugBuffer.MTE, NULL); if(module == NULL) mod = "UNKNOWN"; else mod = module->name; FindSource(module, info.eip, funcName, sourceName, &lineNum); fprintf(logFile, "EIP: %08x, DLL: %s Func: %s\n", info.eip, mod, funcName); DisplaySource(module, sourceName, lineNum); fprintf(logFile, "\n\n"); } } #endif /* ** Get prior EBP, EIP */ if(module->typeFlags & FAPPTYP_32BIT) { debugBuffer.Addr = info.ebp; debugBuffer.Len = 8; debugBuffer.Buffer = (ULONG) &info.ebp; info.ebp = info.eip = 0; DispatchCommand(DBG_C_ReadMemBuf); } else { USHORT codePtr[2]; /* Get the new code pointer. */ debugBuffer.Addr = info.ebp+2; debugBuffer.Len = 4; debugBuffer.Buffer = (ULONG) &codePtr; info.eip = 0; DispatchCommand(DBG_C_ReadMemBuf); /* Now, get the new base pointer. */ debugBuffer.Addr = info.ebp; debugBuffer.Len = 2; debugBuffer.Buffer = (ULONG) &info.ebp; info.ebp = 0; DispatchCommand(DBG_C_ReadMemBuf); info.ebp = Linearize(info.ebp, debugBuffer.SS); /* ** Now for real hocus pocus. Try to find out ** if the pointer is a near or far call! ** ** First, check for NULL pointer, Must be end of chain. */ if((codePtr[0] == 0) && (codePtr[1] == 0)) { info.eip = 0; } else { USHORT tmp; /* ** If supposidly ring 0 or ring 1 caller, then ** that cannot be correct, must be a near call. */ tmp = codePtr[1] & 0x03; if((tmp == 0) || (tmp == 1)) { info.eip = Linearize(codePtr[0], lastCS); } else { /* ** Assume that it is a far pointer. */ lastCS = codePtr[1]; info.eip = Linearize(codePtr[0], lastCS); } } } } debugBuffer.Tid = oldTid; return; }
/* ** View the source for the lines specified. */ int CommandView(char **ptrs) { DebugModule *module; char *srcEnd; ULONG addr; ULONG lineNum; char funcName[MAX_FUNCNAME]; char sourceName[CCHMAXPATH]; /* ** Get the common data. */ module = FindModule(debugBuffer.MTE, NULL); FindSource(module, Linearize(debugBuffer.EIP, debugBuffer.CS), funcName, sourceName, &lineNum); /* ** View the next lines to be displayed. */ if(ptrs[2] == NULL) { DisplaySource(module, sourceName, GetLastLine(module) + 5); return -1; } /* ** View a line. */ if(ptrs[2][0] == '.') { /* ** Find the line number or the file name/line number */ if(isdigit(ptrs[2][1])) { lineNum = atol(&ptrs[2][1]); } else { strcpy(sourceName, &ptrs[2][1]); *strrchr(sourceName, ':') = 0; lineNum = atol(strrchr(ptrs[2], ':') + 1); } DisplaySource(module, sourceName, lineNum); return -1; } /* ** Get a view at a given offset. */ if(isxdigit(ptrs[2][0])) { /* ** Find the module associated with the address specified. */ debugBuffer.Addr = addr = StrToAddr(ptrs[2], TOADDR_CODE); DispatchCommand(DBG_C_AddrToObject); /* ** Find the module/source associated with the information given. */ module = FindModule(debugBuffer.MTE, NULL); FindSource(NULL, addr, funcName, sourceName, &lineNum); DisplaySource(module, sourceName, lineNum); return -1; } /* ** ERROR! */ fprintf(logFile, "Invalid syntax\n"); return -1; }
void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command, parameterlist& params) { User* who = FindSource(prefix, command); if (!who) { ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Command '%s' from unknown prefix '%s'! Dropping entire command.", command.c_str(), prefix.c_str()); return; } /* * Check for fake direction here, and drop any instances that are found. * What is fake direction? Imagine the following server setup: * 0AA <-> 0AB <-> 0AC * Fake direction would be 0AC sending a message to 0AB claiming to be from * 0AA, or something similar. Basically, a message taking a path that *cannot* * be correct. * * When would this be seen? * Well, hopefully never. It could be caused by race conditions, bugs, or * "miscreant" servers, though, so let's check anyway. -- w * * We also check here for totally invalid prefixes (prefixes that are neither * a valid SID or a valid UUID, so that invalid UUID or SID never makes it * to the higher level functions. -- B */ TreeServer* const server = TreeServer::Get(who); if (server->GetSocket() != this) { ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Protocol violation: Fake direction '%s' from connection '%s'", prefix.c_str(), linkID.c_str()); return; } // Translate commands coming from servers using an older protocol if (proto_version < ProtocolVersion) { if (!PreProcessOldProtocolMessage(who, command, params)) return; } ServerCommand* scmd = Utils->Creator->CmdManager.GetHandler(command); CommandBase* cmdbase = scmd; Command* cmd = NULL; if (!scmd) { // Not a special server-to-server command cmd = ServerInstance->Parser.GetHandler(command); if (!cmd) { if (command == "ERROR") { this->Error(params); return; } throw ProtocolException("Unknown command"); } cmdbase = cmd; } if (params.size() < cmdbase->min_params) throw ProtocolException("Insufficient parameters"); if ((!params.empty()) && (params.back().empty()) && (!cmdbase->allow_empty_last_param)) { // the last param is empty and the command handler doesn't allow that, check if there will be enough params if we drop the last if (params.size()-1 < cmdbase->min_params) return; params.pop_back(); } CmdResult res; if (scmd) res = scmd->Handle(who, params); else { res = cmd->Handle(params, who); if (res == CMD_INVALID) throw ProtocolException("Error in command handler"); } if (res == CMD_SUCCESS) Utils->RouteCommand(server->GetRoute(), cmdbase, params, who); }
int DCppTemplate::GetSourceBlockNum() { return FindSource().size(); }