Posts C 가상화 난독화 난독화를 위한 손코딩
Post
Cancel

C 가상화 난독화 난독화를 위한 손코딩

난독화 전 C코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>

int main()
{
  int temp = 10;

  for (int i=0; i<5; i++)
  {
    if(temp < 13){
      temp = temp + 1;
    }
    else{
      temp = temp - 1;
    }
    temp = temp * 10;
  }

  temp = temp-1088890;
  printf("%d\n", temp);
}

난독화 후 C코드 ver01

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
#include <stdio.h>

/*
test.c 난독화 방법 1
-------------------
각 변수들에 대해 미리 선언해 둔 후, switch_variable을 이용해 다음에 어떤 case로 이동할 것인지를 정해 준다.

이때 각 case를 위한 switch_variable은 난수를 생성하여 넣어준다.
*/

int main() {
  // 사용할 변수들 선언
  int temp;
  int i;

  // flattening을 위한 switch문
  int switch_variable = 2934982;
  while (switch_variable != -1) {
    switch (switch_variable) {
    case 2934982:
      temp = 10;
      switch_variable = 33848428;
      break;
    case 33848428:
      i = 0;
      switch_variable = 2339292;
      break;
    case 2339292:
      if (i < 5) {
        switch_variable = 195748;
      }else{
        switch_variable = 8;
      }
      break;
    case 195748:
      if (temp < 13) {
        switch_variable = 8476377;
      }else{
        switch_variable = 4642929;
      }
      break;
    case 8476377:
      temp = temp + 1;
      switch_variable = 6728349;
      break;
    case 4642929:
      temp = temp - 1;
      switch_variable = 6728349;
      break;
    case 6728349:
      temp = temp * 10;
      i++;
      switch_variable = 2339292;
      break;
    case 8:
      temp = temp-1088890;
      printf("%d\n", temp);
      switch_variable = -1;
      break;
    }
  }
}

난독화 후 C코드 ver02

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
#include <stdio.h>

/*
test.c 난독화 방법 2
-------------------
execute_order_stack에 실행될 블럭들을 넣어 두고, execute_order_index을 이동시키면서 각각의 블럭들을 실행할 수 있게 한다.
*/

int main() {
  // 사용할 변수들 선언
  int temp;
  int i;

  // 스택 역할을 할 배열
  int execute_order_stack[100] = {-1, 8, 3, 2, 1};
  int execute_order_index = 4;

  // flattening을 위한 switch문
  int switch_variable = execute_order_stack[execute_order_index];
  while (switch_variable != -1) {
    switch (switch_variable) {
    case 1:
      temp = 10;
      break;
    case 2:
      i = 0;
      break;
    case 3:
      // for문
      if (i < 5) {
        /*
        for while등 루프를 돌 때는 true이면 다시 여기로 돌아와야 해서 위치를 유지하기 위해 이렇게 ++해줌
        */
        execute_order_index++;

        execute_order_stack[execute_order_index] = 4;
        execute_order_index++;
      }
      break;
    case 4:
      // if문
      /*
      if문일 때에는 if문이 끝난 뒤 실행할 블럭을 먼저 스택에 넣어준 후 if문 블럭을 넣음
      */
      execute_order_stack[execute_order_index] = 7;
      execute_order_index++;

      if (temp < 13) {
        execute_order_stack[execute_order_index] = 5;
        execute_order_index++;
      } else {
        execute_order_stack[execute_order_index] = 6;
        execute_order_index++;
      }
      break;
    case 5:
      temp = temp + 1;
      break;
    case 6:
      temp = temp - 1;
      break;
    case 7:
      temp = temp * 10;
      i++;
      break;
    case 8:
      temp = temp - 1088890;
      printf("%d\n", temp);
      break;
    }
    execute_order_index--;
    switch_variable = execute_order_stack[execute_order_index];
  }
}
This post is licensed under CC BY 4.0 by the author.

Contents