Connecting Tech Pros Worldwide Forums | Help | Site Map

changing execution path

Kris
Guest
 
Posts: n/a
#1: Jul 19 '05
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?



André Pönitz
Guest
 
Posts: n/a
#2: Jul 19 '05

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'
Kris
Guest
 
Posts: n/a
#3: Jul 19 '05

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]


André Pönitz
Guest
 
Posts: n/a
#4: Jul 19 '05

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'
Dan Cernat
Guest
 
Posts: n/a
#5: Jul 19 '05

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
Gianni Mariani
Guest
 
Posts: n/a
#6: Jul 19 '05

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();

}

Kevin Goodsell
Guest
 
Posts: n/a
#7: Jul 19 '05

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.

Closed Thread


Similar C / C++ bytes