Esempio n. 1
0
void CConnClient::OnServerCommand(const CGas2GacGC_Tell_Guids* pCmd)
{
	str_guid_t szGuidServer;
	str_guid_t szGuidConnection;

	GuidToString(pCmd->guidConnection, szGuidConnection);
	ErrLogMsg("Conn Guid", szGuidConnection);

	GuidToString(pCmd->guidServer, szGuidServer);	
	ErrLogMsg("Server GUID", szGuidServer);

	m_pSlowSigner = new CSlowSigner( pCmd->guidConnection );
	//memcpy( m_guidConn , pCmd->guidConnection , sizeof( m_guidConn) );

	CAddress address;

	if (GetRemoteAddress(address))
	{
		string strAddr;
		address.GetAddressAndPort(strAddr);
		ErrLogMsg("Server Addr", strAddr.c_str());
	}

	if (GetLocalAddress(address))
	{	
		string strAddr;
		address.GetAddressAndPort(strAddr);
		ErrLogMsg("Client Addr", strAddr.c_str());
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	Generates a string containig the Prefix, random GUID based on spesified Seed, and the Postfix.
//
LPTSTR GuidName(
				IN OUT	PULONG pSeed,				// pointer to a random seed value
				IN		LPTSTR Prefix OPTIONAL		// pointer to a prefix string (optional)
				)
{
	ULONG	NameLen = GUID_STR_LEN + 1;
	LPTSTR	GuidStr, Name = NULL;
	GUID	Guid;

	GenGuid(&Guid, pSeed);
	if (GuidStr = GuidToString(&Guid))
	{
		if (Prefix)
			NameLen += lstrlen(Prefix);

		if (Name = (LPTSTR)vAlloc(NameLen*sizeof(_TCHAR)))
		{
			Name[0] = 0;

			if (Prefix)
				lstrcpy(Name, Prefix);
		
			lstrcat(Name, GuidStr);
		}
		vFree(GuidStr);
		
	}	// if (GuidStr = 
	return(Name);
}
Esempio n. 3
0
EFI_STATUS disk_get_part_uuid(EFI_HANDLE *handle, CHAR16 uuid[37]) {
        EFI_DEVICE_PATH *device_path;
        EFI_STATUS r = EFI_NOT_FOUND;

        /* export the device path this image is started from */
        device_path = DevicePathFromHandle(handle);
        if (device_path) {
                EFI_DEVICE_PATH *path, *paths;

                paths = UnpackDevicePath(device_path);
                for (path = paths; !IsDevicePathEnd(path); path = NextDevicePathNode(path)) {
                        HARDDRIVE_DEVICE_PATH *drive;

                        if (DevicePathType(path) != MEDIA_DEVICE_PATH)
                                continue;
                        if (DevicePathSubType(path) != MEDIA_HARDDRIVE_DP)
                                continue;
                        drive = (HARDDRIVE_DEVICE_PATH *)path;
                        if (drive->SignatureType != SIGNATURE_TYPE_GUID)
                                continue;

                        GuidToString(uuid, (EFI_GUID *)&drive->Signature);
                        r = EFI_SUCCESS;
                        break;
                }
                FreePool(paths);
        }

        return r;
}
Esempio n. 4
0
File: file.c Progetto: tribals/efifs
/**
 * Set file information
 *
 * @v This			File handle
 * @v Type			Type of information
 * @v Len			Buffer size
 * @v Data			Buffer
 * @ret Status		EFI status code
 */
static EFI_STATUS EFIAPI
FileSetInfo(EFI_FILE_HANDLE This, EFI_GUID *Type, UINTN Len, VOID *Data)
{
	EFI_GRUB_FILE *File = _CR(This, EFI_GRUB_FILE, EfiFile);
	CHAR16 GuidString[36];

	GuidToString(GuidString, Type);
	PrintError(L"Cannot set information of type %s for file '%s'\n",
			GuidString, FileName(File));
	return EFI_WRITE_PROTECTED;
}
Esempio n. 5
0
const char* pyAgeVault::GetAgeGuid( void )
{
    RelVaultNode * rvn = VaultGetAgeInfoNodeIncRef();
    if (rvn) {
        VaultAgeInfoNode ageInfo(rvn);
        GuidToString(ageInfo.ageInstUuid, fAgeGuid, arrsize(fAgeGuid));
        rvn->DecRef();
    }
    else {
        fAgeGuid[0] = 0;
    }
    return fAgeGuid;
}
Esempio n. 6
0
LPTSTR	CreateFsDeviceName(VOID)
{
	ULONG	SysTimeStamp;
	LPTSTR	GuidName, DeviceName = NULL;
	GUID	Guid;

	SysTimeStamp = GetSystemTimeStamp();

	GenGuid(&Guid, &SysTimeStamp);
	if (GuidName = GuidToString(&Guid))
	{
		if (DeviceName = (LPTSTR)LocalAlloc( LMEM_FIXED, (_tcslen(tczRoot) + GUID_STR_LEN + 1) * sizeof(_TCHAR)))
			wsprintf(DeviceName, tczRoot, GuidName);
		LocalFree(GuidName);		
	}

	g_VfsRootName = DeviceName;
	return(DeviceName);
}
Esempio n. 7
0
// IUnknown methods
STDMETHODIMP CMemoryStream::QueryInterface(REFIID iid, void **ppvObject)
{
    TraceEnter();

    TraceOut("%S", GuidToString(iid));

    if (NULL == ppvObject)
    {
        return E_INVALIDARG;
    }

    if (IsEqualCLSID(iid, IID_IStream))
    {
        AddRef();
        *ppvObject = this;
        return S_OK;
    }
    else
    {
        return E_NOINTERFACE;
    }
}
Esempio n. 8
0
File: file.c Progetto: tribals/efifs
/**
 * Get file information
 *
 * @v This			File handle
 * @v Type			Type of information
 * @v Len			Buffer size
 * @v Data			Buffer
 * @ret Status		EFI status code
 */
static EFI_STATUS EFIAPI
FileGetInfo(EFI_FILE_HANDLE This, EFI_GUID *Type, UINTN *Len, VOID *Data)
{
	EFI_STATUS Status;
	EFI_GRUB_FILE *File = _CR(This, EFI_GRUB_FILE, EfiFile);
	EFI_FILE_SYSTEM_INFO *FSInfo = (EFI_FILE_SYSTEM_INFO *) Data;
	EFI_FILE_INFO *Info = (EFI_FILE_INFO *) Data;
	CHAR16 GuidString[36];
	EFI_TIME Time;
	CHAR8* label;

	PrintInfo(L"GetInfo(%llx|'%s', %d) %s\n", (UINT64) This,
		FileName(File), *Len, File->IsDir?L"<DIR>":L"");

	/* Determine information to return */
	if (CompareMem(Type, &GenericFileInfo, sizeof(*Type)) == 0) {

		/* Fill file information */
		PrintExtra(L"Get regular file information\n");
		if (*Len < MINIMUM_INFO_LENGTH) {
			*Len = MINIMUM_INFO_LENGTH;
			return EFI_BUFFER_TOO_SMALL;
		}

		ZeroMem(Data, sizeof(EFI_FILE_INFO));

		Info->Attribute = EFI_FILE_READ_ONLY;
		GrubTimeToEfiTime(File->Mtime, &Time);
		CopyMem(&Info->CreateTime, &Time, sizeof(Time));
		CopyMem(&Info->LastAccessTime, &Time, sizeof(Time));
		CopyMem(&Info->ModificationTime, &Time, sizeof(Time));

		if (File->IsDir) {
			Info->Attribute |= EFI_FILE_DIRECTORY;
		} else {
			Info->FileSize = GrubGetFileSize(File);
			Info->PhysicalSize = GrubGetFileSize(File);
		}

		Status = Utf8ToUtf16NoAlloc(File->basename, Info->FileName,
				(INTN)(Info->Size - sizeof(EFI_FILE_INFO)));
		if (EFI_ERROR(Status)) {
			if (Status != EFI_BUFFER_TOO_SMALL)
				PrintStatusError(Status, L"Could not convert basename to UTF-8");
			return Status;
		}

		/* The Info struct size already accounts for the extra NUL */
		Info->Size = sizeof(EFI_FILE_INFO) + 
				StrLen(Info->FileName) * sizeof(CHAR16);
		return EFI_SUCCESS;

	} else if (CompareMem(Type, &FileSystemInfo, sizeof(*Type)) == 0) {

		/* Get file system information */
		PrintExtra(L"Get file system information\n");
		if (*Len < MINIMUM_FS_INFO_LENGTH) {
			*Len = MINIMUM_FS_INFO_LENGTH;
			return EFI_BUFFER_TOO_SMALL;
		}

		ZeroMem(Data, sizeof(EFI_FILE_INFO));
		FSInfo->Size = *Len;
		FSInfo->ReadOnly = 1;
		/* NB: This should really be cluster size, but we don't have access to that */
		FSInfo->BlockSize = File->FileSystem->BlockIo->Media->BlockSize;
		if (FSInfo->BlockSize  == 0) {
			PrintWarning(L"Corrected Media BlockSize\n");
			FSInfo->BlockSize = 512;
		}
		FSInfo->VolumeSize = (File->FileSystem->BlockIo->Media->LastBlock + 1) *
			FSInfo->BlockSize;
		/* No idea if we can easily get this for GRUB, and the device is RO anyway */
		FSInfo->FreeSpace = 0;

		Status = GrubLabel(File, &label);
		if (EFI_ERROR(Status)) {
			PrintStatusError(Status, L"Could not read disk label");
		} else {
			Status = Utf8ToUtf16NoAlloc(label, FSInfo->VolumeLabel,
					(INTN)(FSInfo->Size - sizeof(EFI_FILE_SYSTEM_INFO)));
			if (EFI_ERROR(Status)) {
				if (Status != EFI_BUFFER_TOO_SMALL)
					PrintStatusError(Status, L"Could not convert label to UTF-8");
				return Status;
			}
			Info->Size = sizeof(EFI_FILE_SYSTEM_INFO) +
					StrLen(FSInfo->VolumeLabel) * sizeof(CHAR16);
		}
		return EFI_SUCCESS;

	} else {

		GuidToString(GuidString, Type);
		PrintError(L"'%s': Cannot get information of type %s\n",
				FileName(File), GuidString);
		return EFI_UNSUPPORTED;

	}
}
Esempio n. 9
0
/*
 * Fill the drive properties (size, FS, etc)
 * Returns TRUE if the drive has a partition that can be mounted in Windows, FALSE otherwise
 */
BOOL GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSystemNameSize, BOOL bSilent)
{
	// MBR partition types that can be mounted in Windows
	const uint8_t mbr_mountable[] = { 0x01, 0x04, 0x06, 0x07, 0x0b, 0x0c, 0x0e, 0xef };
	BOOL r, ret = FALSE, isUefiNtfs = FALSE;
	HANDLE hPhysical;
	DWORD size;
	BYTE geometry[256] = {0}, layout[4096] = {0}, part_type;
	PDISK_GEOMETRY_EX DiskGeometry = (PDISK_GEOMETRY_EX)(void*)geometry;
	PDRIVE_LAYOUT_INFORMATION_EX DriveLayout = (PDRIVE_LAYOUT_INFORMATION_EX)(void*)layout;
	char* volume_name;
	char tmp[256];
	DWORD i, j;

	if (FileSystemName == NULL)
		return FALSE;

	SelectedDrive.nPartitions = 0;
	// Populate the filesystem data
	FileSystemName[0] = 0;
	volume_name = GetLogicalName(DriveIndex, TRUE, FALSE);
	if ((volume_name == NULL) || (!GetVolumeInformationA(volume_name, NULL, 0, NULL, NULL, NULL, FileSystemName, FileSystemNameSize))) {
		suprintf("No volume information for drive 0x%02x\n", DriveIndex);
	}
	safe_free(volume_name);

	hPhysical = GetPhysicalHandle(DriveIndex, FALSE, FALSE);
	if (hPhysical == INVALID_HANDLE_VALUE)
		return 0;

	r = DeviceIoControl(hPhysical, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
			NULL, 0, geometry, sizeof(geometry), &size, NULL);
	if (!r || size <= 0) {
		suprintf("Could not get geometry for drive 0x%02x: %s\n", DriveIndex, WindowsErrorString());
		safe_closehandle(hPhysical);
		return 0;
	}
	if (DiskGeometry->Geometry.BytesPerSector < 512) {
		suprintf("Warning: Drive 0x%02x reports a sector size of %d - Correcting to 512 bytes.\n",
			DriveIndex, DiskGeometry->Geometry.BytesPerSector);
		DiskGeometry->Geometry.BytesPerSector = 512;
	}
	SelectedDrive.DiskSize = DiskGeometry->DiskSize.QuadPart;
	memcpy(&SelectedDrive.Geometry, &DiskGeometry->Geometry, sizeof(DISK_GEOMETRY));
	suprintf("Disk type: %s, Sector Size: %d bytes\n", (DiskGeometry->Geometry.MediaType == FixedMedia)?"Fixed":"Removable",
		DiskGeometry->Geometry.BytesPerSector);
	suprintf("Cylinders: %" PRIi64 ", TracksPerCylinder: %d, SectorsPerTrack: %d\n",
		DiskGeometry->Geometry.Cylinders, DiskGeometry->Geometry.TracksPerCylinder, DiskGeometry->Geometry.SectorsPerTrack);

	r = DeviceIoControl(hPhysical, IOCTL_DISK_GET_DRIVE_LAYOUT_EX,
			NULL, 0, layout, sizeof(layout), &size, NULL );
	if (!r || size <= 0) {
		suprintf("Could not get layout for drive 0x%02x: %s\n", DriveIndex, WindowsErrorString());
		safe_closehandle(hPhysical);
		return 0;
	}

#if defined(__GNUC__)
// GCC 4.9 bugs us about the fact that MS defined an expandable array as array[1]
#pragma GCC diagnostic ignored "-Warray-bounds"
#endif
	switch (DriveLayout->PartitionStyle) {
	case PARTITION_STYLE_MBR:
		SelectedDrive.PartitionType = PARTITION_STYLE_MBR;
		for (i=0; i<DriveLayout->PartitionCount; i++) {
			if (DriveLayout->PartitionEntry[i].Mbr.PartitionType != PARTITION_ENTRY_UNUSED) {
				SelectedDrive.nPartitions++;
			}
		}
		suprintf("Partition type: MBR, NB Partitions: %d\n", SelectedDrive.nPartitions);
		SelectedDrive.has_mbr_uefi_marker = (DriveLayout->Mbr.Signature == MBR_UEFI_MARKER);
		suprintf("Disk ID: 0x%08X %s\n", DriveLayout->Mbr.Signature, SelectedDrive.has_mbr_uefi_marker?"(UEFI target)":"");
		AnalyzeMBR(hPhysical, "Drive");
		for (i=0; i<DriveLayout->PartitionCount; i++) {
			if (DriveLayout->PartitionEntry[i].Mbr.PartitionType != PARTITION_ENTRY_UNUSED) {
				part_type = DriveLayout->PartitionEntry[i].Mbr.PartitionType;
				isUefiNtfs = (i == 1) && (part_type == 0xef) &&
					(DriveLayout->PartitionEntry[i].PartitionLength.QuadPart <= 1*MB);
				suprintf("Partition %d%s:\n", i+1, isUefiNtfs?" (UEFI:NTFS)":"");
				for (j=0; j<ARRAYSIZE(mbr_mountable); j++) {
					if (part_type == mbr_mountable[j]) {
						ret = TRUE;
						break;
					}
				}
				// NB: MinGW's gcc 4.9.2 broke "%lld" printout on XP so we use the inttypes.h "PRI##" qualifiers
				suprintf("  Type: %s (0x%02x)\r\n  Size: %s (%" PRIi64 " bytes)\r\n  Start Sector: %d, Boot: %s, Recognized: %s\n",
					((part_type==0x07)&&(FileSystemName[0]!=0))?FileSystemName:GetPartitionType(part_type), part_type,
					SizeToHumanReadable(DriveLayout->PartitionEntry[i].PartitionLength.QuadPart, TRUE, FALSE),
					DriveLayout->PartitionEntry[i].PartitionLength.QuadPart, DriveLayout->PartitionEntry[i].Mbr.HiddenSectors,
					DriveLayout->PartitionEntry[i].Mbr.BootIndicator?"Yes":"No",
					DriveLayout->PartitionEntry[i].Mbr.RecognizedPartition?"Yes":"No");
				if ((part_type == RUFUS_EXTRA_PARTITION_TYPE) || (isUefiNtfs))
					// This is a partition Rufus created => we can safely ignore it
					--SelectedDrive.nPartitions;
				if (part_type == 0xee)	// Flag a protective MBR for non GPT platforms (XP)
					SelectedDrive.has_protective_mbr = TRUE;
			}
		}
		break;
	case PARTITION_STYLE_GPT:
		SelectedDrive.PartitionType = PARTITION_STYLE_GPT;
		suprintf("Partition type: GPT, NB Partitions: %d\n", DriveLayout->PartitionCount);
		suprintf("Disk GUID: %s\n", GuidToString(&DriveLayout->Gpt.DiskId));
		suprintf("Max parts: %d, Start Offset: %" PRIi64 ", Usable = %" PRIi64 " bytes\n",
			DriveLayout->Gpt.MaxPartitionCount, DriveLayout->Gpt.StartingUsableOffset.QuadPart, DriveLayout->Gpt.UsableLength.QuadPart);
		for (i=0; i<DriveLayout->PartitionCount; i++) {
			SelectedDrive.nPartitions++;
			tmp[0] = 0;
			wchar_to_utf8_no_alloc(DriveLayout->PartitionEntry[i].Gpt.Name, tmp, sizeof(tmp));
			suprintf("Partition %d:\r\n  Type: %s\r\n  Name: '%s'\n", i+1,
				GuidToString(&DriveLayout->PartitionEntry[i].Gpt.PartitionType), tmp);
			suprintf("  ID: %s\r\n  Size: %s (%" PRIi64 " bytes)\r\n  Start Sector: %" PRIi64 ", Attributes: 0x%016" PRIX64 "\n",
				GuidToString(&DriveLayout->PartitionEntry[i].Gpt.PartitionId), SizeToHumanReadable(DriveLayout->PartitionEntry[i].PartitionLength.QuadPart, TRUE, FALSE),
				DriveLayout->PartitionEntry[i].PartitionLength, DriveLayout->PartitionEntry[i].StartingOffset.QuadPart / DiskGeometry->Geometry.BytesPerSector,
				DriveLayout->PartitionEntry[i].Gpt.Attributes);
			// Don't register the partitions that we don't care about destroying
			if ( (strcmp(tmp, "UEFI:NTFS") == 0) ||
				 (CompareGUID(&DriveLayout->PartitionEntry[i].Gpt.PartitionType, &PARTITION_MSFT_RESERVED_GUID)) ||
				 (CompareGUID(&DriveLayout->PartitionEntry[i].Gpt.PartitionType, &PARTITION_SYSTEM_GUID)) )
				--SelectedDrive.nPartitions;
			if ( (memcmp(&PARTITION_BASIC_DATA_GUID, &DriveLayout->PartitionEntry[i].Gpt.PartitionType, sizeof(GUID)) == 0) &&
				 (nWindowsVersion >= WINDOWS_VISTA) )
				ret = TRUE;
		}
		break;
	default:
		SelectedDrive.PartitionType = PARTITION_STYLE_MBR;
		suprintf("Partition type: RAW\n");
		break;
	}
#if defined(__GNUC__)
#pragma GCC diagnostic warning "-Warray-bounds"
#endif
	safe_closehandle(hPhysical);

	return ret;
}
Esempio n. 10
0
/*
 * Fill the drive properties (size, FS, etc)
 */
int GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSystemNameSize)
{
	BOOL r, hasRufusExtra = FALSE;
	HANDLE hPhysical;
	DWORD size;
	BYTE geometry[256], layout[4096], part_type;
	PDISK_GEOMETRY_EX DiskGeometry = (PDISK_GEOMETRY_EX)(void*)geometry;
	PDRIVE_LAYOUT_INFORMATION_EX DriveLayout = (PDRIVE_LAYOUT_INFORMATION_EX)(void*)layout;
	char* volume_name;
	char tmp[256];
	DWORD i, nb_partitions = 0;

	// Populate the filesystem data
	FileSystemName[0] = 0;
	volume_name = GetLogicalName(DriveIndex, TRUE, FALSE);
	if ((volume_name == NULL) || (!GetVolumeInformationA(volume_name, NULL, 0, NULL, NULL, NULL, FileSystemName, FileSystemNameSize))) {
		uprintf("No volume information for disk 0x%02x\n", DriveIndex);
	}
	safe_free(volume_name);

	hPhysical = GetPhysicalHandle(DriveIndex, FALSE, FALSE);
	if (hPhysical == INVALID_HANDLE_VALUE)
		return 0;

	r = DeviceIoControl(hPhysical, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
			NULL, 0, geometry, sizeof(geometry), &size, NULL);
	if (!r || size <= 0) {
		uprintf("Could not get geometry for drive 0x%02x: %s\n", DriveIndex, WindowsErrorString());
		safe_closehandle(hPhysical);
		return 0;
	}
	SelectedDrive.DiskSize = DiskGeometry->DiskSize.QuadPart;
	memcpy(&SelectedDrive.Geometry, &DiskGeometry->Geometry, sizeof(DISK_GEOMETRY));
	uprintf("Disk type: %s, Sector Size: %d bytes\n", (DiskGeometry->Geometry.MediaType == FixedMedia)?"Fixed":"Removable",
		DiskGeometry->Geometry.BytesPerSector);
	uprintf("Cylinders: %lld, TracksPerCylinder: %d, SectorsPerTrack: %d\n",
		DiskGeometry->Geometry.Cylinders, DiskGeometry->Geometry.TracksPerCylinder, DiskGeometry->Geometry.SectorsPerTrack);

	r = DeviceIoControl(hPhysical, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, 
			NULL, 0, layout, sizeof(layout), &size, NULL );
	if (!r || size <= 0) {
		uprintf("Could not get layout for drive 0x%02x: %s\n", DriveIndex, WindowsErrorString());
		safe_closehandle(hPhysical);
		return 0;
	}

	switch (DriveLayout->PartitionStyle) {
	case PARTITION_STYLE_MBR:
		SelectedDrive.PartitionType = PARTITION_STYLE_MBR;
		for (i=0; i<DriveLayout->PartitionCount; i++) {
			if (DriveLayout->PartitionEntry[i].Mbr.PartitionType != PARTITION_ENTRY_UNUSED) {
				nb_partitions++;
			}
		}
		uprintf("Partition type: MBR, NB Partitions: %d\n", nb_partitions);
		SelectedDrive.has_mbr_uefi_marker = (DriveLayout->Mbr.Signature == MBR_UEFI_MARKER);
		uprintf("Disk ID: 0x%08X %s\n", DriveLayout->Mbr.Signature, SelectedDrive.has_mbr_uefi_marker?"(UEFI target)":"");
		AnalyzeMBR(hPhysical, "Drive");
		for (i=0; i<DriveLayout->PartitionCount; i++) {
			if (DriveLayout->PartitionEntry[i].Mbr.PartitionType != PARTITION_ENTRY_UNUSED) {
				uprintf("Partition %d:\n", i+1);
				part_type = DriveLayout->PartitionEntry[i].Mbr.PartitionType;
				uprintf("  Type: %s (0x%02x)\r\n  Size: %s (%lld bytes)\r\n  Start Sector: %d, Boot: %s, Recognized: %s\n",
					((part_type==0x07)&&(FileSystemName[0]!=0))?FileSystemName:GetPartitionType(part_type), part_type,
					SizeToHumanReadable(DriveLayout->PartitionEntry[i].PartitionLength.QuadPart, TRUE, FALSE),
					DriveLayout->PartitionEntry[i].PartitionLength, DriveLayout->PartitionEntry[i].Mbr.HiddenSectors,
					DriveLayout->PartitionEntry[i].Mbr.BootIndicator?"Yes":"No",
					DriveLayout->PartitionEntry[i].Mbr.RecognizedPartition?"Yes":"No");
				if (part_type == RUFUS_EXTRA_PARTITION_TYPE)	// This is a partition Rufus created => we can safely ignore it
					hasRufusExtra = TRUE;
				if (part_type == 0xee)	// Flag a protective MBR for non GPT platforms (XP)
					SelectedDrive.has_protective_mbr = TRUE;
			}
		}
		break;
	case PARTITION_STYLE_GPT:
		SelectedDrive.PartitionType = PARTITION_STYLE_GPT;
		uprintf("Partition type: GPT, NB Partitions: %d\n", DriveLayout->PartitionCount);
		uprintf("Disk GUID: %s\n", GuidToString(&DriveLayout->Gpt.DiskId));
		uprintf("Max parts: %d, Start Offset: %lld, Usable = %lld bytes\n",
			DriveLayout->Gpt.MaxPartitionCount, DriveLayout->Gpt.StartingUsableOffset.QuadPart, DriveLayout->Gpt.UsableLength.QuadPart);
		for (i=0; i<DriveLayout->PartitionCount; i++) {
			nb_partitions++;
			tmp[0] = 0;
			wchar_to_utf8_no_alloc(DriveLayout->PartitionEntry[i].Gpt.Name, tmp, sizeof(tmp));
			uprintf("Partition %d:\r\n  Type: %s\r\n  Name: '%s'\n", DriveLayout->PartitionEntry[i].PartitionNumber,
				GuidToString(&DriveLayout->PartitionEntry[i].Gpt.PartitionType), tmp);
			uprintf("  ID: %s\r\n  Size: %s (%lld bytes)\r\n  Start Sector: %lld, Attributes: 0x%016llX\n",
				GuidToString(&DriveLayout->PartitionEntry[i].Gpt.PartitionId), SizeToHumanReadable(DriveLayout->PartitionEntry[i].PartitionLength.QuadPart, TRUE, FALSE),
				DriveLayout->PartitionEntry[i].PartitionLength, DriveLayout->PartitionEntry[i].StartingOffset.QuadPart / DiskGeometry->Geometry.BytesPerSector,
				DriveLayout->PartitionEntry[i].Gpt.Attributes);
		}
		break;
	default:
		SelectedDrive.PartitionType = PARTITION_STYLE_MBR;
		uprintf("Partition type: RAW\n");
		break;
	}
	safe_closehandle(hPhysical);

	if (hasRufusExtra)
		nb_partitions--;
	return (int)nb_partitions;
}
Esempio n. 11
0
BOOL
GetCurrentHwProfileW (
    OUT LPHW_PROFILE_INFOW  lpHwProfileInfo
)

