This repository has been archived by the owner on Jul 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDump.c
117 lines (103 loc) · 3.23 KB
/
Dump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Protocol/SimpleFileSystem.h>
// Transmit Passed-in Data to Server
EFI_STATUS TestNetwork (EFI_HANDLE ImageHandle);//, CHAR8 *Buffer);
// Dump the PCR values into the Buffer with Specific Structure && Dump Data into file
EFI_STATUS ExtractPcrValue(CHAR16* Buffer);
// Convert CHAR8 Ascii to CHAR16 Unicode
VOID AsciiToUnicodeSize( CHAR8 *String, UINT8 length, CHAR16 *UniString);
// Encrypt the input Data with SHA256 Alogorithm
EFI_STATUS CryptoData(IN CHAR8 *HashData);
// Test FTP Client
EFI_STATUS TestMtftpConnection (IN EFI_HANDLE ImageHandle);
VOID
CheckStatus (
IN CHAR16 *Text,
IN EFI_STATUS Status
)
{
if (EFI_ERROR(Status)){
Print(L"Error Status %d of %s", Status, Text);
}
else {
Print(L"Status Success %d\n", Status);
}
}
EFI_STATUS
DumpData (
IN CHAR16 *TextBuffer
)
{
UINTN BufferSize;
EFI_STATUS Status;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;
EFI_FILE_PROTOCOL *Root; // File Handle of the FS Root Directory
Status = gBS->LocateProtocol( &gEfiSimpleFileSystemProtocolGuid,
NULL,
(VOID**)&SimpleFileSystem);
if (EFI_ERROR(Status)) {
Print(L"Cannot Locate SimpleFileSystem Protocol: %d\n", Status);
return Status;
}
// Get the Handle of the FS Root Directory
Status = SimpleFileSystem->OpenVolume(SimpleFileSystem, &Root);
if (EFI_ERROR(Status)) {
Print(L"Failed to acquire the Root Handle: %d\n", Status);
return Status;
}
// Open or Create a new file
EFI_FILE_PROTOCOL *FileHandle = 0;
//CHAR16 *Buf = (CHAR16*)L"This is the Content\n";
Status = Root->Open( Root,
&FileHandle,
(CHAR16*)L"test.txt",
EFI_FILE_MODE_CREATE | EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE,
0);
// Check and write into the file
CheckStatus(L" EFI_FILE_PROTOCOL Create file \n", Status);
if (FileHandle && !(EFI_ERROR(Status))) {
BufferSize = StrLen(TextBuffer) * 2;
Status = FileHandle->Write(FileHandle, &BufferSize, TextBuffer);
CheckStatus(L" EFI_FILE_PROTOCOL Write file \n ", Status);
Status = FileHandle->Close(FileHandle);
return Status;
}
return EFI_ABORTED;
}
EFI_STATUS
EFIAPI
ShellAppMain (
IN UINTN Argc,
IN CHAR16 **Argv
)
{
// Test FileIo Writing
EFI_STATUS Status;
CHAR16 *Text = (CHAR16*)L"This is the content\n";
Status = DumpData(Text);
if (EFI_ERROR(Status)) {
Print(L"The Dumping Process Aborted\n");
}
// Test Char data extraction
CHAR16 Buffer[1024];
//CHAR16 newBuffer[1024];
Status = ExtractPcrValue(Buffer);
if (EFI_ERROR(Status)) {
Print(L"The Extraction Process Aborted\n");
}
else {
Print(L"Extract Success\n");
Print(L"Return Result: %s\n", Buffer);
}
// Test the Cryption
CHAR8 newBuffer[1024];
UnicodeStrToAsciiStrS(Buffer, newBuffer, 1024);
Status = CryptoData(newBuffer);
if (EFI_ERROR(Status)) {
Print(L"The Encrytion Process Aborted\n");
}
Status = TestMtftpConnection (gImageHandle);
return TestNetwork(gImageHandle);//, Buffer);
}