본문으로 바로가기

ASM to C with IDA - 063 (strpbrk)

category Reversing/ASM to C 2018. 7. 18. 12:23

C300_063



C300_소스코드



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <string.h>
 
#define TOKEN    " "
 
void main(void)
{
    char string[100];
    char *pos;
 
    puts("문자열을 입력한 후 Enter키를 치세요 !");
 
    gets(string);
 
    pos = strpbrk(string, TOKEN);
 
    while (pos != NULL)
    {
        puts(pos++);
 
        pos = strpbrk(pos, TOKEN);
    }
}
 
cs



IDA - Layout Graph





IDA - Text View




strpbrk함수

두 개의 인자를 갖는다. operand1, operand2

opernad1 문자열에서 oeprand2의 문자열이 있는지 찾는다. 

만일 일치하는 문자열이 있다면 operand1에 일치하는 첫 문자의 위치를 포인터로 반환한다.

일치하는 문자가 없다면 NULL을 반환한다.




pseudo code - 의사코드



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
#include <stdio.h>
 
void main(void)
{
    char *pos;
    char *Str;
    char string[100];
 
    puts(Str);
 
    eax = string;
    gets(eax);
 
    ecx = string;
    strpbrk(ecx, " ");
    
    pos = eax;
 
    while(pos != NULL){
        edx = pos;
        Str = edx;
        eax = Str;
        puts(eax);
 
        ecx = pos;
        ecx = ecx + 1;
        pos = ecx;
        
        edx = pos;
        strpbrk(edx, " ");
        pos = eax;
    }
    eax = 0;    
}
 
cs



pseudo code - 최종 의사코드



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdio.h>
 
void main(void)
{
    char *pos;
    char *Str;
    char string[100];
 
    puts(Str);
 
    gets(string);
 
    pos = strpbrk(string" ");
    
    while(pos != NULL){
        puts(pos++);
 
        pos = strpbrk(pos, " ");
    }
    return 0;    
}
 
cs












'Reversing > ASM to C' 카테고리의 다른 글

ASM to C with IDA - 065 (strnset)  (0) 2018.07.19
ASM to C with IDA - 064 (strset)  (0) 2018.07.18
ASM to C with IDA - 062 (strtok)  (0) 2018.07.18
ASM to C with IDA - 061 (strspn)  (0) 2018.07.17
ASM to C with IDA - 060 (strcspn)  (0) 2018.07.17