# CVE-2026-119382 — tpm.sys patch diff

`tpm.sys` 10.0.26100.9549 -> 10.0.26100.9818 (ghidriff).

## `CreateWindowsEk`  (modified)

```diff
--- CreateWindowsEk
+++ CreateWindowsEk
@@ -1,77 +1,441 @@
 

 /* WARNING: Function: __security_check_cookie replaced with injection: security_check_cookie */

+/* long __cdecl CreateWindowsEk(class Tpm20Context * __ptr64,class TpmStack * __ptr64,class Event *

+   __ptr64) */

 

 long __cdecl CreateWindowsEk(Tpm20Context *param_1,TpmStack *param_2,Event *param_3)

 

 {

-  int in_EAX;

-  uint uVar1;

-  undefined8 uVar2;

-  _tlgProvider_t *p_Var3;

-  int unaff_EBX;

-  longlong unaff_RBP;

-  undefined *unaff_RSI;

-  int unaff_EDI;

-  _GUID *p_Var4;

-  _GUID *in_R9;

-  void *unaff_R12;

-  void *unaff_R15;

-  char in_stack_00000040;

-  undefined4 in_stack_00000044;

-  undefined4 in_stack_00000060;

-  wchar_t *in_stack_00000068;

-  uint in_stack_00000078;

+  byte bVar1;

+  uint uVar2;

+  uint uVar3;

+  long lVar4;

+  undefined8 uVar5;

+  TPM2B_BUFFER *pTVar6;

+  TPM2B_BUFFER *pTVar7;

+  Tpm20Context *pTVar8;

+  _tlgProvider_t *p_Var9;

+  undefined2 uVar10;

+  int iVar11;

+  TPM2B_BUFFER *pTVar12;

+  _GUID *p_Var14;

+  _TPM20_HANDLE *p_Var15;

+  TPM2B_BUFFER *in_R9;

+  TPM2B_BUFFER *pTVar16;

+  TPM2B_BUFFER *pTVar17;

+  TPM2B_BUFFER *pTVar18;

+  __uint64 unaff_retaddr;

+  undefined1 auStackY_188 [32];

+  TPM2B_BUFFER *in_stack_fffffffffffffe98;

+  EkCertNvIndex *pEVar19;

+  uint local_144;

+  char local_140;

+  uint local_138 [2];

+  uint local_130;

+  uint local_12c;

+  uint local_128;

+  uint local_124;

+  TPM2B_BUFFER *local_120;

+  undefined8 local_118;

+  uint local_110;

+  TPM2B_BUFFER *local_108;

+  TPM2B_BUFFER *local_100;

+  undefined2 local_f8 [4];

+  uchar *local_f0;

+  undefined2 local_e8 [4];

+  uchar *local_e0;

+  undefined2 local_d8 [4];

+  undefined8 local_d0;

+  undefined2 local_c8 [4];

+  undefined8 local_c0;

+  uchar local_b8 [24];

+  uchar local_a0 [24];

+  undefined8 local_88;

+  undefined8 uStack_80;

+  undefined8 local_78;

+  undefined8 uStack_70;

+  undefined8 local_68;

+  undefined8 uStack_60;

+  undefined8 local_58;

+  undefined2 local_50;

+  ulonglong local_48;

+  TPM2B_BUFFER *pTVar13;

   

-  uVar1 = in_EAX + 0x5a0860f;

-  *(char *)(ulonglong)uVar1 = *(char *)(ulonglong)uVar1 + (char)uVar1;

-  uVar2 = _tlgKeywordOn();

-  if ((char)uVar2 != '\0') {

-    *(undefined8 *)(unaff_RBP + -0x80) = 0x1000000;

-    in_stack_00000068 = L"Persistent EK already present; EK creation not needed.";

+  local_48 = __security_cookie ^ (ulonglong)auStackY_188;

+  pTVar13 = (TPM2B_BUFFER *)0x0;

+  pTVar12 = (TPM2B_BUFFER *)0x0;

+  local_100 = (TPM2B_BUFFER *)0x0;

+  local_130 = 0;

+  local_12c = 0;

+  pTVar18 = (TPM2B_BUFFER *)0x0;

+  local_124 = 0;

+  pTVar17 = (TPM2B_BUFFER *)0x0;

+  local_c8[0] = 0;

+  local_c0 = 0;

+  TPM2B_BUFFER::Clear((TPM2B_BUFFER *)local_c8,'\x01');

+  local_d8[0] = 0;

+  local_d0 = 0;

+  TPM2B_BUFFER::Clear((TPM2B_BUFFER *)local_d8,'\x01');

+  local_e8[0] = 0;

+  local_e0 = (uchar *)0x0;

+  local_58 = 0;

+  local_50 = 0;

+  local_88 = 0;

+  uStack_80 = 0;

+  local_a0[0x10] = '\0';

+  local_a0[0x11] = '\0';

+  local_a0[0x12] = '\0';

+  local_a0[0x13] = '\0';

+  local_78 = 0;

+  uStack_70 = 0;

+  local_68 = 0;

+  uStack_60 = 0;

+  local_a0[0] = '\0';

+  local_a0[1] = '\0';

+  local_a0[2] = '\0';

+  local_a0[3] = '\0';

+  local_a0[4] = '\0';

+  local_a0[5] = '\0';

+  local_a0[6] = '\0';

+  local_a0[7] = '\0';

+  local_a0[8] = '\0';

+  local_a0[9] = '\0';

+  local_a0[10] = '\0';

+  local_a0[0xb] = '\0';

+  local_a0[0xc] = '\0';

+  local_a0[0xd] = '\0';

+  local_a0[0xe] = '\0';

+  local_a0[0xf] = '\0';

+  TPM2B_BUFFER::Clear((TPM2B_BUFFER *)local_e8,'\x01');

+  local_108 = (TPM2B_BUFFER *)0x0;

+  local_f8[0] = 0;

+  local_b8[0x10] = '\0';

+  local_b8[0x11] = '\0';

+  local_b8[0x12] = '\0';

+  local_b8[0x13] = '\0';

+  local_f0 = (uchar *)0x0;

+  local_b8[0] = '\0';

+  local_b8[1] = '\0';

+  local_b8[2] = '\0';

+  local_b8[3] = '\0';

+  local_b8[4] = '\0';

+  local_b8[5] = '\0';

+  local_b8[6] = '\0';

+  local_b8[7] = '\0';

+  local_b8[8] = '\0';

+  local_b8[9] = '\0';

+  local_b8[10] = '\0';

+  local_b8[0xb] = '\0';

+  local_b8[0xc] = '\0';

+  local_b8[0xd] = '\0';

+  local_b8[0xe] = '\0';

+  local_b8[0xf] = '\0';

+  TPM2B_BUFFER::Clear((TPM2B_BUFFER *)local_f8,'\x01');

+  local_120 = (TPM2B_BUFFER *)0x0;

+  local_118 = 0;

+  local_110 = 0;

+  local_140 = '\0';

+  bVar1 = 0;

+  local_128 = 0;

+  uVar3 = CheckForCancellation(param_3);

+  pTVar7 = pTVar17;

+  pTVar6 = pTVar13;

+  if (-1 < (int)uVar3) {

+    in_R9 = (TPM2B_BUFFER *)0x0;

+    p_Var14 = (_GUID *)0x0;

+    uVar3 = Tpm20ReadPublicEk(param_1,param_2,(TPM2B_BUFFER *)0x0,(TPM2B_BUFFER *)0x0);

+    pTVar6 = pTVar18;

+    if ((int)uVar3 < 0) {

+      uVar3 = CheckForCancellation(param_3);

+      if (-1 < (int)uVar3) {

+        local_144 = 0;

+        uVar3 = Tpm20GetPermanent(param_1,param_2,&local_144);

+        uVar2 = local_144;

+        if (-1 < (int)uVar3) {

+          if ((local_144 & 2) == 0) {

+LAB_0:

+            if ((uVar2 & 1) == 0) {

+LAB_1:

+              uVar3 = CheckForCancellation(param_3);

+              if (((-1 < (int)uVar3) &&

+                  (uVar3 = GetEkNvIndex2kFirst((EkCertNvIndex *)&local_118,

+                                               *(_tlgProvider_t **)(param_2 + 0x28),param_3),

+                  -1 < (int)uVar3)) && (uVar3 = CheckForCancellation(param_3), -1 < (int)uVar3)) {

+                in_R9 = (TPM2B_BUFFER *)&local_12c;

+                lVar4 = Tpm20NVReadPublic(param_1,param_2,local_118._4_4_,(uint *)in_R9,

+                                          in_stack_fffffffffffffe98);

+                pTVar6 = pTVar13;

+                if ((lVar4 < 0) || (local_12c == 0)) {

+LAB_2:

+                  uVar3 = CheckForCancellation(param_3);

+                  pTVar18 = pTVar13;

+                  pTVar7 = pTVar13;

+                  if ((int)uVar3 < 0) goto LAB_3;

+                  if (local_110 == 0) {

+LAB_4:

+                    local_124 = 0x187;

+                    pTVar7 = (TPM2B_BUFFER *)TpmAlloc(true,0x187,unaff_retaddr);

+                    pTVar16 = in_R9;

+                    if (pTVar7 == (TPM2B_BUFFER *)0x0) {

+LAB_5:

+                      in_R9 = pTVar16;

+                      uVar3 = 0xc000009a;

+                      pTVar18 = pTVar13;

+                    }

+                    else {

+                      in_R9 = (TPM2B_BUFFER *)(ulonglong)local_12c;

+                      pEVar19 = (EkCertNvIndex *)&local_118;

+                      uVar3 = PrepareEkTemplate((uchar *)pTVar7,&local_124,(uchar *)pTVar6,local_12c

+                                                ,(uchar *)local_100,local_130,pEVar19);

+                      if (uVar3 == 0xc000003c) {

+                        TpmFree(pTVar7);

+                        pTVar7 = (TPM2B_BUFFER *)TpmAlloc(true,(ulonglong)local_124,unaff_retaddr);

+                        pTVar16 = in_R9;

+                        if (pTVar7 == (TPM2B_BUFFER *)0x0) goto LAB_5;

+                        in_R9 = (TPM2B_BUFFER *)(ulonglong)local_12c;

+                        pEVar19 = (EkCertNvIndex *)&local_118;

+                        uVar3 = PrepareEkTemplate((uchar *)pTVar7,&local_124,(uchar *)pTVar6,

+                                                  local_12c,(uchar *)local_100,local_130,pEVar19);

+                      }

+                      pTVar18 = pTVar12;

+                      if (-1 < (int)uVar3) {

+                        p_Var15 = (_TPM20_HANDLE *)&local_128;

+                        pTVar8 = param_1;

+                        in_R9 = pTVar7;

+                        uVar3 = Tpm20CreatePrimaryEk

+                                          (param_1,param_2,p_Var15,(uchar *)pTVar7,local_124,

+                                           local_120,(TPM2B_BUFFER *)pEVar19);

+                        if ((5 < DAT_6) && (uVar5 = _tlgKeywordOn(), (char)uVar5 != '\0')) {

+                          local_120 = (TPM2B_BUFFER *)0x1000000;

+                          local_144 = uVar3;

+                          _tlgWriteTemplate<long___cdecl(_tlgProvider_t_const*___ptr64,void_const*___ptr64,_GUID_const*___ptr64,_GUID_const*___ptr64,unsigned_int,_EVENT_DATA_DESCRIPTOR*___ptr64),&long___cdecl__tlgWriteTransfer_EtwWriteTransfer(struct__tlgProvider_t_const*___ptr64,void_const*___ptr64,struct__GUID_const*___ptr64,struct__GUID_const*___ptr64,unsigned_int,struct__EVENT_DATA_DESCRIPTOR*___ptr64),_GUID_const*___ptr64,_GUID_const*___ptr64>

+                          ::Write<_tlgWrapperByVal<8>,_tlgWrapperByVal<4>_>

+                                    ((_tlgProvider_t *)pTVar8,&DAT_7,(_GUID *)p_Var15,

+                                     (_GUID *)in_R9,(_tlgWrapperByVal<8> *)&local_120,

+                                     (_tlgWrapperByVal<4> *)&local_144);

+                        }

+                        if ((int)uVar3 < 0) {

+                          pTVar18 = (TPM2B_BUFFER *)(ulonglong)local_128;

+                        }

+                        else {

+                          uVar3 = CheckForCancellation(param_3);

+                          pTVar18 = (TPM2B_BUFFER *)(ulonglong)local_128;

+                          if (-1 < (int)uVar3) {

+                            in_R9 = (TPM2B_BUFFER *)0x81010001;

+                            uVar3 = Tpm20EvictControl();

+                            if (-1 < (int)uVar3) {

+                              in_R9 = (TPM2B_BUFFER *)local_d8;

+                              uVar3 = Tpm20ReadPublicEk(param_1,param_2,(TPM2B_BUFFER *)local_c8,

+                                                        in_R9);

+                              if (-1 < (int)uVar3) {

+                                if (((undefined **)WPP_GLOBAL_Control != &WPP_GLOBAL_Control) &&

+                                   ((*(uint *)(WPP_GLOBAL_Control + 0x2c) & 4) != 0)) {

+                                  WPP_SF_(*(undefined8 *)(WPP_GLOBAL_Control + 0x18),0x16,

+                                          &WPP_712c6ef29221392127b07027e960d3a7_Traceguids);

+                                }

+                                UpdateRegistryEkValues

+                                          ((TPM2B_BUFFER *)local_c8,(TPM2B_BUFFER *)local_d8);

+                              }

+                              if (((undefined **)WPP_GLOBAL_Control != &WPP_GLOBAL_Control) &&

+                                 ((*(uint *)(WPP_GLOBAL_Control + 0x2c) & 4) != 0)) {

+                                WPP_SF_(*(undefined8 *)(WPP_GLOBAL_Control + 0x18),0x17,

+                                        &WPP_712c6ef29221392127b07027e960d3a7_Traceguids);

+                              }

+                            }

+                          }

+                        }

+                      }

+                    }

+                  }

+                  else {

+                    pTVar16 = (TPM2B_BUFFER *)&local_130;

+                    lVar4 = Tpm20NVReadPublic(param_1,param_2,local_110,(uint *)pTVar16,

+                                              in_stack_fffffffffffffe98);

+                    in_R9 = pTVar16;

+                    if ((lVar4 < 0) || (local_130 == 0)) {

+LAB_8:

+                      uVar3 = CheckForCancellation(param_3);

+                      pTVar18 = pTVar12;

+                      pTVar7 = pTVar17;

+                      if (-1 < (int)uVar3) goto LAB_4;

+                    }

+                    else {

+                      uVar3 = CheckForCancellation(param_3);

+                      in_R9 = pTVar16;

+                      pTVar7 = pTVar17;

+                      if (-1 < (int)uVar3) {

+                        in_R9 = (TPM2B_BUFFER *)TpmAlloc(true,(ulonglong)local_130,unaff_retaddr);

+                        pTVar7 = pTVar13;

+                        local_100 = in_R9;

+                        if (in_R9 == (TPM2B_BUFFER *)0x0) goto LAB_5;

+                        uVar3 = Tpm20NVRead(param_1,param_2,local_110,(uchar *)in_R9,&local_130,

+                                            local_108);

+                        pTVar18 = pTVar12;

+                        pTVar7 = pTVar17;

+                        if (-1 < (int)uVar3) {

+                          bVar1 = 1;

+                          goto LAB_8;

+                        }

+                      }

+                    }

+                  }

+LAB_3:

+                  iVar11 = (int)pTVar18;

+                  pTVar12 = pTVar18;

+                  if (local_140 != '\0') {

+                    p_Var14 = (_GUID *)(local_118 >> 0x20);

+                    goto LAB_9;

+                  }

+                  goto LAB_10;

+                }

+                uVar3 = CheckForCancellation(param_3);

+                if (-1 < (int)uVar3) {

+                  pTVar6 = (TPM2B_BUFFER *)TpmAlloc(true,(ulonglong)local_12c,unaff_retaddr);

+                  if (pTVar6 == (TPM2B_BUFFER *)0x0) {

+                    uVar3 = 0xc000009a;

+                  }

+                  else {

+                    in_stack_fffffffffffffe98 = (TPM2B_BUFFER *)&local_12c;

+                    in_R9 = pTVar6;

+                    uVar3 = Tpm20NVRead(param_1,param_2,local_118._4_4_,(uchar *)pTVar6,

+                                        (uint *)in_stack_fffffffffffffe98,local_108);

+                    if (-1 < (int)uVar3) {

+                      local_140 = '\x01';

+                      goto LAB_2;

+                    }

+                  }

+                  goto LAB_10;

+                }

+              }

+              pTVar6 = (TPM2B_BUFFER *)0x0;

+              goto LAB_10;

+            }

+            in_stack_fffffffffffffe98 =

+                 (TPM2B_BUFFER *)CONCAT44((int)((ulonglong)in_stack_fffffffffffffe98 >> 0x20),0x3a);

+            in_R9 = (TPM2B_BUFFER *)&local_88;

+            uVar3 = TpmRegistry::QueryValue

+                              (3,(ushort *)L"StorageOwnerAuth",1,(TPM2B_BUFFER *)&local_88,0x3a,

+                               (ulong *)0x0);

+            if ((int)uVar3 < 0) {

+              if (((undefined **)WPP_GLOBAL_Control != &WPP_GLOBAL_Control) &&

+                 ((*(uint *)(WPP_GLOBAL_Control + 0x2c) & 4) != 0)) {

+                uVar10 = 0x14;

+LAB_11:

+                WPP_SF_(*(undefined8 *)(WPP_GLOBAL_Control + 0x18),uVar10,

+                        &WPP_712c6ef29221392127b07027e960d3a7_Traceguids);

+              }

+            }

+            else {

+              local_144 = 0x14;

+              uVar3 = TpmBase64Decode((ushort *)&local_88,local_a0,&local_144);

+              if (-1 < (int)uVar3) {

+                local_e8[0] = (undefined2)local_144;

+                local_e0 = local_a0;

+                local_108 = (TPM2B_BUFFER *)local_e8;

+                goto LAB_1;

+              }

+              if (((undefined **)WPP_GLOBAL_Control != &WPP_GLOBAL_Control) &&

+                 ((*(uint *)(WPP_GLOBAL_Control + 0x2c) & 4) != 0)) {

+                uVar10 = 0x15;

+                goto LAB_11;

+              }

+            }

+          }

+          else {

+            in_stack_fffffffffffffe98 =

+                 (TPM2B_BUFFER *)CONCAT44((int)((ulonglong)in_stack_fffffffffffffe98 >> 0x20),0x3a);

+            in_R9 = (TPM2B_BUFFER *)&local_88;

+            uVar3 = TpmRegistry::QueryValue

+                              (4,(ushort *)L"EndorsementAuth",1,(TPM2B_BUFFER *)&local_88,0x3a,

+                               (ulong *)0x0);

+            if ((int)uVar3 < 0) {

+              if (((undefined **)WPP_GLOBAL_Control != &WPP_GLOBAL_Control) &&

+                 ((*(uint *)(WPP_GLOBAL_Control + 0x2c) & 4) != 0)) {

+                uVar10 = 0x12;

+                goto LAB_11;

+              }

+            }

+            else {

+              local_144 = 0x14;

+              uVar3 = TpmBase64Decode((ushort *)&local_88,local_b8,&local_144);

+              if (-1 < (int)uVar3) {

+                local_f8[0] = (undefined2)local_144;

+                local_f0 = local_b8;

+                local_120 = (TPM2B_BUFFER *)local_f8;

+                goto LAB_0;

+              }

+              if (((undefined **)WPP_GLOBAL_Control != &WPP_GLOBAL_Control) &&

+                 ((*(uint *)(WPP_GLOBAL_Control + 0x2c) & 4) != 0)) {

+                uVar10 = 0x13;

+                goto LAB_11;

+              }

+            }

+          }

+          pTVar6 = (TPM2B_BUFFER *)0x0;

+        }

+      }

+    }

+    else {

+      p_Var9 = (_tlgProvider_t *)WPP_GLOBAL_Control;

+      if (((undefined **)WPP_GLOBAL_Control != &WPP_GLOBAL_Control) &&

+         ((*(uint *)(WPP_GLOBAL_Control + 0x2c) & 4) != 0)) {

+        p_Var9 = *(_tlgProvider_t **)(WPP_GLOBAL_Control + 0x18);

+        p_Var14 = (_GUID *)&WPP_712c6ef29221392127b07027e960d3a7_Traceguids;

+        WPP_SF_(p_Var9,0x11,&WPP_712c6ef29221392127b07027e960d3a7_Traceguids);

+      }

+      pTVar12 = pTVar13;

+      pTVar7 = pTVar13;

+      pTVar6 = pTVar13;

+      if ((5 < DAT_6) &&

+         (uVar5 = _tlgKeywordOn(), pTVar7 = pTVar17, pTVar6 = pTVar18, (char)uVar5 != '\0')) {

+        local_108 = (TPM2B_BUFFER *)0x1000000;

+        local_120 = (TPM2B_BUFFER *)0x14003ddf0;

+        _tlgWriteTemplate<long___cdecl(_tlgProvider_t_const*___ptr64,void_const*___ptr64,_GUID_const*___ptr64,_GUID_const*___ptr64,unsigned_int,_EVENT_DATA_DESCRIPTOR*___ptr64),&long___cdecl__tlgWriteTransfer_EtwWriteTransfer(struct__tlgProvider_t_const*___ptr64,void_const*___ptr64,struct__GUID_const*___ptr64,struct__GUID_const*___ptr64,unsigned_int,struct__EVENT_DATA_DESCRIPTOR*___ptr64),_GUID_const*___ptr64,_GUID_const*___ptr64>

+        ::Write<_tlgWrapperByVal<8>,_tlgWrapSz<unsigned_short>_>

+                  (p_Var9,&DAT_12,p_Var14,(_GUID *)in_R9,(_tlgWrapperByVal<8> *)&local_108,

+                   (_tlgWrapSz<unsigned_short> *)&local_120);

+      }

+    }

+  }

+LAB_10:

+  iVar11 = (int)pTVar12;

+  p_Var14 = (_GUID *)0x0;

+LAB_9:

+  p_Var9 = (_tlgProvider_t *)(ulonglong)(-(uint)bVar1 & local_110);

+  if ((5 < DAT_6) && (uVar5 = _tlgKeywordOn(), (char)uVar5 != '\0')) {

+    local_128 = (uint)p_Var9;

+    local_144 = (uint)p_Var14;

+    local_120 = (TPM2B_BUFFER *)0x1000000;

+    local_138[0] = uVar3;

     _tlgWriteTemplate<long___cdecl(_tlgProvider_t_const*___ptr64,void_const*___ptr64,_GUID_const*___ptr64,_GUID_const*___ptr64,unsigned_int,_EVENT_DATA_DESCRIPTOR*___ptr64),&long___cdecl__tlgWriteTransfer_EtwWriteTransfer(struct__tlgProvider_t_const*___ptr64,void_const*___ptr64,struct__GUID_const*___ptr64,struct__GUID_const*___ptr64,unsigned_int,struct__EVENT_DATA_DESCRIPTOR*___ptr64),_GUID_const*___ptr64,_GUID_const*___ptr64>

-    ::Write<_tlgWrapperByVal<8>,_tlgWrapSz<unsigned_short>_>

-              ((_tlgProvider_t *)param_1,&DAT_0,(_GUID *)param_3,in_R9,

-               (_tlgWrapperByVal<8> *)(unaff_RBP + -0x80),

-               (_tlgWrapSz<unsigned_short> *)&stack0x00000068);

-  }

-  p_Var4 = (_GUID *)0x0;

-  p_Var3 = (_tlgProvider_t *)(ulonglong)(-(uint)(in_stack_00000040 != '\0') & in_stack_00000078);

-  if (5 < DAT_1) {

-    uVar2 = _tlgKeywordOn();

-    if ((char)uVar2 != '\0') {

-      in_stack_00000060 = SUB84(p_Var3,0);

-      in_stack_00000044 = SUB84(p_Var4,0);

-      in_stack_00000068 = (wchar_t *)0x1000000;

-      _tlgWriteTemplate<long___cdecl(_tlgProvider_t_const*___ptr64,void_const*___ptr64,_GUID_const*___ptr64,_GUID_const*___ptr64,unsigned_int,_EVENT_DATA_DESCRIPTOR*___ptr64),&long___cdecl__tlgWriteTransfer_EtwWriteTransfer(struct__tlgProvider_t_const*___ptr64,void_const*___ptr64,struct__GUID_const*___ptr64,struct__GUID_const*___ptr64,unsigned_int,struct__EVENT_DATA_DESCRIPTOR*___ptr64),_GUID_const*___ptr64,_GUID_const*___ptr64>

-      ::Write<_tlgWrapperByVal<8>,_tlgWrapperByVal<4>,_tlgWrapperByVal<4>,_tlgWrapperByVal<4>_>

-                (p_Var3,&DAT_2,p_Var4,in_R9,(_tlgWrapperByVal<8> *)&stack0x00000068,

-                 (_tlgWrapperByVal<4> *)&stack0x00000050,(_tlgWrapperByVal<4> *)&stack0x00000044,

-                 (_tlgWrapperByVal<4> *)&stack0x00000060);

-    }

-  }

-  if (unaff_EBX != 0) {

-    Tpm20CmdFlushContextWorker();

-  }

-  if (((unaff_EDI == -0x3ffffee0) && (WPP_GLOBAL_Control != unaff_RSI)) &&

+    ::Write<_tlgWrapperByVal<8>,_tlgWrapperByVal<4>,_tlgWrapperByVal<4>,_tlgWrapperByVal<4>_>

+              (p_Var9,&DAT_13,p_Var14,(_GUID *)in_R9,(_tlgWrapperByVal<8> *)&local_120,

+               (_tlgWrapperByVal<4> *)local_138,(_tlgWrapperByVal<4> *)&local_144,

+               (_tlgWrapperByVal<4> *)&local_128);

+  }

+  if (iVar11 != 0) {

+    Tpm20CmdFlushContextWorker(param_1,param_2,0,iVar11);

+  }

+  if (((uVar3 == 0xc0000120) && ((undefined **)WPP_GLOBAL_Control != &WPP_GLOBAL_Control)) &&

      ((*(uint *)(WPP_GLOBAL_Control + 0x2c) & 4) != 0)) {

     WPP_SF_(*(undefined8 *)(WPP_GLOBAL_Control + 0x18),0x18,

             &WPP_712c6ef29221392127b07027e960d3a7_Traceguids);

   }

-  *(undefined8 *)(unaff_RBP + -0x58) = 0;

-  *(undefined8 *)(unaff_RBP + -0x68) = 0;

-  if (*(void **)(unaff_RBP + -0x78) != (void *)0x0) {

-    TpmFree(*(void **)(unaff_RBP + -0x78));

-  }

-  if (unaff_R15 != (void *)0x0) {

-    TpmFree(unaff_R15);

-  }

-  if (unaff_R12 != (void *)0x0) {

-    TpmFree(unaff_R12);

-  }

-  TPM2B_BUFFER::Clear((TPM2B_BUFFER *)(unaff_RBP + -0x70),'\0');

-  TPM2B_BUFFER::Clear((TPM2B_BUFFER *)(unaff_RBP + -0x60),'\0');

-  TPM2B_BUFFER::Clear((TPM2B_BUFFER *)(unaff_RBP + -0x50),'\0');

-  TPM2B_BUFFER::Clear((TPM2B_BUFFER *)(unaff_RBP + -0x40),'\0');

-  return unaff_EDI;

+  local_e0 = (uchar *)0x0;

+  local_f0 = (uchar *)0x0;

+  if (local_100 != (TPM2B_BUFFER *)0x0) {

+    TpmFree(local_100);

+  }

+  if (pTVar6 != (TPM2B_BUFFER *)0x0) {

+    TpmFree(pTVar6);

+  }

+  if (pTVar7 != (TPM2B_BUFFER *)0x0) {

+    TpmFree(pTVar7);

+  }

+  TPM2B_BUFFER::Clear((TPM2B_BUFFER *)local_f8,'\0');

+  TPM2B_BUFFER::Clear((TPM2B_BUFFER *)local_e8,'\0');

+  TPM2B_BUFFER::Clear((TPM2B_BUFFER *)local_d8,'\0');

+  TPM2B_BUFFER::Clear((TPM2B_BUFFER *)local_c8,'\0');

+  return uVar3;

 }
```

