node/lib/metasm/samples/dynamic_ruby.rb
# dynamic trace of all rb_funcall made from our module
dynamic trace of all rb_funcall made from our module
dynamic trace of all rb_funcall made from our module
def rb_funcall(recv, meth, *args)
		if not defined? @rb_fcid
			@cp.parse <<EOS
int atexit(void(*)(void));
int printf(char*, ...);
static unsigned rb_fcid_max = 1;
static unsigned rb_fcntr[1];
static void rb_fcstat(void)
{
	unsigned i;
	for (i=0 ; i<rb_fcid_max ; ++i)
		if (rb_fcntr[i])
			printf("%u %u\\n", i, rb_fcntr[i]);
}
EOS
			@rb_fcid = -1
			@rb_fcntr = @cp.toplevel.symbol['rb_fcntr']
			@rb_fcid_max = @cp.toplevel.symbol['rb_fcid_max']
			init.statements << fcall('atexit', @cp.toplevel.symbol['rb_fcstat'])
		end
		@rb_fcid += 1
		@rb_fcid_max.initializer = C::CExpression[[@rb_fcid+1], @rb_fcid_max.type]
		@rb_fcntr.type.length = @rb_fcid+1
		ctr = C::CExpression[:'++', [@rb_fcntr, :'[]', [@rb_fcid]]]
		C::CExpression[ctr, :',', super(recv, meth, *args)]
	end
def rb_funcall ( recv , meth , * args ) if not defined? @rb_fcid @cp . parse <<EOS 
int atexit(void(*)(void));
int printf(char*, ...);

static unsigned rb_fcid_max = 1;
static unsigned rb_fcntr[1];

static void rb_fcstat(void)
{
	unsigned i;
	for (i=0 ; i<rb_fcid_max ; ++i)
		if (rb_fcntr[i])
			printf("%u %u \\ n", i, rb_fcntr[i]);
}
 EOS @rb_fcid = - 1 @rb_fcntr = @cp . toplevel . symbol [ 'rb_fcntr' ] @rb_fcid_max = @cp . toplevel . symbol [ 'rb_fcid_max' ] init . statements << fcall ( 'atexit' , @cp . toplevel . symbol [ 'rb_fcstat' ] ) end @rb_fcid += 1 @rb_fcid_max . initializer = C :: CExpression [ [ @rb_fcid + 1 ] , @rb_fcid_max . type ] @rb_fcntr . type . length = @rb_fcid + 1 ctr = C :: CExpression [ :' ++ ' , [ @rb_fcntr , :' [] ' , [ @rb_fcid ] ] ] C :: CExpression [ ctr , :' , ' , super ( recv , meth , * args ) ] end
dynamic trace of all rb_funcall made from our module
dynamic trace of all rb_funcall made from our module
recv
meth
args