예제 #1
0
bool CryptManager::VerifyFileWithFile( RString sPath, RString sSignatureFile, RString sPublicKeyFile )
{
	if( sSignatureFile.empty() )
		sSignatureFile = sPath + SIGNATURE_APPEND;

	RString sPublicKey;
	if( !GetFileContents(sPublicKeyFile, sPublicKey) )
		return false;

	int iBytes = FILEMAN->GetFileSizeInBytes( sSignatureFile );
	if( iBytes > MAX_SIGNATURE_SIZE_BYTES )
		return false;

	RString sSignature;
	if( !GetFileContents(sSignatureFile, sSignature) )
		return false;

	RageFile file;
	if( !file.Open(sPath) )
	{
		LOG->Warn( "Verify: open(%s) failed: %s", sPath.c_str(), file.GetError().c_str() );
		return false;
	}

	return Verify( file, sSignature, sPublicKey );
}
예제 #2
0
void CryptManager::GenerateGlobalKeys()
{
	//
	// generate keys if none are available
	//
	bool bGenerate = false;
	RSAKeyWrapper key;
	RString sKey;
	RString sError;
	if( !DoesFileExist(PRIVATE_KEY_PATH) ||
	    !GetFileContents(PRIVATE_KEY_PATH, sKey) ||
	    !key.Load(sKey, sError) )
		bGenerate = true;
	if( !sError.empty() )
		LOG->Warn( "Error loading RSA key: %s", sError.c_str() );

	sError.clear();
	if( !DoesFileExist(PUBLIC_KEY_PATH) ||
	    !GetFileContents(PUBLIC_KEY_PATH, sKey) ||
	    !key.Load(sKey, sError) )
		bGenerate = true;
	if( !sError.empty() )
		LOG->Warn( "Error loading RSA key: %s", sError.c_str() );

	if( bGenerate )
	{
		LOG->Warn( "Keys missing or failed to load.  Generating new keys" );
		GenerateRSAKeyToFile( KEY_LENGTH, PRIVATE_KEY_PATH, PUBLIC_KEY_PATH );
	}
}
예제 #3
0
String FindHaxelib(String inLib)
{
   bool gLoadDebug = getenv("HXCPP_LOAD_DEBUG");

   // printf("FindHaxelib %S\n", inLib.__s);
   String haxepath = GetEnv("HAXEPATH");
   if (gLoadDebug) printf("HAXEPATH env:%s\n", haxepath.__s);
   if (haxepath.length==0)
   {
       String home = GetEnv("HOME") + HX_CSTRING("/.haxelib");
       haxepath = GetFileContents(home);
       if (gLoadDebug) printf("HAXEPATH home:%s\n", haxepath.__s);
   }
   else
   {
      haxepath += HX_CSTRING("/lib");
   }
   if (gLoadDebug) printf("HAXEPATH dir:%s\n", haxepath.__s);

   if (haxepath.length==0)
   {
       haxepath = GetFileContents(HX_CSTRING("/etc/.haxepath"));
       if (gLoadDebug) printf("HAXEPATH etc:%s\n", haxepath.__s);
   }

   if (haxepath.length==0)
   {
      #ifdef _WIN32
      haxepath = HX_CSTRING("C:\\Program Files\\Motion-Twin\\haxe\\lib");
      #else
      haxepath = HX_CSTRING("/usr/lib/haxe/lib");
      #endif
       if (gLoadDebug) printf("HAXEPATH default:%s\n", haxepath.__s);
   }

   String dir = haxepath + HX_CSTRING("/") + inLib + HX_CSTRING("/");


   String dev = dir + HX_CSTRING(".dev");
   String path = GetFileContents(dev);
   if (gLoadDebug) printf("Read dev location from file :%s, got %s\n", dev.__s, path.__s);
   if (path.length==0)
   {
      path = GetFileContents(dir + HX_CSTRING(".current"));
      if (path.length==0)
         return null();
      // Replace "." with "," ...
      String with_commas;
      for(int i=0;i<path.length;i++)
         if (path.getChar(i)=='.')
            with_commas += HX_CSTRING(",");
         else
            with_commas += path.substr(i,1);

      path = dir + with_commas + HX_CSTRING("/");
   }

   return path;
}
예제 #4
0
    SEXPR* PARSER::ParseFromFile( const std::string &aFileName )
    {
        std::string str = GetFileContents( aFileName );

        std::string::const_iterator it = str.begin();
        return parseString( str, it );
    }
