본문으로 바로가기

ASM to C with IDA - 060 (strcspn)

category ReversingASM to C 7년 전

C300_060



C300_소스코드



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
#include <string.h>
 
void main(void)
{
    char *string = "This is a string $$$";
    char *strCharSet = "~!@#$%^&*()_+-={}[]:;'<>./?";
    unsigned int pos;
 
    pos = strcspn(string, strCharSet);
 
    puts("0         1         2         3");
    puts("0123456789012345678901234567890");
    puts(string);
    puts(strCharSet);
 
    printf("%d 위치에서 일치되는 첫 문자를 발견하였습니다. \n", pos);
}
cs




IDA - Layout Graph





IDA - Text View




strcspn: size_t strcspn(const char *str1, const char *str2)

str1문자열에서 str2의 문자가 있는지 검색한다.

str1문자열에서 처음으로 만난 문자까지 읽어들인 개수를 리턴한다.




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
#include <stdio.h>
 
void main(void)
{
    char *string;
    char *strCharSet;
    int pos;
 
    string = aThisIsAString;
    strCharSet = asc_403094;
 
    eax = strCharSet;
    ecx = string;
    strcspn(ecx, eax):
    pos = eax;
 
    puts(Str);
    
    puts(a01234567890123);
    
    edx = string;
    puts(edx);
 
    eax = strCharSet
    puts(eax);
    
    ecx = pos;
    printf(_Format, ecx);
 
    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
23
24
25
#include <stdio.h>
 
void main(void)
{
    char *string;
    char *strCharSet;
    int pos;
 
    string = aThisIsAString;
    strCharSet = asc_403094;
 
    pos = strcspn(string, strCharSet):
 
    puts(Str);
    
    puts(a01234567890123);
    
    puts(string);
 
    puts(strCharSet);
    
    printf(_Format, pos);
 
    return 0;
}
cs





ReversingASM to C카테고리의 다른글

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 - 059 (strchr)  (0) 2018.07.17
ASM to C with IDA - 058 (strstr)  (0) 2018.07.16
ASM to C with IDA - 057 (strlen)  (0) 2018.07.16