/*++

Routine Description:


Arguments:

    lpHwProfileInfo  Points to a HW_PROFILE_INFO structure that will receive
                     the information for the current hardware profile.

Return Value:

    If the function succeeds, the return value is TRUE.  If the function
    fails, the return value is FALSE.  To get extended error information,
    call GetLastError.

--*/

{
    BOOL     Status = TRUE;
    WCHAR    RegStr[MAX_PATH];
    HKEY     hKey = NULL, hCfgKey = NULL;
    ULONG    ulCurrentConfig = 1, ulSize = 0;
    UUID     NewGuid;


    try {
        //
        // validate parameter
        //
        if (lpHwProfileInfo == NULL) {
            SetLastError(ERROR_INVALID_PARAMETER);
            Status = FALSE;
            goto Clean0;
        }

        //
        // open the IDConfigDB key
        //
        if (RegOpenKeyEx(
                    HKEY_LOCAL_MACHINE, pszRegIDConfigDB, 0,
                    KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) {

            SetLastError(ERROR_REGISTRY_CORRUPT);
            Status = FALSE;
            goto Clean0;
        }

        //
        // retrieve the current config id
        //
        ulSize = sizeof(ULONG);
        if (RegQueryValueEx(
                    hKey, pszRegCurrentConfig, NULL, NULL,
                    (LPBYTE)&ulCurrentConfig, &ulSize) != ERROR_SUCCESS) {

            SetLastError(ERROR_REGISTRY_CORRUPT);
            Status = FALSE;
            goto Clean0;
        }

        //
        // open the profile key for the current configuration
        //
        wsprintf(RegStr, L"%s\\%04u",
                 pszRegKnownDockingStates,
                 ulCurrentConfig);

        if (RegOpenKeyEx(
                    hKey, RegStr, 0, KEY_QUERY_VALUE | KEY_SET_VALUE,
                    &hCfgKey) != ERROR_SUCCESS) {

            SetLastError(ERROR_REGISTRY_CORRUPT);
            Status = FALSE;
            goto Clean0;
        }

        //
        // retrieve the dock state
        //
        ulSize = sizeof(ULONG);
        if (RegQueryValueEx(
                    hCfgKey, pszRegDockState, NULL, NULL,
                    (LPBYTE)&lpHwProfileInfo->dwDockInfo,
                    &ulSize) != ERROR_SUCCESS) {

            //
            // If the dock state isn't available, use default (unknown)
            //
            lpHwProfileInfo->dwDockInfo =
                DOCKINFO_USER_SUPPLIED | DOCKINFO_DOCKED | DOCKINFO_UNDOCKED;
        }

        //
        // retrieve the profile guid
        //
        ulSize = HW_PROFILE_GUIDLEN * sizeof(WCHAR);
        if (RegQueryValueEx(
                    hCfgKey, pszRegHwProfileGuid, NULL, NULL,
                    (LPBYTE)&lpHwProfileInfo->szHwProfileGuid,
                    &ulSize) != ERROR_SUCCESS ||
                lpHwProfileInfo->szHwProfileGuid[0] == '\0') {

            //
            // if no HwProfileGuid value set or the string is
            // zero-length, create a new guid
            //
            if (UuidCreate(&NewGuid) != RPC_S_OK) {

                SetLastError(ERROR_INTERNAL_ERROR);
                Status = FALSE;
                goto Clean0;
            }

            if (GuidToString(&NewGuid, lpHwProfileInfo->szHwProfileGuid) != RPC_S_OK) {

                SetLastError(ERROR_INTERNAL_ERROR);
                Status = FALSE;
                goto Clean0;
            }

            //
            // save the newly create guid in the registry
            //
            ulSize = (lstrlen(lpHwProfileInfo->szHwProfileGuid) + 1)
                     * sizeof(WCHAR);

            RegSetValueEx(
                hCfgKey, pszRegHwProfileGuid, 0, REG_SZ,
                (LPBYTE)lpHwProfileInfo->szHwProfileGuid, ulSize);
        }

        //
        // retrieve the friendly name
        //
        ulSize = MAX_PROFILE_LEN * sizeof(WCHAR);
        if (RegQueryValueEx(
                    hCfgKey, pszRegFriendlyName, NULL, NULL,
                    (LPBYTE)&lpHwProfileInfo->szHwProfileName,
                    &ulSize) != ERROR_SUCCESS ||
                lpHwProfileInfo->szHwProfileName[0] == '\0') {

            //
            // if no FriendlyName value set or the string is
            // zero-length, create a default name (for compatibility
            // with Windows 95)
            //
            lstrcpy(lpHwProfileInfo->szHwProfileName,
                    pszRegDefaultFriendlyName);

            ulSize = (lstrlen(pszRegFriendlyName) + 1) * sizeof(WCHAR);

            RegSetValueEx(
                hCfgKey, pszRegFriendlyName, 0, REG_SZ,
                (LPBYTE)pszRegDefaultFriendlyName, ulSize);
        }


Clean0:
        ;

    }
    except(EXCEPTION_EXECUTE_HANDLER) {

        SetLastError(ERROR_INVALID_PARAMETER);
        Status = FALSE;
    }

    if (hKey != NULL) RegCloseKey(hKey);
    if (hCfgKey != NULL) RegCloseKey(hCfgKey);

    return Status;

} // GetCurrentHwProfileW
Esempio n. 12
0
std::string CallHprose::DownloadHprose( std::string strHproseDownloadUrl, std::string strFileDir, std::string strFileName )
{
	CInternetSession sess;
	CHttpFile* pHttpFile;
	try
	{
		pHttpFile=(CHttpFile*)sess.OpenURL(strHproseDownloadUrl.c_str());
	}
	catch(CException* e)
	{
		pHttpFile = 0;
		TCHAR msg[1024];
		memset(msg, 0, 1024);
		e->GetErrorMessage(msg, 1023, NULL);
		ZTools::WriteZToolsFormatLog("打开URL失败:%s", msg);
		return "";
	}

	DWORD dwStatus;
	DWORD dwBuffLen = sizeof(dwStatus);
	BOOL bSuccess = pHttpFile->QueryInfo(HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &dwStatus, &dwBuffLen);

	int nReadBlockSize = 256*1024;
	char* pBuffer = new char[nReadBlockSize];
	if( bSuccess && dwStatus>= 200&& dwStatus<300 )
	{
		if (strFileName.length() == 0)
		{
			CString sContentDisposition;
			DWORD dwIndex = 0;
			bSuccess = pHttpFile->QueryInfo(HTTP_QUERY_CONTENT_DISPOSITION, sContentDisposition, &dwIndex);
			std::string strContentDisposition((LPCTSTR)sContentDisposition);
			std::string strKeyBegin("filename=\"");
			std::string strKeyEnd("\"");

			if (!strContentDisposition.empty())
			{
				size_t nBegin = strContentDisposition.find(strKeyBegin) + strKeyBegin.length();
				if (nBegin < strContentDisposition.length())
				{
					size_t nEnd = strContentDisposition.find(strKeyEnd, nBegin);
					strFileName = strContentDisposition.substr(nBegin, nEnd - nBegin);
				}
				strFileName = deescapeURL(strFileName);
				ZTools::UTF8ToMB(strFileName);
			}
		}

		if (strFileName.length() == 0)
		{
			delete[] pBuffer;
			pBuffer = NULL;
			pHttpFile->Close();
			//delete pHttpFile;
			sess.Close();
			ZTools::WriteZToolsFormatLog("没有找到文件名");
			return "";
		}

		std::replace(strFileDir.begin(), strFileDir.end(), '/', '\\');
		strFileDir.erase(strFileDir.find_last_not_of('\\') + 1);
		std::replace(strFileName.begin(), strFileName.end(), '/', '\\');
		strFileName.erase(0, strFileName.find_first_not_of('\\'));
		std::string strFilePath = ZTools::FormatString("%s\\%s", strFileDir.c_str(), strFileName.c_str());
		//先下载到临时文件中,下载成功后重命名
		std::string strFilePathTemp = ZTools::FormatString("%s\\%s", strFileDir.c_str(), GuidToString(CreateGuid()).c_str());

		if (!MakeSureDirectoryPathExists(strFilePath.c_str()))
		{
			delete[] pBuffer;
			pBuffer = NULL;
			pHttpFile->Close();
			//delete pHttpFile;
			sess.Close();
			ZTools::WriteZToolsFormatLog("创建文件夹失败:%s", strFilePath.c_str());
			return "";
		}

		CFile fileWrite;
		ULONGLONG dwFileLen = 0;
		DWORD dwWriteIndex = 0;
		dwFileLen = pHttpFile->SeekToEnd();
		pHttpFile->SeekToBegin();
		if(fileWrite.Open(strFilePathTemp.c_str(), CFile::modeWrite|CFile::modeCreate))
		{
			int nCount = 0;
			while(dwWriteIndex < dwFileLen)
			{
				nCount = pHttpFile->Read(pBuffer, nReadBlockSize);
				fileWrite.Write(pBuffer, nCount);
				dwWriteIndex += nCount;                
			}
			fileWrite.Close();

			rename(strFilePathTemp.c_str(), strFilePath.c_str());

			delete[] pBuffer;
			pBuffer = NULL;
			pHttpFile->Close();
			delete pHttpFile;
			sess.Close();

			if (PathFileExists(strFilePath.c_str()))
			{
				return strFilePath;
			}
			else
			{
				return "";
			}
		}
		else
		{
			delete[] pBuffer;
			pBuffer = NULL;
			pHttpFile->Close();
			//delete pHttpFile;
			sess.Close();
			ZTools::WriteZToolsFormatLog("本地文件%s打开出错", strFilePath.c_str());
			return "";
		}
	}
	else
	{
		delete[] pBuffer;
		pBuffer = NULL;
		pHttpFile->Close();
		//delete pHttpFile;
		sess.Close();
		ZTools::WriteZToolsFormatLog("打开网页文件出错,错误码:%d", dwStatus);
		return "";
	}

	delete[] pBuffer;
	pBuffer = NULL;
	pHttpFile->Close();
	//delete pHttpFile;
	sess.Close();	
	return "";
}