예제 #5
0
cl_program OCL_Device::GetProgram (const char* sProgramName)
{
	std::string sFile = GetFileContents(sProgramName);
	const char* pFile = sFile.c_str();
	const size_t lFile = sFile.length();

	cl_int err;
	cl_program program = clCreateProgramWithSource(m_context, 1, 
		(const char** const)&pFile, &lFile, &err); 
	CHECK_OPENCL_ERROR(err);

	err = clBuildProgram(program, 1, &m_device_id, NULL, NULL, NULL);
	if (err != CL_SUCCESS)
	{
		size_t size;
		clGetProgramBuildInfo (program, m_device_id, 
			CL_PROGRAM_BUILD_LOG, 0, NULL, &size);
		char* sLog = (char*) malloc (size);
		clGetProgramBuildInfo (program, m_device_id, 
			CL_PROGRAM_BUILD_LOG, size, sLog, NULL);
		
		printf ("\n");
		printf("Build Log:\n");
		printf("%s\n", sLog);
		free(sLog);

		CHECK_OPENCL_ERROR(err);
	}

	return program;
}
예제 #6
0
// Attempt to read aFile's contents into aContents, if aFile
// does not exist, create it and initialize its contents
// by calling aInitFunc for the data.
static nsresult
GetOrInit(nsIFile* aDir, const nsACString& filename,
          nsACString& aContents, InitDataFunc aInitFunc)
{
  PRBool exists;

  nsCOMPtr<nsIFile> dataFile;
  nsresult rv = aDir->Clone(getter_AddRefs(dataFile));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = dataFile->AppendNative(filename);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = dataFile->Exists(&exists);
  NS_ENSURE_SUCCESS(rv, rv);

  if (!exists) {
    if (aInitFunc) {
      // get the initial value and write it to the file
      rv = aInitFunc(aContents);
      NS_ENSURE_SUCCESS(rv, rv);
      rv = WriteDataToFile(dataFile, aContents);
    }
    else {
      // didn't pass in an init func
      rv = NS_ERROR_FAILURE;
    }
  }
  else {
    // just get the file's contents
    rv = GetFileContents(dataFile, aContents);
  }

  return rv;
}
예제 #7
0
int CSendMailCombineable::SendAsCombinedMail(const CTGitPathList &list, CGitProgressList* instance)
{
	ASSERT(instance);

	CStringArray attachments;
	CString body;
	for (int i = 0; i < list.GetCount(); ++i)
	{
		if (m_bAttachment)
		{
			attachments.Add(list[i].GetWinPathString());
		}
		else
		{
			CString filename(list[i].GetWinPathString());
			body += filename + _T(":\n");
			if (GetFileContents(filename, body))
			{
				instance->ReportError(_T("Could not open ") + filename);
				return -2;
			}
			body += _T("\n");
		}
	}
	return SendMail(CTGitPath(), instance, m_sSenderName, m_sSenderMail, m_sTo, m_sCC, m_sSubject, body, attachments);
}
예제 #8
0
bool CryptManager::Verify( CString sPath, CString sSignature )
{
	ASSERT( PREFSMAN->m_bSignProfileData );

	CString sPublicKeyFile = PUBLIC_KEY_PATH;
	CString sMessageFilename = sPath;

	CString sPublicKey;
	if( !GetFileContents(sPublicKeyFile, sPublicKey) )
		return false;

	RageFile file;
	if( !file.Open(sPath) )
	{
		LOG->Warn( "Verify: open(%s) failed: %s", sPath.c_str(), file.GetError().c_str() );
		return false;
	}

	CString sError;
	if( !CryptHelpers::VerifyFile(file, sSignature, sPublicKey, sError) )
	{
		LOG->Warn( "Verify(%s) failed: %s", sPath.c_str(), sError.c_str() );
		return false;
	}

	return true;
}
예제 #9
0
json_value* GetApplicationSettings() {
    static json_value* ret = new json_value();
    static bool settings_fetched = false;
    if (settings_fetched)
        return ret;
    settings_fetched = true;
    LOG_DEBUG << "Fetching settings from settings.json file";

    std::string settingsFile = GetExecutableDirectory() + "\\settings.json";
    std::string contents = GetFileContents(settingsFile);
    if (contents.empty()) {
        LOG_WARNING << "Error opening settings.json file";
        return ret;
    }

    json_settings settings;
    memset(&settings, 0, sizeof(json_settings));
    char error[256];
    json_value* json_parsed = json_parse_ex(&settings, contents.c_str(),
                                            &error[0]);
    if (json_parsed == 0) {
        LOG_WARNING << "Error while parsing settings.json file: " << error;
        return ret;
    }
    ret = json_parsed;
    return ret;
}
// IDataObject methods
STDMETHODIMP nsDataObjCollection::GetData(LPFORMATETC pFE, LPSTGMEDIUM pSTM)
{
  static CLIPFORMAT fileDescriptorFlavorA =
                               ::RegisterClipboardFormat(CFSTR_FILEDESCRIPTORA);
  static CLIPFORMAT fileDescriptorFlavorW =
                               ::RegisterClipboardFormat(CFSTR_FILEDESCRIPTORW);
  static CLIPFORMAT fileFlavor = ::RegisterClipboardFormat(CFSTR_FILECONTENTS);

  switch (pFE->cfFormat) {
  case CF_TEXT:
  case CF_UNICODETEXT:
    return GetText(pFE, pSTM);
  case CF_HDROP:
    return GetFile(pFE, pSTM);
  default:
    if (pFE->cfFormat == fileDescriptorFlavorA ||
        pFE->cfFormat == fileDescriptorFlavorW) {
      return GetFileDescriptors(pFE, pSTM);
    }
    if (pFE->cfFormat == fileFlavor) {
      return GetFileContents(pFE, pSTM);
    }
  }
  return GetFirstSupporting(pFE, pSTM);
}
예제 #11
0
static void AllocFFNameTab( char *name, libfile io, arch_header *arch )
/*********************************************************************/
{
    MemFree( arch->ffnametab );
    GetFileContents( name, io, arch, &arch->ffnametab );
    arch->nextffname = arch->ffnametab;
    arch->lastffname = arch->nextffname + arch->size;
}
예제 #12
0
파일: g_loader.c 프로젝트: eygbey/Cynfiny
void ParseObj(Loader* loader, char* filename)
{
	if(filename)
	{
		FileContents contents = GetFileContents(filename);


	}
}
예제 #13
0
bool USBDevice::GetInterfaceProperty( const CString &sProperty, const unsigned iInterface, CString &out)
{
	if (iInterface > m_sInterfaceDeviceDirs.size() - 1)
	{
		LOG->Warn( "Cannot access interface %i with USBDevice interface count %i", iInterface, m_sInterfaceDeviceDirs.size() );
		return false;
	}
	CString sTargetFile = "/rootfs/sys/bus/usb/devices/" + m_sDeviceDir + ":" + m_sInterfaceDeviceDirs[iInterface] + "/" + sProperty;
	return GetFileContents( sTargetFile, out, true );
}
예제 #14
0
bool Shader::LoadFromFile(const std::string& vertexShaderFilename, const std::string& fragmentShaderFilename)
{
    // Read the vertex shader file
    std::vector<char> vertexShader;
    if (!GetFileContents(vertexShaderFilename, vertexShader))
    {
        Err() << "Failed to open vertex shader file \"" << vertexShaderFilename << "\"" << std::endl;
        return false;
    }

    // Read the fragment shader file
    std::vector<char> fragmentShader;
    if (!GetFileContents(fragmentShaderFilename, fragmentShader))
    {
        Err() << "Failed to open fragment shader file \"" << fragmentShaderFilename << "\"" << std::endl;
        return false;
    }

    // Compile the shader program
    return Compile(&vertexShader[0], &fragmentShader[0]);
}
예제 #15
0
bool CryptManager::VerifyFileWithFile( CString sPath, CString sSignatureFile, CString sPublicKeyFile )
{
	ASSERT( PREFSMAN->m_bSignProfileData );

	CString sMessageFilename = sPath;
	if( sSignatureFile.empty() )
		sSignatureFile = sPath + SIGNATURE_APPEND;

	CString sPublicKey;
	if( !GetFileContents(sPublicKeyFile, sPublicKey) )
		return false;

	int iBytes = FILEMAN->GetFileSizeInBytes( sSignatureFile );
	if( iBytes > MAX_SIGNATURE_SIZE_BYTES )
		return false;

	CString sSignature;
	if( !GetFileContents(sSignatureFile, sSignature) )
		return false;

	RageFile file;
	if( !file.Open(sPath) )
	{
		LOG->Warn( "VerifyFileWithFile: open(%s) failed: %s", sPath.c_str(), file.GetError().c_str() );
		return false;
	}

	CString sError;
	if( !CryptHelpers::VerifyFile(file, sSignature, sPublicKey, sError) )
	{
		LOG->Warn( "VerifyFile(%s) failed: %s", sPath.c_str(), sError.c_str() );
		return false;
	}

	return true;
}
예제 #16
0
bool EmbedderTest::OpenDocument(const std::string& filename) {
  file_contents_ = GetFileContents(filename.c_str(), &file_length_);
  if (!file_contents_) {
    return false;
  }

  loader_ = new TestLoader(file_contents_, file_length_);
  file_access_.m_FileLen = static_cast<unsigned long>(file_length_);
  file_access_.m_GetBlock = Get_Block;
  file_access_.m_Param = loader_;

  file_avail_.version = 1;
  file_avail_.IsDataAvail = Is_Data_Avail;

  hints_.version = 1;
  hints_.AddSegment = Add_Segment;

  avail_ = FPDFAvail_Create(&file_avail_, &file_access_);
  (void)FPDFAvail_IsDocAvail(avail_, &hints_);

  if (!FPDFAvail_IsLinearized(avail_)) {
    document_ = FPDF_LoadCustomDocument(&file_access_, nullptr);
  } else {
    document_ = FPDFAvail_GetDocument(avail_, nullptr);
  }

  (void)FPDF_GetDocPermissions(document_);
  (void)FPDFAvail_IsFormAvail(avail_, &hints_);

  IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this);
  memset(platform, 0, sizeof(IPDF_JSPLATFORM));
  platform->version = 2;
  platform->app_alert = AlertTrampoline;

  FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this);
  memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO));
  formfillinfo->version = 1;
  formfillinfo->FFI_SetTimer = SetTimerTrampoline;
  formfillinfo->FFI_KillTimer = KillTimerTrampoline;
  formfillinfo->FFI_GetPage = GetPageTrampoline;
  formfillinfo->m_pJsPlatform = platform;

  form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, formfillinfo);
  FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD);
  FPDF_SetFormFieldHighlightAlpha(form_handle_, 100);

  return true;
}
예제 #17
0
bool Shader::LoadFromFile(const std::string& filename, Type type)
{
    // Read the file
    std::vector<char> shader;
    if (!GetFileContents(filename, shader))
    {
        Err() << "Failed to open shader file \"" << filename << "\"" << std::endl;
        return false;
    }

    // Compile the shader program
    if (type == Vertex)
        return Compile(&shader[0], NULL);
    else
        return Compile(NULL, &shader[0]);
}
예제 #18
0
void CryptManager::SignFileToFile( RString sPath, RString sSignatureFile )
{
	RString sPrivFilename = PRIVATE_KEY_PATH;
	if( sSignatureFile.empty() )
		sSignatureFile = sPath + SIGNATURE_APPEND;

	RString sPrivKey;
	if( !GetFileContents(sPrivFilename, sPrivKey) )
		return;

	RString sSignature;
	if( !Sign(sPath, sSignature, sPrivKey) )
		return;

	WriteFile( sSignatureFile, sSignature );
}
예제 #19
0
bool EmbedderTest::OpenDocument(const std::string& filename) {
  file_contents_ = GetFileContents(filename.c_str(), &file_length_);
  if (!file_contents_) {
    return false;
  }

  loader_ = new TestLoader(file_contents_, file_length_);
  file_access_.m_FileLen = static_cast<unsigned long>(file_length_);
  file_access_.m_GetBlock = Get_Block;
  file_access_.m_Param = loader_;

  file_avail_.version = 1;
  file_avail_.IsDataAvail = Is_Data_Avail;

  hints_.version = 1;
  hints_.AddSegment = Add_Segment;

  avail_ = FPDFAvail_Create(&file_avail_, &file_access_);
  (void) FPDFAvail_IsDocAvail(avail_, &hints_);

  if (!FPDFAvail_IsLinearized(avail_)) {
    document_ = FPDF_LoadCustomDocument(&file_access_, NULL);
  } else {
    document_ = FPDFAvail_GetDocument(avail_, NULL);
  }

  (void) FPDF_GetDocPermissions(document_);
  (void) FPDFAvail_IsFormAvail(avail_, &hints_);

  IPDF_JSPLATFORM platform_callbacks;
  memset(&platform_callbacks, '\0', sizeof(platform_callbacks));
  platform_callbacks.version = 1;
  platform_callbacks.app_alert = Form_Alert;

  FPDF_FORMFILLINFO form_callbacks;
  memset(&form_callbacks, '\0', sizeof(form_callbacks));
  form_callbacks.version = 1;
  form_callbacks.m_pJsPlatform = &platform_callbacks;

  form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, &form_callbacks);
  FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD);
  FPDF_SetFormFieldHighlightAlpha(form_handle_, 100);

  return true;
}
예제 #20
0
int CSendMailCombineable::SendAsSingleMail(const CTGitPath& path, CGitProgressList* instance)
{
	ASSERT(instance);

	CString pathfile(path.GetWinPathString());

	CString body;
	CStringArray attachments;
	if (m_bAttachment)
		attachments.Add(pathfile);
	else if (GetFileContents(pathfile, body))
	{
		instance->ReportError(_T("Could not open ") + pathfile);
		return -2;
	}

	return SendMail(path, instance, m_sSenderName, m_sSenderMail, m_sTo, m_sCC, m_sSubject, body, attachments);
}
예제 #21
0
void CryptManager::SignFileToFile( CString sPath, CString sSignatureFile )
{
	ASSERT( PREFSMAN->m_bSignProfileData );

	CString sPrivFilename = PRIVATE_KEY_PATH;
	CString sMessageFilename = sPath;
	if( sSignatureFile.empty() )
		sSignatureFile = sPath + SIGNATURE_APPEND;

	CString sPrivKey;
	if( !GetFileContents(sPrivFilename, sPrivKey) )
		return;

	if( !IsAFile(sMessageFilename) )
	{
		LOG->Trace( "SignFileToFile: \"%s\" doesn't exist", sMessageFilename.c_str() );
		return;
	}

	RageFile file;
	if( !file.Open(sMessageFilename) )
	{
		LOG->Warn( "VerifyFileWithFile: open(%s) failed: %s", sPath.c_str(), file.GetError().c_str() );
		return;
	}

	CString sSignature;
	CString sError;
	if( !CryptHelpers::SignFile(file, sPrivKey, sSignature, sError) )
	{
		LOG->Warn( "SignFileToFile failed: %s", sError.c_str() );
		return;
	}

	WriteFile( sSignatureFile, sSignature );
}
예제 #22
0
   Handle<Script> ScriptSystem::GetScriptFromFile(const std::string& path)
   {
     
      std::string code;
      bool success = GetFileContents(path, code);
      if(!success)
      {
         LOG_ERROR("Could not load script file from " + path);
         return Handle<Script>();
      }

      HandleScope handle_scope;
      Context::Scope context_scope(GetGlobalContext());
      TryCatch try_catch;
      Local<Script> compiled_script = Script::Compile(ToJSString(code), ToJSString(path));

      if(try_catch.HasCaught())
      {
         ReportException(&try_catch);
         return Handle<Script>();
      }

      return handle_scope.Close(compiled_script);
   }
