Connecting Tech Pros Worldwide Help | Site Map

changing execution path

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 19th, 2005, 05:55 PM
Kris
Guest
 
Posts: n/a
Default changing execution path

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

eg:

int* arrayEncrypted
int* arrayUnEncrypted

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

asm
{
push arrayUnEncrypted
ret
}

Is there a c++ way of doing this?



  #2  
Old July 19th, 2005, 05:55 PM
André Pönitz
Guest
 
Posts: n/a
Default Re: changing execution path

Kris <sonkris@optusnet.com.au> wrote:[color=blue]
> Is it possible to change execution path in c++ without jumping to asm
>
> eg:
>
> int* arrayEncrypted
> int* arrayUnEncrypted
>
> after unencrypting from the encrypted to the unencrypted can I jump the ip
> address to arrayUnEncrypted without resorting to assembly. currently doing
> it like this but it defeats the point of my exercise to use assembly
>
> asm
> {
> push arrayUnEncrypted
> 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'
  #3  
Old July 19th, 2005, 05:55 PM
Kris
Guest
 
Posts: n/a
Default Re: changing execution path

Yep, more properly arrayEncrypted & arrayUnEncrypted 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.net> wrote in message
news:bkc4fa$lsj$5@anderson.hrz.tu-chemnitz.de...[color=blue]
> Kris <sonkris@optusnet.com.au> wrote:[color=green]
> > Is it possible to change execution path in c++ without jumping to asm
> >
> > eg:
> >
> > int* arrayEncrypted
> > int* arrayUnEncrypted
> >
> > after unencrypting from the encrypted to the unencrypted can I jump the[/color][/color]
ip[color=blue][color=green]
> > address to arrayUnEncrypted 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 arrayUnEncrypted
> > 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]


  #4  
Old July 19th, 2005, 05:55 PM
André Pönitz
Guest
 
Posts: n/a
Default Re: changing execution path

Kris <sonkris@optusnet.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'
  #5  
Old July 19th, 2005, 05:56 PM
Dan Cernat
Guest
 
Posts: n/a
Default Re: changing execution path

"Kris" <sonkris@optusnet.com.au> wrote in message news:<3f698e2d$0$15898$afc38c87@news.optusnet.com. au>...[color=blue]
> Is it possible to change execution path in c++ without jumping to asm
>
> eg:
>
> int* arrayEncrypted
> int* arrayUnEncrypted
>
> after unencrypting from the encrypted to the unencrypted can I jump the ip
> address to arrayUnEncrypted without resorting to assembly. currently doing
> it like this but it defeats the point of my exercise to use assembly
>
> asm
> {
> push arrayUnEncrypted
> 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
  #6  
Old July 19th, 2005, 05:56 PM
Gianni Mariani
Guest
 
Posts: n/a
Default 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* arrayUnEncrypted
>
> after unencrypting from the encrypted to the unencrypted can I jump the ip
> address to arrayUnEncrypted without resorting to assembly. currently doing
> it like this but it defeats the point of my exercise to use assembly
>
> asm
> {
> push arrayUnEncrypted
> 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();

}

  #7  
Old July 19th, 2005, 05:58 PM
Kevin Goodsell
Guest
 
Posts: n/a
Default 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.

http://www.parashift.com/c++-faq-lite/

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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.