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
: