gaming pointers

g g g at g.g
Tue Dec 28 13:27:41 PST 2010


I know this is just playing dangerous, still tempting to use for things like plugins ,"member interfaces" or even struct interfaces.
It is easy to do without unions because delegates have ptr and funcptr pointers with just a swap of pointers.
Are .ptr and .funcptr really needed to be writeable?
"could be a warning" (:

Here a example (note that the union it is used only to pretty print)

module gccmembug;
import std.stdio;

union dlgtrick(T){
    void delegate() aptr;
    struct{
        T* cptr;
        void* mptr;
    }
}

class bypassing{
    private int x;
    void outx(){writeln(x);}
}
class dump{
    int x;
    void changex(){
        x +=2;
    }
}
void gamingboard(){
    dump tool = new dump();
    bypassing instance = new bypassing();
    dlgtrick!bypassing drill;
    drill.aptr = &instance.outx;
    writeln("real bypassing \t",drill.cptr," ",drill.mptr);
    drill.aptr = &tool.changex;
    writeln("real tool \t",drill.cptr," ",drill.mptr);
    drill.aptr.ptr = (&instance.outx).ptr;
    writeln("faked \t",drill.cptr," ",drill.mptr);
    writeln("original function called : ");
    instance.outx();
    writeln("hacked version called :");
    drill.aptr();
    instance.outx();
}

Excuse my if I maade something obvious or silly.
Thanks g.


More information about the Digitalmars-d-learn mailing list