MINERVA/Python 2021. 9. 7. 14:11
반응형

C/C++ 에서 사용하던 dumpcode(https://choiwonwoo.tistory.com/entry/%EB%94%94%EB%B2%84%EA%B9%85-3264-bits-dumpcodeh?category=267468) 함수를 Python에서 사용가능하게 바꾸어 보았습니다.

 

nMaxLineLen만 조절하셔서 사용하시면 됩니다.

[사용결과]

반응형
posted by choiwonwoo
:
MINERVA/Python 2021. 9. 7. 11:10
반응형

##################################
# id(x): 객체(x) 주소(address) 확인
##################################
name = 'Python'
print(f'My name is {name} and object id is {id(name)}')

# passed by Assignment!!!(추후 정리)
obj_copy = name # passed by Assignment(o) call by reference(x) call by value(x)
print(f'My name is {obj_copy} and obj_copy id is {id(obj_copy)}')

#################################################
# type(x): 객체(x) 타입(type) 확인
# immutable objects: int, float, string, tuple
# mutable objects: list, dict, set
#################################################
age = 18
colors = ('red','blue','yellow')
print(f'type is {type(name)}')
print(f'type is {type(age)}')
print(f'type is {type(colors)}')

########################################################
# len(x): x 길이(문자열) 또는 원소의 갯수(tuple,list, dic...
########################################################
print(len(name),len(colors))

##################################
# eval(x): (x) 결과를 반환
##################################
a = eval ('"hello" + "python"')
b = eval ('100+40')
c = eval ('len(colors)')
print(f'results are {a}, {b},{c}')

반응형
posted by choiwonwoo
:
MINERVA/C_CPP 2021. 9. 6. 16:34
반응형

초기 보안과 해킹을 공부할때 (예: BOF/FSB 등) 자주 사용사용하던, 32비트 dumpcode.h(initial written by ohhara)를 32비트와 64비트에서 동시 사용가능하게 업그레이드한 코드 입니다.

 

[dumpcode.h]

 

#define     MAX_LINE_LEN   (16)     //-- 출력하고자 하는 라인의 길이를 나타냅니다.

 

void printchar(unsigned char c)
{
    if (isprint(c))
        printf("%c", c);
    else
        printf(".");
}
void dumpcode(unsigned char* buff, int len)
{
    int i;
    
    for (i = 0; i < len; i++)
    {
        //-- address
        if (i % MAX_LINE_LEN == 0)
        {
            printf("0x%p  ", &buff[i]);
        }

        //-- one by one 
        printf("%02x ", buff[i]);

        //-- fulls
        if (((i % MAX_LINE_LEN) - (MAX_LINE_LEN-1)) == 0) {

            printf(" ");

            for (int j = i - (MAX_LINE_LEN-1); j <=i ; j++)
                printchar(buff[j]);

            printf("\n");
        }        

    }
    
    //-- remainer
    if (i % MAX_LINE_LEN != 0)
    {
        int j;
        //int spaces = (len - i + MAX_LINE_LEN - i % MAX_LINE_LEN) * 3 + 2;
        int spaces = (len - i + MAX_LINE_LEN - i % MAX_LINE_LEN) * 3 + 1;

        for (j = 0; j < spaces; j++)
            printf(" ");
        for (j = i - i % MAX_LINE_LEN; j < len; j++)
            printchar(buff[j]);
    }

    printf("\n");
}

 

[사용방법 및 결과]

32 bits 예제
64  bits 예제

반응형
posted by choiwonwoo
: