aboutsummaryrefslogtreecommitdiffstats
path: root/fw/pseudo/merit.merit_cmd04.after.c
blob: 1cafa40f4fb255958a62ee3a2d6659e234e32093 (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
// Slot lookup, CORRECTLY bounded (checked, negative).
// 
// v5 = *(params+16) host index
// guard (v5 - 1) <= 0x3F -> v5 in [1,64]
// slot presence byte at off_401CE0 + 257*v5, required != 0 (liveness IS checked)
// 
// The 1-based range is right, not an off-by-one: the allocator merit_cmd01 walks v1 = 1
// while v1 != 65 with v2 += 257 starting at base+257, so valid slots are 1..64, and
// merit_TA_CreateEntryPoint zero-fills 0x4141 = 257*65 bytes, i.e. the whole array
// including the unused slot 0. So index 64 is the last valid slot and the guard matches
// the allocator exactly.
// 
// Flagged by fw/ta_liveness_audit.py only because its liveness test is '!= 0' rather than
// a compare against a small constant; recorded so the lead is not re-opened.
int __fastcall merit_cmd04(void *ctx, struct ta_params *params)
{
  int v2; // r7
  int *v3; // r8
  _DWORD *v4; // r6
  int v6; // r0
  int result; // r0
  char *v8; // r5
  int v9; // r0
  int v10; // r1
  _BYTE *v11; // r5
  unsigned int dst[4]; // [sp+8h] [bp-104h] BYREF
  int v13; // [sp+28h] [bp-E4h]
  int v14; // [sp+2Ch] [bp-E0h]
  int v15; // [sp+108h] [bp-4h]

  v4 = (_DWORD *)off_401BD8;
  v15 = *(_DWORD *)off_401BD8;
  v6 = *((_DWORD *)ctx + 4);
  if ( (unsigned int)(v6 - 1) <= 0x3F && (v3 = (int *)off_401CE0, v2 = 257 * v6, *((_BYTE *)off_401CE0 + 257 * v6) != 0) )
  {
    merit_lib_zero_fill_words(dst, len: 0x100u);
    if ( merit_cmd04__h1(ctx: (char *)ctx + 20, params: *((struct ta_params **)ctx + 69)) == 0 )
      goto LABEL_8;
    result = 267;
  }
  else
  {
    result = 259;
  }
  while ( *v4 != v15 )
  {
    ((void (__fastcall *)(int, int))loc_40202C)(a1: result, a2: *v4 - v15);
LABEL_8:
    v8 = (char *)v3 + v2;
    if ( merit_lib_52b900d8_88(a1: (int)v3 + v2 + 1, a2: (int)dst, a3: 16) != 0 )
    {
      result = 560;
    }
    else
    {
      merit_lib_thunk_tailjump(a1: (int)(v8 + 17));
      v9 = v13;
      v10 = v14;
      v8[33] = v13;
      v11 = v8 + 33;
      v11[4] = v10;
      v11 += 4;
      v11[3] = HIBYTE(v10);
      v11[2] = BYTE2(v10);
      v11[1] = BYTE1(v10);
      *(v11 - 1) = HIBYTE(v9);
      *(v11 - 2) = BYTE2(v9);
      *(v11 - 3) = BYTE1(v9);
      result = 0;
    }
  }
  return result;
}