Пример #1
0
bool DeleteReparsePoint(const string& Object)
{
	block_ptr<REPARSE_DATA_BUFFER> rdb(MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
	if (!GetREPARSE_DATA_BUFFER(Object, rdb.get()))
		return false;

	const os::fs::file fObject(Object, GetDesiredAccessForReparsePointChange(), 0, nullptr, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT);
	if (!fObject)
		return false;

	DWORD dwBytes;
	REPARSE_GUID_DATA_BUFFER rgdb{rdb->ReparseTag};
	return fObject.IoControl(FSCTL_DELETE_REPARSE_POINT,&rgdb,REPARSE_GUID_DATA_BUFFER_HEADER_SIZE,nullptr,0,&dwBytes);
}
      void test_result(const std::string& filename, const unsigned int line_count) {

        typedef Result_database_from_file<ParserResult, result_type> result_database;
        typedef typename result_database::database_type database;
        typedef ElementaryAnalysis<database> indexed_database;
        typedef LexicographicalEvaluation<indexed_database, LexicographicalSeriesPolicy<result_type> > lexicographical_evaluation_type;
        typedef typename lexicographical_evaluation_type::size_type size_type;
        typedef typename lexicographical_evaluation_type::number_type number_type;
        typedef typename lexicographical_evaluation_type::map_solver_evaluation_type map_solver_evaluation_type;
        typedef typename lexicographical_evaluation_type::numerics_solver_on_series_type numerics_solver_on_series_type;

        result_database rdb(filename);
        assert(rdb.result_sequence.size() == line_count);
        indexed_database idb(rdb.db);
        lexicographical_evaluation_type lexicographical_evaluation(idb);

        typedef typename indexed_database::map_solver_benchmarks map_solver_benchmarks;
        typedef typename IteratorHandling::IteratorFirst<typename map_solver_benchmarks::const_iterator>::type iterator;
        const map_solver_benchmarks& map_benchmarks(idb.solved_benchmarks());
        const iterator end(map_benchmarks.end());
        for (iterator i(map_benchmarks.begin()); i != end; ++i) { // loop over all solvers
          const Solver& solver(*i);
          
          const map_solver_evaluation_type& map(lexicographical_evaluation.evaluation(solver));
          typedef typename map_solver_evaluation_type::const_iterator iterator;
          typedef typename IteratorHandling::IteratorSecond<iterator>::type iterator_second;
          OKLIB_TEST_EQUAL(OKlib::SetAlgorithms::sum_sizes(iterator_second(map.begin()), iterator_second(map.end())), OKlib::SetAlgorithms::map_value(idb.solved_series(), solver).size());
          size_type sum = 0;
          const iterator& end(map.end());
          for (iterator j(map.begin()); j != end; ++j) {
            typedef typename lexicographical_evaluation_type::map_series_numerics_type map_series_numerics_type;
            const map_series_numerics_type& map(j -> second);

            typedef typename map_series_numerics_type::const_iterator iterator;
            const iterator& end(map.end());
            for (iterator k(map.begin()); k != end; ++k) {
              const numerics_solver_on_series_type& n(k -> second);

              if (n.first <= 0)
                OKLIB_THROW("n.first <= 0, namely n.first = " + boost::lexical_cast<std::string>(n.first));
              sum += n.first;
              if (n.first != 0 and n.second < 0)
                OKLIB_THROW("n.first = " +  boost::lexical_cast<std::string>(n.first) + ", and n.second < 0, namely n.second = " + boost::lexical_cast<std::string>(n.second));
            }
          }
          if (sum != OKlib::SetAlgorithms::map_value(map_benchmarks, solver).size())
            OKLIB_THROW("sum != OKlib::SetAlgorithms::map_value(map_benchmarks, solver).size(), namely sum = " +  boost::lexical_cast<std::string>(sum) + ", while map_value(map_benchmarks, solver).size() = " + boost::lexical_cast<std::string>(OKlib::SetAlgorithms::map_value(map_benchmarks, solver).size()) + "\nContext: solver = " + boost::lexical_cast<std::string>(solver));
        }
                
      }
Пример #3
0
bool ModifyReparsePoint(const string& Object,const string& NewData)
{
	block_ptr<REPARSE_DATA_BUFFER> rdb(MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
	if (!GetREPARSE_DATA_BUFFER(Object, rdb.get()))
		return false;

	switch (rdb->ReparseTag)
	{
	case IO_REPARSE_TAG_MOUNT_POINT:
		{
			const auto strPrintName = ConvertNameToFull(NewData);
			const auto strSubstituteName = KernelPath(NTPath(strPrintName));
			if (!FillREPARSE_DATA_BUFFER(rdb.get(), strPrintName, strSubstituteName))
			{
				SetLastError(ERROR_INSUFFICIENT_BUFFER);
				return false;
			}
		}
		break;

	case IO_REPARSE_TAG_SYMLINK:
		{
			const auto& strPrintName = NewData;
			auto strSubstituteName = NewData;

			if (IsAbsolutePath(NewData))
			{
				strSubstituteName = KernelPath(NTPath(strSubstituteName));
				rdb->SymbolicLinkReparseBuffer.Flags=0;
			}
			else
			{
				rdb->SymbolicLinkReparseBuffer.Flags=SYMLINK_FLAG_RELATIVE;
			}

			if (!FillREPARSE_DATA_BUFFER(rdb.get(), strPrintName, strSubstituteName))
			{
				SetLastError(ERROR_INSUFFICIENT_BUFFER);
				return false;
			}
		}
		break;

	default:
		return false;
	}

	return SetREPARSE_DATA_BUFFER(Object,rdb.get());
}
Пример #4
0
int main(int argc, char *argv[]){
      	struct stat buf;
        void *start;
        char *point;
        char *point1;
      	if (argc != 3) {
	        fprintf(stderr, "Error input \n");
	        exit(EXIT_FAILURE);
      	}
       	int imgfile = open(argv[1], O_RDONLY);
        char *filename=argv[2];
       	if (imgfile < 0){
            fprintf(stderr, "Error no such file \n");
	          exit(EXIT_FAILURE);
      	}
        fstat(imgfile, &buf);
        start = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, imgfile, 0);
     
        if(start == MAP_FAILED) 
        return;
        
        point=start;
        point1=start;
        block_size=blocksize(point);
        int rd_s=rds(point);
        int rd_b=rdb(point);
        int n=0;
        ss=block_size*rd_s;
        point=point+block_size*rd_s;
        while(point[0]!=0x00){
        readfile(point);

        n++;
        point=point+64;
        }
      //  printf("%d",n);
        getfile(point1,filename,n);


        

//info end

        munmap(start, buf.st_size);
        close(imgfile);

return 0;

}
Пример #5
0
bool GetReparsePointInfo(const string& Object, string &strDestBuff,LPDWORD ReparseTag)
{
	block_ptr<REPARSE_DATA_BUFFER> rdb(MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
	if (!GetREPARSE_DATA_BUFFER(Object, rdb.get()))
		return false;

	if (ReparseTag)
		*ReparseTag=rdb->ReparseTag;

	const auto& Extract = [&](const auto& Buffer)
	{
		const wchar_t *PathBuffer = nullptr;
		auto NameLength = Buffer.PrintNameLength / sizeof(wchar_t);

		if (NameLength)
		{
			PathBuffer = &Buffer.PathBuffer[Buffer.PrintNameOffset / sizeof(wchar_t)];
		}
		else
		{
			NameLength = Buffer.SubstituteNameLength / sizeof(wchar_t);
			PathBuffer = &Buffer.PathBuffer[Buffer.SubstituteNameOffset / sizeof(wchar_t)];
		}

		if (!NameLength)
			return false;

		strDestBuff.assign(PathBuffer, NameLength);
		return true;
	};

	switch (rdb->ReparseTag)
	{
	case IO_REPARSE_TAG_SYMLINK:
		return Extract(rdb->SymbolicLinkReparseBuffer);

	case IO_REPARSE_TAG_MOUNT_POINT:
		return Extract(rdb->MountPointReparseBuffer);

	default:
		return false;
	}
}
Пример #6
0
	void Master::FullResyncRedisSlave(SlaveConnection& slave)
	{
		std::string dump_file_path = m_server->m_cfg.repl_data_dir + "/dump.rdb";
		slave.state = SLAVE_STATE_WAITING_DUMP_DATA;
		if (m_dumping_db)
		{
			slave.sync_offset = m_dumpdb_offset;
			return;
		}
		INFO_LOG("[Master]Start dump data to file:%s", dump_file_path.c_str());
		m_dumping_db = true;
		m_dumpdb_offset = m_backlog.GetReplEndOffset();
		slave.sync_offset = m_dumpdb_offset;

		RedisDumpFile rdb(m_server->m_db, dump_file_path);
		rdb.Dump(DumpRDBRoutine, &m_channel_service);
		INFO_LOG("[REPL]Saved rdb dump file:%s", dump_file_path.c_str());
		OnDumpComplete();
	}
      void test_result(const std::string& filename, const unsigned int line_count) {

        typedef ResultRandomSat result_type;

        typedef Result_database_from_file<ParserResult, result_type> result_database;
        typedef typename result_database::database_type database;
        typedef ElementaryAnalysis<database> indexed_database;
        typedef LexicographicalEvaluationRandom<indexed_database> lexicographical_evaluation_random_unfolded_type;
        typedef typename lexicographical_evaluation_random_unfolded_type::size_type size_type;
        typedef typename lexicographical_evaluation_random_unfolded_type::number_type number_type;
        typedef typename lexicographical_evaluation_random_unfolded_type::numerics_solver_on_series_type numerics_solver_on_series_type;

        result_database rdb(filename);
        assert(rdb.result_sequence.size() == line_count);
        indexed_database idb(rdb.db);
        lexicographical_evaluation_random_unfolded_type lexicographical_evaluation(idb);

        // ###############################################                
      }
Пример #8
0
bool DuplicateReparsePoint(const string& Src,const string& Dst)
{
	block_ptr<REPARSE_DATA_BUFFER> rdb(MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
	return GetREPARSE_DATA_BUFFER(Src, rdb.get()) && SetREPARSE_DATA_BUFFER(Dst, rdb.get());
}
Пример #9
0
bool CreateReparsePoint(const string& Target, const string& Object,ReparsePointTypes Type)
{
	bool Result=false;

	{
		switch (Type)
		{
			case RP_HARDLINK:
				break;
			case RP_EXACTCOPY:
				Result=DuplicateReparsePoint(Target,Object);
				break;
			case RP_SYMLINK:
			case RP_SYMLINKFILE:
			case RP_SYMLINKDIR:
				{
					os::fs::file_status ObjectStatus(Object);
					if(Type == RP_SYMLINK)
					{
						Type = os::fs::is_directory(Target)? RP_SYMLINKDIR : RP_SYMLINKFILE;
					}
					if (imports.CreateSymbolicLinkW && !os::fs::exists(ObjectStatus))
					{
						Result=os::fs::CreateSymbolicLink(Object,Target,Type==RP_SYMLINKDIR?SYMBOLIC_LINK_FLAG_DIRECTORY:0);
					}
					else
					{
						const auto ObjectCreated = Type==RP_SYMLINKDIR?
							os::fs::is_directory(ObjectStatus) || os::fs::create_directory(Object) :
							os::fs::is_file(ObjectStatus) || os::fs::file(Object, 0, 0, nullptr, CREATE_NEW);

						if (ObjectCreated)
						{
							block_ptr<REPARSE_DATA_BUFFER> rdb(MAXIMUM_REPARSE_DATA_BUFFER_SIZE);

							rdb->ReparseTag=IO_REPARSE_TAG_SYMLINK;
							const auto& strPrintName = Target;
							auto strSubstituteName = Target;

							if (IsAbsolutePath(Target))
							{
								strSubstituteName = KernelPath(NTPath(strSubstituteName));
								rdb->SymbolicLinkReparseBuffer.Flags=0;
							}
							else
							{
								rdb->SymbolicLinkReparseBuffer.Flags=SYMLINK_FLAG_RELATIVE;
							}

							if (FillREPARSE_DATA_BUFFER(rdb.get(), strPrintName, strSubstituteName))
							{
								Result=SetREPARSE_DATA_BUFFER(Object,rdb.get());
							}
							else
							{
								SetLastError(ERROR_INSUFFICIENT_BUFFER);
							}
						}
					}
				}
				break;
			case RP_JUNCTION:
			case RP_VOLMOUNT:
			{
				const auto strPrintName = ConvertNameToFull(Target);
				auto strSubstituteName = KernelPath(NTPath(strPrintName));
				block_ptr<REPARSE_DATA_BUFFER> rdb(MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
				rdb->ReparseTag=IO_REPARSE_TAG_MOUNT_POINT;

				if (FillREPARSE_DATA_BUFFER(rdb.get(), strPrintName, strSubstituteName))
				{
					Result=SetREPARSE_DATA_BUFFER(Object,rdb.get());
				}
				else
				{
					SetLastError(ERROR_INSUFFICIENT_BUFFER);
				}
			}
			break;
		}
	}

	return Result;
}
Пример #10
0
void KeyboardInterrupt(int intNum)
{
	ProgramWindow->PrintText("Keypress(%c)\n", (char)rdb(KEY_BUF_ADDR));
	NonspecificEOI();
}
Пример #11
0
bool wxvbamApp::OnInit()
{
	// use consistent names for config
	SetAppName(_("vbam"));
#if (wxMAJOR_VERSION >= 3)
	SetAppDisplayName(_T("VisualBoyAdvance-M"));
#endif
	// load system default locale, if available
	locale.Init();
	locale.AddCatalog(_T("wxvbam"));
	// make built-in xrc file available
	// this has to be done before parent OnInit() so xrc dump works
	wxFileSystem::AddHandler(new wxMemoryFSHandler);
	wxFileSystem::AddHandler(new wxArchiveFSHandler);
	wxMemoryFSHandler::AddFileWithMimeType(wxT("wxvbam.xrs"), builtin_xrs, sizeof(builtin_xrs), wxT("application/zip"));

	if (!wxApp::OnInit())
		return false;

	// prepare for loading xrc files
	wxXmlResource* xr = wxXmlResource::Get();
	// note: if linking statically, next 2 pull in lot of unused code
	// maybe in future if not wxSHARED, load only builtin-needed handlers
	xr->InitAllHandlers();
	wxInitAllImageHandlers();
	get_config_path(config_path);
	// first, load override xrcs
	// this can only override entire root nodes
	// 2.9 has LoadAllFiles(), but this is 2.8, so we'll do it manually
	wxString cwd = wxGetCwd();

	for (int i = 0; i < config_path.size(); i++)
		if (wxDirExists(config_path[i]) && wxSetWorkingDirectory(config_path[i]))
		{
			// *.xr[cs] doesn't work (double the number of scans)
			// 2.9 gives errors for no files found, so manual precheck needed
			// (yet another double the number of scans)
			if (!wxFindFirstFile(wxT("*.xrc")).empty())
				xr->Load(wxT("*.xrc"));

			if (!wxFindFirstFile(wxT("*.xrs")).empty())
				xr->Load(wxT("*.xrs"));
		}

	wxFileName xrcDir(GetConfigurationPath() + wxT("//xrc"), wxEmptyString);

	if (xrcDir.DirExists() && wxSetWorkingDirectory(xrcDir.GetFullPath()) && !wxFindFirstFile(wxT("*.xrc")).empty())
	{
		xr->Load(wxT("*.xrc"));
	}
	else
	{
		// finally, load built-in xrc
		xr->Load(wxT("memory:wxvbam.xrs"));
	}

	wxSetWorkingDirectory(cwd);
	// set up config file
	// this needs to be in a subdir to support other config as well
	// but subdir flag behaves differently 2.8 vs. 2.9.  Oh well.
	// NOTE: this does not support XDG (freedesktop.org) paths
#if defined(__WXMSW__) || defined(__APPLE__)
	wxFileName vbamconf(GetConfigurationPath(), _T("vbam.ini"));
	cfg = new wxFileConfig(wxT("vbam"), wxEmptyString,
	                       vbamconf.GetFullPath(),
	                       wxEmptyString, wxCONFIG_USE_LOCAL_FILE);
#else
	cfg = new wxFileConfig(wxEmptyString, wxEmptyString, wxEmptyString,
	                       wxEmptyString,
	                       // style =
	                       wxCONFIG_USE_GLOBAL_FILE | wxCONFIG_USE_LOCAL_FILE |
	                       wxCONFIG_USE_SUBDIR);
#endif
	// set global config for e.g. Windows font mapping
	wxFileConfig::Set(cfg);
	// yet another bug/deficiency in wxConfig: dirs are not created if needed
	// since a default config is always written, dirs are always needed
	// Can't figure out statically if using wxFileConfig w/o duplicating wx's
	// logic, so do it at run-time
	// wxFileConfig *f = wxDynamicCast(cfg, wxFileConfig);
	// wxConfigBase does not derive from wxObject!!! so no wxDynamicCast
	wxFileConfig* fc = dynamic_cast<wxFileConfig*>(cfg);

	if (fc)
	{
		wxFileName s(wxFileConfig::GetLocalFileName(GetAppName()));
		// at least up to 2.8.12, GetLocalFileName returns the dir if
		// SUBDIR is specified instead of actual file name
		// and SUBDIR only affects UNIX
#if defined(__UNIX__) && !wxCHECK_VERSION(2,9,0)
		s.AppendDir(s.GetFullName());
#endif
		// only the path part gets created
		// note that 0777 is default (assumes umask will do og-w)
		s.Mkdir(0777, wxPATH_MKDIR_FULL);
		s = wxFileName::DirName(GetConfigurationPath());
		s.Mkdir(0777, wxPATH_MKDIR_FULL);
	}

	load_opts();

	// process command-line options
	for (int i = 0; i < pending_optset.size(); i++)
	{
		wxString p = pending_optset[i];
		size_t eqat = p.find(wxT('='));
		p[eqat] = 0;
		opt_set(p.c_str(), p.c_str() + eqat + 1);
	}

	pending_optset.clear();
	wxFileName vba_over(GetConfigurationPath(), wxT("vba-over.ini"));
	wxFileName rdb(GetConfigurationPath(), wxT("Nintendo - Game Boy Advance*.dat"));
	wxFileName scene_rdb(GetConfigurationPath(), wxT("Nintendo - Game Boy Advance (Scene)*.dat"));
	wxFileName nointro_rdb(GetConfigurationPath(), wxT("Official No-Intro Nintendo Gameboy Advance Number (Date).xml"));
	wxString f = wxFindFirstFile(nointro_rdb.GetFullPath(), wxFILE);

	if (!f.empty() && wxFileName(f).IsFileReadable())
		rom_database_nointro = f;

	f = wxFindFirstFile(scene_rdb.GetFullPath(), wxFILE);

	if (!f.empty() && wxFileName(f).IsFileReadable())
		rom_database_scene = f;

	f = wxFindFirstFile(rdb.GetFullPath(), wxFILE);

	while (!f.empty())
	{
		if (f == rom_database_scene.GetFullPath())
		{
			f = wxFindNextFile();
		}
		else if (wxFileName(f).IsFileReadable())
		{
			rom_database = f;
			break;
		}
	}

	// load vba-over.ini
	// rather than dealing with wxConfig's broken search path, just use
	// the same one that the xrc overrides use
	// this also allows us to override a group at a time, add commments, and
	// add the file from which the group came
	wxMemoryInputStream mis(builtin_over, sizeof(builtin_over));
	overrides = new wxFileConfig(mis);
	wxRegEx cmtre;
	// not the most efficient thing to do: read entire file into a string
	// just to parse the comments out
	wxString bovs((const char*)builtin_over, wxConvUTF8, sizeof(builtin_over));
	bool cont;
	wxString s;
	long grp_idx;
#define CMT_RE_START wxT("(^|[\n\r])# ?([^\n\r]*)(\r?\n|\r)\\[")

	for (cont = overrides->GetFirstGroup(s, grp_idx); cont;
	        cont = overrides->GetNextGroup(s, grp_idx))
	{
		// apparently even MacOSX sometimes uses the old \r by itself
		wxString cmt(CMT_RE_START);
		cmt += s + wxT("\\]");

		if (cmtre.Compile(cmt) && cmtre.Matches(bovs))
			cmt = cmtre.GetMatch(bovs, 2);
		else
			cmt = wxEmptyString;

		overrides->Write(s + wxT("/comment"), cmt);
	}

	if (vba_over.FileExists())
	{
		wxStringOutputStream sos;
		wxFileInputStream fis(vba_over.GetFullPath());
		// not the most efficient thing to do: read entire file into a string
		// just to parse the comments out
		fis.Read(sos);
		// rather than assuming the file is seekable, use the string we just
		// read as an input stream
		wxStringInputStream sis(sos.GetString());
		wxFileConfig ov(sis);

		for (cont = ov.GetFirstGroup(s, grp_idx); cont;
		        cont = ov.GetNextGroup(s, grp_idx))
		{
			overrides->DeleteGroup(s);
			overrides->SetPath(s);
			ov.SetPath(s);
			overrides->Write(wxT("path"), GetConfigurationPath());
			// apparently even MacOSX sometimes uses \r by itself
			wxString cmt(CMT_RE_START);
			cmt += s + wxT("\\]");

			if (cmtre.Compile(cmt) && cmtre.Matches(sos.GetString()))
				cmt = cmtre.GetMatch(sos.GetString(), 2);
			else
				cmt = wxEmptyString;

			overrides->Write(wxT("comment"), cmt);
			long ent_idx;

			for (cont = ov.GetFirstEntry(s, ent_idx); cont;
			        cont = ov.GetNextEntry(s, ent_idx))
				overrides->Write(s, ov.Read(s, wxEmptyString));

			ov.SetPath(wxT("/"));
			overrides->SetPath(wxT("/"));
		}
	}

	// create the main window
	frame = wxDynamicCast(xr->LoadFrame(NULL, wxT("MainFrame")), MainFrame);

	if (!frame)
	{
		wxLogError(_("Could not create main window"));
		return false;
	}

	// Create() cannot be overridden easily
	if (!frame->BindControls())
		return false;

	frame->Show(true);
	return true;
}