Re: please look into this and respond

"rafael_ortolan_666" <[email protected]> Fri, 30 Dec 2005 16:00:05 -0000
Newsgroups gmane.comp.programming.cppug
Message-ID <[email protected]>
Hi,

One approach to make this work in VC is to use inline assembly:

void change() {
    long a[2];
    int k;
    k = 0;
l1: k = 1;
l2: //k = (&&l2 - &&l1);
    //calculate the lenght of the instruction to jump over
    __asm {
	mov eax, l2 ;
	sub eax, l1 ;
	mov k, eax  ;
    }
    //a[4] -> return address put on the stack by "call"
    a[4] += k;
}

I have made this in VC7 and it worked fine.
Post any doubts that you have regarding the functionality
of this example.

Regards,
Rafael Giovanni A. Ortolan.


--- In [email protected], sumit kumar <sumit_india1998@y...> wrote:
>
>   Please Refer Bottem Post....
>    
>   > > Hi geeks,
> > > can any body give me the code for the following
> > > void main()
> > > {
> > >   int i=5;
> > >   change();
> > >   i=10;
> > >   printf("%d", i);
> > > }  // end of main
> > > write something in change() function only, such that after
executing the
> > > program it should print 5 but not 10;
> > > i know the method but i dont know how to implement it,
> > > HINT: here we have increment the program counter.
> 
>   > This problem demonstrates havocs that may be caused by Buffer
Overrun.
> > void change() {
> >      long a[2];
> >      int k;
> >      k = 0;
> >  l1: k = 1;
> >  l2: k = (&&l2 - &&l1);
> >      a[3] += k;
> > }
> 
>   > If you don't initialize  the k to zero and reinitialize it to the 1,
> > compiler may not generate the code for the instruction of k=1; but may
> > put the 1 at the stack address of k directly. all that is because of
> > optimization. And you may fail to find the diff btw the labels.
> >
> > Check the archieves for the same problem. We had spent a lot of energy
> > and bandwidth on this. The only point behind these problems is to
> > learn the logic. How variables are used in stacks, and where the
> > programs may lead to, if not properly written.
>    
>    
>   Dear All,
>   If this code is run on VC++ it would report an error i.e. :
>    
>   error C2059: syntax error : '&&'
>    
>   on unix it works fine, but I dont understand use of "&&" before
label name I mean can we extract addresses of labels if yes why VC++
compiler dosen't recognise this. Can any of us elaborate more on this.
So the picture becomes more clear, If you refer to some previous post
chain please mention dates because finding some perticular information
from a whole lot is pretty difficult and would take days. 
>    
>   Thanks and Regards,
>   Sumit Kumar 
>   +91-80-30956948
>    
> 
> 
> 		
> ---------------------------------
>  Yahoo! DSL Something to write home about. Just $16.99/mo. or less
>






------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/KIlPFB/vlQLAA/TtwFAA/EbFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/cppug/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/