diff options
author | kavsrf <kavsrf@gmail.com> | 2017-02-05 23:45:29 +0300 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2017-06-05 17:36:54 +0200 |
commit | fdfe9f849c15dc4b864a72fcbc5266edb68171c1 (patch) | |
tree | ec625901931928af079611f8af9cc3dc5d6ed3f9 /DcsCfg | |
parent | abf3adcd2f37f4e278fc9ef7634ca0c8f5171893 (diff) | |
download | VeraCrypt-DCS-fdfe9f849c15dc4b864a72fcbc5266edb68171c1.tar.gz VeraCrypt-DCS-fdfe9f849c15dc4b864a72fcbc5266edb68171c1.zip |
DcsCfg dumps of secregion and tables
Diffstat (limited to 'DcsCfg')
-rw-r--r-- | DcsCfg/DcsCfg.h | 7 | ||||
-rw-r--r-- | DcsCfg/DcsCfgCrypt.c | 72 | ||||
-rw-r--r-- | DcsCfg/DcsCfgMain.c | 22 |
3 files changed, 101 insertions, 0 deletions
diff --git a/DcsCfg/DcsCfg.h b/DcsCfg/DcsCfg.h index 8a9a15a..6fda422 100644 --- a/DcsCfg/DcsCfg.h +++ b/DcsCfg/DcsCfg.h @@ -95,6 +95,13 @@ EFI_STATUS SecRigionAdd(
IN UINTN regIdx
);
+
+EFI_STATUS
+SecRigionDump(
+ IN EFI_HANDLE hBio,
+ IN CHAR16 *prefix
+ );
+
//////////////////////////////////////////////////////////////////////////
// Set DcsInt parameters
//////////////////////////////////////////////////////////////////////////
diff --git a/DcsCfg/DcsCfgCrypt.c b/DcsCfg/DcsCfgCrypt.c index 94f8768..dc87534 100644 --- a/DcsCfg/DcsCfgCrypt.c +++ b/DcsCfg/DcsCfgCrypt.c @@ -18,6 +18,7 @@ https://opensource.org/licenses/LGPL-3.0 #include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/BaseMemoryLib.h>
+#include <Library/PrintLib.h>
#include <Guid/Gpt.h>
#include <Guid/GlobalVariable.h>
@@ -1372,6 +1373,77 @@ error: }
EFI_STATUS
+SecRigionDump(
+ IN EFI_HANDLE hBio,
+ IN CHAR16 *prefix
+ )
+{
+ EFI_STATUS res = EFI_SUCCESS;
+ EFI_BLOCK_IO_PROTOCOL* bio;
+ DCS_AUTH_DATA_MARK* adm = NULL;
+ UINT32 crc;
+ UINT8* SecRegionData = NULL;
+ UINTN SecRegionSize = 0;
+ UINTN SecRegionOffset = 0;
+ UINTN saveSize = 0;
+ UINTN idx = 0;
+ CHAR16 name[128];
+
+ adm = (DCS_AUTH_DATA_MARK*)MEM_ALLOC(512);
+ if (adm == NULL) {
+ ERR_PRINT(L"no memory\n");
+ return EFI_BUFFER_TOO_SMALL;
+ }
+
+ bio = EfiGetBlockIO(hBio);
+ if (bio == NULL) {
+ ERR_PRINT(L"No block IO");
+ res = EFI_ACCESS_DENIED;
+ goto err;
+ }
+
+ CE(bio->ReadBlocks(bio, bio->Media->MediaId, 61, 512, adm));
+ CE(gBS->CalculateCrc32(&adm->PlatformCrc, sizeof(*adm) - 4, &crc));
+
+ if (adm->HeaderCrc != crc) {
+ res = EFI_INVALID_PARAMETER;
+ }
+
+ SecRegionSize = adm->AuthDataSize * 128 * 1024;
+ SecRegionData = MEM_ALLOC(SecRegionSize);
+ if (SecRegionData == NULL) {
+ res = EFI_BUFFER_TOO_SMALL;
+ goto err;
+ }
+ CE(bio->ReadBlocks(bio, bio->Media->MediaId, 62, SecRegionSize, SecRegionData));
+
+ do {
+ // EFI tables?
+ if (TablesVerify(SecRegionSize - SecRegionOffset, SecRegionData + SecRegionOffset)) {
+ EFI_TABLE_HEADER *mhdr = (EFI_TABLE_HEADER *)(SecRegionData + SecRegionOffset);
+ UINTN tblZones = (mhdr->HeaderSize + 1024 * 128 - 1) / (1024 * 128);
+ saveSize = tblZones * 1024 * 128;
+ } else {
+ saveSize = 1024 * 128;
+ }
+ UnicodeSPrint(name, sizeof(name), L"%s%d", prefix, idx);
+ CE(FileSave(NULL, name, SecRegionData + SecRegionOffset, saveSize));
+ OUT_PRINT(L"%s saved\n", name);
+ idx += saveSize / (1024 * 128);
+ SecRegionOffset += saveSize;
+ } while (SecRegionOffset < SecRegionSize);
+
+err:
+ if (EFI_ERROR(res)) {
+ ERR_PRINT(L"%r\n", res);
+ }
+ MEM_FREE(adm);
+ MEM_FREE(SecRegionData);
+ return res;
+}
+
+
+EFI_STATUS
SecRigionAdd(
IN UINTN regIdx
)
diff --git a/DcsCfg/DcsCfgMain.c b/DcsCfg/DcsCfgMain.c index ec92b25..daf0fb0 100644 --- a/DcsCfg/DcsCfgMain.c +++ b/DcsCfg/DcsCfgMain.c @@ -75,6 +75,7 @@ https://opensource.org/licenses/LGPL-3.0 #define OPT_SECREGION_MARK L"-srm"
#define OPT_SECREGION_WIPE L"-srw"
#define OPT_SECREGION_ADD L"-sra"
+#define OPT_SECREGION_DUMP L"-srdump"
#define OPT_WIPE L"-wipe"
#define OPT_OS_DECRYPT L"-osdecrypt"
#define OPT_OS_RESTORE_KEY L"-osrestorekey"
@@ -88,8 +89,10 @@ https://opensource.org/licenses/LGPL-3.0 #define OPT_TBL_NAME L"-tbn"
#define OPT_TBL_DELETE L"-tbd"
#define OPT_TBL_APPEND L"-tba"
+#define OPT_TBL_DUMP L"-tbdump"
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
+ { OPT_TBL_DUMP, TypeValue },
{ OPT_TBL_FILE, TypeValue },
{ OPT_TBL_ZERO, TypeFlag },
{ OPT_TBL_LIST, TypeFlag },
@@ -137,6 +140,7 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = { { OPT_SECREGION_MARK, TypeValue },
{ OPT_SECREGION_WIPE, TypeValue },
{ OPT_SECREGION_ADD, TypeValue },
+ { OPT_SECREGION_DUMP, TypeValue },
{ OPT_WIPE, TypeDoubleValue },
{ OPT_OS_DECRYPT, TypeFlag },
{ OPT_OS_RESTORE_KEY, TypeFlag },
@@ -264,6 +268,13 @@ DcsCfgMain( res = TablesNew(opt1, opt2);
}
+ if (ShellCommandLineGetFlag(Package, OPT_TBL_DUMP))
+ {
+ CONST CHAR16* opt = NULL;
+ opt = ShellCommandLineGetValue(Package, OPT_TBL_DUMP);
+ res = TablesDump((CHAR16*)opt);
+ }
+
if (ShellCommandLineGetFlag(Package, OPT_TBL_LIST)) {
if (gDcsTables == NULL) TablesLoad();
OUT_PRINT(L"Size = %d, Zones=%d\n", gDcsTablesSize, (gDcsTablesSize + 128 * 1024 - 1) / (128 * 1024));
@@ -692,6 +703,17 @@ DcsCfgMain( }
}
+ if (ShellCommandLineGetFlag(Package, OPT_SECREGION_DUMP)) {
+ if (ShellCommandLineGetFlag(Package, OPT_DISK_START)) {
+ CONST CHAR16* opt = NULL;
+ opt = ShellCommandLineGetValue(Package, OPT_SECREGION_DUMP);
+ SecRigionDump(gBIOHandles[BioIndexStart], (CHAR16*)opt);
+ } else {
+ ERR_PRINT(L"Select disk");
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+
// Encrypt, decrypt, change password
if (ShellCommandLineGetFlag(Package, OPT_DISK_CHECK)) {
DisksAuthCheck();
|