Linux/System Programming

    ptrace - process tracer (writing....)

    ptrace (process trace) ptrace에 대해서 간단히 알아보겠습니다.ptrace() system call은 어느 프로세스(tracer)가 다른 프로세스(tracee)의 실행을 추적 및 제어할 수 있는 기능을 제공합니다. tracer는 tracee의 메모리, 레지스터, 코드, 데이터, 스택, 힙 등의 정보를 확인할 수 있으며 변경도 할 수 있는 기능을 제공하며, 여러분들이 gdb 와 같은 디버거에서 많이 사용하는 중단점을 이용한 디버깅이 가능합니다. 또한 system call 추적 등의 기능을 구현할 때 자주 사용되죠. 리눅스나 유닉스 같은 운영체제에서 ptrace를 이용하여 ELF를 분석, 디버깅 등을 가능케 해주는 좋은 녀석입니다. ptrace를 사용해 프로세스의 실행 흐름을 제어할 수..

    Elf Header, Program Header, Section Header 얻어오기

    #include #include #include #include #include #include #include #include #include #include int main(int argc, char *argv[]){int ret;int fd;int i;uint8_t *mem;struct stat st; Elf32_Ehdr *ehdr = NULL;Elf32_Phdr *phdr = NULL;Elf32_Shdr *shdr = NULL; if (argc < 2) {printf("Usage: %s \n", argv[0]);exit(0);} errno = 0;fd = open(argv[1], O_RDONLY);if (errno < 0 || fd == -1) {perror("open");exit(-1);} er..

    [socket] socketpair non-blocking read write

    #include #include #include #include #define RCV_SOCK 0#define SND_SOCK 1 #define MAX_RETRY_CNT 5#define WRITE_TIMEOUT 20 /* milliseconds*/ static int read_buf_size = -1;static int write_buf_size = -1; static int __get_socket_buffer_size(int fd, int optname){int err;int size;socklen_t len = sizeof(int); errno = 0;err = getsockopt(fd, SOL_SOCKET, optname, (void *)&size, &len);if (err != 0) {printf..

    SocketPair

    socketpair()[문법]#include int socketpair(int domain, int type, int protocol, int sockfd[2]); [설명]한 쌍의 연결된 Socket을 만든다.socket()을 두 번 호출하고, bind(), listen(), connect(), accept()를 호출하는 과정등을 포함하고 있다. [Parameter]domain - AF_UNIX, socketpair는 unix_domain으로만 사용할 수 있다. type - SOCK_STREAM Provides sequenced, reliable, two-way, connection-based byte streams. An out-of-band data transmission mechanism may b..

    Warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

    -Wwrite-strings In C++, nonzero means warn about deprecated conversion from string literals to 'char *'. In C, similar warning, except that the conversion is of course not deprecated by the ISO C standard. g++ 옵션 중 -Wno-write-strings 을 붙여서 컴파일 하면 된다.

    [프로세스][펌] Daemon Process

    http://cinsk.github.io/articles/daemon.html