aboutsummaryrefslogtreecommitdiffstats
path: root/fw/pseudo/gcp.gcp_cmdFE09_ConfigureAuthenticatedSession.after.c
blob: d4d0d97760c62dc8bb3f44cde8aadaf206fe56cd (plain) (blame)
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
117
118
119
120
121
122
123
124
125
// COPY AUDIT: 3 call(s) with a non-literal length.
// sub_405084(a1: 0, a2: off_402B28[0], v8, v11) len=v11
// sub_405084(a1: 0, a2: (const char *)dword_402B6C, v8, v11) len=v11
// sub_405084(a1: 0, a2: off_402B70[0], v8, v11) len=v11
// 
// Guards seen in this function:
// if ( v4 >> 28 == 0 ) /*0x4029a4*/
// if ( v6 > 0xFFFFFFFB || v6 + 4 <= v7 ) /*0x4029d2*/
// if ( v9 != 1 ) /*0x4029f2*/
// if ( *(_DWORD *)(v14 + 792) == 3 ) /*0x402a14*/
// if ( sub_4052AC() == 0 ) /*0x402a22*/
// if ( v15 <= *(_DWORD *)(v14 + 840) ) /*0x402a70*/
// 
// Heuristic lead, not a verdict: a non-literal length may still be bounded elsewhere (HDCP carries bounded ubfx and unbounded ldrb paths in one function).
int __fastcall gcp_cmdFE09_ConfigureAuthenticatedSession(struct gcp_ctx *ctx, struct ta_params *params)
{
  unsigned int arg10; // r0
  int v5; // r6
  unsigned int v6; // r7
  unsigned int v7; // r10
  unsigned int v8; // r2
  int v9; // r8
  int v10; // r11
  int v11; // r3
  const char *v12; // r1
  bool v14; // cc
  char *v15; // r6
  unsigned int v16; // r0
  unsigned __int8 *v17; // r0
  struct gcp_ctx *v18; // [sp+0h] [bp-4h]

  gcp_log(level: 0, fmt: (const char *)sub_402AF4);
  arg10 = params->arg10;
  if ( arg10 >> 28 == 0 )
  {
    v6 = *(_DWORD *)&params->data20[2056];
    v7 = *(_DWORD *)&params->data20[2040];
    v8 = *(_DWORD *)&params->data20[1012];
    v9 = *(_DWORD *)&params->data20[2048];
    v10 = *(_DWORD *)&params->data20[2052];
    v11 = *(_DWORD *)&params->data20[2060];
    if ( v6 > 0xFFFFFFFB || v6 + 4 <= v7 )
    {
      if ( v9 != 1 )
      {
        v15 = (char *)ctx + 80 * HIBYTE(arg10);
        if ( *((_DWORD *)v15 + 198) == 3 )
        {
          v18 = (struct gcp_ctx *)(v15 + 792);
          if ( gcp_VerifyOMAC(
                 ctx: (struct gcp_ctx *)(v15 + 792),
                 params: (struct ta_params *)((char *)&params->arg10 + 4)) == 0 )
          {
            v16 = *((unsigned __int8 *)&params->arg10 + v10 + 4)
                | (*((unsigned __int8 *)&params->arg10 + v10 + 5) << 8)
                | ((*((unsigned __int8 *)&params->arg10 + v10 + 6)
                  | (*((unsigned __int8 *)&params->arg10 + v10 + 7) << 8)) << 16);
            if ( v16 <= *((_DWORD *)v15 + 210) )
            {
              gcp_log(level: 0, fmt: aAmdTaGcpErrorI);
              v5 = 560;
              goto LABEL_7;
            }
            *((_DWORD *)v15 + 210) = v16;
            if ( v9 != 2 )
            {
              if ( v9 == 3 )
              {
                v5 = gcp_ConfigureCryptoSession(ctx, params);
                if ( v5 != 0 )
                  goto LABEL_7;
              }
              else if ( v9 != 4 )
              {
                gcp_log(level: 0, fmt: (const char *)off_402B68);
                v5 = 561;
                goto LABEL_7;
              }
            }
            v5 = 0;
            v17 = &params->data20[v6 + 1016];
            *v17 = 0;
            v17[3] = 0;
            v17[2] = 0;
            v17[1] = 0;
            gcp_lib_db5482d6_100(a1: (int)&params->out1950, a2: (int)&params->data20[1016], a3: 1024);
            if ( gcp_GenerateOMAC(ctx: v18, params: (struct ta_params *)&params->out1950) == 0 )
            {
              v5 = 0;
              *(_DWORD *)&params[1].data20[984] = v7;
            }
            goto LABEL_7;
          }
          gcp_log(level: 0, fmt: (const char *)off_402B2C);
          v5 = 562;
        }
        else
        {
          gcp_log(level: 0, fmt: (const char *)off_402B28);
          v5 = 610;
        }
LABEL_7:
        gcp_log(level: 0, fmt: (const char *)off_402B74);
        return v5;
      }
      v14 = v11 + 4 > v8;
      if ( v11 + 4 <= v8 )
        v14 = *(_DWORD *)&params->data20[2064] + 4 > v8;
      if ( !v14 )
      {
        v5 = gcp_ConfigureInitialize(ctx, params);
        goto LABEL_7;
      }
      v12 = (const char *)dword_402B6C;
    }
    else
    {
      v12 = (const char *)off_402B70;
    }
    gcp_log(level: 0, fmt: v12);
    v5 = 256;
    goto LABEL_7;
  }
  return 256;
}