## `IsRsaEkCertIndex2kOver3k`  (modified)

```diff
--- IsRsaEkCertIndex2kOver3k
+++ CreateWindowsEk
@@ -1,10 +1,77 @@
 

-/* WARNING: Control flow encountered bad instruction data */

+/* WARNING: Function: __security_check_cookie replaced with injection: security_check_cookie */

 

-undefined8 IsRsaEkCertIndex2kOver3k(uint param_1)

+long __cdecl CreateWindowsEk(Tpm20Context *param_1,TpmStack *param_2,Event *param_3)

 

 {

-                    /* WARNING: Bad instruction - Truncating control flow here */

-  halt_baddata();

+  int in_EAX;

+  uint uVar1;

+  undefined8 uVar2;

+  _tlgProvider_t *p_Var3;

+  int unaff_EBX;

+  longlong unaff_RBP;

+  undefined *unaff_RSI;

+  int unaff_EDI;

+  _GUID *p_Var4;

+  _GUID *in_R9;

+  void *unaff_R12;

+  void *unaff_R15;

+  char in_stack_00000040;

+  undefined4 in_stack_00000044;

+  undefined4 in_stack_00000060;

+  wchar_t *in_stack_00000068;

+  uint in_stack_00000078;

+  

+  uVar1 = in_EAX + 0x5a0860f;

+  *(char *)(ulonglong)uVar1 = *(char *)(ulonglong)uVar1 + (char)uVar1;

+  uVar2 = _tlgKeywordOn();

+  if ((char)uVar2 != '\0') {

+    *(undefined8 *)(unaff_RBP + -0x80) = 0x1000000;

+    in_stack_00000068 = L"Persistent EK already present; EK creation not needed.";

+    _tlgWriteTemplate<long___cdecl(_tlgProvider_t_const*___ptr64,void_const*___ptr64,_GUID_const*___ptr64,_GUID_const*___ptr64,unsigned_int,_EVENT_DATA_DESCRIPTOR*___ptr64),&long___cdecl__tlgWriteTransfer_EtwWriteTransfer(struct__tlgProvider_t_const*___ptr64,void_const*___ptr64,struct__GUID_const*___ptr64,struct__GUID_const*___ptr64,unsigned_int,struct__EVENT_DATA_DESCRIPTOR*___ptr64),_GUID_const*___ptr64,_GUID_const*___ptr64>

+    ::Write<_tlgWrapperByVal<8>,_tlgWrapSz<unsigned_short>_>

+              ((_tlgProvider_t *)param_1,&DAT_0,(_GUID *)param_3,in_R9,

+               (_tlgWrapperByVal<8> *)(unaff_RBP + -0x80),

+               (_tlgWrapSz<unsigned_short> *)&stack0x00000068);

+  }

+  p_Var4 = (_GUID *)0x0;

+  p_Var3 = (_tlgProvider_t *)(ulonglong)(-(uint)(in_stack_00000040 != '\0') & in_stack_00000078);

+  if (5 < DAT_1) {

+    uVar2 = _tlgKeywordOn();

+    if ((char)uVar2 != '\0') {

+      in_stack_00000060 = SUB84(p_Var3,0);

+      in_stack_00000044 = SUB84(p_Var4,0);

+      in_stack_00000068 = (wchar_t *)0x1000000;

+      _tlgWriteTemplate<long___cdecl(_tlgProvider_t_const*___ptr64,void_const*___ptr64,_GUID_const*___ptr64,_GUID_const*___ptr64,unsigned_int,_EVENT_DATA_DESCRIPTOR*___ptr64),&long___cdecl__tlgWriteTransfer_EtwWriteTransfer(struct__tlgProvider_t_const*___ptr64,void_const*___ptr64,struct__GUID_const*___ptr64,struct__GUID_const*___ptr64,unsigned_int,struct__EVENT_DATA_DESCRIPTOR*___ptr64),_GUID_const*___ptr64,_GUID_const*___ptr64>

+      ::Write<_tlgWrapperByVal<8>,_tlgWrapperByVal<4>,_tlgWrapperByVal<4>,_tlgWrapperByVal<4>_>

+                (p_Var3,&DAT_2,p_Var4,in_R9,(_tlgWrapperByVal<8> *)&stack0x00000068,

+                 (_tlgWrapperByVal<4> *)&stack0x00000050,(_tlgWrapperByVal<4> *)&stack0x00000044,

+                 (_tlgWrapperByVal<4> *)&stack0x00000060);

+    }

+  }

+  if (unaff_EBX != 0) {

+    Tpm20CmdFlushContextWorker();

+  }

+  if (((unaff_EDI == -0x3ffffee0) && (WPP_GLOBAL_Control != unaff_RSI)) &&

+     ((*(uint *)(WPP_GLOBAL_Control + 0x2c) & 4) != 0)) {

+    WPP_SF_(*(undefined8 *)(WPP_GLOBAL_Control + 0x18),0x18,

+            &WPP_712c6ef29221392127b07027e960d3a7_Traceguids);

+  }

+  *(undefined8 *)(unaff_RBP + -0x58) = 0;

+  *(undefined8 *)(unaff_RBP + -0x68) = 0;

+  if (*(void **)(unaff_RBP + -0x78) != (void *)0x0) {

+    TpmFree(*(void **)(unaff_RBP + -0x78));

+  }

+  if (unaff_R15 != (void *)0x0) {

+    TpmFree(unaff_R15);

+  }

+  if (unaff_R12 != (void *)0x0) {

+    TpmFree(unaff_R12);

+  }

+  TPM2B_BUFFER::Clear((TPM2B_BUFFER *)(unaff_RBP + -0x70),'\0');

+  TPM2B_BUFFER::Clear((TPM2B_BUFFER *)(unaff_RBP + -0x60),'\0');

+  TPM2B_BUFFER::Clear((TPM2B_BUFFER *)(unaff_RBP + -0x50),'\0');

+  TPM2B_BUFFER::Clear((TPM2B_BUFFER *)(unaff_RBP + -0x40),'\0');

+  return unaff_EDI;

 }
```

