Пример #1
0
bool ObserverModule::Load()
{
	string strPluginsPath = Info.ModuleName;

	CutToSlash(strPluginsPath);
	strPluginsPath += _T("Formats");

	FSF.FarRecursiveSearch(strPluginsPath, _T("*.so"), (FRSUSERFUNC)LoadObserverPlugins, FRS_RECUR, this);

	m_pPluginInfo = new ArchivePluginInfo[m_Plugins.count()];

	for (unsigned int i = 0; i < m_Plugins.count(); i++)
	{
		ArchivePluginInfo* info = &m_pPluginInfo[i];
		memset(info, 0, sizeof(ArchivePluginInfo));

		ObserverPlugin* pPlugin = m_Plugins[i];

		info->uid = pPlugin->GetUID();
		info->lpModuleName = StrDuplicate(pPlugin->GetModuleName());
		info->uFormats = pPlugin->GetNumberOfFormats();
		info->pFormats = pPlugin->GetFormats();
		info->dwFlags = 0; //нет смысла поддерживать "запрос одного UID", все равно один плагин == один формат
	}

	return m_Plugins.count() > 0;
}
Пример #2
0
int __stdcall ScanDirectory(
		const FAR_FIND_DATA *fdata,
		const TCHAR *lpFullName,
		ScanStruct *pSS
		)
{
	string strFileNameCopy;

	const TCHAR *lpFileName = lpFullName+_tcslen(pSS->lpSourcePath);

	if ( (*lpFileName == _T('\\')) || (*lpFileName == _T('/')) )
		lpFileName++;

	strFileNameCopy = lpFileName;

	ArchiveItem *item = pSS->items->add();

	FindDataToArchiveItem(fdata, item);

	StrFree((void*)item->lpFileName);

	item->lpFileName = StrDuplicate(strFileNameCopy);

	if ( (item->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY )
	{
		pSS->pOS->uTotalFiles++;
		pSS->pOS->uTotalSize += item->nFileSize;
	}

	return TRUE;
}
Пример #3
0
RarModule::RarModule (
		const char *lpFileName
		)
{
	char *lpModuleName = StrDuplicate(Info.ModuleName, 260);

	CutToSlash(lpModuleName);

	strcat (lpModuleName, "unrar.dll");

	m_hModule = LoadLibraryEx (
			lpModuleName,
			NULL,
			LOAD_WITH_ALTERED_SEARCH_PATH
			);

	StrFree (lpModuleName);

	if ( m_hModule )
	{
		m_pfnOpenArchiveEx = (RAROPENARCHIVEEX)GetProcAddress (m_hModule, "RAROpenArchiveEx");
		m_pfnCloseArchive = (RARCLOSEARCHIVE)GetProcAddress (m_hModule, "RARCloseArchive");
		m_pfnReadHeader = (RARREADHEADER)GetProcAddress (m_hModule, "RARReadHeader");
		m_pfnReadHeaderEx = (RARREADHEADEREX)GetProcAddress (m_hModule, "RARReadHeaderEx");
		m_pfnProcessFile = (RARPROCESSFILE)GetProcAddress (m_hModule, "RARProcessFile");
		m_pfnProcessFileW = (RARPROCESSFILEW)GetProcAddress (m_hModule, "RARProcessFileW");
		m_pfnSetCallback = (RARSETCALLBACK)GetProcAddress (m_hModule, "RARSetCallback");
		m_pfnSetProcessDataProc = (RARSETPROCESSDATAPROC)GetProcAddress (m_hModule, "RARSetProcessDataProc");
		m_pfnGetDllVersion = (RARGETDLLVERSION)GetProcAddress (m_hModule, "RARGetDllVersion");
		m_pfnSetPassword = (RARSETPASSWORD)GetProcAddress (m_hModule, "RARSetPassword");
	}
}
Пример #4
0
/**
 * Set a filesystem GUID according to the filesystem name
 * We use a static ID for the first 8 bytes, and then roll the lowercase name
 * for the last 8 bytes (eg. exfat => {'e', 'x', 'f', 'a', 't', 'e', 'x', 'f'})
 */
EFI_GUID *
GetFSGuid(VOID)
{
	INTN i, j, k, Len = StrLen(ShortDriverName);
	static EFI_GUID Guid = { 0xEF1F5EF1, 0xF17E, 0x5857, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } };
	CHAR16 *FsName = StrDuplicate(ShortDriverName);
	const CHAR16 *PlusName = L"plus";
	UINT8 Data4[12];	/* +4 so that we can also reduce something like "1234567plus" into "1234567+" */

	StrLwr(FsName);
	for (i = 0, j = 0, k = 0; j < ARRAYSIZE(Data4); i = (i+1)%Len, j++) {
		/* Convert any 'plus' that is part of the name to '+' */
		if (FsName[i] == PlusName[k]) {
			if (++k == 4) {
				k = 0;
				j -= 3;
				Data4[j] = (UINT8) '+';
			} else {
				Data4[j] = (UINT8) FsName[i];
			}
		} else {
			k = 0;
			Data4[j] = (UINT8) FsName[i];
		}
	}
	FreePool(FsName);
	CopyMem(Guid.Data4, Data4, 8);

	return &Guid;
}
Пример #5
0
int OnConfigureFormat(ConfigureFormatStruct* pCFS)
{
	//пока считаем, что тут у нас uidFormat уникален (а так оно и есть)

	const CompressionFormatInfo* pFormat = GetCompressionFormatInfo(pCFS->uidFormat);

	if ( pFormat )
	{
		SevenZipCompressionConfig* pCfg = SevenZipCompressionConfig::FromString(pFormat, pCFS->lpConfig);

		if ( dlgSevenZipPluginConfigure(pCfg) )
		{
			string strResult;

			pCfg->ToString(strResult);

			MessageBoxW (0, strResult, strResult, MB_OK);

			pCFS->lpResult = StrDuplicate(strResult);
			pCFS->bResult = true;

			return NAERROR_SUCCESS;
		}

		pCFS->bResult = false;
		pCFS->lpResult = nullptr;
	}
	
	return NAERROR_SUCCESS;
}
Пример #6
0
int MultiExPlugin::GetArchiveItem(int hArchive, int& hSearch, ArchiveItem* pItem)
{
	AnsiGuard guard;

	bool bLast = false;

	if ( hSearch == NULL )
		hSearch = m_pfnMpFindFirstFile(hArchive, "*");
	else
		bLast = !m_pfnMpFindNextFile(hSearch);

	if ( hSearch == 0 )
		return E_BROKEN;

	AnsiString strFileSize = m_pfnMpFindInfo(hSearch, "FileSize");

	pItem->nFileSize = atoi(strFileSize);

#ifdef UNICODE
	pItem->lpFileName = AnsiToUnicode(m_pfnMpFindInfo(hSearch, "FileName"));
#else
	pItem->lpFileName = StrDuplicate(m_pfnMpFindInfo(hSearch, "FileName"));
#endif

	if ( bLast )
	{
		m_pfnMpFindClose(hSearch);
		hSearch = 0;

		return E_EOF;
	}

	return E_SUCCESS;
}
Пример #7
0
Archive::Archive (
		ArchivePlugin *pPlugin,
		const char *lpFileName,
		HANDLE hArchive
		)
{

	m_hArchive = hArchive;
	m_pPlugin = pPlugin;
	m_lpFileName = StrDuplicate (lpFileName);
//	m_lpListPassword = NULL;
	m_lpLastUsedPassword = NULL;

	m_nMode = 0;
	m_pInfo = NULL;

	memset (&m_ArchiveLastAccessTime, 0, sizeof (FILETIME));
	m_dwArchiveFileSizeLow = 0;

	GetArchiveFormatStruct GAF;

	GAF.hArchive = m_hArchive;

	if ( m_pPlugin->m_pfnPluginEntry (FID_GETARCHIVEFORMAT, (void*)&GAF) == NAERROR_SUCCESS )
		m_pInfo = m_pPlugin->GetArchiveFormatInfo (GAF.uid);

	m_pCallbackThunk = CreateThunkFastEx(this, (void *)ArchiveCallbackThunk);
}
Пример #8
0
EFI_STATUS
MainMenuF9Func(
  IN EFI_MENU_PAGE                *Page
  )
