일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- LLVM 난독화
- linux debugging
- Linux custom packer
- LLVM
- pinpoint
- apm
- initial-exec
- v8 optimizing
- Injection
- linux thread
- TLS
- LLVM Obfuscator
- on stack replacement
- tracerpid
- on-stack replacement
- Obfuscator
- OSR
- Android
- thread local storage
- anti debugging
- pthread
- custom packer
- android inject
- uftrace
- v8 tracing
- so inject
- 안티디버깅
- 난독화
- tracing
- Linux packer
Archives
- Today
- Total
Why should I know this?
C에서 TRY-CATCH 구현 본문
Droid knights에서 발표한 "Android Native Module 안정적으로 개발하기" 내용 중에 내가 만든 TRY-CATCH 매크로를 공유했었는데 대충 이런식이었다.
void do_signal_handling()
{
int sig = 0;
int watch_signals = sigill | sigtrap | sigabrt | sigbus | sigsegv;
fprintf(stderr, "fn size : %lx\n", get_func_size((unsigned long)&do_segv));
TRY(sig, watch_signals, do_segv1) {
do_segv1();
}
CATCH (sig, sigsegv, e) {
fprintf(stderr, "inside catch!!\n");
fprintf(stderr, "catch!! signal %d\n", sig);
fprintf(stderr, "exception code: %d addr: %lx \n", e.code, e.addr);
}
FINAL(watch_signals);
}
최근에 GDB 내에 구현한 코드를 우연히 찾아 공유함.
/* Macro to wrap up standard try/catch behavior.
The double loop lets us correctly handle code "break"ing out of the
try catch block. (It works as the "break" only exits the inner
"while" loop, the outer for loop detects this handling it
correctly.) Of course "return" and "goto" are not so lucky.
For instance:
*INDENT-OFF*
TRY_SJLJ
{
}
CATCH_SJLJ (e, RETURN_MASK_ERROR)
{
switch (e.reason)
{
case RETURN_ERROR: ...
}
}
END_CATCH_SJLJ
The SJLJ variants are needed in some cases where gdb exceptions
need to cross third-party library code compiled without exceptions
support (e.g., readline). */
#define TRY_SJLJ \
{ \
jmp_buf *buf = \
exceptions_state_mc_init (); \
setjmp (*buf); \
} \
while (exceptions_state_mc_action_iter ()) \
while (exceptions_state_mc_action_iter_1 ())
#define CATCH_SJLJ(EXCEPTION, MASK) \
{ \
struct gdb_exception EXCEPTION; \
if (exceptions_state_mc_catch (&(EXCEPTION), MASK))
#define END_CATCH_SJLJ \
}
다음 커밋 참고
commit 284e6217cf8f96c7648b13274431dcf73aa084a9 (HEAD)
Author: Pedro Alves <palves@redhat.com>
Date: Sat Mar 7 14:50:03 2015 +0000
kill volatile struct gdb_exception
After the previous patch, this is the last remaining use of a volatile
struct gdb_exception. Kill it, as it's troublesome for C++: we can't
assign volatile <-> non-volatile without copy constructors /
assignment operators that do that, which I'd rather avoid.
gdb/ChangeLog:
2015-03-07 Pedro Alves <palves@redhat.com>
* main.c (handle_command_errors): Remove volatile qualifier from
parameter.
'Technic' 카테고리의 다른 글
파일 무결성 검사 (hashmap 방식 응용) (0) | 2022.11.15 |
---|---|
Git blame으로 C/C++ 코드 첫 머지버전 찾는 미립자팁 (0) | 2022.09.21 |
오픈소스에서 원하는 코드 쉽게 찾기 (feat. GDB) (0) | 2022.02.11 |
nox 탐지 (0) | 2021.11.02 |
Runtime에 C/C++ 함수 크기 구하기 (0) | 2021.06.02 |
Comments