changing execution path

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kris

    changing execution path

    Is it possible to change execution path in c++ without jumping to asm

    eg:

    int* arrayEncrypted
    int* arrayUnEncrypte d

    after unencrypting from the encrypted to the unencrypted can I jump the ip
    address to arrayUnEncrypte d without resorting to assembly. currently doing
    it like this but it defeats the point of my exercise to use assembly

    asm
    {
    push arrayUnEncrypte d
    ret
    }

    Is there a c++ way of doing this?


  • André Pönitz

    #2
    Re: changing execution path

    Kris <sonkris@optusn et.com.au> wrote:[color=blue]
    > Is it possible to change execution path in c++ without jumping to asm
    >
    > eg:
    >
    > int* arrayEncrypted
    > int* arrayUnEncrypte d
    >
    > after unencrypting from the encrypted to the unencrypted can I jump the ip
    > address to arrayUnEncrypte d without resorting to assembly. currently doing
    > it like this but it defeats the point of my exercise to use assembly
    >
    > asm
    > {
    > push arrayUnEncrypte d
    > ret
    > }
    >
    > Is there a c++ way of doing this?[/color]

    I.e. arrayDecrypted contains a sequence of ints which would be
    interpreted by your processor as machine code if the IP would point
    there?

    If so, no, there is no portable way to do that in C++, and using asm
    seems to be a reasonable alternative in this case.

    Andre'

    Comment

    • Kris

      #3
      Re: changing execution path

      Yep, more properly arrayEncrypted & arrayUnEncrypte d are unsigned chars
      which is equivalent to bytes for me here.

      unencrypted will contain executable code once finished unencryptins so would
      like to jump to there.

      If this is clearer.

      Thanks for the advice Andre.

      I am trying to avoid jumping to assembly language here as Im converting back
      from it to c++.
      just a reverse engineering exercise.
      Can it be done in c or another language?

      I remember vaguly about labels ending with : to mark point in executable but
      I think this was assembly language for some processor again.

      Can a goto handle the jumpmaybe?

      "André Pönitz" <poenitz@gmx.ne t> wrote in message
      news:bkc4fa$lsj $5@anderson.hrz .tu-chemnitz.de...[color=blue]
      > Kris <sonkris@optusn et.com.au> wrote:[color=green]
      > > Is it possible to change execution path in c++ without jumping to asm
      > >
      > > eg:
      > >
      > > int* arrayEncrypted
      > > int* arrayUnEncrypte d
      > >
      > > after unencrypting from the encrypted to the unencrypted can I jump the[/color][/color]
      ip[color=blue][color=green]
      > > address to arrayUnEncrypte d without resorting to assembly. currently[/color][/color]
      doing[color=blue][color=green]
      > > it like this but it defeats the point of my exercise to use assembly
      > >
      > > asm
      > > {
      > > push arrayUnEncrypte d
      > > ret
      > > }
      > >
      > > Is there a c++ way of doing this?[/color]
      >
      > I.e. arrayDecrypted contains a sequence of ints which would be
      > interpreted by your processor as machine code if the IP would point
      > there?
      >
      > If so, no, there is no portable way to do that in C++, and using asm
      > seems to be a reasonable alternative in this case.
      >
      > Andre'[/color]


      Comment

      • André Pönitz

        #4
        Re: changing execution path

        Kris <sonkris@optusn et.com.au> wrote:[color=blue]
        > Can it be done in c or another language?[/color]

        Not in C.

        [In fact almost everything that can be done in C can be done in C++]
        [color=blue]
        > I remember vaguly about labels ending with : to mark point in executable but
        > I think this was assembly language for some processor again.
        >
        > Can a goto handle the jumpmaybe?[/color]

        No.

        Andre'

        Comment

        • Dan Cernat

          #5
          Re: changing execution path

          "Kris" <sonkris@optusn et.com.au> wrote in message news:<3f698e2d$ 0$15898$afc38c8 7@news.optusnet .com.au>...[color=blue]
          > Is it possible to change execution path in c++ without jumping to asm
          >
          > eg:
          >
          > int* arrayEncrypted
          > int* arrayUnEncrypte d
          >
          > after unencrypting from the encrypted to the unencrypted can I jump the ip
          > address to arrayUnEncrypte d without resorting to assembly. currently doing
          > it like this but it defeats the point of my exercise to use assembly
          >
          > asm
          > {
          > push arrayUnEncrypte d
          > ret
          > }
          >
          > Is there a c++ way of doing this?[/color]



          C++ has no knowledge of IP (instruction pointer I presume). So what is
          your real problem? If you want to swap the contents of arrays, swap
          the pointers values. If not, let us know more.

          Dan

          Comment

          • Gianni Mariani

            #6
            Re: changing execution path

            Kris wrote:[color=blue]
            > Is it possible to change execution path in c++ without jumping to asm
            >
            > eg:
            >
            > int* arrayEncrypted
            > int* arrayUnEncrypte d
            >
            > after unencrypting from the encrypted to the unencrypted can I jump the ip
            > address to arrayUnEncrypte d without resorting to assembly. currently doing
            > it like this but it defeats the point of my exercise to use assembly
            >
            > asm
            > {
            > push arrayUnEncrypte d
            > ret
            > }
            >
            > Is there a c++ way of doing this?
            >
            >[/color]

            In most C/C++ implementations this will work.

            typedef void (*funcptr)();

            void execute_buffer( void * buffer )
            {

            funcptr ptr = (funcptr) ( buffer );

            ptr();

            }

            Comment

            • Kevin Goodsell

              #7
              Re: changing execution path

              Kris wrote:
              [color=blue]
              > Yep, more properly...[/color]
              <snip>

              Kris, please don't top-post. See section 5 of the FAQ for posting
              guidelines.



              -Kevin
              --
              My email address is valid, but changes periodically.
              To contact me please use the address from a recent posting.

              Comment

              Working...