/*++

Routine Description:

  Handle F9 key in case menu

Arguments:

  Page          - A pointer to the menu

Returns:

  EFI_SUCCESS   - Handle Space key successfully
  Other Value   - Something failed

--*/
{
  EFI_STATUS                Status;
  EFI_INPUT_KEY             Key;
  EFI_DIALOG_CONTEXT        MsgDialogContext;
  CHAR16                   *MsgDialogTitle;

  //
  //check parameter.
  //
  if (Page == NULL) {
    return EFI_INVALID_PARAMETER;
  }

  MsgDialogTitle = StrDuplicate (L"Prepare running...");
  MsgDialogContext.Type = EFI_DIALOG_TYPE_REMINDER;
  DoDialog (MsgDialogTitle, &MsgDialogContext);

  ST->ConOut->SetAttribute (
                ST->ConOut,
                EFI_LIGHTGRAY | EFI_BACKGROUND_BLACK
                );
  ST->ConOut->ClearScreen (ST->ConOut);

  Status = SctExecute ();
  if (Status != EFI_SUCCESS) {
    EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Execute - %r", Status));
  }

  //
  //Clear surplus key stroke.
  //
  Status = EFI_SUCCESS;
  while(!EFI_ERROR(Status)) {
    Status = ST->ConIn->ReadKeyStroke (ST->ConIn, &Key);
  }

  MenuPageRefresh (Page);
  return Status;
}
Пример #9
0
bool ObserverPlugin::Load(const TCHAR* lpModuleName)
{
	m_strModuleName = lpModuleName;
		
	m_hModule = LoadLibraryEx(
			lpModuleName, 
			0, 
			LOAD_WITH_ALTERED_SEARCH_PATH
			);

	if ( m_hModule )
	{
		m_pfnLoadSubModule = (LoadSubModuleFunc)GetProcAddress(m_hModule, "LoadSubModule");
		m_pfnUnloadSubModule = (UnloadSubModuleFunc)GetProcAddress(m_hModule, "UnloadSubModule");
		
		if ( m_pfnLoadSubModule && m_pfnUnloadSubModule ) //в обсервере так
		{
			ModuleLoadParameters params;
			memset(&params, 0, sizeof(params));

			if ( m_pfnLoadSubModule(&params) )
			{
				m_pfnOpenStorage = params.OpenStorage;
				m_pfnCloseStorage = params.CloseStorage;
				m_pfnGetStorageItem = params.GetItem;
				m_pfnExtract = params.ExtractItem;

				m_pFormatInfo = new ArchiveFormatInfo;
				memset(m_pFormatInfo, 0, sizeof(ArchiveFormatInfo));

				m_pFormatInfo->uid = CreateFormatUID(m_uid, FSF.PointToName(lpModuleName)); 
				m_pFormatInfo->dwFlags = AFF_SUPPORT_INTERNAL_EXTRACT|AFF_NEED_EXTERNAL_NOTIFICATIONS;

				string strName = FSF.PointToName(lpModuleName);
				strName += _T(" [observer]");

				m_pFormatInfo->lpName = StrDuplicate(strName);
				m_pFormatInfo->lpDefaultExtention = StrDuplicate(strName); //BUGBUG

				return true;
			}
		}
	}

	return false;
}
Пример #10
0
EFI_STATUS
CreateSingleSupportFile (
  IN EFI_DEVICE_PATH_PROTOCOL     *DevicePath,
  IN CHAR16                       *FileName,
  IN EFI_HANDLE                   ImageHandle,
  IN VOID                         *Context,
  OUT EFI_SCT_TEST_FILE           **SupportFile
  )
