This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature update, disk backups and ffu conversion
Added: - FFU Conversion, limited to wp8 ffu format - whole disk and seperate partition backup
- Loading branch information
1 parent
d38214c
commit 3599a51
Showing
16 changed files
with
2,960 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.32126.315 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Windows 10 Mobile Toolbox", "Windows 10 Mobile Toolbox\Windows 10 Mobile Toolbox.csproj", "{DE89CF07-5C70-4BAC-BEFF-5F204561A800}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{DE89CF07-5C70-4BAC-BEFF-5F204561A800}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{DE89CF07-5C70-4BAC-BEFF-5F204561A800}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{DE89CF07-5C70-4BAC-BEFF-5F204561A800}.Debug|x64.ActiveCfg = Debug|x64 | ||
{DE89CF07-5C70-4BAC-BEFF-5F204561A800}.Debug|x64.Build.0 = Debug|x64 | ||
{DE89CF07-5C70-4BAC-BEFF-5F204561A800}.Debug|x86.ActiveCfg = Debug|x86 | ||
{DE89CF07-5C70-4BAC-BEFF-5F204561A800}.Debug|x86.Build.0 = Debug|x86 | ||
{DE89CF07-5C70-4BAC-BEFF-5F204561A800}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{DE89CF07-5C70-4BAC-BEFF-5F204561A800}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{DE89CF07-5C70-4BAC-BEFF-5F204561A800}.Release|x64.ActiveCfg = Release|x64 | ||
{DE89CF07-5C70-4BAC-BEFF-5F204561A800}.Release|x64.Build.0 = Release|x64 | ||
{DE89CF07-5C70-4BAC-BEFF-5F204561A800}.Release|x86.ActiveCfg = Release|x86 | ||
{DE89CF07-5C70-4BAC-BEFF-5F204561A800}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {316B38F1-956D-4FA7-A052-4177606D8BCD} | ||
EndGlobalSection | ||
EndGlobal |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Runtime.InteropServices; | ||
using System.IO; | ||
using System.Windows; | ||
|
||
namespace DiskManager | ||
{ | ||
public class DiskManager | ||
{ | ||
//-------------------------------------------------------------------------------------------------------- | ||
[DllImport("kernel32.dll")] | ||
private static extern int CreateFile( | ||
string lpFileName, int dwDesiredAccess, | ||
int dwShareMode, int lpSecurityAttributes, | ||
int dwCreationDisposition, int dwFlagsAndAttributes, | ||
int hTemplateFile); | ||
|
||
[DllImport("kernel32.dll")] | ||
private static extern int CloseHandle(int hObject); | ||
|
||
[DllImport("kernel32.dll")] | ||
private static extern int ReadFile( | ||
int hFile, | ||
byte[] lpBuffer, | ||
int nNumberOfBytesToRead, | ||
ref int lpNumberOfBytesRead, | ||
int lpOverlapped); | ||
|
||
[DllImport("kernel32.dll")] | ||
private static extern int WriteFile( | ||
int hFile, | ||
byte[] lpBuffer, | ||
int nNumberOfBytesToWrite, | ||
ref int lpNumberOfBytesWritten, | ||
int lpOverlapped); | ||
|
||
[DllImport("kernel32.dll")] | ||
private static extern int SetFilePointer( | ||
int hFile, | ||
int nDistanceToMove, | ||
ref int lpDistanceToMoveHigh, | ||
uint nMoveMethod); | ||
|
||
const int BUFFERSIZE = 8335360; | ||
const int BYTES_PER_SECTOR = 4096; | ||
char diskLetter; | ||
int diskHandle; | ||
string filePath; | ||
|
||
const int GENERIC_READ = unchecked((int)0x80000000); | ||
const int FILE_SHARE_READ = 1; | ||
const int FILE_SHARE_WRITE = 2; | ||
const int OPEN_EXISTING = 3; | ||
const Int64 INVALID_HANDLE_VALUE = -1; | ||
const int FILE_ATTRIBUTE_NORMAL = 0x80; | ||
const int FILE_BEGIN = 0; | ||
//-------------------------------------------------------------------------------------------------------- | ||
|
||
public byte [] readDisk(char diskLetter) | ||
{ | ||
this.diskLetter = diskLetter; | ||
createDiskHandle(); | ||
|
||
int lpNumberOfBytesRead=0; | ||
byte [] buf = new byte[BUFFERSIZE]; | ||
if (ReadFile(diskHandle, buf, BUFFERSIZE, ref lpNumberOfBytesRead, 0) == 0) | ||
{ | ||
|
||
/*TO DO: | ||
throw and handle exceptions | ||
Terminal failure: Unable to read from disk. | ||
*/ | ||
CloseHandle(diskHandle); | ||
throw new Exception("ERROR MESSAGE"); | ||
|
||
} | ||
return buf; | ||
} | ||
|
||
public void writeToDisk(byte [] sectorBuffer, int sectorNumber) | ||
{ | ||
int nNumberOfBytesToWrite = BYTES_PER_SECTOR; | ||
int lpNumberOfBytesWritten = 0; | ||
int lpDistanceToMoveHigh = 0; | ||
|
||
SetFilePointer(diskHandle, BYTES_PER_SECTOR * sectorNumber, ref lpDistanceToMoveHigh, FILE_BEGIN); | ||
|
||
if (WriteFile(diskHandle, sectorBuffer, nNumberOfBytesToWrite, ref lpNumberOfBytesWritten, 0) == 0) | ||
{ | ||
/*TO DO: | ||
throw and handle exceptions | ||
Terminal failure: Unable to write to disk. | ||
*/ | ||
throw new Exception("ERROR MESSAGE"); | ||
|
||
} | ||
} | ||
|
||
public void createImage(string filePath, byte [] buf) | ||
{ | ||
this.filePath = filePath; | ||
FileInfo fileInfo = new FileInfo(filePath); | ||
bool exists = System.IO.Directory.Exists(fileInfo.Directory.ToString()); | ||
|
||
if (!exists) | ||
{ | ||
System.IO.Directory.CreateDirectory(fileInfo.Directory.ToString()); | ||
} | ||
//File.WriteAllBytes(filePath, buf); | ||
BinaryWriter write = new BinaryWriter(new FileStream(filePath, FileMode.Create)); | ||
write.Write(buf, 0, buf.Length); | ||
write.Flush(); | ||
write.Close(); | ||
|
||
} | ||
|
||
|
||
public void createDiskHandle() | ||
{ | ||
diskHandle = CreateFile( | ||
"\\\\.\\"+diskLetter+":", | ||
GENERIC_READ, | ||
FILE_SHARE_READ | FILE_SHARE_WRITE, | ||
0, | ||
OPEN_EXISTING, | ||
FILE_ATTRIBUTE_NORMAL, | ||
0); | ||
|
||
if (diskHandle == INVALID_HANDLE_VALUE) | ||
{ | ||
/*TO DO: | ||
throw and handle exceptions | ||
*/ | ||
throw new Exception("ERROR MESSAGE"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Runtime.InteropServices; | ||
using System.IO; | ||
using System.Management; | ||
using System.Diagnostics; | ||
|
||
namespace DiskManager | ||
{ | ||
public class WPDiskChecker | ||
{ | ||
static string EFIESP_DRIVE; | ||
static string DATA_DRIVE; | ||
static string MAINOS_DRIVE; | ||
static string EFIESP_PHYSICAL; | ||
static string DATA_PHYSICAL; | ||
static string MAINOS_PHYSICAL; | ||
static string EFIESP_NAME; | ||
static string DATA_NAME; | ||
static string MAINOS_NAME; | ||
static string EFIESP_FILESYSTEM; | ||
static string DATA_FILESYSTEM; | ||
static string MAINOS_FILESYSTEM; | ||
|
||
public static string[] CheckForDiskInfo() | ||
{ | ||
StringBuilder sbmain = new StringBuilder(); | ||
sbmain.Append(""); | ||
StringBuilder sbdata = new StringBuilder(); | ||
sbdata.Append(""); | ||
StringBuilder sbefi = new StringBuilder(); | ||
sbefi.Append(""); | ||
|
||
|
||
// ADD FREE SPACE AND CAPACITY // | ||
|
||
var driveQuery = new ManagementObjectSearcher("select * from Win32_DiskDrive"); | ||
foreach (ManagementObject d in driveQuery.Get()) | ||
{ | ||
var deviceId = d.Properties["DeviceId"].Value; | ||
//Console.WriteLine("Device"); | ||
//Console.WriteLine(d); | ||
var partitionQueryText = string.Format("associators of {{{0}}} where AssocClass = Win32_DiskDriveToDiskPartition", d.Path.RelativePath); | ||
var partitionQuery = new ManagementObjectSearcher(partitionQueryText); | ||
foreach (ManagementObject p in partitionQuery.Get()) | ||
{ | ||
//Console.WriteLine("Partition"); | ||
//Console.WriteLine(p); | ||
var logicalDriveQueryText = string.Format("associators of {{{0}}} where AssocClass = Win32_LogicalDiskToPartition", p.Path.RelativePath); | ||
var logicalDriveQuery = new ManagementObjectSearcher(logicalDriveQueryText); | ||
foreach (ManagementObject ld in logicalDriveQuery.Get()) | ||
{ | ||
//Console.WriteLine("Logical drive"); | ||
//Console.WriteLine(ld); | ||
|
||
var physicalName = Convert.ToString(d.Properties["Name"].Value); // \\.\PHYSICALDRIVE2 | ||
var diskName = Convert.ToString(d.Properties["Caption"].Value); // WDC WD5001AALS-xxxxxx | ||
var diskModel = Convert.ToString(d.Properties["Model"].Value); // WDC WD5001AALS-xxxxxx | ||
var diskInterface = Convert.ToString(d.Properties["InterfaceType"].Value); // IDE | ||
var capabilities = (UInt16[])d.Properties["Capabilities"].Value; // 3,4 - random access, supports writing | ||
var mediaLoaded = Convert.ToBoolean(d.Properties["MediaLoaded"].Value); // bool | ||
var mediaType = Convert.ToString(d.Properties["MediaType"].Value); // Fixed hard disk media | ||
var mediaSignature = Convert.ToUInt32(d.Properties["Signature"].Value); // int32 | ||
var mediaStatus = Convert.ToString(d.Properties["Status"].Value); // OK | ||
|
||
var driveName = Convert.ToString(ld.Properties["Name"].Value); // C: | ||
var driveId = Convert.ToString(ld.Properties["DeviceId"].Value); // C: | ||
var driveCompressed = Convert.ToBoolean(ld.Properties["Compressed"].Value); | ||
var driveType = Convert.ToUInt32(ld.Properties["DriveType"].Value); // C: - 3 | ||
var fileSystem = Convert.ToString(ld.Properties["FileSystem"].Value); // NTFS | ||
var freeSpace = Convert.ToUInt64(ld.Properties["FreeSpace"].Value); // in bytes | ||
var totalSpace = Convert.ToUInt64(ld.Properties["Size"].Value); // in bytes | ||
var driveMediaType = Convert.ToUInt32(ld.Properties["MediaType"].Value); // c: 12 | ||
var volumeName = Convert.ToString(ld.Properties["VolumeName"].Value); // System | ||
var volumeSerial = Convert.ToString(ld.Properties["VolumeSerialNumber"].Value); // 12345678 | ||
if (volumeName == "EFIESP") | ||
{ | ||
Debug.WriteLine($"EFIESP: {volumeName}"); | ||
EFIESP_NAME = volumeName; | ||
Debug.WriteLine($"{physicalName}"); | ||
EFIESP_PHYSICAL = physicalName; | ||
Debug.WriteLine($"{driveName}"); | ||
EFIESP_DRIVE = driveName; | ||
Debug.WriteLine($"{fileSystem}"); | ||
EFIESP_FILESYSTEM = fileSystem; | ||
Debug.WriteLine(new string('-', 79)); | ||
} | ||
if (volumeName == "Data") | ||
{ | ||
Debug.WriteLine($"Data: {volumeName}"); | ||
DATA_NAME = volumeName; | ||
Debug.WriteLine($"{physicalName}"); | ||
DATA_PHYSICAL = physicalName; | ||
Debug.WriteLine($"{driveName}"); | ||
DATA_DRIVE = driveName; | ||
Debug.WriteLine($"{fileSystem}"); | ||
DATA_FILESYSTEM = fileSystem; | ||
Debug.WriteLine(new string('-', 79)); | ||
} | ||
if (volumeName == "MainOS") | ||
{ | ||
Debug.WriteLine($"MainOS: {volumeName}"); | ||
MAINOS_NAME = volumeName; | ||
Debug.WriteLine($"{physicalName}"); | ||
MAINOS_PHYSICAL = physicalName; | ||
Debug.WriteLine($"{driveName}"); | ||
MAINOS_DRIVE = driveName; | ||
Debug.WriteLine($"{fileSystem}"); | ||
MAINOS_FILESYSTEM = fileSystem; | ||
Debug.WriteLine(new string('-', 79)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
List<string> noresult = null; | ||
if (EFIESP_NAME != "EFIESP") | ||
{ | ||
noresult.Add("EFIESP NOT FOUND ABORTING"); | ||
return noresult.ToArray(); | ||
|
||
} | ||
if (DATA_NAME != "DATA") | ||
{ | ||
noresult.Add("DATA NOT FOUND ABORTING"); | ||
return noresult.ToArray(); | ||
} | ||
if (MAINOS_NAME != "MainOS") | ||
{ | ||
noresult.Add("MAINOS NOT FOUND ABORTING"); | ||
return noresult.ToArray(); | ||
} | ||
|
||
string[] result = | ||
{ | ||
EFIESP_PHYSICAL, | ||
EFIESP_NAME, | ||
EFIESP_DRIVE, | ||
EFIESP_FILESYSTEM, | ||
DATA_PHYSICAL, | ||
DATA_NAME, | ||
DATA_DRIVE, | ||
DATA_FILESYSTEM, | ||
MAINOS_PHYSICAL, | ||
MAINOS_NAME, | ||
MAINOS_DRIVE, | ||
MAINOS_FILESYSTEM | ||
}; | ||
|
||
|
||
return result; | ||
|
||
|
||
|
||
} | ||
} | ||
} |
Oops, something went wrong.