내 프로젝트 중 하나에서 glibc의 printf()를 해킹하고 일부 문제가 발생했습니다. 몇 가지 단서를 주시겠습니까? 그리고 내 관심사 중 하나는 왜 malloc/free에 대한 동일한 솔루션이 완벽하게 작동하는지입니다!LD_PRELOAD 메서드를 사용하여 printf에 주입 할 때의 문제
"PrintfHank.c"에는 표준 라이브러리보다 먼저 미리로드되는 printf() 솔루션이 포함되어 있습니다. "main.c"는 printf()를 사용하여 문장을 출력합니다. 두 개의 파일을 편집 한 후, 나는 다음과 같은 명령을 발행 :
- 컴파일 main.c에 GCC 내 자신의 라이브러리
- 주요 main.c의를 -o 만들 -Wall을 의 gcc -Wall -fPIC -shared -o PrintfHank.so PrintfHank.c -ldl
- 테스트의 주요 새 라이브러리 LD_PRELOAD = "$의 MYPATH/PrintfHank.so"$의 MYPATH/
하지만 콘솔에서 "내 printf 내"대신 "hello world"를 받았습니다. malloc/free 함수를 해킹 할 때 괜찮습니다.
"root"로 시스템에 로그인하고 2.6.23.1-42.fc8-i686을 사용 중입니다. 모든 의견은 높이 평가됩니다!
main.c의
#include <stdio.h>
int main(void)
{
printf("hello world\n");
return 0;
}
PrintfHank.c
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdio.h>
#include <dlfcn.h>
static int (*orig_printf)(const char *format, ...) = NULL;
int printf(const char *format, ...)
{
if (orig_printf == NULL)
{
orig_printf = (int (*)(const char *format, ...))dlsym(RTLD_NEXT, "printf");
}
// TODO: print desired message from caller.
return orig_printf("within my own printf\n");
}
) (풋에 함수의 printf()를 변경하는 GCC를 해제하는 방법이 있나요? – bawejakunal