## `Feature_Prefer2kEkOver3k__private_IsEnabledDeviceUsageNoInline`  (modified)

```diff
--- Feature_Prefer2kEkOver3k__private_IsEnabledDeviceUsageNoInline
+++ CheckForCancellation
@@ -1,10 +1,21 @@
 

-/* WARNING: Control flow encountered bad instruction data */

+/* long __cdecl CheckForCancellation(class Event * __ptr64) */

 

-ulonglong Feature_Prefer2kEkOver3k__private_IsEnabledDeviceUsageNoInline(void)

+long __cdecl CheckForCancellation(Event *param_1)

 

 {

-                    /* WARNING: Bad instruction - Truncating control flow here */

-  halt_baddata();

+  int iVar1;

+  long lVar2;

+  undefined8 local_res8 [4];

+  

+  lVar2 = 0;

+  if (param_1 != (Event *)0x0) {

+    local_res8[0] = 0;

+    iVar1 = KeWaitForSingleObject(*(undefined8 *)param_1,0,0,0,local_res8);

+    if (iVar1 == 0) {

+      lVar2 = -0x3ffffee0;

+    }

+  }

+  return lVar2;

 }
```

## `TpmTransportMemBase::MapMemoryFromAcpiTable`  (modified)

```diff
--- TpmTransportMemBase::MapMemoryFromAcpiTable
+++ TpmTransportMemBase::MapMemoryFromAcpiTable
@@ -1,2 +1,126 @@
-Failed to decompile tpm.sys - .ProgramDB TpmTransportMemBase::MapMemoryFromAcpiTable : Error: Decompile error: 
-Marshaling error: Did not see expected closing element+

+/* WARNING: Function: _guard_dispatch_icall replaced with injection: guard_dispatch_icall */

+/* protected: virtual long __cdecl TpmTransportMemBase::MapMemoryFromAcpiTable(void) __ptr64 */

+

+long __thiscall TpmTransportMemBase::MapMemoryFromAcpiTable(TpmTransportMemBase *this)

+

+{

+  long lVar1;

+  undefined8 uVar2;

+  undefined2 uVar3;

+  longlong lVar4;

+  undefined4 uVar5;

+  undefined4 uVar6;

+  undefined8 local_res8;

+  

+  local_res8 = 0;

+  uVar5 = 0x204;

+  uVar6 = 0x202;

+  if (*(longlong *)(this + 0x138) != 0) {

+    return 0;

+  }

+  lVar1 = TpmTransportType::GetAcpiTableControlArea((_LARGE_INTEGER *)&local_res8);

+  lVar4 = local_res8;

+  if (lVar1 < 0) goto LAB_0;

+  if (local_res8 == 0) {

+    if (TpmTransportType::m_TalkingToTpmSimulator == 0) {

+      if ((undefined **)WPP_GLOBAL_Control == &WPP_GLOBAL_Control) {

+        return 0;

+      }

+      if ((*(uint *)(WPP_GLOBAL_Control + 0x2c) & 4) == 0) {

+        return 0;

+      }

+      WPP_SF_(*(undefined8 *)(WPP_GLOBAL_Control + 0x18),0x1b,

+              &WPP_dd815132aa8832781f59fec37e24cff4_Traceguids);

+      return 0;

+    }

+    lVar1 = PrepareMemoryForSimulator(this);

+    if (lVar1 == -0x3fffffff) {

+      lVar1 = TpmTransportType::GetAcpiTableControlArea((_LARGE_INTEGER *)&local_res8);

+      lVar4 = local_res8;

+      if (lVar1 < 0) goto LAB_0;

+    }

+    else if (lVar1 == -0x3fffff66) {

+      return 0;

+    }

+  }

+  if (*(int *)(this + 0x200) != 1) {

+    lVar1 = (**(code **)(*(longlong *)this + 0x68))(this,lVar4);

+    if (lVar1 < 0) goto LAB_0;

+    uVar2 = MmMapIoSpaceEx(lVar4,0x30,0x204);

+    *(undefined8 *)(this + 0x138) = uVar2;

+  }

+  lVar4 = *(longlong *)(this + 0x138);

+  if (lVar4 == 0) {

+    if (((undefined **)WPP_GLOBAL_Control != &WPP_GLOBAL_Control) &&

+       ((*(uint *)(WPP_GLOBAL_Control + 0x2c) & 1) != 0)) {

+      uVar3 = 0x1c;

+      goto LAB_1;

+    }

+  }

+  else {

+    if (TpmTransportType::m_TalkingToTpmSimulator != 0) {

+      uVar5 = 4;

+      uVar6 = 2;

+    }

+    if (((*(int *)(lVar4 + 0x20) == 0) && (*(int *)(lVar4 + 0x1c) == 0)) ||

+       ((*(int *)(lVar4 + 0x2c) == 0 && (*(int *)(lVar4 + 0x28) == 0)))) {

+      if (((undefined **)WPP_GLOBAL_Control != &WPP_GLOBAL_Control) &&

+         ((*(uint *)(WPP_GLOBAL_Control + 0x2c) & 1) != 0)) {

+        uVar3 = 0x1d;

+        goto LAB_1;

+      }

+    }

+    else {

+      if (*(int *)(this + 0x200) != 1) {

+        local_res8 = CONCAT44(*(int *)(lVar4 + 0x20),*(undefined4 *)(lVar4 + 0x1c));

+        uVar2 = MmMapIoSpaceEx(local_res8,*(undefined4 *)(lVar4 + 0x18),uVar5);

+        *(undefined8 *)(this + 0x140) = uVar2;

+      }

+      if (*(longlong *)(this + 0x140) == 0) {

+        if (((undefined **)WPP_GLOBAL_Control != &WPP_GLOBAL_Control) &&

+           ((*(uint *)(WPP_GLOBAL_Control + 0x2c) & 1) != 0)) {

+          uVar3 = 0x1e;

+          goto LAB_1;

+        }

+      }

+      else if ((*(uint *)(this + 0x140) & 3) == 0) {

+        if (*(int *)(this + 0x200) != 1) {

+          local_res8 = *(longlong *)(*(longlong *)(this + 0x138) + 0x28);

+          uVar2 = MmMapIoSpaceEx(local_res8,*(undefined4 *)(*(longlong *)(this + 0x138) + 0x24),

+                                 uVar6);

+          *(undefined8 *)(this + 0x148) = uVar2;

+        }

+        if (*(longlong *)(this + 0x148) == 0) {

+          if (((undefined **)WPP_GLOBAL_Control != &WPP_GLOBAL_Control) &&

+             ((*(uint *)(WPP_GLOBAL_Control + 0x2c) & 1) != 0)) {

+            uVar3 = 0x20;

+LAB_1:

+            WPP_SF_(*(undefined8 *)(WPP_GLOBAL_Control + 0x18),uVar3,

+                    &WPP_dd815132aa8832781f59fec37e24cff4_Traceguids);

+          }

+        }

+        else {

+          if ((*(uint *)(this + 0x148) & 3) == 0) {

+            return 0;

+          }

+          if (((undefined **)WPP_GLOBAL_Control != &WPP_GLOBAL_Control) &&

+             ((*(uint *)(WPP_GLOBAL_Control + 0x2c) & 1) != 0)) {

+            uVar3 = 0x21;

+            goto LAB_1;

+          }

+        }

+      }

+      else if (((undefined **)WPP_GLOBAL_Control != &WPP_GLOBAL_Control) &&

+              ((*(uint *)(WPP_GLOBAL_Control + 0x2c) & 1) != 0)) {

+        uVar3 = 0x1f;

+        goto LAB_1;

+      }

+    }

+  }

+  lVar1 = -0x3fffffff;

+LAB_0:

+  (**(code **)(*(longlong *)this + 0x70))(this);

+  return lVar1;

+}

+
```

