Thread overview
Messing with a class's v-table
Jul 06, 2005
Andrew Fedoniouk
Jul 07, 2005
Ben Hinkle
July 06, 2005
This.. uhh, shouldn't be legal:

import std.stdio;

class A
{
 void fork()
 {
  writefln("hi");
 }

 void knife()
 {
  writefln("maybe");
 }
}

void main()
{
 A.classinfo.vtbl[6]=A.classinfo.vtbl[7];
 A a=new A;
 a.fork();
}

Prints "maybe" (i.e. calls knife())!

I know the classinfo is probably still kind of beta-ish, but I don't think we should be able to _modify_ it..


July 06, 2005
"Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:dah8kn$2n0a$1@digitaldaemon.com...
> This.. uhh, shouldn't be legal:
>
> import std.stdio;
>
> class A
> {
> void fork()
> {
>  writefln("hi");
> }
>
> void knife()
> {
>  writefln("maybe");
> }
> }
>
> void main()
> {
> A.classinfo.vtbl[6]=A.classinfo.vtbl[7];
> A a=new A;
> a.fork();
> }
>
> Prints "maybe" (i.e. calls knife())!
>
> I know the classinfo is probably still kind of beta-ish, but I don't think we should be able to _modify_ it..
>

Yep, it should be declared as:

class ClassInfo : Object
{
    void* #[] vtbl;  // virtual function pointer table
}

isn't it? :)


July 07, 2005
"Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:dah8kn$2n0a$1@digitaldaemon.com...
> This.. uhh, shouldn't be legal:
>
> import std.stdio;
>
> class A
> {
> void fork()
> {
>  writefln("hi");
> }
>
> void knife()
> {
>  writefln("maybe");
> }
> }
>
> void main()
> {
> A.classinfo.vtbl[6]=A.classinfo.vtbl[7];
> A a=new A;
> a.fork();
> }
>
> Prints "maybe" (i.e. calls knife())!
>
> I know the classinfo is probably still kind of beta-ish, but I don't think we should be able to _modify_ it..

presumably you can also set the entire vtbl to point somewhere else or change just about anything, no?


July 07, 2005
"Ben Hinkle" <bhinkle@mathworks.com> wrote in message news:dajc4r$18nt$1@digitaldaemon.com...
> presumably you can also set the entire vtbl to point somewhere else or change just about anything, no?

I suppose so..

You would think that this stuff would be stored in a read-only section of the EXE!