예제 #23
0
파일: Lib.cpp 프로젝트: Gama11/hxcpp
String FindHaxelib(String inLib)
{
   bool loadDebug = getenv("HXCPP_LOAD_DEBUG");

   // printf("FindHaxelib %S\n", inLib.__s);

   String haxepath;

   #if !defined(HX_WINRT) && !defined(EPPC)
      struct stat s;
      if ( (stat(".haxelib",&s)==0 && (s.st_mode & S_IFDIR) ) )
         haxepath = HX_CSTRING(".haxelib");
      if (loadDebug)
          printf( haxepath.length ? "Found local .haxelib\n" : "No local .haxelib\n");
   #endif

   if (haxepath.length==0)
   {
      haxepath = GetEnv("HAXELIB_PATH");
      if (loadDebug)
         printf("HAXELIB_PATH env:%s\n", haxepath.__s);
   }

   if (haxepath.length==0)
   {
       #ifdef _WIN32
       String home = GetEnv("HOMEDRIVE") + GetEnv("HOMEPATH") + HX_CSTRING("/.haxelib");
       #else
       String home = GetEnv("HOME") + HX_CSTRING("/.haxelib");
       #endif
       haxepath = GetFileContents(home);
       if (loadDebug)
          printf("HAXEPATH home:%s\n", haxepath.__s);
   }

   if (haxepath.length==0)
   {
      haxepath = GetEnv("HAXEPATH");
      if (loadDebug)
         printf("HAXEPATH env:%s\n", haxepath.__s);
      if (haxepath.length>0)
      {
         haxepath += HX_CSTRING("/lib");
      }
   }

   if (loadDebug)
      printf("HAXEPATH dir:%s\n", haxepath.__s);

   if (haxepath.length==0)
   {
       haxepath = GetFileContents(HX_CSTRING("/etc/.haxepath"));
       if (loadDebug) printf("HAXEPATH etc:%s\n", haxepath.__s);
   }

   if (haxepath.length==0)
   {
      #ifdef _WIN32
      haxepath = HX_CSTRING("C:\\HaxeToolkit\\haxe\\lib");
      #else
      haxepath = HX_CSTRING("/usr/lib/haxe/lib");
      #endif
       if (loadDebug) printf("HAXEPATH default:%s\n", haxepath.__s);
   }

   String dir = haxepath + HX_CSTRING("/") + inLib + HX_CSTRING("/");


   String dev = dir + HX_CSTRING(".dev");
   String path = GetFileContents(dev);
   if (loadDebug) printf("Read dev location from file :%s, got %s\n", dev.__s, path.__s);
   if (path.length==0)
   {
      path = GetFileContents(dir + HX_CSTRING(".current"));
      if (path.length==0)
         return null();
      // Replace "." with "," ...
      String with_commas;
      for(int i=0;i<path.length;i++)
         if (path.getChar(i)=='.')
            with_commas += HX_CSTRING(",");
         else
            with_commas += path.substr(i,1);

      path = dir + with_commas + HX_CSTRING("/");
   }

   return path;
}
예제 #24
0
bool ScreenArcadePatch::VerifyPatch( RageFileBasic *pFile, const CStringArray &vsKeyPaths )
{
	/* get the 128-byte patch signature from the end of the file */
	unsigned iFileSize = pFile->GetFileSize() - 128;

	/* fZip contains the ZIP data, fSig contains the RSA signature */
	RageFileBasic *fZip = new RageFileDriverSlice( pFile, 0, iFileSize );
	RageFileBasic *fSig = new RageFileDriverSlice( pFile, iFileSize, 128 );

	CString sPatchSig;
	if( fSig->Read(sPatchSig, 128) < 128 )
	{
		STATE_TEXT( "Patch signature verification failed:\nunexpected end of file." );
		SAFE_DELETE( fSig );
		SAFE_DELETE( fZip );
		return false;
	}

	// attempt to check the signature against all given RSA keys
	bool bVerified = false;

	// if no key paths worked, use this error message
	CString sError = "no signature keys available";

	for( unsigned i = 0; i < vsKeyPaths.size(); i++ )
	{
		if( !IsAFile(vsKeyPaths[i]) )
		{
			LOG->Warn( "RSA key \"%s\" missing.", vsKeyPaths[i].c_str() );
			continue;
		}

		CString sRSAData;
		GetFileContents( vsKeyPaths[i], sRSAData );
		LOG->Trace( "Attempting to verify with %s.", vsKeyPaths[i].c_str() );

		// attempt to verify, early abort if we have a match.
		if( CryptHelpers::VerifyFile(*fZip, sPatchSig, sRSAData, sError) )
			bVerified = true;

		// ignore signature mismatches
		else if( !sError.CompareNoCase("Signature mismatch") )
			continue;

		// if we encountered anything besides a mismatch, continue processing
		break;
	}

	CString sMessage;
	if( bVerified )
		sMessage = "Patch signature verified.";
	else
		sMessage = ssprintf( "Patch signature verification failed:\n"
			"%s\n\n" "The patch file may be corrupt.", sError.c_str() );

	LOG->Trace( sMessage );
	STATE_TEXT( sMessage );

	SAFE_DELETE( fSig );
	SAFE_DELETE( fZip );
	
	return bVerified;
}
예제 #25
0
파일: g_debug.c 프로젝트: eygbey/Cynfiny
FileContents GetLog(){
    char* fname = {"../DebugFile.dm"};

    return GetFileContents(fname);
}
예제 #26
0
static void AllocFNameTab( char *name, libfile io, arch_header *arch )
/********************************************************************/
{
    MemFree( arch->fnametab );
    GetFileContents( name, io, arch, &arch->fnametab );
}
예제 #27
0
bool USBDevice::GetDeviceProperty( const CString &sProperty, CString &out )
{
	CString sTargetFile = "/rootfs/sys/bus/usb/devices/" + m_sDeviceDir + "/" + sProperty;
	return GetFileContents(sTargetFile, out, true);
}
예제 #28
0
int main(int argc,const char** argv)
{
  if(argc <= 3) {
    printf("USAGE: ContactPlan [options] world_file configs stance\n");
    printf("OPTIONS:\n");
    printf("-o filename: the output linear path or multipath (default contactplan.xml)\n");
    printf("-p settings: set the planner configuration file\n");
    printf("-opt: do optimal planning (do not terminate on the first found solution)\n");
    printf("-n iters: set the default number of iterations per step (default 1000)\n");
    printf("-t time: set the planning time limit (default infinity)\n");
    printf("-m margin: set support polygon margin (default 0)\n");
    printf("-r robotindex: set the robot index (default 0)\n");
    return 0;
  }
  Srand(time(NULL));
  int robot = 0;
  const char* outputfile = "contactplan.xml";
  HaltingCondition termCond;
  string plannerSettings;
  int i;
  //parse command line arguments
  for(i=1;i<argc;i++) {
    if(argv[i][0]=='-') {
      if(0==strcmp(argv[i],"-n")) {
	termCond.maxIters = atoi(argv[i+1]);
	i++;
      }
      else if(0==strcmp(argv[i],"-t")) {
	termCond.timeLimit = atof(argv[i+1]);
	i++;
      }
      else if(0==strcmp(argv[i],"-opt")) {
	termCond.foundSolution = false;
      }
      else if(0==strcmp(argv[i],"-p")) {
	if(!GetFileContents(argv[i+1],plannerSettings)) {
	  printf("Unable to load planner settings file %s\n",argv[i+1]);
	  return 1;
	}
	i++;
      }
      else if(0==strcmp(argv[i],"-r")) {
	robot = atoi(argv[i+1]);
	i++;
      }
      else if(0==strcmp(argv[i],"-m")) {
	gSupportPolygonMargin = atof(argv[i+1]);
	i++;
      }
      else if(0==strcmp(argv[i],"-o")) {
	outputfile = argv[i+1];
	i++;
      }
      else {
	printf("Invalid option %s\n",argv[i]);
	return 1;
      }
    }
    else break;
  }
  if(i+3 < argc) {
    printf("USAGE: ContactPlan [options] world_file configs stance\n");
    return 1;
  }
  if(i+3 > argc) {
    printf("Warning: extra arguments provided\n");
  }
  const char* worldfile = argv[i];
  const char* configsfile = argv[i+1];
  const char* stancefile = argv[i+2];

  //Read in the world file
  XmlWorld xmlWorld;
  RobotWorld world;
  if(!xmlWorld.Load(worldfile)) {
    printf("Error loading world XML file %s\n",worldfile);
    return 1;
  }
  if(!xmlWorld.GetWorld(world)) {
    printf("Error loading world file %s\n",worldfile);
    return 1;
  }

  vector<Config> configs;
  {
    //Read in the configurations specified in configsfile
    ifstream in(configsfile);
    if(!in) {
      printf("Error opening configs file %s\n",configsfile);
      return false;
    }
    while(in) {
      Config temp;
      in >> temp;
      if(in) configs.push_back(temp);
    }
    if(configs.size() < 2) {
      printf("Configs file does not contain 2 or more configs\n");
      return 1;
    }
    in.close();
  }

  Stance stance;
  {
    //read in the stance specified by stancefile
    ifstream in(stancefile,ios::in);
    in >> stance;
    if(!in) {
      printf("Error loading stance file %s\n",stancefile);
      return 1;
    }
    in.close();
  }

  //If the stance has no contacts, use ContactPlan.  Otherwise, use StancePlan
  bool ignoreContactForces = false;
  if(NumContactPoints(stance)==0) {
    printf("No contact points in stance, planning without stability constraints\n");
    ignoreContactForces = true;
  }

  //set up the command line, store it into the MultiPath settings
  string cmdline;
  cmdline = argv[0];
  for(int i=1;i<argc;i++) {
    cmdline += " ";
    cmdline += argv[i];
  }
  MultiPath path;
  path.settings["robot"] = world.robots[robot].name;
  path.settings["command"] = cmdline;
  //begin planning
  bool feasible = true;
  Config qstart = world.robots[robot].robot->q;
  for(size_t i=0;i+1<configs.size();i++) {
    MilestonePath mpath;
    bool res = false;
    if(ignoreContactForces)
      res = ContactPlan(world,robot,configs[i],configs[i+1],stance,mpath,termCond,plannerSettings);
    else
      res = StancePlan(world,robot,configs[i],configs[i+1],stance,mpath,termCond,plannerSettings);
    if(!res) {
      printf("Planning from stance %d to %d failed\n",i,i+1);
      path.sections.resize(path.sections.size()+1);
      path.SetStance(stance,path.sections.size()-1);
      path.sections.back().milestones[0] = configs[i];
      path.sections.back().milestones[1] = configs[i+1];
      break;
    }
    else {
      path.sections.resize(path.sections.size()+1);
      path.sections.back().milestones.resize(mpath.NumMilestones());
      path.SetStance(stance,path.sections.size()-1);
      for(int j=0;j<mpath.NumMilestones();j++)
	path.sections.back().milestones[j] = mpath.GetMilestone(j);
      qstart = path.sections.back().milestones.back();
    }
  }
  if(feasible)
    printf("Path planning success! Saving to %s\n",outputfile);
  else
    printf("Path planning failure. Saving placeholder path to %s\n",outputfile);
  const char* ext = FileExtension(outputfile);
  if(ext && 0==strcmp(ext,"path")) {
    printf("Converted to linear path format\n");
    LinearPath lpath;
    Convert(path,lpath);
    ofstream f(outputfile,ios::out);
    lpath.Save(f);
    f.close();
  }
  else 
    path.Save(outputfile);
  return 0;
}
예제 #29
0
void ImportJson(COMMAND_T* pCommand)
{
   char* selectedFile = BrowseForFiles("Select Auphonic JSON file", 0, 0, false, "Auphonic JSON (*.json)\0*.json\0All Files (*.*)\0*.*\0");
   if((selectedFile != 0) && (strlen(selectedFile) > 0))
   {
      std::string rawData = GetFileContents(std::string(selectedFile));
      std::string errorMessage;
      json11::Json cookedData = json11::Json::parse(rawData, errorMessage);
      if(errorMessage.empty() == true)
      {
         std::map<std::string, std::set<ActivityItem>> trackActivities;
         
         const json11::Json statistics = cookedData["statistics"];
         for(const json11::Json& track : statistics["tracks"].array_items())
         {
            const std::string trackId = track["identifier"].string_value();
            if(trackId.empty() == false)
            {
               std::set<ActivityItem> activities;
               for(const json11::Json& activity : track["activity"].array_items())
               {
                  const double begin = activity.array_items()[0].number_value();
                  const double end = activity.array_items()[1].number_value();
                  activities.insert(ActivityItem(begin, end));
               }
               
               if(activities.empty() == false)
               {
                  trackActivities.insert(std::map<std::string, std::set<ActivityItem>>::value_type(trackId, activities));
               }
               else
               {
                  ErrorMessage("No activities for track");
               }
            }
            else
            {
               ErrorMessage("Found invalid track identifier");
            }
         }

         std::map<std::string, MediaTrack*> reaperTracks;
         for(int i = 0; i < GetNumTracks(); ++i)
         {
            MediaTrack* reaperTrack = GetTrack(0, i);
            AssertTrue(reaperTrack != 0);
            std::string trackName = MediaTrack_GetStringProperty(reaperTrack, "P_NAME");
            reaperTracks[trackName] = reaperTrack;
         }
         
         for(const std::map<std::string, std::set<ActivityItem>>::value_type& trackActivity : trackActivities)
         {
            const std::string& trackId = trackActivity.first;
            std::map<std::string, MediaTrack*>::iterator trackIterator = reaperTracks.find(trackId);
            if(trackIterator != reaperTracks.end())
            {
               MediaTrack* reaperTrack = trackIterator->second;
               if(reaperTrack != 0)
               {
                  MediaItem* reaperItem = AddMediaItemToTrack(reaperTrack);
                  if(reaperItem != 0)
                  {
                     const std::set<ActivityItem>& activities = trackActivity.second;
                     for(const ActivityItem& activity : activities)
                     {
                        SetMediaItemPosition(reaperItem, activity.Begin(), true);
                        SetMediaItemLength(reaperItem, activity.Duration(), true);
                        MediaItem_SetStringProperty(reaperItem, "P_NOTES", trackId);
                        
//                        int color = MediaTrack_GetIntProperty(reaperTrack, "I_CUSTOMCOLOR");
                        int color = MediaTrack_GetProperty<int>(reaperTrack, "I_CUSTOMCOLOR");
                        
                        char buffer[4096] = {0};
                        sprintf(buffer, "%s (%.2fs)", trackId.c_str(), activity.Duration());
                        const char* activityLabel = AllocCopyString(buffer);

                        AddProjectMarker2(0, true, activity.Begin(), activity.End(), activityLabel, 0, color);
                     }
                  }
                  else
                  {
                     ErrorMessage("Failed to add activity");
                  }
               }
               else
               {
                  ErrorMessage("Failed to find track");
               }
            }
         }
      }
      else
      {
         ErrorMessage(errorMessage.c_str());
      }
   }
}
예제 #30
0
void Alsa9Buf::GetSoundCardDebugInfo()
{
	static bool done = false;	
	if( done )
		return;
	done = true;

	if( DoesFileExist("/rootfs/proc/asound/version") )
	{
		RString sVersion;
		GetFileContents( "/rootfs/proc/asound/version", sVersion, true );
		LOG->Info( "ALSA: %s", sVersion.c_str() );
	}

	InitializeErrorHandler();

	int card = -1;
	while( dsnd_card_next( &card ) >= 0 && card >= 0 )
	{
		const RString id = ssprintf( "hw:%d", card );
		snd_ctl_t *handle;
		int err;
		err = dsnd_ctl_open( &handle, id, 0 );
		if ( err < 0 )
		{
			LOG->Info( "Couldn't open card #%i (\"%s\") to probe: %s", card, id.c_str(), dsnd_strerror(err) );
			continue;
		}

		snd_ctl_card_info_t *info;
		dsnd_ctl_card_info_alloca(&info);
		err = dsnd_ctl_card_info( handle, info );
		if ( err < 0 )
		{
			LOG->Info( "Couldn't get card info for card #%i (\"%s\"): %s", card, id.c_str(), dsnd_strerror(err) );
			dsnd_ctl_close( handle );
			continue;
		}

		int dev = -1;
		while ( dsnd_ctl_pcm_next_device( handle, &dev ) >= 0 && dev >= 0 )
		{
			snd_pcm_info_t *pcminfo;
			dsnd_pcm_info_alloca(&pcminfo);
			dsnd_pcm_info_set_device(pcminfo, dev);
			dsnd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_PLAYBACK);

			err = dsnd_ctl_pcm_info(handle, pcminfo);
			if ( err < 0 )
			{
				if (err != -ENOENT)
					LOG->Info("dsnd_ctl_pcm_info(%i) (%s) failed: %s", card, id.c_str(), dsnd_strerror(err));
				continue;
			}

			LOG->Info( "ALSA Driver: %i: %s [%s], device %i: %s [%s], %i/%i subdevices avail",
					card, dsnd_ctl_card_info_get_name(info), dsnd_ctl_card_info_get_id(info), dev,
					dsnd_pcm_info_get_id(pcminfo), dsnd_pcm_info_get_name(pcminfo),
					dsnd_pcm_info_get_subdevices_avail(pcminfo),
					dsnd_pcm_info_get_subdevices_count(pcminfo) );

		}
		dsnd_ctl_close(handle);
	}

	if( card == 0 )
		LOG->Info( "No ALSA sound cards were found.");
	
	if( !PREFSMAN->m_iSoundDevice.Get().empty() )
		LOG->Info( "ALSA device overridden to \"%s\"", PREFSMAN->m_iSoundDevice.Get().c_str() );
}