Skip to content

Commit

Permalink
ExtendedTools TPM incremental read
Browse files Browse the repository at this point in the history
  • Loading branch information
jxy-s committed Oct 21, 2024
1 parent f208aa3 commit f08098c
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions plugins/ExtendedTools/tpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,10 @@ NTSTATUS EtTpmReadPublic(
}

_Must_inspect_result_
NTSTATUS EtTpmRead(
NTSTATUS EtTpmReadOffset(
_In_ TBS_HCONTEXT TbsContextHandle,
_In_ TPM_NV_INDEX Index,
_In_ USHORT Offset,
_Out_writes_bytes_all_(DataSize) PBYTE Data,
_In_ USHORT DataSize
)
Expand Down Expand Up @@ -232,7 +233,7 @@ NTSTATUS EtTpmRead(
command->AuthSession.PasswordSize = 0;
footer = (TPM_NV_READ_CMD_FOOTER*)&command->AuthSession.Password[0];

footer->Offset = 0;
footer->Offset = _byteswap_ushort(Offset);
footer->Size = _byteswap_ushort(DataSize);

size = FIELD_OFFSET(TPM_NV_READ_REPLY, Data);
Expand Down Expand Up @@ -275,6 +276,50 @@ NTSTATUS EtTpmRead(
return status;
}

_Must_inspect_result_
NTSTATUS EtTpmRead(
_In_ TBS_HCONTEXT TbsContextHandle,
_In_ TPM_NV_INDEX Index,
_Out_writes_bytes_all_(DataSize) PBYTE Data,
_In_ USHORT DataSize
)
{
NTSTATUS status;
USHORT remaining;
USHORT offset;

RtlZeroMemory(Data, DataSize);

remaining = DataSize;
offset = 0;

while (remaining)
{
USHORT readSize;

//
// Certain TPMs do not support reads over a certain sizes that is
// smaller than the specification recommends.
//
readSize = min(remaining, 512);

status = EtTpmReadOffset(TbsContextHandle,
Index,
offset,
PTR_ADD_OFFSET(Data, offset),
readSize);
if (!NT_SUCCESS(status))
{
return status;
}

offset += readSize;
remaining -= readSize;
}

return STATUS_SUCCESS;
}

NTSTATUS TpmOpen(
_Out_ PHANDLE FileHandle
)
Expand Down

0 comments on commit f08098c

Please sign in to comment.