示例#1
0
void  CTextFile::WriteString( const CUString& wString )
{
	ASSERT( m_pFile );

	CUString strOut( wString );

	if ( m_bWriteAsDosFile )
	{
		strOut += m_strCRLF;
	}
	else
	{
		strOut += m_strLF;
	}
#ifdef _UNICODE
	CHAR* pszUtf = new CHAR[ strOut.GetLength() * 4 ];

		// convert ASCII string to WideCharacter string based on active code page
	int nLen = WideCharToMultiByte(	CP_UTF8 , 
									0,
									strOut,
									-1,
									pszUtf,
									strOut.GetLength() * 4,
									NULL,
									NULL );

	fwrite( pszUtf, 1, nLen - 1, m_pFile );

	delete [] pszUtf;
#else
	fwrite( strOut, 1, strOut.GetLength(), m_pFile );
#endif
}
void DocLatticeReader::Worker::doRun() {

    if (processor_.isActive()) {

        char * tmpFileIn = tempnam(NULL, "psii_");
        char * tmpFileOut = tempnam(NULL, "psio_");
        std::string tmpFileInName(tmpFileIn);
        std::string tmpFileOutName(tmpFileOut);

        std::ofstream strIn(tmpFileIn);
        strIn << inputStream_.rdbuf() << std::flush;
        processor_.getAdapter()->convertWordToText(tmpFileInName, tmpFileOutName);

        std::ifstream strOut(tmpFileOut);
        std::string line;
        while (std::getline(strOut, line)) {
            appendParagraphToLattice_(line, textTags_);
            lattice_.appendString("\n");
        }

        std::remove(tmpFileIn);
        std::remove(tmpFileOut);
        free(tmpFileIn);
        free(tmpFileOut);

    }

}
 std::string StringReadingRandom::value( const shawn::Vec &pos )
    const throw()
 {
    std::string strOut("str");
    int ival = rand() % 1001;
    strOut += ival;
    return strOut;
 }
