二进制炸弹bomb 计算机组成原理作业实战

分析

https://blog.csdn.net/CXY_YZ/article/details/115585852

反汇编:

点击查看代码
int __cdecl phase_2(char *s)
{
  int i; // ebx
  int result; // eax
  int v3[6]; // [esp+10h] [ebp-18h] BYREF

  read_six_numbers(s, (int)v3);
  if ( v3[0] != 1 )
    explode_bomb();
  for ( i = 1; i <= 5; ++i )
  {
    result = v3[i - 1] * (i + 1);
    if ( v3[i] != result )
      explode_bomb();
  }
  return result;
}

int __cdecl phase_3(char *s)
{
  int result; // eax
  char v2; // bl
  int v3; // [esp+Ch] [ebp-Ch] BYREF
  char v4; // [esp+13h] [ebp-5h] BYREF
  int v5; // [esp+14h] [ebp-4h] BYREF

  if ( sscanf(s, "%d %c %d", &v3, &v4, &v5) <= 2 )
    explode_bomb();
  result = v3;
  switch ( v3 )
  {
    case 0:
      v2 = 113;
      if ( v5 != 777 )
        explode_bomb();
      return result;
    case 1:
      v2 = 98;
      if ( v5 != 214 )
        explode_bomb();
      return result;
    case 2:
      v2 = 98;
      if ( v5 != 755 )
        explode_bomb();
      return result;
    case 3:
      v2 = 107;
      if ( v5 != 251 )
        explode_bomb();
      return result;
    case 4:
      v2 = 111;
      if ( v5 != 160 )
        explode_bomb();
      return result;
    case 5:
      v2 = 116;
      if ( v5 != 458 )
        explode_bomb();
      return result;
    case 6:
      v2 = 118;
      if ( v5 != 780 )
        explode_bomb();
      return result;
    case 7:
      v2 = 98;
      if ( v5 != 524 )
        explode_bomb();
      return result;
    default:
      explode_bomb();
  }
  if ( v2 != v4 )
    explode_bomb();
  return result;
}

int __cdecl func4(int a1)
{
  int v1; // esi

  if ( a1 <= 1 )
    return 1;
  v1 = func4(a1 - 1);
  return v1 + func4(a1 - 2);
}

int __cdecl phase_4(char *s)
{
  int result; // eax
  int v2; // [esp+14h] [ebp-4h] BYREF

  if ( sscanf(s, "%d", &v2) != 1 || v2 <= 0 )
    explode_bomb();
  result = func4(v2);
  if ( result != 55 )
    explode_bomb();
  return result;
}

int __cdecl phase_5(int a1)
{
  int i; // edx
  int result; // eax
  char v3[8]; // [esp+10h] [ebp-8h] BYREF

  if ( string_length(a1) != 6 )
    explode_bomb();
  for ( i = 0; i <= 5; ++i )
    v3[i] = array_123[*(_BYTE *)(i + a1) & 0xF];
  v3[6] = 0;
  result = strings_not_equal(v3, "giants");
  if ( result )
    explode_bomb();
  return result;
}
int __cdecl phase_5(_BYTE *a1)
{
  int v1; // ecx
  int i; // edx
  int result; // eax
  int v4; // ecx
  char v5[8]; // [esp+10h] [ebp-8h] BYREF

  if ( string_length(a1) != 6 )
    explode_bomb(v1);
  for ( i = 0; i <= 5; ++i )
    v5[i] = array_123[a1[i] & 0xF];
  v5[6] = 0;
  result = strings_not_equal(v5, "giants");
  if ( result )
    explode_bomb(v4);
  return result;
}

int __cdecl phase_6(char *s)
{
  int v1; // ecx
  int i; // edi
  int j; // ebx
  int k; // edi
  _DWORD *v5; // esi
  int m; // ebx
  int v7; // esi
  int n; // edi
  int v9; // eax
  int v10; // esi
  int ii; // edi
  int result; // eax
  int v13; // [esp+24h] [ebp-34h]
  int v14[6]; // [esp+28h] [ebp-30h]
  int v15[6]; // [esp+40h] [ebp-18h] BYREF

  read_six_numbers(s, (int)v15);
  for ( i = 0; i <= 5; ++i )
  {
    if ( (unsigned int)(v15[i] - 1) > 5 )
      explode_bomb(v1);
    for ( j = i + 1; j <= 5; ++j )
    {
      if ( v15[i] == v15[j] )
        explode_bomb(v1);
    }
  }
  for ( k = 0; k <= 5; ++k )
  {
    v5 = &node1;
    for ( m = 1; m < v15[k]; ++m )
      v5 = (_DWORD *)v5[2];
    v14[k] = (int)v5;
  }
  v7 = v14[0];
  v13 = v14[0];
  for ( n = 1; n <= 5; ++n )
  {
    v9 = v14[n];
    *(_DWORD *)(v7 + 8) = v9;
    v7 = v9;
  }
  *(_DWORD *)(v9 + 8) = 0;
  v10 = v13;
  for ( ii = 0; ii <= 4; ++ii )
  {
    result = *(_DWORD *)v10;
    if ( *(_DWORD *)v10 < **(_DWORD **)(v10 + 8) )
      explode_bomb(v15);
    v10 = *(_DWORD *)(v10 + 8);
  }
  return result;
}

void phase_defused()
{
  char v0; // [esp+14h] [ebp-54h] BYREF
  char v1[80]; // [esp+18h] [ebp-50h] BYREF

  if ( num_input_strings == 6 )
  {
    if ( sscanf(s, "%d %s", &v0, v1) == 2 && !strings_not_equal(v1, "austinpowers") )
    {
      printf("Curses, you've found the secret phase!\n");
      printf("But finding it and solving it are quite different...\n");
      secret_phase();
    }
    printf("Congratulations! You've defused the bomb!\n");
  }
}
int __cdecl fun7(_DWORD *a1, int a2)
{
  if ( !a1 )
    return -1;
  if ( a2 < *a1 )
    return 2 * fun7(a1[1], a2);
  if ( a2 == *a1 )
    return 0;
  return 2 * fun7(a1[2], a2) + 1;
}
void secret_phase()
{
  const char *line; // eax
  int v1; // ecx
  int v2; // ebx
  int v3; // ecx

  line = (const char *)read_line();
  v2 = __strtol_internal(line, 0, 10, 0);
  if ( (unsigned int)(v2 - 1) > 0x3E8 )
    explode_bomb(v1);
  if ( fun7(&n1, v2) != 7 )
    explode_bomb(v3);
  printf("Wow! You've defused the secret stage!\n");
  phase_defused();
}
posted @ 2022-11-30 23:01  Nolca  阅读(98)  评论(0编辑  收藏  举报