發表文章

目前顯示的是 2014的文章

LLVM's use_iterator example

LLVM 3.5 Instruction::use_iterator     for (Instruction::use_iterator ui = instruction->use_begin(),            ue = instruction->use_end();          ui != ue; ++ui) { #if defined LLVM_3_2 || defined LLVM_3_3 || defined LLVM_3_4       llvm::Instruction *user = cast<Instruction>(*ui); #else       llvm::Instruction *user = cast<Instruction> (ui->getUser()); #endif Value *v = pending.back(); for (Value::use_iterator i = v->use_begin(), e = v->use_end(); != e; ++i) { } llvm::Function *F = M.getFunction(BARRIER_FUNCTION_NAME); if (F != NULL) {   for (llvm::Function::use_iterator i = F->use_begin(), e = F->use_end();        i != e; ++i)     B.push_back(llvm::cast<Barrier>(*i)); }

anti debugging

ref: http://erenyagdiran.github.io/I-was-just-asked-to-crack-a-program-Part-1/ #include<stdio.h> #include <sys/ptrace.h> int main() {     if (ptrace(PTRACE_TRACEME, 0, 1, 0) < 0) {             printf("DEBUGGING... Bye\n");             return 1;         }     printf("Hello\n");     return 0; } zakk@lex:[~/test]$ ./a.out Hello zakk@lex:[~/test]$ gdb ./a.out (gdb) r Starting program: /home/zakk/test/a.out DEBUGGING... Bye [Inferior 1 (process 338) exited with code 01] http://blog.linux.org.tw/~jserv/archives/002027.html http://www.oenhan.com/gdb-principle gdb主要功能的实现依赖于一个系统函数ptrace,通过man手册可以了解到,ptrace可以让父进程观察和控制其子进程的检查、执行,改变其寄存器和内存的内容,主要应用于打断点(也是gdb的主要功能)和打印系统调用轨迹。 gdb使用ptrace的基本流程 gdb调试一个新进程:通过fork函数创建一个新进程,在子进程中执行ptrace(PTRACE_TRACEME, 0, 0, 0)函数,然后通过execv()调用准备调试的程序。 attach到已运行进程:将pid传递给gdb,然后执行ptrace(PTRACE_ATTACH, p...

Continuation-passing Style

圖片
To compare it to C, the current continuation is like the current state of the stack (http://stackoverflow.com/questions/612761/what-is-call-cc) A function written in continuation-passing style takes an extra argument: an explicit "continuation" i.e. a function of one argument. When the CPS function has computed its result value, it "returns" it by calling the continuation function with this value as the argument. To compare it to C, the current continuation is like the current state of the stack A programmer can discover continuation-passing style by themselves if subjected to one constraint: No procedure is allowed to return to its caller--ever. One hint makes programming in this style possible: When a procedure is ready to "return" to its caller, it invokes the "current continuation" callback (provided by its caller) on the return value. below code is reference from http://matt.might.net/articles/by-example-continuation-passing...