## `TpmTransportMemBase::PrepareMemoryForSimulator`  (modified)

```diff
--- TpmTransportMemBase::PrepareMemoryForSimulator
+++ TpmTransportMemBase::PrepareMemoryForSimulator
@@ -1,2 +1,63 @@
-Failed to decompile tpm.sys - .ProgramDB TpmTransportMemBase::PrepareMemoryForSimulator : Error: Decompile error: 
-Marshaling error: Did not see expected closing element+

+/* WARNING: Function: _guard_dispatch_icall replaced with injection: guard_dispatch_icall */

+/* private: long __cdecl TpmTransportMemBase::PrepareMemoryForSimulator(void) __ptr64 */

+

+long __thiscall TpmTransportMemBase::PrepareMemoryForSimulator(TpmTransportMemBase *this)

+

+{

+  long lVar1;

+  undefined8 *puVar2;

+  longlong lVar3;

+  undefined8 uVar4;

+  undefined8 local_res18;

+  undefined8 local_res20;

+  

+  local_res20 = 0;

+  local_res18 = 0;

+  puVar2 = (undefined8 *)MmAllocateContiguousMemorySpecifyCache(0x30,0,0xffffffffffffffff,0,0);

+  *(undefined8 **)(this + 0x138) = puVar2;

+  if (puVar2 != (undefined8 *)0x0) {

+    *puVar2 = 0;

+    puVar2[1] = 0;

+    puVar2[2] = 0;

+    puVar2[3] = 0;

+    puVar2[4] = 0;

+    puVar2[5] = 0;

+    **(undefined4 **)(this + 0x138) = 0;

+    *(undefined4 *)(*(longlong *)(this + 0x138) + 4) = 0;

+    *(undefined4 *)(*(longlong *)(this + 0x138) + 8) = 0;

+    *(undefined4 *)(*(longlong *)(this + 0x138) + 0xc) = 0;

+    *(undefined4 *)(*(longlong *)(this + 0x138) + 0x18) = 0x2000;

+    *(undefined4 *)(*(longlong *)(this + 0x138) + 0x24) = 0x2000;

+    lVar3 = MmAllocateContiguousNodeMemory(0x2000,0,0xffffffffffffffff,0,4,0x80000000);

+    *(longlong *)(this + 0x140) = lVar3;

+    if (lVar3 != 0) {

+      uVar4 = MmGetPhysicalAddress(lVar3);

+      *(int *)(*(longlong *)(this + 0x138) + 0x20) = (int)((ulonglong)uVar4 >> 0x20);

+      *(int *)(*(longlong *)(this + 0x138) + 0x1c) = (int)uVar4;

+      lVar3 = MmAllocateContiguousNodeMemory(0x2000,0,0xffffffffffffffff,0,2,0x80000000);

+      *(longlong *)(this + 0x148) = lVar3;

+      if (lVar3 != 0) {

+        uVar4 = MmGetPhysicalAddress(lVar3);

+        *(int *)(*(longlong *)(this + 0x138) + 0x2c) = (int)((ulonglong)uVar4 >> 0x20);

+        *(int *)(*(longlong *)(this + 0x138) + 0x28) = (int)uVar4;

+        uVar4 = MmGetPhysicalAddress(*(undefined8 *)(this + 0x138));

+        lVar1 = TpmTransportType::SwapAcpiTableControlArea(uVar4,&local_res18);

+        if (-1 < lVar1) {

+          *(undefined4 *)(this + 0x200) = 1;

+          if ((local_res18._4_4_ == 0) && ((int)local_res18 == 0)) {

+            return lVar1;

+          }

+          lVar1 = -0x3fffffff;

+        }

+        goto LAB_0;

+      }

+    }

+  }

+  lVar1 = -0x3fffff66;

+LAB_0:

+  (**(code **)(*(longlong *)this + 0x70))(this);

+  *(undefined4 *)(this + 0x200) = 0;

+  return lVar1;

+}

+
```
