On Friday, 17 June 2016 at 19:49:18 UTC, Johan Engelen wrote:
Hi all,
Is there another way to get access to Voldemort class methods, or private class members, other than using "pragma(mangle, ...)" on user symbols?

Well, I'm sure you know that's a horrible idea. Anyway, a trick I use in C++ is to copy and paste the class's source into my own file, and change everything to public, then just cast to my hiijacking class type.

So, in D...

import std.stdio;

final class SeriousBusiness {
private:
        int soconfidential;
        char wow;
        void thisIsTotallyProtectedHonest() {
                // import underlying.implementation;
                // import dependency.hell
                // import kitchen.sink
                writeln("We can totally put sensitive data in here");
        }
        this(int s, char w) {
                this.soconfidential = s;
                this.wow = w;
        }
}

final class ProtectionAttributesSuck {
  int soconfidential;
  char wow;
  void thisIsTotallyProtectedHonest() {
          // import underlying.implementation;
          // import dependency.hell
          // import kitchen.sink
          writeln("We can totally put sensitive data in here");
          writeln("see ",wow," for any equipment you need.");
        }
}

void main() {
        SeriousBusiness srs = new SeriousBusiness(42,'Q');
ProtectionAttributesSuck* hack = cast(ProtectionAttributesSuck*)&srs;
        writeln("the answer is ",hack.soconfidential);
        hack.thisIsTotallyProtectedHonest();
}

Reply via email to