tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Patching symbols after tcc_relocate


From: Henry Weller
Subject: Re: [Tinycc-devel] Patching symbols after tcc_relocate
Date: Sun, 10 Feb 2013 13:46:19 +0000
User-agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (Gojō) APEL/10.8 Emacs/24.2 (x86_64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO)

Hi Grischka,

> Everything is possible.  This is software after all.

Yep :-)

> Say your original function is:
>      int add(int a, int b) { return a + b; }

> Your replacement (same prototype) is:
>      int sub(int a, int b) { return a - b; }

> Have a tool to make it happen:
>      void replace_function(TCCState *s, const char *name, void *new)
>      {
>          char *old = tcc_get_symbol(s, name);
>          set_pages_executable(old, 5); //from tccrun.c
>      #ifdef ___i386__
>          *old = 0xe9;
>          *(unsigned*)(old + 1) = (char *)new - old - 5;
>      #endif
>      }

Excellent! that is way simpler than I expected.  I will take it for a spin now.

Thanks a lot for your help

Henry



reply via email to

[Prev in Thread] Current Thread [Next in Thread]