/*++

Routine Description:

  Create a test support file data structure.

--*/
{
  EFI_STATUS  Status;

  //
  // Check parameter
  //
  if ((DevicePath == NULL) || (FileName == NULL) || (SupportFile == NULL)) {
    return EFI_INVALID_PARAMETER;
  }

  //
  // Allocate memory for the support file
  //
  Status = BS->AllocatePool (
                 EfiBootServicesData,
                 sizeof(EFI_SCT_TEST_FILE),
                 SupportFile
                 );
  if (EFI_ERROR(Status)) {
    EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Allocate pool - %r", Status));
    return Status;
  }

  ZeroMem (*SupportFile, sizeof(EFI_SCT_TEST_FILE));

  //
  // Initialize the items of support file
  //
  (*SupportFile)->Signature   = EFI_SCT_TEST_FILE_SIGNATURE;
  (*SupportFile)->Revision    = EFI_SCT_TEST_FILE_REVISION;

  (*SupportFile)->DevicePath  = DuplicateDevicePath (DevicePath);
  (*SupportFile)->FileName    = StrDuplicate (FileName);
  (*SupportFile)->ImageHandle = ImageHandle;
  (*SupportFile)->Type        = EFI_SCT_TEST_FILE_TYPE_SUPPORT;
  (*SupportFile)->Context     = Context;

  //
  // Done
  //
  return EFI_SUCCESS;
}
Пример #11
0
RarArchive::RarArchive (RarModule *pModule, const char *lpFileName)
{
	m_pModule = pModule;

	m_pfnRarCallback = CreateThunkFastEx (this, (void *)RarCallbackThunk);
	m_lpFileName = StrDuplicate (lpFileName);

	m_bAborted = false;
}
Пример #12
0
bool ArchivePlugin::Initialize (
		const char *lpModuleName,
		const char *lpLanguage
		)
{
	m_hModule = LoadLibrary (lpModuleName);

	m_pfnGetMsgThunk = NULL;

	m_pLanguageStrings = NULL;
	m_nStringsCount = 0;

	if ( m_hModule )
	{
		m_lpModuleName = StrDuplicate (lpModuleName);

		// global

		m_pfnPluginEntry = (PLUGINENTRY)GetProcAddress (m_hModule, "PluginEntry");

		if ( m_pfnPluginEntry )
		{
			StartupInfo _si;
			FARSTANDARDFUNCTIONS _FSF;
			Helpers _HF;

			_si.Info = Info;

			_HF.Allocate = Allocate;
			_HF.Free = Free;

			_FSF  = FSF;

			_si.Info.FSF = &_FSF;
			_si.HF = _HF;

			m_pfnGetMsgThunk = CreateThunkFastEx(this, (void *)GetMsgThunk);

			strcpy (_si.Info.ModuleName, lpModuleName);

			memcpy (&_si.Info.GetMsg, &m_pfnGetMsgThunk, sizeof(void*));
			ReloadLanguage (lpLanguage);

            m_pfnPluginEntry (FID_INITIALIZE, (void*)&_si);

			memset (&m_ArchivePluginInfo, 0, sizeof (ArchivePluginInfo));

			m_pfnPluginEntry (FID_GETARCHIVEPLUGININFO, (void*)&m_ArchivePluginInfo);

			return true;
		}
	}

	return false;
}
Пример #13
0
void FindDataToArchiveItem(const FAR_FIND_DATA *src, ArchiveItem *dest)
{
	dest->nFileSize = FINDDATA_GET_SIZE_PTR(src);
	dest->dwFileAttributes = src->dwFileAttributes;
			
	memcpy(&dest->ftCreationTime, &src->ftCreationTime, sizeof(FILETIME));
	memcpy(&dest->ftLastWriteTime, &src->ftLastWriteTime, sizeof(FILETIME));
	memcpy(&dest->ftLastAccessTime, &src->ftLastAccessTime, sizeof(FILETIME));

	dest->lpFileName = StrDuplicate(FINDDATA_GET_NAME_PTR(src));
	dest->lpAlternateFileName = NULL;
}
Пример #14
0
int MaPlugin::GetArchiveItem(ArchiveItem* pItem, ArcItemInfo* pInfo)
{
	oldfar::PluginPanelItem item;
	memset(&item, 0, sizeof(oldfar::PluginPanelItem)); //модули глючат и считают, что тут нули

	ArcItemInfo MaItemInfo;
	memset(&MaItemInfo, 0, sizeof(ArcItemInfo));

	int nResult = m_pfnGetArcItem(&item, &MaItemInfo);

	if ( nResult == GETARC_SUCCESS )
	{
#ifdef UNICODE
		pItem->lpFileName = AnsiToUnicode(item.FindData.cFileName);
		pItem->lpAlternateFileName = AnsiToUnicode(item.FindData.cAlternateFileName);
#else
		pItem->lpFileName = StrDuplicate(item.FindData.cFileName);
		pItem->lpAlternateFileName = StrDuplicate(item.FindData.cFileName);
#endif

		pItem->nFileSize = ((unsigned __int64)item.FindData.nFileSizeHigh << 32)+(unsigned __int64)item.FindData.nFileSizeLow;
		pItem->dwFileAttributes = item.FindData.dwFileAttributes;

		pItem->nPackSize = ((unsigned __int64)item.PackSizeHigh << 32)+(unsigned __int64)item.PackSize;
		pItem->dwCRC32 = item.CRC32;

		if ( MaItemInfo.Encrypted )
			pItem->dwFlags |= AIF_CRYPTED;

		if ( MaItemInfo.Solid )
			pItem->dwFlags |= AIF_SOLID;

		if ( pInfo )
			memcpy(pInfo, &MaItemInfo, sizeof(ArcItemInfo));

		return E_SUCCESS;
	}

	return ConvertResult (nResult);
}
Пример #15
0
bool SearchAndLoadLanguageFile(
		const TCHAR* lpPath,
		const TCHAR* lpLanguage,
		TCHAR**& pStrings,
		int& nStringsCount
		)
{
	return FALSE; //BUGBUG

	bool bResult = false;

	TCHAR* lpMask = StrDuplicate(lpPath);
	CutToSlash (lpMask);

	_tcscat (lpMask, _T("*.lng"));

	WIN32_FIND_DATA FindData;

	HANDLE hSearch = FindFirstFile (
			lpMask,
			(WIN32_FIND_DATA*)&FindData
			);

	if ( hSearch != INVALID_HANDLE_VALUE )
	{
		do {

			CutToSlash (lpMask);
			_tcscat (lpMask, FindData.cFileName);

			pStrings = NULL;

			bResult = LoadLanguageFile(
					lpMask,
					lpLanguage,
					pStrings,
					nStringsCount
					);

		} while ( !bResult && FindNextFile (hSearch, (WIN32_FIND_DATA*)&FindData) );

		FindClose (hSearch);
	}

	StrFree(lpMask);

	return bResult;
}
Пример #16
0
void ArchivePlugin::ReloadLanguage (
		const char *lpLanguage
		)
{
	FinalizeLanguageStrings (m_pLanguageStrings, m_nStringsCount);

	char *lpPath = StrDuplicate (m_lpModuleName);

	CutToSlash (lpPath);

	if ( !SearchAndLoadLanguageFile (lpPath, lpLanguage, m_pLanguageStrings, m_nStringsCount) )
		if ( !SearchAndLoadLanguageFile(lpPath, "English", m_pLanguageStrings, m_nStringsCount) )
			SearchAndLoadLanguageFile (lpPath, NULL, m_pLanguageStrings, m_nStringsCount);

	StrFree (lpPath);
}
Пример #17
0
SevenZipArchive::SevenZipArchive (
		const SevenZipModule *pModule,
		unsigned int nFormatIndex,
		const char *lpFileName,
		bool bNewArchive
		)
{
	m_pArchive = NULL;
	m_pInFile = NULL;

	m_nFormatIndex = nFormatIndex;
	m_pModule = pModule;
	m_lpFileName = StrDuplicate (lpFileName);

	//m_bForcedUpdate = false;
	m_bOpened = false;
	m_bNewArchive = bNewArchive;
}
Пример #18
0
bool D5DModule::Load()
{
	string strPluginsPath = Info.ModuleName;

	CutToSlash(strPluginsPath);
	strPluginsPath += _T("Formats");

	FSF.FarRecursiveSearch(strPluginsPath, _T("*.d5d"), (FRSUSERFUNC)LoadD5DPlugins, FRS_RECUR, this);

	m_pPluginInfo = new ArchivePluginInfo[m_Plugins.count()];

	for (int i = 0; i < m_Plugins.count(); i++)
	{
		D5DPlugin* pPlugin = m_Plugins[i];
		ArchivePluginInfo* info = &m_pPluginInfo[i];

		info->dwFlags = 0;
		info->uid = pPlugin->GetUID();
		info->lpModuleName = StrDuplicate(pPlugin->GetModuleName());
		info->uFormats = pPlugin->GetNumberOfFormats();
		info->pFormats = pPlugin->GetFormats();
	}

	string strLanguageFilePath = Info.ModuleName;
	CutToSlash(strLanguageFilePath);

	string strLanguageFileName = strLanguageFilePath;

	string strLanguage;
	apiGetEnvironmentVariable(_T("FARLANG"), strLanguage);

	strLanguageFileName += strLanguage;
	strLanguageFileName += _T(".lng");

	if ( !lng.Load(strLanguageFileName) )
	{
		strLanguageFileName = strLanguageFilePath;
		strLanguageFileName += _T("english.lng");

		lng.Load(strLanguageFileName);
	}

	return (m_Plugins.count() > 0);
}
Пример #19
0
int OnInitialize (StartupInfo *pInfo)
{
    Info = pInfo->Info;
	FSF = *pInfo->Info.FSF;

	char *lpModuleName = StrDuplicate(Info.ModuleName, 260);

	CutToSlash(lpModuleName);
    strcat (lpModuleName, "zlib.dll");
	InitZlib (lpModuleName);

	CutToSlash(lpModuleName);
	strcat (lpModuleName, "bzip2.dll");
	InitBlib (lpModuleName);

	StrFree (lpModuleName);

	return NAERROR_SUCCESS;
}
Пример #20
0
int ObserverPlugin::GetStorageItem(HANDLE hArchive, int nIndex, ArchiveItem* pItem, unsigned int& uNumberOfFiles)
{
	int nResult = E_BROKEN;

	if ( m_pfnGetStorageItem )
	{
		StorageItemInfo item;
		//WIN32_FIND_DATAW fdata;
		//wchar_t wszTempBuffer[4096];

		nResult = m_pfnGetStorageItem(hArchive, nIndex, &item);
		//fdata, wszTempBuffer, sizeof(wszTempBuffer));

		if ( nResult == GET_ITEM_NOMOREITEMS )
			return E_EOF;

		if ( nResult == GET_ITEM_OK )
		{
			memset(pItem, 0, sizeof(ArchiveItem));

#ifdef UNICODE
			pItem->lpFileName = StrDuplicate(item.Path);
#else
			pItem->lpFileName = UnicodeToAnsi(item.Path); 
#endif
			pItem->dwFileAttributes = item.Attributes;
			pItem->nFileSize = item.Size;
				
			memcpy(&pItem->ftCreationTime, &item.CreationTime, sizeof(FILETIME));
			//memcpy(&pItem->ftLastAccessTime, &fdata.ftLastAccessTime, sizeof(FILETIME));
			memcpy(&pItem->ftLastWriteTime, &item.ModificationTime, sizeof(FILETIME));
			
		    pItem->UserData = nIndex+1; 

			if ( !OptionIsOn(pItem->dwFileAttributes, FILE_ATTRIBUTE_DIRECTORY) )
				uNumberOfFiles++;

		    nResult = E_SUCCESS;
		}
	}

	return nResult;
}
Пример #21
0
bool AceModule::Load()
{
	bool bResult = false;

	m_pPlugin = new AcePlugin;

	if ( m_pPlugin )
	{
		string strModuleName = Info.ModuleName;

		CutToSlash(strModuleName);
		strModuleName += _T("unacev2.dll");

		if ( m_pPlugin->Load(strModuleName) )
			bResult = true;
		else
		{
			CutToSlash(strModuleName);
			strModuleName += _T("acev2.dll");

			if ( m_pPlugin->Load(strModuleName) )
				bResult = true;
		}
	}

	if ( bResult )
	{
		m_pPluginInfo = new ArchivePluginInfo;
		memset(m_pPluginInfo, 0, sizeof(ArchivePluginInfo));

		m_pPluginInfo->uid = m_pPlugin->GetUID();
		m_pPluginInfo->lpModuleName = StrDuplicate(m_pPlugin->GetModuleName());
		m_pPluginInfo->uFormats = m_pPlugin->GetNumberOfFormats();
		m_pPluginInfo->pFormats = m_pPlugin->GetFormats();
		m_pPluginInfo->dwFlags = APF_SUPPORT_SINGLE_FORMAT_QUERY;
	}

	return bResult;
}
Пример #22
0
// Function to tell the firmware that OS X is being launched. This is
// required to work around problems on some Macs that don't fully
// initialize some hardware (especially video displays) when third-party
// OSes are launched in EFI mode.
EFI_STATUS SetAppleOSInfo() {
    CHAR16 *AppleOSVersion = NULL;
    CHAR8 *AppleOSVersion8 = NULL;
    EFI_STATUS Status;
    EFI_GUID apple_set_os_guid = EFI_APPLE_SET_OS_PROTOCOL_GUID;
    EfiAppleSetOsInterface *SetOs = NULL;

    Status = refit_call3_wrapper(BS->LocateProtocol, &apple_set_os_guid, NULL, (VOID**) &SetOs);

    // If not a Mac, ignore the call....
    if ((Status != EFI_SUCCESS) || (!SetOs))
        return EFI_SUCCESS;

    if ((SetOs->Version != 0) && GlobalConfig.SpoofOSXVersion) {
        AppleOSVersion = StrDuplicate(L"Mac OS X");
        MergeStrings(&AppleOSVersion, GlobalConfig.SpoofOSXVersion, ' ');
        if (AppleOSVersion) {
            AppleOSVersion8 = AllocateZeroPool((StrLen(AppleOSVersion) + 1) * sizeof(CHAR8));
            UnicodeStrToAsciiStr(AppleOSVersion, AppleOSVersion8);
            if (AppleOSVersion8) {
                Status = refit_call1_wrapper (SetOs->SetOsVersion, AppleOSVersion8);
                if (!EFI_ERROR(Status))
                    Status = EFI_SUCCESS;
                MyFreePool(AppleOSVersion8);
            } else {
                Status = EFI_OUT_OF_RESOURCES;
                Print(L"Out of resources in SetAppleOSInfo!\n");
            }
            if ((Status == EFI_SUCCESS) && (SetOs->Version == 2))
                Status = refit_call1_wrapper (SetOs->SetOsVendor, (CHAR8 *) "Apple Inc.");
            MyFreePool(AppleOSVersion);
        } // if (AppleOSVersion)
    } // if
    if (Status != EFI_SUCCESS)
        Print(L"Unable to set firmware boot type!\n");

    return (Status);
} // EFI_STATUS SetAppleOSInfo()
Пример #23
0
EFI_STATUS
MainMenuClearFunc (
  IN EFI_MENU_PAGE                *Page
  )
{
  EFI_STATUS               Status;
  EFI_DIALOG_CONTEXT       MsgDialogContext;
  CHAR16                  *MsgDialogTitle;

  MsgDialogTitle = StrDuplicate (L"Deleting files ...");
  MsgDialogContext.Type = EFI_DIALOG_TYPE_REMINDER;

  DoDialog (MsgDialogTitle, &MsgDialogContext);

  Status = ResetAllTestResults ();
  MenuPageRefresh (Page);
  if (EFI_ERROR(Status)) {
    EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Reset test results - %r", Status));
    return Status;
  }

  gContinueExec = FALSE;
  return EFI_SUCCESS;
}
Пример #24
0
bool MaModule::Load()
{
	string strPluginsPath = Info.ModuleName;

#ifdef UNICODE
	CutToSlash(strPluginsPath);

	strPluginsPath += _T("ansi.dll");

	bool bAnsiModuleLoaded = false;
	GETPLUGINSSTARTUPINFO pfnGetPluginStartupInfo = nullptr;



	if ( Info.PluginsControl(
			INVALID_HANDLE_VALUE, 
			2/*PCTL_FORCEDLOADPLUGIN*/,  //BUGBUG
			PLT_PATH, 
			(LONG_PTR)strPluginsPath.GetString()
			) )
	{
		HMODULE hAnsiModule = LoadLibraryEx(
				strPluginsPath, 
				NULL, 
				LOAD_WITH_ALTERED_SEARCH_PATH
				);

		if ( hAnsiModule )
		{
			pfnGetPluginStartupInfo = (GETPLUGINSSTARTUPINFO)GetProcAddress(hAnsiModule, "GetPluginStartupInfo");

			if ( pfnGetPluginStartupInfo && pfnGetPluginStartupInfo(&m_pInfo, &m_pFSF) )
				bAnsiModuleLoaded = true;

			FreeLibrary(hAnsiModule);
		}
	}

	if ( !bAnsiModuleLoaded )
	{
		__debug(pfnGetPluginStartupInfo ? _T("ansi.dll was not loaded before ma.module") : _T("error with ansi.dll"));
		return false;
	}

#else
	m_pInfo = (oldfar::PluginStartupInfo*)&Info;
	m_pFSF = (oldfar::FARSTANDARDFUNCTIONS*)&FSF;
#endif


	CutToSlash(strPluginsPath);
	strPluginsPath += _T("Formats");

	FSF.FarRecursiveSearch(strPluginsPath, _T("*.fmt"), (FRSUSERFUNC)LoadMaPlugins, FRS_RECUR, this);

	m_pPluginInfo = new ArchivePluginInfo[m_Plugins.count()];

	for (unsigned int i = 0; i < m_Plugins.count(); i++)
	{
		MaPlugin *pPlugin = m_Plugins[i];
		ArchivePluginInfo *info = &m_pPluginInfo[i];

		info->uid = pPlugin->GetUID();
		info->uFormats = pPlugin->GetNumberOfFormats();
		info->pFormats = pPlugin->GetFormats();
		info->lpModuleName = StrDuplicate(pPlugin->GetModuleName());
		info->dwFlags = 0; //не поддерживаем запрос отдельных форматов
	}

	return m_Plugins.count() > 0;
}
Пример #25
0
CHAR16 *
GetFileNameUnderDir (
  IN  EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,
  IN  CHAR16                      *DirName,
  IN  CHAR16                      *FileName,
  IN OUT UINTN                    *Index
  )
