Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #67491

Re: Relocatable functions in C?

From jt@toerring.de (Jens Thoms Toerring)
Newsgroups comp.lang.c
Subject Re: Relocatable functions in C?
Date 2015-08-15 23:44 +0000
Organization Freie Universitaet Berlin
Message-ID <d3a17lFsemqU2@mid.uni-berlin.de> (permalink)
References <2764e28b-d6e9-44d5-8ff4-b612a3d7e9a4@googlegroups.com> <88f5c11c-bbf6-4b38-8277-53b5a982a0cc@googlegroups.com> <d39rl7Frd15U1@mid.uni-berlin.de> <mqodu1$7sf$1@dont-email.me>

Show all headers | View raw


jacobnavia <jacob@jacob.remcomp.fr> wrote:
> Le 16/08/2015 00:09, Jens Thoms Toerring a écrit :
> > How do you actually "copy" the functions?

> There is no way to do that since all the "ad hoc" methods will fail. You 
> can suppose that all functions start with the byte codes for

> push rsp
> move rbp, rsp

> etc...

> And that will work with a few examples.

> Then you search for the sequence
> leave
> ret

> But then you need a good disassembler to find out where the return is,
> and a fast disassembler is difficult to write...

On a certain architecture and possibly OS...

> > First question is
> > how do you determine their sizes?

> No way...

> > And the second snag I'd be
> > worried about is that typically you can't execute stuff in
> > "normal" (data) memory - on many modern systems you neither
> > can modify code in memory nor "run" code in normal heap me-
> > mory as obtained by malloc() (for obvious security reasons,
> > see e.g.https://en.wikipedia.org/wiki/NX_bit).

> That is one of the minor problems. You can solve it by reading the 
> appropiate documentation.

On a certain architecture and and a certain OS...

> But then how do you resolve the calls?

> If function f() calls printf or something how do you find out where is 
> printf in memory to fix that call?

> Specially since all calls are RIP relative in the x86...

Well, every call in the functions to something outside will
be "interesting" to deal with (once one has figured out where
that happens). Even if one wants to do that for only one
architecture one knows a lot about. I gues I'd prefer to
leave all that to the existing runtime loader I dont have
to write myself;-)
                         Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-14 09:57 -0700
  Re: Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-14 10:13 -0700
    Re: Relocatable functions in C? Ken Brody <kenbrody@spamcop.net> - 2015-08-14 13:33 -0400
      Re: Relocatable functions in C? jacobnavia <jacob@jacob.remcomp.fr> - 2015-08-14 19:51 +0200
        Re: Relocatable functions in C? Robert Wessel <robertwessel2@yahoo.com> - 2015-08-14 16:12 -0500
      Re: Relocatable functions in C? David Brown <david.brown@hesbynett.no> - 2015-08-15 16:17 +0200
  Re: Relocatable functions in C? Bartc <bc@freeuk.com> - 2015-08-14 18:29 +0100
  Re: Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-14 11:37 -0700
    Re: Relocatable functions in C? Bartc <bc@freeuk.com> - 2015-08-14 19:43 +0100
      Re: Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-14 11:46 -0700
        Re: Relocatable functions in C? Bartc <bc@freeuk.com> - 2015-08-14 19:57 +0100
          Re: Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-14 11:59 -0700
            Re: Relocatable functions in C? jt@toerring.de (Jens Thoms Toerring) - 2015-08-14 20:27 +0000
          Re: Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-14 12:01 -0700
    Re: Relocatable functions in C? Waldek Hebisch <hebisch@antispam.uni.wroc.pl> - 2015-08-25 22:36 +0000
      Re: Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-26 05:55 -0700
  Re: Relocatable functions in C? fir <profesor.fir@gmail.com> - 2015-08-14 12:57 -0700
    Re: Relocatable functions in C? fir <profesor.fir@gmail.com> - 2015-08-14 13:26 -0700
      Re: Relocatable functions in C? fir <profesor.fir@gmail.com> - 2015-08-14 13:39 -0700
        Re: Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-14 13:46 -0700
        Re: Relocatable functions in C? fir <profesor.fir@gmail.com> - 2015-08-14 14:00 -0700
          Re: Relocatable functions in C? fir <profesor.fir@gmail.com> - 2015-08-14 15:07 -0700
            Re: Relocatable functions in C? fir <profesor.fir@gmail.com> - 2015-08-14 16:02 -0700
  Re: Relocatable functions in C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-08-14 23:11 -0700
    Re: Relocatable functions in C? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-08-15 10:31 +0100
  Re: Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-15 11:56 -0700
    Re: Relocatable functions in C? jacobnavia <jacob@jacob.remcomp.fr> - 2015-08-15 23:48 +0200
      Re: Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-15 15:05 -0700
        Re: Relocatable functions in C? jacobnavia <jacob@jacob.remcomp.fr> - 2015-08-16 00:12 +0200
          Re: Relocatable functions in C? David Brown <david.brown@hesbynett.no> - 2015-08-16 16:09 +0200
      Re: Relocatable functions in C? Ian Collins <ian-news@hotmail.com> - 2015-08-16 10:47 +1200
        Re: Relocatable functions in C? jacobnavia <jacob@jacob.remcomp.fr> - 2015-08-16 01:09 +0200
    Re: Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-15 15:07 -0700
    Re: Relocatable functions in C? jt@toerring.de (Jens Thoms Toerring) - 2015-08-15 22:09 +0000
      Re: Relocatable functions in C? jacobnavia <jacob@jacob.remcomp.fr> - 2015-08-16 00:21 +0200
        Re: Relocatable functions in C? jt@toerring.de (Jens Thoms Toerring) - 2015-08-15 23:44 +0000
          Re: Relocatable functions in C? jacobnavia <jacob@jacob.remcomp.fr> - 2015-08-16 02:25 +0200
            Re: Relocatable functions in C? jacobnavia <jacob@jacob.remcomp.fr> - 2015-08-16 02:34 +0200
            Re: Relocatable functions in C? jt@toerring.de (Jens Thoms Toerring) - 2015-08-16 01:11 +0000
      Re: Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-15 15:26 -0700
        Re: Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-15 15:36 -0700
          Re: Relocatable functions in C? jt@toerring.de (Jens Thoms Toerring) - 2015-08-15 23:29 +0000
            Re: Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-15 16:34 -0700
  Re: Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-15 17:03 -0700
    Re: Relocatable functions in C? jacobnavia <jacob@jacob.remcomp.fr> - 2015-08-16 02:32 +0200
      Re: Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-15 18:25 -0700
    Re: Relocatable functions in C? jt@toerring.de (Jens Thoms Toerring) - 2015-08-16 01:26 +0000
      Re: Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-15 18:38 -0700
      Re: Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-15 18:49 -0700
    Re: Relocatable functions in C? Ian Collins <ian-news@hotmail.com> - 2015-08-16 14:04 +1200
      Re: Relocatable functions in C? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-08-15 20:19 -0700

csiph-web