bogus control flow (bcf)

핵심 : 불투명 술어로 코드 제어

예시

int x = 1;
if (x + x == 3)
{
	// 불투명 술어 거짓. 실행되면 안되므로 더미 코드가 들어감
}
if (x - 1 == 0)
{
	// 불투명 술어 참. 실행되어야 하는 코드
}
#include <stdio.h>
#include <time.h>
#include <stdlib.h>

int main()
{
        srand(time(NULL));  
        int i = rand() % 3;      

        if (i == 0)
        {
               printf("0\n");
        }
        else if (i == 1)
        {
               printf("1\n");
        }
        else if (i == 2)
        {
               printf("2\n");
        }
        else if (i == 3)
        {
               printf("3\n");
        }

        return i;
}

IDA Result (Original)

int __cdecl main(int argc, const char **argv, const char **envp)
{
  unsigned int v3; // w0
  int v5; // [xsp+8h] [xbp-8h]

  v3 = time(0LL);
  srand(v3);
  v5 = rand() % 3;
  if ( v5 )
  {
    switch ( v5 )
    {
      case 1:
        printf("1\n");
        break;
      case 2:
        printf("2\n");
        break;
      case 3:
        printf("3\n");
        break;
    }
  }
  else
  {
    printf("0\n");
  }
  return v5;
}

IDA Result (Obfuscation)

int __cdecl main(int argc, const char **argv, const char **envp)
{
  unsigned int v3; // w0
  int v4; // w19

  v3 = time(0LL);
  srand(v3);
  v4 = rand() % 3;
  switch ( v4 )
  {
    case 2:
      puts("2");
      break;
    case 1:
      if ( ((x + x * x) & 1) != 0 && y > 9 )
        goto LABEL_16;
      while ( 1 )
      {
        puts("1");
        if ( ((x + x * x) & 1) == 0 || y < 10 )
          break;
LABEL_16:
        puts("1");
      }
      break;
    case 0:
      if ( ((x + x * x) & 1) != 0 && y > 9 )
        goto LABEL_13;
      while ( 1 )
      {
        puts("0");
        if ( ((x + x * x) & 1) == 0 || y < 10 )
          break;
LABEL_13:
        puts("0");
      }
      break;
  }
  return v4;
}

 

+ Recent posts