Commit 28c5bad9 authored by Billy Hulbert's avatar Billy Hulbert
Browse files

Add flash reading/dumping.

parent cf85b015
Loading
Loading
Loading
Loading

Source/Include/XBFS.h

0 → 100644
+52 −0
Original line number Diff line number Diff line
#pragma once

static const char* XBFS_ENTRIES[] = {
	"1smcbl_a.bin",	// 0
	"header.bin",	// 1
	"devkit.ini",	// 2
	"mtedata.cfg",	// 3
	"certkeys.bin", // 4
	"smcerr.log",	// 5
	"system.xvd",	// 6
	"$sospf.xvd",	// 7
	"download.xvd", // 8
	"smc_s.cfg",	// 9
	"sp_s.cfg",		// 10
	"os_s.cfg",		// 11
	"smc_d.cfg",	// 12
	"sp_d.cfg",		// 13
	"os_d.cfg",		// 14
	"smcfw.bin",	// 15
	"boot.bin",		// 16
	"host.xvd",		// 17
	"settings.xvd", // 18
	"1smcbl_b.bin", // 19
	"bootanim.dat", // 20
	"obsolete.001", // 2
	"update.cfg",	// 22
	"obsolete.002",	// 23
	"hwinit.cfg",	// 24
	"qaslt.xvd",	// 25
	"sp_s.bak",		// 26
	"update2.cfg",	// 27
	"obsolete.003",	// 28
	"dump.lng",		// 29
	"os_d_dev.cfg", // 30
	"os_glob.cfg",	// 31
	"sp_s.alt",		// 32
	"sysauxf.xvd",	// 33
};

class XBFS
{
public:
	bool Open(LPCSTR lpszFile, bool bRawDump);
	void Close();

	bool Read(LPCSTR lpszFileName, LPCSTR lpszDestination, bool bRawDump);

private:
	HANDLE hFlash;
	DWORD XBFS_BUFFER_LEN = 1048576;
};
+33 −0
Original line number Diff line number Diff line
#include "PCH.h"
#include "XRF.h"
#include "XBFS.h"

#define CMD_CONSOLE_INFO "cinfo"
#define CMD_DISPFLASH "dispflash"
#define CMD_READFLASH "readflash"
#define CMD_DUMPFLASH "dumpflash"
#define CMD_WHOAMI "whoami"

int main(int argc, char *argv[])
{
@@ -17,6 +22,34 @@ int main(int argc, char *argv[])
		PrintConsoleRevision();
		PrintDevkitType();
	}
	else if (strncmp(CMD_DISPFLASH, argv[1], strlen(CMD_DISPFLASH)) == 0) {
		printf("List of XBFS Entires:\n");
		for (int i = 0; i < sizeof(XBFS_ENTRIES) / sizeof(char*); ++i) {
			printf("XBFS Entry: %s\n", XBFS_ENTRIES[i]);
		}
	}
	else if (strncmp(CMD_READFLASH, argv[1], strlen(CMD_READFLASH)) == 0) {
		if (argc < 3) {
			printf("Read Flash: Please supply a filename!\n");
			printf("Example: readflash sp_s.cfg D:\\DevelopmentFiles\n");
			return 3;
		}
		printf("WARNING! REQUIRES ADMINISTRATOR PRIVILEGES!\n");
		XBFS xbfs;
		xbfs.Read(argv[2], argv[3], false);
	}
	else if (strncmp(CMD_DUMPFLASH, argv[1], strlen(CMD_DUMPFLASH)) == 0) {
		if (argc < 2) {
			printf("Dump Flash: Please supply a destination file name to dump to!\n");
			return 3;
		}
		printf("WARNING! REQUIRES ADMINISTRATOR PRIVILEGES!\n");
		XBFS xbfs;
		xbfs.Read("", argv[2], true);
	}
	else if (strncmp(CMD_WHOAMI, argv[1], strlen(CMD_WHOAMI)) == 0) {
		PrintCurrentUser();
	}
	else {
		printf("[XRF] Unknown command passed.\n");
		return 2;

Source/Source/XBFS.cpp

0 → 100644
+76 −0
Original line number Diff line number Diff line
#include "PCH.h"
#include "XBFS.h"
#include "XRF.h"

bool XBFS::Open(LPCSTR lpszFile, bool bRawDump)
{
	char path[10000];
	if (bRawDump)
		strcat_s(path, PIPE_NAME_XVUC_FLASH);
	else
		strcat_s(path, PIPE_NAME_XVUC_FLASHFS);

	strcat_s(path, lpszFile);

	hFlash = CreateFileA(path, GENERIC_READ, 
		FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

	if (!hFlash) {
		printf("[XBFS] Unable to open flash!\n");
		return false;
	}

	return true;
}

void XBFS::Close()
{
	if (hFlash) {
		CloseHandle(hFlash);
	}
}

bool XBFS::Read(LPCSTR lpszFileName, LPCSTR lpszDestination, bool bRawDump)
{
	DWORD dwNumRead = 0;
	FILE* f = NULL;

	if (!this->Open(lpszFileName, bRawDump)) {
		return false;
	}

	char* buffer = (char*)VirtualAlloc(0, XBFS_BUFFER_LEN, MEM_COMMIT, PAGE_READWRITE);
	if (!buffer) {
		printf("[XBFS] Failed to allocate memory: 0x%08\r\n", GetLastError());
		return false;
	}

	printf("[XBFS] Attempting to read %s from flash...\n", lpszFileName);
	for (;;) {
		if (!ReadFile(hFlash, buffer, XBFS_BUFFER_LEN, &dwNumRead, 0)) {
			printf("[XBFS] Unable to read from flash! Error: %ld\n", GetLastError());
			return false;
		}
		if (!dwNumRead)
			break;
		if (!f)
			f = fopen(lpszDestination, "wb");
		fwrite(buffer, dwNumRead, 1, f);
		printf(".");
	}

	printf("\n\n");

	this->Close();

	if (!f) {
		printf("[XBFS] File does not exist!\n");
		return false;
	}

	printf("[XBFS] Copied %i bytes from %s successfully!\n", ftell(f), lpszFileName);

	fclose(f);

	return true;
}
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
@@ -105,10 +105,12 @@
    <ClCompile Include="Source\PCH.cpp">
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
    </ClCompile>
    <ClCompile Include="Source\XBFS.cpp" />
    <ClCompile Include="Source\XRF.cpp" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="Include\PCH.h" />
    <ClInclude Include="Include\XBFS.h" />
    <ClInclude Include="Include\XRF.h" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+6 −0
Original line number Diff line number Diff line
@@ -18,6 +18,9 @@
    <ClCompile Include="Source\XRF.cpp">
      <Filter>Source</Filter>
    </ClCompile>
    <ClCompile Include="Source\XBFS.cpp">
      <Filter>Source</Filter>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="Include\XRF.h">
@@ -26,5 +29,8 @@
    <ClInclude Include="Include\PCH.h">
      <Filter>Include</Filter>
    </ClInclude>
    <ClInclude Include="Include\XBFS.h">
      <Filter>Include</Filter>
    </ClInclude>
  </ItemGroup>
</Project>
 No newline at end of file