/*++

Routine Description:

  Get file name under this dir with index
  
Arguments:

  DebuggerPrivate - EBC Debugger private data structure
  DirName         - The dir to be read.
  FileName        - The file name pattern under this dir
  Index           - The file index under this dir

Returns:

  File Name which match the pattern and index.

--*/
{
  EFI_STATUS                        Status;
  EFI_FILE_HANDLE                   RootDir;
  EFI_FILE_HANDLE                   Handle;
  UINTN                             FileInfoSize;
  EFI_FILE_INFO                     *FileInfo;
  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL   *Vol;
  VOID                              *TempName;
  UINTN                             FileIndex;

  if (DebuggerPrivate->Vol == NULL) {
    Status = gBS->LocateProtocol (
                    &gEfiSimpleFileSystemProtocolGuid,
                    NULL,
                    &DebuggerPrivate->Vol
                    );
    if (EFI_ERROR(Status)) {
      return NULL;
    }
  }
  Vol = DebuggerPrivate->Vol;

  //
  // Open the root directory
  //
  Status = Vol->OpenVolume (Vol, &RootDir);
  if (EFI_ERROR (Status)) {
    return NULL;
  }

  //
  // Open the file
  //
  Status = RootDir->Open (
                      RootDir,
                      &Handle,
                      DirName,
                      EFI_FILE_MODE_READ,
                      EFI_FILE_DIRECTORY
                      );
  if (EFI_ERROR (Status)) {
    RootDir->Close (RootDir);
    return NULL;
  }
  RootDir->Close (RootDir);

  //
  // Set Dir Position
  //
  Status = Handle->SetPosition (Handle, 0);
  if (EFI_ERROR (Status)) {
    Handle->Close (Handle);
    return NULL;
  }

  //
  // Get the file information
  //
  FileInfoSize = sizeof(EFI_FILE_INFO) + 1024;

  FileInfo = EfiLibAllocateZeroPool (FileInfoSize);
  if (FileInfo == NULL) {
    Handle->Close (Handle);
    return NULL;
  }

  //
  // Walk through each file in the directory
  //
  FileIndex = 0;
  TempName = NULL;
  while (TRUE) {
    //
    // Read a file entry
    //
    FileInfoSize = sizeof(EFI_FILE_INFO) + 1024;

    Status = Handle->Read (
                       Handle,
                       &FileInfoSize,
                       FileInfo
                       );
    if (EFI_ERROR (Status) || (FileInfoSize == 0)) {
      break;
    }

    if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == 0) {
      //
      // This is a file
      //

      //
      // Only deal with the EFI key file
      //
      if (!StrEndWith (FileInfo->FileName, FileName)) {
        continue;
      }

      if (FileIndex == *Index) {
        TempName = StrDuplicate (FileInfo->FileName);
        *Index = *Index + 1;
        break;
      }
      FileIndex ++;
    }
  }

  //
  // Free resources
  //
  gBS->FreePool (FileInfo);
  Handle->Close (Handle);

  return TempName;
}
Пример #26
0
bool ScanMsgsBuf(
		char* buf,
		char* eob,
		const char* lpLanguage,
		TCHAR** pMsgs = NULL,
		int* pStringsCount = NULL
		)
{
	bool bLanguageFound = (lpLanguage == NULL);
	bool bResult = true;

	char* b = buf, *e;
	char *qb, *qe;

	int nCount = 0;

	while ( (b < eob) && bResult )
	{
		e = FindStrEnd(b, eob);

		if ( FindQuotedSubstr(b, e, &qb, &qe) )
		{
			if ( pMsgs )
			{
				INT_PTR nLength = qe-qb;

				char* pSrc = new char[nLength+1];
				memcpy(pSrc, qb, nLength);
				pSrc[nLength] = 0;

#ifdef UNICODE
				TCHAR* pStr = AnsiToUnicode(pSrc, CP_OEMCP);
#else
				TCHAR* pStr = StrDuplicate(pSrc);
#endif

				TCHAR* pDest = new TCHAR[_tcslen(pStr)+1];

				TranslateMessage (pStr, pDest);

				pMsgs[nCount] = pDest;

				delete [] pSrc;
				free(pStr);
			};

			nCount++;
		}
		else
		{
			if ( !bLanguageFound )
			{
				if ( GetLngHlfParam(b, e, &qb, &qe, "Language") )
				{
					bLanguageFound = true;

					int nLength = qe-qb;

					char* lpFileLanguage = new char[nLength+1];
					memcpy(lpFileLanguage, qb, nLength);
					lpFileLanguage[nLength] = 0;

					char* p = strchr(lpFileLanguage, ',');

					if ( p )
						*p = '\0';

					if ( strcmp(lpLanguage, lpFileLanguage) )
						bResult = false;

					delete [] lpFileLanguage;
				}
			}
		}

		b = FindNextStr(e, eob);
    };

    if ( pStringsCount )
    	*pStringsCount = nCount;

    return bResult;
}
Пример #27
0
char*  StrReplace (char* String1, const char *String2)
{
	StrFree (String1);
	return StrDuplicate (String2);
}
Пример #28
0
EFI_STATUS
LoadReportInfor (
  IN CHAR16                       *CaseIndexStr,
  IN CHAR16                       *CaseIterationStr,
  IN CHAR16                       *Buffer,
  IN CHAR16                       *FileName
  )
