VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkavsrf <kavsrf@gmail.com>2017-02-05 20:45:29 (GMT)
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2017-06-05 15:36:54 (GMT)
commitfdfe9f849c15dc4b864a72fcbc5266edb68171c1 (patch)
treeec625901931928af079611f8af9cc3dc5d6ed3f9
parentabf3adcd2f37f4e278fc9ef7634ca0c8f5171893 (diff)
downloadVeraCrypt-DCS-fdfe9f849c15dc4b864a72fcbc5266edb68171c1.zip
VeraCrypt-DCS-fdfe9f849c15dc4b864a72fcbc5266edb68171c1.tar.gz
DcsCfg dumps of secregion and tables
-rw-r--r--DcsCfg/DcsCfg.h7
-rw-r--r--DcsCfg/DcsCfgCrypt.c72
-rw-r--r--DcsCfg/DcsCfgMain.c22
-rw-r--r--Include/Library/DcsCfgLib.h5
-rw-r--r--Library/DcsCfgLib/GptEdit.c45
5 files changed, 151 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();
diff --git a/Include/Library/DcsCfgLib.h b/Include/Library/DcsCfgLib.h
index 259004e..4c8153b 100644
--- a/Include/Library/DcsCfgLib.h
+++ b/Include/Library/DcsCfgLib.h
@@ -138,6 +138,11 @@ TablesList(
IN VOID* tables
);
+EFI_STATUS
+TablesDump(
+ IN CHAR16 *prefix
+ );
+
//////////////////////////////////////////////////////////////////////////
// Random
//////////////////////////////////////////////////////////////////////////
diff --git a/Library/DcsCfgLib/GptEdit.c b/Library/DcsCfgLib/GptEdit.c
index d486909..5545791 100644
--- a/Library/DcsCfgLib/GptEdit.c
+++ b/Library/DcsCfgLib/GptEdit.c
@@ -14,6 +14,7 @@ https://opensource.org/licenses/LGPL-3.0
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DevicePathLib.h>
#include <Library/BaseMemoryLib.h>
+#include <Library/PrintLib.h>
#include <Uefi/UefiGpt.h>
#include <Guid/Gpt.h>
@@ -815,6 +816,50 @@ err:
}
EFI_STATUS
+TablesDump(
+ IN CHAR16 *prefix
+ ) {
+ EFI_TABLE_HEADER *mhdr = NULL;
+ EFI_STATUS res = EFI_SUCCESS;
+ CHAR16 name[128];
+
+ if (gDcsTables == NULL) {
+ CE(TablesLoad());
+ }
+
+ mhdr = (EFI_TABLE_HEADER *)gDcsTables;
+ if (gDcsTables != NULL &&
+ mhdr->Signature == EFITABLE_HEADER_SIGN &&
+ GptHeaderCheckCrc(gDcsTablesSize, mhdr)) {
+ UINT8* raw = (UINT8*)gDcsTables;
+ UINTN rawSize = mhdr->HeaderSize;
+ UINTN tpos = sizeof(EFI_TABLE_HEADER);
+ while (tpos < rawSize) {
+ EFI_TABLE_HEADER *hdr = (EFI_TABLE_HEADER *)(raw + tpos);
+ CHAR8 asc_sign[sizeof(hdr->Signature) + 1] = { 0 };
+ CopyMem(asc_sign, &hdr->Signature, sizeof(hdr->Signature));
+ asc_sign[sizeof(hdr->Signature)] = 0;
+ UnicodeSPrint(name, sizeof(name), L"%s%a", prefix, asc_sign);
+ OUT_PRINT(L"%s, SZ=%d", name, hdr->HeaderSize);
+ if (!GptHeaderCheckCrc(rawSize - tpos, hdr)) {
+ ERR_PRINT(L" - wrong crc\n");
+ return EFI_CRC_ERROR; // wrong crc
+ }
+ CE(FileSave(NULL, name, raw + tpos + sizeof(EFI_TABLE_HEADER), hdr->HeaderSize - sizeof(EFI_TABLE_HEADER)));
+ OUT_PRINT(L" - saved\n");
+ tpos += hdr->HeaderSize;
+ }
+ return EFI_SUCCESS;
+ }
+
+err:
+ if (EFI_ERROR(res)) {
+ ERR_PRINT(L"Tables load error %r\n", res);
+ }
+ return res;
+}
+
+EFI_STATUS
TablesNew(
IN CONST CHAR16* signStr,
IN CONST CHAR16* dataFileName