示例#4
0
void KdeSudo::receivedOut(KProcess*, char*buffer, int buflen)
{
	char *pcTmp= new char[buflen+1];
	strncpy(pcTmp,buffer,buflen);
	pcTmp[buflen]='\0';
	QString strOut(pcTmp);

	std::cout << strOut << endl;

	static int badpass = 0;

	if (strOut.find("Sorry, try again")!=-1)
	{
		badpass++;
		if (badpass>2)
		{
			bError=true;
			KMessageBox::error(this, i18n("Wrong password! Exiting..."));
			kapp->quit();
		}
	}
	if (strOut.find("command not found")!=-1)
	{
		bError=true;
		KMessageBox::error(this, i18n("Command not found!"));
		kapp->quit();
	}
	if (strOut.find("is not in the sudoers file")!=-1)
	{
		bError=true;
		KMessageBox::error(this, i18n("Your username is unknown to sudo!"));
                kapp->quit();
	}
	if (strOut.find("is not allowed to execute")!=-1)
	{
		bError=true;
		KMessageBox::error(this, i18n("Your user is not allowed to run the specified command!"));
		kapp->quit();
	}
	if (strOut.find("is not allowed to run sudo on")!=-1)
	{
		bError=true;
		KMessageBox::error(this, i18n("Your user is not allowed to run sudo on this host!"));
                kapp->quit();
	}
	if (strOut.find("may not run sudo on")!=-1)
	{
		bError=true;
		KMessageBox::error(this, i18n("Your user is not allowed to run sudo on this host!"));
                kapp->quit();
	}
	if ((strOut.find("passprompt")!=-1) || (strOut.find("PIN (CHV2)")!=-1))
	{
		this->clearPassword();
		this->show();
	}
}
std::string eSDKTool::unicode_w_2_utf8(const std::wstring & uni_str)
{
	if (uni_str.empty())
	{
		return std::string();
	}
	std::string strOut(ctk::to_utf8str(uni_str.c_str()));

	return strOut;
}
示例#6
0
STDMETHODIMP CTNTServer::get_RejectTradeAdd(BYTE* pVal, BSTR *bsReason)
{
	*pVal = m_bRejectTradeAdd? 1:0;
	char chOut[2];
	memset(chOut,0,2);
	chOut[0] = m_chTradeAddRejectionReason;
	_bstr_t strOut(chOut);
	*bsReason = strOut.copy();

	return S_OK;
}
	std::string Utils::TestParameters(std::vector<ScriptParam> testparams, std::vector<ScriptParam> refparams, bool bAllowMore)
	{
		std::string strOut("");
		//test the number of parameters
		if(testparams.size()<refparams.size() || (testparams.size()>refparams.size() && !bAllowMore))
		{
			std::stringstream sstr;
			std::string strNum;
			std::string strErr=std::string("expecting ") + (bAllowMore ? std::string("at least ") : std::string(""));
			sstr<<refparams.size();
			sstr>>strNum;
			sstr.clear();
			strErr=strErr + strNum + std::string(" , not ");
			sstr<<testparams.size();
			sstr>>strNum;
			strErr=strErr + strNum + std::string(" parameters! ");
			strOut=strOut + strErr;
		}
__declspec(noreturn) void __cdecl DumpError(const TCHAR *format, ...)
{
    va_list arglist;

    va_start(arglist, format);

    String strOut(L"\r\nError: ");
    strOut << FormattedStringva(format, arglist);

    OpenLogFile();
    LogFile.WriteAsUTF8(strOut);
    LogFile.WriteStr(TEXT("\r\n"));
    CloseLogFile();

    OSMessageBoxva(format, arglist);

    OSRaiseException(0xDEAD0B5);
}
示例#9
0
std::wstring CStringUtils::Encrypt(const wchar_t * text)
{
    DATA_BLOB blobin = { 0 };
    DATA_BLOB blobout = { 0 };
    std::wstring result;

    blobin.cbData = (DWORD)wcslen(text)*sizeof(wchar_t);
    blobin.pbData = (BYTE*)(LPCWSTR)text;
    if (CryptProtectData(&blobin, L"TSVNAuth", NULL, NULL, NULL, CRYPTPROTECT_UI_FORBIDDEN, &blobout) == FALSE)
        return result;
    DWORD dwLen = 0;
    if (CryptBinaryToStringW(blobout.pbData, blobout.cbData, CRYPT_STRING_HEX | CRYPT_STRING_NOCRLF, NULL, &dwLen) == FALSE)
        return result;
    std::unique_ptr<wchar_t[]> strOut(new wchar_t[dwLen + 1]);
    if (CryptBinaryToStringW(blobout.pbData, blobout.cbData, CRYPT_STRING_HEX | CRYPT_STRING_NOCRLF, strOut.get(), &dwLen) == FALSE)
        return result;
    LocalFree(blobout.pbData);

    result = strOut.get();

    return result;
}
示例#10
0
void __cdecl AppWarning(const TCHAR *format, ...)
{
    if(!format) return;

    va_list arglist;

    va_start(arglist, format);

    String strOut(L"Warning -- ");
    strOut << FormattedStringva(format, arglist);

    if(bLogStarted)
    {
        OpenLogFile();
        LogFile.WriteAsUTF8(strOut, strOut.Length());
        LogFile.WriteAsUTF8(TEXT("\r\n"));
        CloseLogFile();
    }

    OSDebugOut(TEXT("Warning -- "));
    OSDebugOutva(format, arglist);
    OSDebugOut(TEXT("\r\n"));

    //------------------------------------------------------
    // NOTE:
    // If you're seeting this, you can safely continue running, but I recommend fixing whatever's causing this warning.
    //
    // The debug output window contains the warning that has occured.
    //------------------------------------------------------

#if defined(_DEBUG) && defined(_WIN32)
    if(bDebugBreak && OSDebuggerPresent())
    {
        ProgramBreak();
    }
#endif

    StringLog.Append(strOut);
}
示例#11
0
CStringA CStringUtils::Encrypt( const char * text )
{
    DATA_BLOB blobin = {0};
    DATA_BLOB blobout = {0};
    CStringA result;

    blobin.cbData = (DWORD)strlen(text);
    blobin.pbData = (BYTE*) (LPCSTR)text;
    if (CryptProtectData(&blobin, L"TSVNAuth", NULL, NULL, NULL, CRYPTPROTECT_UI_FORBIDDEN, &blobout)==FALSE)
        return result;
    DWORD dwLen = 0;
    if (CryptBinaryToStringA(blobout.pbData, blobout.cbData, CRYPT_STRING_HEX, NULL, &dwLen)==FALSE)
        return result;
    std::unique_ptr<char[]> strOut(new char[dwLen + 1]);
    if (CryptBinaryToStringA(blobout.pbData, blobout.cbData, CRYPT_STRING_HEX, strOut.get(), &dwLen)==FALSE)
        return result;
    LocalFree(blobout.pbData);

    result = strOut.get();

    return result;
}
示例#12
0
//note to self:  do try not to rely on this too much.
__declspec(noreturn) void __cdecl CrashError(const TCHAR *format, ...)
{
    va_list arglist;

    va_start(arglist, format);

    String strOut(L"\r\nError: ");
    strOut << FormattedStringva(format, arglist);

    OpenLogFile();
    LogFile.WriteAsUTF8(strOut);
    LogFile.WriteStr(TEXT("\r\n"));
    CloseLogFile();

    OSMessageBoxva(format, arglist);

#if defined(_DEBUG) && defined(_WIN32)
    if(bDebugBreak && OSDebuggerPresent())
        ProgramBreak();
#endif

    CriticalExit();
}
示例#13
0
文件: Arch.cpp 项目: kumarak/mcsema
// Convert the given assembly instruction into an inline ASM operation in lieu
// of decompiling it. The output instruction will look something like this
// (although note that i128 doesn't work properly with LLVM codegen for the
// inline ASM instructions, necessitating a vector instead).
// %151 = load i128, i128* %XMM0_read
// %152 = bitcast i128 %151 to <16 x i8>
// %153 = load i128, i128* %XMM1_read
// %154 = bitcast i128 %153 to <16 x i8>
// %AESDECrr = call <16 x i8> asm "\09aesdec\09%xmm1, %xmm0", "={XMM0},{XMM0},{XMM1}"(<16 x i8> %152, <16 x i8> %154)
// %155 = bitcast <16 x i8> %AESDECrr to i128
// store volatile i128 %155, i128* %XMM0_write
void ArchBuildInlineAsm(llvm::MCInst &inst, llvm::BasicBlock *block) {
  auto opcode = inst.getOpcode();

  // Use the printer to build the ASM string. We'll need to escape the $ in
  // register names with $$.
  std::stringstream asmString;
  {
    std::string outS;
    llvm::raw_string_ostream strOut(outS);
    gIP->printInst(&inst, strOut, "", *gSTI);
    for (char c : strOut.str()) {
      if (c == '$')
        asmString << "$$";
      else
        asmString << c;
    }
  }

  // Next, find all the registers being used as definitions or uses in the
  // inline ASM. This will write up the constraints for us, as well as
  // provide us with a list of types (for the inline ASM output) and a list of
  // values to pass into the string.
  llvm::SmallVector<llvm::Value *, 3> operands;
  llvm::SmallVector<llvm::Type *, 3> resultTypes;
  std::stringstream constraints;
  for (unsigned i = 0; i < inst.getNumOperands(); i++) {
    llvm::MCOperand &op = inst.getOperand(i);
    if (op.isReg()) {
      unsigned regSize = ArchRegisterSize(op.getReg());
      if (constraints.tellp() > 0) constraints << ",";
      if (i < gMII->get(opcode).getNumDefs()) {
        constraints << "=";

        if (regSize > 64) {
          // LLVM can't handle register constraints of i128, so we
          // need to map this to <16 x i8>.
          resultTypes.push_back(llvm::VectorType::get(
            llvm::Type::getInt8Ty(block->getContext()), regSize / 8));
        } else {
          resultTypes.push_back(llvm::IntegerType::get(block->getContext(),
            regSize));
        }
      } else {
        auto readReg = GENERIC_MC_READREG(block, op.getReg(), regSize);
        if (regSize > 64) {
          // LLVM can't handle register constraints of i128, so we
          // need to map this to <16 x i8>.
          readReg = llvm::CastInst::Create(llvm::Instruction::BitCast, readReg,
            llvm::VectorType::get(llvm::Type::getInt8Ty(block->getContext()), regSize / 8),
            "", block);
        }
        operands.push_back(readReg);
      }
      constraints << "{" << gMRI->getName(op.getReg()) << "}";
    }
  }

  // With all of these pieces, piece together the actual call to the inline ASM
  // string.
  llvm::SmallVector<llvm::Type *, 3> argTypes;
  for (auto val : operands)
    argTypes.push_back(val->getType());

  llvm::Type *returnTy;
  if (resultTypes.empty())
    returnTy = llvm::Type::getVoidTy(block->getContext());
  else if (resultTypes.size() == 1)
    returnTy = resultTypes[0];
  else
    returnTy = llvm::StructType::get(block->getContext(), resultTypes);

  auto asmTy = llvm::FunctionType::get(returnTy, argTypes, false);
  auto callee = llvm::InlineAsm::get(asmTy, asmString.str(), constraints.str(),
      false);
  llvm::Value *resultPack =
    llvm::CallInst::Create(callee, operands, "", block);

  // Unpack the called registers into the LLVM values.
  for (unsigned i = 0; i < resultTypes.size(); i++) {
    llvm::Value *result = resultTypes.size() == 1 ? resultPack :
      llvm::ExtractValueInst::Create(resultPack, i, "", block);
    llvm::Type *ty = resultTypes[i];
    // Cast vector outputs to iXYZ for R_WRITE.
    if (ty->isVectorTy()) {
      ty = llvm::Type::getIntNTy(block->getContext(),
        ty->getVectorNumElements() * 8);
      result = llvm::CastInst::Create(llvm::Instruction::BitCast, result,
        ty, "", block);
    }
    unsigned regNo = inst.getOperand(i).getReg();
    GENERIC_MC_WRITEREG(block, regNo, result);
  }
}
//================================================================================================================
void CreateGameDirectory::CopyAllFiles(char path_in[MAX_PATH], char path_out[MAX_PATH], char sub_path[MAX_PATH])
{
	BetterString strIn(path_in);
	strIn += "\\";

	BetterString strOut(path_out);
	strOut += "\\";

	strcpy_s(path_in, strIn.size(), strIn.toString().c_str());
	strcpy_s(path_out, strOut.size(), strOut.toString().c_str());

	//if (path_in[strlen(path_in) - 1] != '\\')
	//	strcat_s(path_in, strlen(path_in) - 1, "\\");

	//if (path_out[strlen(path_out) -1] != '\\')
	//	strcat_s(path_out, strlen(path_out) - 1, "\\");


	//varibles used for the searching
	HANDLE hFind;
	WIN32_FIND_DATA dataFind;
	bool bMoreFiles = true;

	//strings
	char findpath[250];
	char fullsrcpath[250];
	char fulldestpath[250];
	char in_temp[250];
	char out_temp[250];

	//tell it to find *.*
	sprintf_s(fullsrcpath, "%s%s*.*", path_in, sub_path);
	hFind = FindFirstFile(fullsrcpath, &dataFind);

	while (hFind != INVALID_HANDLE_VALUE && bMoreFiles == true)
	{
		sprintf_s(in_temp, "%s%s%s", path_in, sub_path, dataFind.cFileName);
		sprintf_s(out_temp, "%s%s%s", path_out, sub_path, dataFind.cFileName);

		CopyFile(in_temp, out_temp, TRUE);
		bMoreFiles = FindNextFile(hFind, &dataFind);
	}

	//find new directory
	sprintf_s(fullsrcpath, "%s%s*.", path_in, sub_path);
	hFind = FindFirstFile(fullsrcpath, &dataFind);
	bMoreFiles = true;

	while (hFind != INVALID_HANDLE_VALUE && bMoreFiles == true)
	{
		//make sure it's directory
		if ((dataFind.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 && dataFind.cFileName[0] != '.')
		{
			char temp[50];

			sprintf_s(temp, "%s\\", dataFind.cFileName);

			sprintf_s(in_temp, "%s%s%s", path_in, sub_path, temp);
			sprintf_s(out_temp, "%s%s%s", path_out, sub_path, temp);
			sprintf_s(fullsrcpath, "%s%s", path_in, sub_path);
			sprintf_s(fulldestpath, "%s%s", path_out, sub_path);

			CreateDirectory(out_temp, NULL);
			CopyAllFiles(fullsrcpath, fulldestpath, temp);
		}
		bMoreFiles = FindNextFile(hFind, &dataFind);
	}
}