bool CAppreciation::Initialization(PVOID pData)
{
	CHAR szTempPath[MAX_PATH+1] = {0};
	WCHAR szTempPathW[MAX_PATH+1] = {0};
	GetTempPathA(MAX_PATH,szTempPath);
	PathAddBackslashA(szTempPath);
	strcat_s(szTempPath,MAX_PATH,this->DoGetClassName());
	PathAddBackslashA(szTempPath);
	strcat_s(szTempPath,MAX_PATH,"Download");
	PathAddBackslashA(szTempPath);
	MbsToWcs(szTempPath,szTempPathW);
	SHCreateDirectory(NULL,szTempPathW);
	m_cAppreciationTaskList.Initialization("lpvoidray.lingpao8.com","00000000_00027C47",szTempPath,NULL);

	return true;
}
示例#2
0
static BOOL BuildAndSetFolderPath(
    HKEY hKey,
    DWORD dwFlags,
    DWORD csidl,
    LPSTR szPath)
{
    if (dwFlags & CSIDL_MYFLAG_RELATIVE)
    {
        if (!GetWindowsDirectoryA(szPath, MAX_PATH))
            return FALSE;
        PathAddBackslashA(szPath);
    }
#ifdef __APPLE__
    /* On the Apple, user prefs are stored on P:\ which gets
       mapped into the user's preferences folder */
    else if ((dwFlags & (CSIDL_MYFLAG_USERPREFS | CSIDL_MYFLAG_ALLPREFS)) &&
             PathIsDirectoryA ("P:\\"))
    {
        if (dwFlags & CSIDL_MYFLAG_USERPREFS)
            strcpy (szPath, "P:\\User\\");
        else if (dwFlags & CSIDL_MYFLAG_ALLPREFS)
            strcpy (szPath, "P:\\All Users\\");
    }
#endif
    else
    {
        strcpy(szPath, "C:\\");
        if (dwFlags & CSIDL_MYFLAG_USERPREFS)
            strcat (szPath, "Documents and Settings\\User\\");
        else if (dwFlags & CSIDL_MYFLAG_ALLPREFS)
            strcat (szPath, "Documents and Settings\\All Users\\");
    }
    if (CSIDL_Data[csidl].szDefaultPath[0])
        strcat(szPath, CSIDL_Data[csidl].szDefaultPath);
    else
    {
       size_t Len;

       /* Remove trailing backslash, as paths from this set of shell functions
          shouldn't have them */
       Len = strlen (szPath);
       if (szPath[Len - 1] == '\\')
          szPath[Len - 1] = 0;
    }

    if (hKey && RegSetValueExA(hKey,CSIDL_Data[csidl].szValueName,0,REG_SZ,
                               (LPBYTE)szPath,strlen(szPath)+1))
    {
        return FALSE;
    }

    SHCreateDirectoryExA (NULL, szPath, NULL);
    return TRUE;
}
示例#3
0
	Path getApplicationDirectory()
	{
	  string result;
	  string l_drive;
	  string l_directory;
	  char   l_path[MAX_PATH];

	  splitApplicationPath( &l_drive, &l_directory, NULL, NULL );
	  _makepath_s( l_path, l_drive.c_str(), l_directory.c_str(), NULL, NULL );
	  PathAddBackslashA( l_path );
	  result = reinterpret_cast<char*>(l_path);

	  return Path(result);
	}
示例#4
0
int CreateShortcuts(const char *run_cfg_fn, json_t *games)
{
#ifdef _DEBUG
	const char *loader_exe = "thcrap_loader_d.exe";
#else
	const char *loader_exe = "thcrap_loader.exe";
#endif
	int ret = 0;
	size_t self_fn_len = GetModuleFileNameU(NULL, NULL, 0) + 1;
	VLA(char, self_fn, self_fn_len);

	GetModuleFileNameU(NULL, self_fn, self_fn_len);
	PathRemoveFileSpec(self_fn);
	PathAddBackslashA(self_fn);

	// Yay, COM.
	CoInitializeEx(NULL, COINIT_MULTITHREADED);
	{
		const char *key = NULL;
		json_t *cur_game = NULL;
		VLA(char, self_path, self_fn_len);
		strcpy(self_path, self_fn);

		strcat(self_fn, loader_exe);

		log_printf("Creating shortcuts");

		json_object_foreach(games, key, cur_game) {
			const char *game_fn = json_string_value(cur_game);
			const char *link_fn = strings_sprintf(LINK_FN, "%s (%s).lnk", key, run_cfg_fn);
			const char *link_args = strings_sprintf(LINK_ARGS, "\"%s.js\" %s", run_cfg_fn, key);

			log_printf(".");

			if(
				CreateLink(link_fn, self_fn, link_args, self_path, game_fn)
				&& !file_write_error(link_fn)
			) {
				ret = 1;
				break;
			}
		}
		VLA_FREE(self_path);
	}
	VLA_FREE(self_fn);
	CoUninitialize();
	return ret;
}
示例#5
0
/**************************************************************************
 *  CreateCPanelEnumList()
 */
