changing execution path

K

Kris

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?
 
?

=?iso-8859-1?Q?Andr=E9_P=F6nitz?=

Kris said:
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?

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'
 
K

Kris

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?
 
?

=?iso-8859-1?Q?Andr=E9_P=F6nitz?=

Kris said:
Can it be done in c or another language?

Not in C.

[In fact almost everything that can be done in C can be done in C++]
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?

No.

Andre'
 
D

Dan Cernat

Kris said:
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?



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
 
G

Gianni Mariani

Kris said:
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?

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

typedef void (*funcptr)();

void execute_buffer( void * buffer )
{

funcptr ptr = (funcptr) ( buffer );

ptr();

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top