/*++

Routine Description:

  Load the report information from a buffer.

--*/
{
  EFI_STATUS  Status;
  CHAR16      *LineBuffer;
  CHAR16      *GuidStr;
  CHAR16      *AssertionStr;
  UINTN       AssertionType;
  CHAR16      *TestNameStr;
  CHAR16      *TestCategoryStr;
  CHAR16      *DevicePathStr;
  CHAR16      *TitleStr;
  CHAR16      *RuntimeInforStr;
  CHAR16      *CaseRevisionStr;
  CHAR16      *CaseGuidStr;
  CHAR16      *CaseNameStr;
  CHAR16      GenericGuidStr[EFI_SCT_GUID_LEN];
  CHAR16      SystemHangGuidStr[EFI_SCT_GUID_LEN];

  //
  // Check parameters
  //
  if ((CaseIndexStr == NULL) || (CaseIterationStr == NULL) || (Buffer == NULL)) {
    return EFI_INVALID_PARAMETER;
  }

  //
  // Initialize
  //
  ZeroMem (GenericGuidStr, EFI_SCT_GUID_LEN * sizeof(CHAR16));
  SctGuidToStr (&gTestGenericFailureGuid, GenericGuidStr);

  ZeroMem (SystemHangGuidStr, EFI_SCT_GUID_LEN * sizeof(CHAR16));
  SctGuidToStr (&gEfiSystemHangAssertionGuid, SystemHangGuidStr);

  CaseGuidStr      = NULL;
  CaseRevisionStr  = NULL;
  CaseNameStr      = NULL;
  TestNameStr      = NULL;
  TestCategoryStr  = NULL;
  DevicePathStr    = NULL;

  //
  // Start to deal with the ekl file data
  //
  if (Buffer[0] != 0xFEFF) {
    return EFI_SUCCESS;
  }

  LineBuffer = StrTokenLine (Buffer + 1, L"\n\r");

  while (LineBuffer != NULL) {
    if (LineBuffer[0] == L'|') {
      if (LineBuffer[1] == L'H') {
        //
        // The head line
        //

        StrTokenField (LineBuffer, L"|");

        //
        // Skip the HEAD characters
        //
        StrTokenField (NULL, L"|");

        //
        // Skip the first empty string
        //
        StrTokenField (NULL, L"|");

        //
        // Skip the second empry string
        //
        StrTokenField (NULL, L"|");

        //
        // Skip the configuration number
        //
        StrTokenField (NULL, L"|");

        //
        // Skip the scenario string
        //
        StrTokenField (NULL, L"|");

        //
        // Skip the execution date
        //
        StrTokenField (NULL, L"|");

        //
        // Skip the execution time
        //
        StrTokenField (NULL, L"|");

        //
        // Get the case's GUID
        //
        CaseGuidStr = StrTokenField (NULL, L"|");

        //
        // Get the case's revision
        //
        CaseRevisionStr = StrTokenField (NULL, L"|");

        //
        // Get the case's name
        //
        CaseNameStr = StrTokenField (NULL, L"|");

        //
        // Get the test name
        //
        TestNameStr = StrTokenField (NULL, L"|");

        //
        // Get the test category
        //
        TestCategoryStr = StrTokenField (NULL, L"|");

        //
        // Get the device path
        //
        // Note: Don't use "|" to split the device path token, some device path
        //  include that. And from the other way, the device path token should
        //  be the last token in the .ekl header.
        //
        DevicePathStr = StrTokenField (NULL, L"\n");

      } else if (LineBuffer[1] == L'T') {
        //
        // The terminate line, do nothing
        //
      }

      LineBuffer = StrTokenLine (NULL, L"\n\r");
      continue;
    }

    //
    // The item line
    //

    //
    // Get the assertion's GUID
    //
    GuidStr = StrTokenField (LineBuffer, L":");
    if (GuidStr == NULL) {
      LineBuffer = StrTokenLine (NULL, L"\n\r");
      continue;
    }

    //
    // Ignore the generic GUID
    //
    if (StrCmp (GuidStr, GenericGuidStr) == 0) {
      LineBuffer = StrTokenLine (NULL, L"\n\r");
      continue;
    }

    //
    // Get the assertion's type
    //
    AssertionStr = StrTokenField (NULL, L"|");
    if (AssertionStr == NULL) {
      LineBuffer = StrTokenLine (NULL, L"\n\r");
      continue;
    }

    if (StrCmp (AssertionStr, L"PASS") == 0) {
      AssertionType = EFI_SCT_GUID_ASSERTION_TYPE_PASS;
    } else if (StrCmp (AssertionStr, L"FAILURE") == 0) {
      AssertionType = EFI_SCT_GUID_ASSERTION_TYPE_FAIL;
    } else {
      AssertionType = EFI_SCT_GUID_ASSERTION_TYPE_WARN;
    }

    //
    // Get the Title
    //
    TitleStr = StrTokenField (NULL, L":");
    if (StrCmp (GuidStr, SystemHangGuidStr) == 0) {
      TitleStr = StrDuplicate (L"System hangs or stops abnormally.");
    }

    //
    // Get the runtime information
    //
    RuntimeInforStr = StrTokenField (NULL, L"\n\r");
    if (StrCmp (GuidStr, SystemHangGuidStr) == 0) {
      RuntimeInforStr = PoolPrint (L"System hang in %s - %s", TestCategoryStr, CaseNameStr);
    }

    //
    // Set the report item
    //
    Status = InsertReportInfor (
               CaseIndexStr,
               CaseIterationStr,
               TestNameStr,
               TestCategoryStr,
               GuidStr,
               AssertionType,
               TitleStr,
               RuntimeInforStr,
               DevicePathStr,
               CaseRevisionStr,
               CaseGuidStr,
               FileName
               );
    if (EFI_ERROR (Status)) {
      EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Set report item - %r", Status));
      if (StrCmp (GuidStr, SystemHangGuidStr) == 0) {
        BS->FreePool (TitleStr);
        BS->FreePool (RuntimeInforStr);
      }
      return Status;
    }

    if (StrCmp (GuidStr, SystemHangGuidStr) == 0) {
      BS->FreePool (TitleStr);
      BS->FreePool (RuntimeInforStr);
    }

    //
    // Next line
    //
    LineBuffer = StrTokenLine (NULL, L"\n\r");
  }

  return EFI_SUCCESS;
}
Пример #29
0
EFI_STATUS
MainMenuSaveSeqFunc (
  IN EFI_MENU_PAGE                *Page
  )
{
  EFI_STATUS              Status;
  EFI_FILE_DIALOG_CONTEXT *DialogContext;
  CHAR16                  *FileName;
  EFI_DIALOG_CONTEXT       MsgDialogContext;
  CHAR16                  *MsgDialogTitle;

  DialogContext = NULL;
  //
  //allocate a new efi file dialog context.
  //
  Status = BS->AllocatePool (
                 EfiBootServicesData,
                 sizeof(EFI_FILE_DIALOG_CONTEXT),
                 (VOID **)&DialogContext
                 );
  if (EFI_ERROR (Status)) {
    return EFI_DEVICE_ERROR;
  }

  BS->SetMem (DialogContext, sizeof(EFI_FILE_DIALOG_CONTEXT), 0);
  DialogContext->DialogType = EFI_FILE_DIALOG_TYPE_SAVE_FILE;
  DialogContext->FileType = EFI_FILTER_FILE_TYPE_SEQ;

  //
  //get devicepath and filename through FileDialog
  //
  Status = DoFileDialog (DialogContext);

  if (EFI_ERROR (Status)) {
    MsgDialogTitle = StrDuplicate (L"Save Sequence Error!");
    MsgDialogContext.Type = EFI_DIALOG_TYPE_MESSAGE;
    MenuPageRefresh (Page);
    DoDialog (MsgDialogTitle, &MsgDialogContext);
  } else if (DialogContext->DevicePath != NULL && DialogContext->FileName != NULL
    && DialogContext->FileName[0] != L'\0') {
    //
    //make up file name
    //
    if (StrLen (DialogContext->FileName) > 4 &&
      StriCmp (DialogContext->FileName + StrLen (DialogContext->FileName) - 4, L".seq") == 0) {
      FileName = StrDuplicate (DialogContext->FileName);
    }else if ( StrLen (DialogContext->FileName) > 1 &&
       StriCmp (DialogContext->FileName + StrLen (DialogContext->FileName) - 1, L".") == 0) {
       FileName = PoolPrint (L"%sseq", DialogContext->FileName);
    }else {
      FileName = PoolPrint (L"%s.seq", DialogContext->FileName);
    }
    if (FileName == NULL) {
      BS->FreePool (DialogContext->DevicePath);
      BS->FreePool (DialogContext->FileName);
      BS->FreePool (DialogContext);
      return EFI_DEVICE_ERROR;
    }

    Status = SaveTestSequence (
               gFT->DevicePath,
               FileName,
               &gFT->TestCaseList
               );
    if (EFI_ERROR (Status)) {
      MsgDialogTitle = StrDuplicate (L"Save sequence Error!");
    } else {
      MsgDialogTitle = StrDuplicate (L"Save sequence Succeed!");
    }

    MsgDialogContext.Type = EFI_DIALOG_TYPE_MESSAGE;
    MenuPageRefresh (Page);
    DoDialog (MsgDialogTitle, &MsgDialogContext);

    BS->FreePool (FileName);
    BS->FreePool (DialogContext->DevicePath);
    BS->FreePool (DialogContext->FileName);
  } else {
    if (DialogContext->FileName != NULL) {
      BS->FreePool (DialogContext->FileName);
    }
    if (DialogContext->DevicePath != NULL) {
      BS->FreePool (DialogContext->DevicePath);
    }
  }

  BS->FreePool (DialogContext);
  MenuPageRefresh (Page);
  return EFI_SUCCESS;
}
Пример #30
0
EFI_STATUS
EFIAPI
TOLOpen (
    IN EFI_TEST_OUTPUT_LIBRARY_PROTOCOL       *This,
    IN EFI_DEVICE_PATH_PROTOCOL               *DevicePath,
    IN CHAR16                                 *FileName,
    IN BOOLEAN                                OverwriteFile,
    OUT EFI_FILE                              **FileHandle
)
/*++

Routine Description:

  One interface function of the TestOutputLibrary to open a file.

Arguments:

  This                  - the protocol instance structure.
  DevicePath            - the file's root device path.
  FileName              - the file's name relative to the root.
  OverwriteFile         - whether to overwrite the file.
  FileHandle            - return the file's handle.

Returns:

  EFI_SUCCESS           - open the file successfully.
  EFI_NOT_READY         - to overwrite an opened file is not allowed.
  EFI_OUT_OF_RESOURCES  - not enough memory.

--*/
{
    EFI_STATUS                        Status;
    TEST_OUTPUT_FILE                  *OutputFile;
    TEST_OUTPUT_PRIVATE_DATA          *Private;
    EFI_HANDLE                        DeviceHandle;
    EFI_SIMPLE_FILE_SYSTEM_PROTOCOL   *Vol;
    EFI_FILE_HANDLE                   RootDir;
    EFI_FILE_HANDLE                   Handle;
    UINTN                             BufSize;
    CHAR8                             Buffer[2];
    EFI_DEVICE_PATH_PROTOCOL          *PreDevicePath;

    Private = TEST_OUTPUT_PRIVATE_DATA_FROM_THIS (This);

    //
    // Search the file in OutputFileList to see whether the file has been opened
    //
    OutputFile = Private->OutputFileList;
    while (OutputFile != NULL) {
        if ((SctDevicePathCompare (DevicePath, OutputFile->DevicePath) == 0) &&
                (StrCmp (FileName, OutputFile->FileName)                   == 0)) {
            break;
        }
        OutputFile = OutputFile->Next;
    }

    if (OutputFile == NULL) {
        //
        // Not found, open the file and add to the list
        //

        PreDevicePath = DevicePath;
        //
        //  Determine device handle for fs protocol on specified device path
        //
        Status = BS->LocateDevicePath (
                     &gEfiSimpleFileSystemProtocolGuid,
                     &PreDevicePath,
                     &DeviceHandle
                 );
        if (EFI_ERROR (Status)) {
            return Status;
        }

        //
        //  Determine volume for file system on device handle
        //
        Status = BS->HandleProtocol (
                     DeviceHandle,
                     &gEfiSimpleFileSystemProtocolGuid,
                     (VOID*)&Vol
                 );
        if (EFI_ERROR (Status)) {
            return Status;
        }

        //
        // Open volume for file system on device path
        //
        Status = Vol->OpenVolume (Vol, &RootDir);
        if (EFI_ERROR (Status)) {
            return Status;
        }

        //
        // Determine the existence of the file
        //
        Status = RootDir->Open (
                     RootDir,
                     &Handle,
                     FileName,
                     EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ,
                     0
                 );
        if (Status == EFI_NOT_FOUND) {
            //
            // The file not exist, create it
            //
            Status = SctCreateFile (RootDir, FileName, &Handle);
            if (EFI_ERROR (Status)) {
                RootDir->Close (RootDir);
                return Status;
            }

            //
            // Write the head of Unicode text file
            //
            Buffer[0] = 0xff;
            Buffer[1] = 0xfe;
            BufSize = 2;
            Status = Handle->Write (Handle, &BufSize, Buffer);
            if (EFI_ERROR (Status)) {
                Handle->Close (Handle);
                return Status;
            }
        } else if (EFI_ERROR (Status)) {
            RootDir->Close(RootDir);
            return Status;
        }

        if (OverwriteFile) {
            //
            // Overwrite the file
            //

            //
            // Delete the file
            //
            Status = Handle->Delete (Handle);

            //
            // EFI_FILE.Delete() return a warning status
            //
            if (Status != EFI_SUCCESS) {
                RootDir->Close (RootDir);
                return EFI_UNSUPPORTED;
            }

            //
            // Recreate the file
            //
            Status = RootDir->Open (
                         RootDir,
                         &Handle,
                         FileName,
                         EFI_FILE_MODE_CREATE|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ,
                         0
                     );
            if (EFI_ERROR (Status)) {
                RootDir->Close (RootDir);
                return Status;
            }

            //
            // Write the head of Unicode text file
            //
            Buffer[0] = 0xff;
            Buffer[1] = 0xfe;
            BufSize = 2;
            Status = Handle->Write (Handle, &BufSize, Buffer);
            if (EFI_ERROR (Status)) {
                Handle->Close (Handle);
                return Status;
            }
        } else {
            //
            // Append the file
            //

            //
            // Set position to the end of file
            //
            Status = Handle->SetPosition (Handle, (UINT64)-1);
            if (EFI_ERROR (Status)) {
                RootDir->Close (RootDir);
                return Status;
            }
        }
        RootDir->Close (RootDir);

        //
        // Add the opened file to the OutputFileList
        //
        Status = BS->AllocatePool (
                     EfiBootServicesData,
                     sizeof(TEST_OUTPUT_FILE),
                     (VOID **)&OutputFile
                 );
        if (EFI_ERROR (Status)) {
            Handle->Close (Handle);
            return Status;
        }
        ZeroMem (OutputFile, sizeof(TEST_OUTPUT_FILE));

        OutputFile->DevicePath = DuplicateDevicePath (DevicePath);
        if (OutputFile->DevicePath == NULL) {
            Handle->Close (Handle);
            BS->FreePool (OutputFile);
            return EFI_OUT_OF_RESOURCES;
        }
        OutputFile->FileName = StrDuplicate (FileName);
        if (OutputFile->FileName == NULL) {
            Handle->Close (Handle);
            BS->FreePool (OutputFile->DevicePath);
            BS->FreePool (OutputFile);
            return EFI_OUT_OF_RESOURCES;
        }

        OutputFile->FileHandle = Handle;
        OutputFile->Next = Private->OutputFileList;
        Private->OutputFileList = OutputFile;
    }

    //
    // Add the open count and return the file handle
    //
    OutputFile->OpenCount ++;
    *FileHandle = OutputFile->FileHandle;

    return EFI_SUCCESS;
}