static BOOL CreateCPanelEnumList(IEnumIDListImpl *list, DWORD dwFlags)
{
    CHAR szPath[MAX_PATH];
    WIN32_FIND_DATAA wfd;
    HANDLE hFile;

    TRACE("(%p)->(flags=0x%08x)\n", list, dwFlags);

    /* enumerate control panel folders */
    if (dwFlags & SHCONTF_FOLDERS)
        SHELL_RegisterCPanelFolders(list, HKEY_LOCAL_MACHINE,
                "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace");

    /* enumerate the control panel applets */
    if (dwFlags & SHCONTF_NONFOLDERS)
    {
        LPSTR p;

        GetSystemDirectoryA(szPath, MAX_PATH);
        p = PathAddBackslashA(szPath);
        strcpy(p, "*.cpl");

        TRACE("-- (%p)-> enumerate SHCONTF_NONFOLDERS of %s\n", list, debugstr_a(szPath));
        hFile = FindFirstFileA(szPath, &wfd);

        if (hFile != INVALID_HANDLE_VALUE)
        {
            do
            {
                if (!(dwFlags & SHCONTF_INCLUDEHIDDEN) && (wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
                    continue;

                if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
                    strcpy(p, wfd.cFileName);
                    SHELL_RegisterCPanelApp(list, szPath);
                }
            } while(FindNextFileA(hFile, &wfd));
            FindClose(hFile);
        }

        SHELL_RegisterRegistryCPanelApps(list, HKEY_LOCAL_MACHINE,
                "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls");
        SHELL_RegisterRegistryCPanelApps(list, HKEY_CURRENT_USER,
                "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls");
    }
    return TRUE;
}
示例#6
0
文件: inject.c 项目: GovanifY/thcrap
int thcrap_inject_into_running(HANDLE hProcess, const char *run_cfg_fn)
{
	int ret = -1;
	HMODULE inj_mod = NULL;

	if(GetModuleHandleEx(
		GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
		(LPTSTR)thcrap_inject_into_running,
		&inj_mod
	)) {
		size_t cur_dir_len = GetCurrentDirectory(0, NULL) + 1;
		size_t inj_dir_len = GetModuleFileNameU(inj_mod, NULL, 0) + 1;
		VLA(char, inj_dll, inj_dir_len);
		VLA(char, inj_dir, inj_dir_len);

		STRLEN_DEC(run_cfg_fn);
		size_t param_len = cur_dir_len + run_cfg_fn_len;
		VLA(char, abs_run_cfg_fn, param_len);
		const char *param;

		GetModuleFileNameU(inj_mod, inj_dir, inj_dir_len);
		strncpy(inj_dll, inj_dir, inj_dir_len);
		PathRemoveFileSpec(inj_dir);
		PathAddBackslashA(inj_dir);

		// Allow for relative directory names
		if(PathIsRelativeA(run_cfg_fn)) {
			GetCurrentDirectory(cur_dir_len, abs_run_cfg_fn);
			PathAppendA(abs_run_cfg_fn, run_cfg_fn);
			param = abs_run_cfg_fn;
		} else {
			param = run_cfg_fn;
			param_len = run_cfg_fn_len;
		}
		ret = Inject(hProcess, inj_dir, inj_dll, "thcrap_init", param, param_len);
		VLA_FREE(abs_run_cfg_fn);
		VLA_FREE(inj_dir);
		VLA_FREE(inj_dll);
	}
	return ret;
}
示例#7
0
/*************************************************************************
	Constructor
*************************************************************************/
CHelperSystem::CHelperSystem() : 
	m_pXMLParser(0)
{
	s_pMe = this;

	//Set work dir
	char szDir[MAX_PATH] = {0};
	GetCurrentDirectoryA(MAX_PATH, szDir);
	PathAppendA(szDir, "..\\Helper");
	PathAddBackslashA(szDir);
	m_strWorkDictory = szDir;

	// create TinyXML Parser.
	m_pXMLParser = new CHelperTinyXMLParser;
	// load all helper items.
	m_pHelpItemSet = new CHelperItemSet();
	//debug begin
	//m_pHelpItemSet->ShowPaihang(true);
	//m_pHelpItemSet->InitPaihangTree("104");
	//enddebug
	m_pHelpItemSet->LoadItemSet(CHelperSystem::GetMe()->GetWorkDictory() + "HelperItems.xml");
}
int _tmain(int argc, _TCHAR* argv[])
{
  char *path = NULL, *pathDir = NULL;
  FILE *fpMview = NULL;
  FILE *fpDst = NULL;

  DWORD flag, sizeData, sizeDataDecompressed;

  if(argc<2)goto err;
  fpMview = _wfopen(argv[1], L"rb");
  if(fpMview==NULL)goto err;

  path = (char *)malloc(4096);
  if(path==NULL)goto err;
  pathDir = (char *)malloc(4096);
  if(pathDir==NULL)goto err;

  buf = (BYTE *)malloc(bufSize);
  if(buf==NULL)goto err;

  while(1)
  {
    flag=0;
    sizeData=0;
    sizeDataDecompressed=0;

    int numPath = freadNullStr(fpMview, path, 4096);
    if(numPath==0)goto err;

    SanitizePath(path);

    freadNullStr(fpMview, NULL, 0);
    if(fread(&flag, 1, 4, fpMview)!=4)goto err;
    if(fread(&sizeData, 1, 4, fpMview)!=4)goto err;
    if(fread(&sizeDataDecompressed, 1, 4, fpMview)!=4)goto err;
    
    if(flag & 0x1)printf("\"%s\"  flag=%u (compressed!), size=%u, decompressedSize=%u\n", path, flag, sizeData, sizeDataDecompressed);
    else          printf("\"%s\"  flag=%u, size=%u\n", path, flag, sizeData);

    if(PathCombineA(path, "out\\", path)==NULL)goto err;
    strcpy_s(pathDir, 4096, path);

    PathRemoveFileSpecA(pathDir);
    PathAddBackslashA(pathDir);
    BOOL bRet = MakeSureDirectoryPathExists(pathDir);

    fpDst = fopen(path, "wb");
    if(fpDst==NULL)goto err;

    if(!FILEtoFILE(fpDst, fpMview, sizeData))goto err;

    fclose(fpDst);
  }
  
  if(buf)free(buf);
  if(path)free(path);
  if(pathDir)free(pathDir);
  if(fpMview)fclose(fpMview);
  if(fpDst)fclose(fpDst);
	return 0;

err:
  if(buf)free(buf);
  if(path)free(path);
  if(pathDir)free(pathDir);
  if(fpMview)fclose(fpMview);
  if(fpDst)fclose(fpDst);
  return 0;
}
示例#9
0
void CCommandObj::InitializationConfig(LPCWSTR lpConfigFileFullPath)
{
	Out(Outputs,_T("Initialization Config Starting."));

	bool bRet = false;
	LPCSTR pszValue = NULL;
	TiXmlDocument cXmlDocument;
	TiXmlHandle cConfigObj(&cXmlDocument);
	TiXmlElement * Root;
	ULONG uElementQuantity = 0,uValue = 0;
	char szConfigFilePath[MAX_PATH+1] = {0};


	if(0 == GetModuleFileNameA(NULL,szConfigFilePath,MAX_PATH))
	{
		strcpy_s(szConfigFilePath,ws2s(lpConfigFileFullPath).c_str());
	}else
	{
		PathRemoveFileSpecA(szConfigFilePath);
		PathAddBackslashA(szConfigFilePath);
		strcat_s(szConfigFilePath,ws2s(lpConfigFileFullPath).c_str());
	}

	bRet = cXmlDocument.LoadFile(szConfigFilePath);

	cConfigObj = cConfigObj.FirstChildElement("Monitor");

	if (cConfigObj.ToElement() != NULL)
	{
		m_SecurityData.Type				=	GetBhoListType(cConfigObj.ToElement()->Attribute("BHO"));


		//////////////////////////////////////////////////////////////////////////
		// BHO

		uElementQuantity = 0;

		for(Root = cConfigObj.FirstChildElement("BHO").ToElement();Root;Root = Root->NextSiblingElement("BHO"))
		{
			++uElementQuantity;
		}

		m_SecurityData.ArraySize = uElementQuantity;
		m_SecurityData.BHO = new DATA_BHO[m_SecurityData.ArraySize];
		m_SecurityData.ArrayOffset = sizeof(DATA_SECURITY_BHO);

		uElementQuantity = 0;

		for (Root = cConfigObj.FirstChildElement("BHO").ToElement();Root;Root = Root->NextSiblingElement("BHO"))
		{
			wcscpy_s(m_SecurityData.BHO[uElementQuantity].CLSID,MAX_CLSID_LEN,s2ws_lwr(Root->Attribute("CLSID")).c_str());
			m_SecurityData.BHO[uElementQuantity].CLSID[MAX_CLSID_LEN] = L'\0';

			++uElementQuantity;
		}
	}
	else
	{
		bRet = false;
	}


	Runend(bRet,_T("Initialization Config Successful."));
}
示例#10
0
int __cdecl wmain(int argc, wchar_t *wargv[])
{
	int ret = 0;

	// Global URL cache to not download anything twice
	json_t *url_cache = json_object();
	// Repository ID cache to prioritize the most local repository if more
	// than one repository with the same name is discovered in the network
	json_t *id_cache = json_object();

	json_t *repo_list = NULL;

	const char *start_repo = "http://thcrap.nmlgc.net/repos/nmlgc/";

	json_t *sel_stack = NULL;
	json_t *new_cfg = json_pack("{s[]}", "patches");

	size_t cur_dir_len = GetCurrentDirectory(0, NULL) + 1;
	VLA(char, cur_dir, cur_dir_len);
	json_t *games = NULL;

	const char *run_cfg_fn = NULL;
	const char *run_cfg_fn_js = NULL;
	char *run_cfg_str = NULL;

	json_t *args = json_array_from_wchar_array(argc, wargv);

	wine_flag = GetProcAddress(
		GetModuleHandleA("kernel32.dll"), "wine_get_unix_file_name"
	) != 0;

	strings_mod_init();
	log_init(1);

	// Necessary to correctly process *any* input of non-ASCII characters
	// in the console subsystem
	w32u8_set_fallback_codepage(GetOEMCP());

	GetCurrentDirectory(cur_dir_len, cur_dir);
	PathAddBackslashA(cur_dir);
	str_slash_normalize(cur_dir);

	// Maximize the height of the console window... unless we're running under
	// Wine, where this 1) doesn't work and 2) messes up the console buffer
	if(!wine_flag) {
		CONSOLE_SCREEN_BUFFER_INFO sbi = {0};
		HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
		COORD largest = GetLargestConsoleWindowSize(console);
		HWND console_wnd = GetConsoleWindow();
		RECT console_rect;

		GetWindowRect(console_wnd, &console_rect);
		SetWindowPos(console_wnd, NULL, console_rect.left, 0, 0, 0, SWP_NOSIZE);
		GetConsoleScreenBufferInfo(console, &sbi);
		sbi.srWindow.Bottom = largest.Y - 4;
		SetConsoleWindowInfo(console, TRUE, &sbi.srWindow);
	}

	http_init();

	if(json_array_size(args) > 1) {
		start_repo = json_array_get_string(args, 1);
	}

	log_printf(
		"==========================================\n"
		"Touhou Community Reliant Automatic Patcher - Patch configuration tool\n"
		"==========================================\n"
		"\n"
		"\n"
		"This tool will create a new patch configuration for the\n"
		"Touhou Community Reliant Automatic Patcher.\n"
		"\n"
		"\n"
		"The configuration process has two steps:\n"
		"\n"
		"\t\t1. Selecting patches\n"
		"\t\t2. Download game-independent data\n"
		"\t\t3. Locating game installations\n"
		"\t\t4. Download game-specific data\n"
		"\n"
		"\n"
		"\n"
		"Patch repository discovery will start at\n"
		"\n"
		"\t%s\n"
		"\n"
		"You can specify a different URL as a command-line parameter.\n"
		"Additionally, all patches from previously discovered repositories, stored in\n"
		"subdirectories of the current directory, will be available for selection.\n"
		"\n"
		"\n",
		start_repo
	);
	pause();

	if(RepoDiscoverAtURL(start_repo, id_cache, url_cache)) {
		goto end;
	}
	if(RepoDiscoverFromLocal(id_cache, url_cache)) {
		goto end;
	}
	repo_list = RepoLoad();
	if(!json_object_size(repo_list)) {
		log_printf("No patch repositories available...\n");
		pause();
		goto end;
	}
	sel_stack = SelectPatchStack(repo_list);
	if(json_array_size(sel_stack)) {
		json_t *new_cfg_patches = json_object_get(new_cfg, "patches");
		size_t i;
		json_t *sel;

		log_printf("Downloading game-independent data...\n");
		stack_update(update_filter_global, NULL);

		/// Build the new run configuration
		json_array_foreach(sel_stack, i, sel) {
			json_array_append_new(new_cfg_patches, patch_build(sel));
		}
	}
示例#11
0
bool CCommandObj::FormatResourceHander(PRESOURCEREQUIT pResourceRequit,PRESOURCESENDINFO pResourceObj,__out LPTSTR lpFileFullName)
{
	OutA(Dbg,("Format Resource[%s] Hander Starting."),pResourceRequit->szResourceID);
	bool bRet = TRUE;
	FILE * fConfigFile = NULL;
	CFileExpress cFileExpress;
	DATAPHOENIX dDataPhoenix;

	FormatResourceFullName(pResourceRequit->szResourceID,lpFileFullName,MAX_PATH);
	if (!stricmp(pResourceRequit->szResourceID,MANAGER_CLSID))
	{
		Out(Dbg,_T("Format Resource Config: [%s] Starting."),lpFileFullName);
		cFileExpress.Initialization(lpFileFullName);

		strcpy_s(dDataPhoenix.FilePath,".\\");
		strcpy_s(dDataPhoenix.MD5,cFileExpress.GetFileMD5(32));
		strcpy_s(dDataPhoenix.FileName,"System.Initialization.DLL");
		strcpy_s(dDataPhoenix.CLSID,pResourceRequit->szResourceID);

		dDataPhoenix.dwFileSize = cFileExpress.GetFileSize();
		Out(Dbg,_T("Format Resource Config:[%s] Success."),lpFileFullName);

		pResourceObj->dwResourceType = TYPE_RESOURCE_SYSTEM;
	}else
	{	
		PathRemoveExtension(lpFileFullName);
		PathAddExtension(lpFileFullName,_T(".Cfg"));

		Out(Dbg,_T("Format Resource Config: [%s] Starting."),lpFileFullName);
		if (0 !=_tfopen_s(&fConfigFile,lpFileFullName,_T("rb")))
		{
			Out(Dbg,_T("Format Resource Config: [%s] Failed."),lpFileFullName);
			bRet =  false;
			return bRet;
		}else
		{
			fseek(fConfigFile,sizeof(RESOURCEREQUIT),SEEK_SET);
			fread(&dDataPhoenix,1,sizeof(DATAPHOENIX),fConfigFile);
			fflush(fConfigFile);
			fclose(fConfigFile);
			bRet = true;
		}

		Out(Dbg,_T("Format Resource Config:[%s] Success."),lpFileFullName);

		FormatResourceFullName(pResourceRequit->szResourceID,lpFileFullName,MAX_PATH);


		pResourceObj->dwResourceType = TYPE_RESOURCE_EXECFILE;//TYPE_RESOURCE_DATAFILE;
	}


	pResourceObj->dwResourceLen = dDataPhoenix.dwFileSize;

//	memcpy_s(&pResourceObj->btResourceBag,MAX_BAG_LEN,&m_btResourceBag,MAX_BAG_LEN);

	strcpy_s(pResourceObj->szResourceID,dDataPhoenix.CLSID);

	strcpy_s(pResourceObj->szResourceMD5,dDataPhoenix.MD5);

	strcpy_s(pResourceObj->szResourcePath,dDataPhoenix.FilePath);
	PathAddBackslashA(pResourceObj->szResourcePath);
	strcat_s(pResourceObj->szResourcePath,dDataPhoenix.FileName);

	OutA(Dbg,("Resource[%s] Info: Size:%d MD5:%s FilePath:%s FileName:%s."),dDataPhoenix.CLSID,dDataPhoenix.dwFileSize,dDataPhoenix.MD5,dDataPhoenix.FilePath,dDataPhoenix.FileName);
	OutA(Dbg,("Format Resource[%s] Hander Successful."),pResourceRequit->szResourceID);

	return bRet;
}
示例#12
0
/*************************************************************************
 * PathAddBackslash		[SHELL32.32]
 */
LPVOID WINAPI PathAddBackslashAW(LPVOID lpszPath)
{
	if(SHELL_OsIsUnicode())
	  return PathAddBackslashW(lpszPath);
	return PathAddBackslashA(lpszPath);
}