Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Accessing .NET private members

Accessing .NET private members

Scheduled Pinned Locked Moved The Lounge
csharpquestionlearning
20 Posts 13 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Jim Crafton

    Martin C Cook wrote: with a little creative casting (yea, I'm a C++ programmer) almost any private member can be accessed Yeah but it's more work, and you may very well be wrong depending on the compiler, etc. The article review implied that you could do this pretty easily and accurately, using introspection, and some of the assembly tools(?). Anyways just seemed kind of funny. ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!

    M Offline
    M Offline
    Marc Clifton
    wrote on last edited by
    #6

    Jim Crafton wrote: The article review implied that you could do this pretty easily and accurately, using introspection, and some of the assembly tools(?). Anyways just seemed kind of funny. Well, for $10, I'll splurge to possibly learn something new. Umm, the next thing I was about to say would be very unethical, not to mention illegal. :-O (Although, I must say, this guy looks like he's got quite the racket going--lots of little $10, 50 page books. Maybe this is the future of publishing, eh?) Marc Help! I'm an AI running around in someone's f*cked up universe simulator.
    Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus
    Every line of code is a liability - Taka Muraoka
    Microsoft deliberately adds arbitrary layers of complexity to make it difficult to deliver Windows features on non-Windows platforms--Microsoft's "Halloween files"

    T 1 Reply Last reply
    0
    • J Jim Crafton

      I just noticed a book review[^] on slashdot regarding techniques that allow you to access private members of classes. Anyone here know or has heard anything about this? Thought it was interesting, not sure how big a deal it is, though the book review seems to imply that it is not very difficult to do at all. Seems weird. ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!

      B Offline
      B Offline
      Brian Delahunty
      wrote on last edited by
      #7

      I really like the:

      #define private public
      #define protected public

      way of doing it in C++... does this work.. can't try it here. Regards, Brian Dela :-)

      B 1 Reply Last reply
      0
      • B Brian Delahunty

        I really like the:

        #define private public
        #define protected public

        way of doing it in C++... does this work.. can't try it here. Regards, Brian Dela :-)

        B Offline
        B Offline
        Brit
        wrote on last edited by
        #8

        Brian Delahunty wrote: I really like the: #define private public #define protected public way of doing it in C++... does this work.. can't try it here. Yes, it does work in VS 6. ------------------------------------------ "What happened in that Rhode Island club is shocking. To think that over a hundred people would attend a Great White concert." - The Onion

        B 1 Reply Last reply
        0
        • J Jim Crafton

          I just noticed a book review[^] on slashdot regarding techniques that allow you to access private members of classes. Anyone here know or has heard anything about this? Thought it was interesting, not sure how big a deal it is, though the book review seems to imply that it is not very difficult to do at all. Seems weird. ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!

          D Offline
          D Offline
          Daniel Turini
          wrote on last edited by
          #9

          Jim Crafton wrote: I just noticed a book review[^] on slashdot regarding techniques that allow you to access private members of classes. Anyone here know or has heard anything about this? Thought it was interesting, not sure how big a deal it is, though the book review seems to imply that it is not very difficult to do at all. Seems weird. I never tried to do such a thing. In fact, IMHO, it is an abomination. But if .NET allows you to do this, I bet you can do it through Reflection or through IL. For, e.g., a field, maybe through reflection, using a FieldInfo object, you could set/get a field value. If this doesn’t work, I bet the ldfield/ldsfield opcode would do the trick. My latest article: GBVB - Converting VB.NET code to C#

          1 Reply Last reply
          0
          • M Marc Clifton

            Jim Crafton wrote: The article review implied that you could do this pretty easily and accurately, using introspection, and some of the assembly tools(?). Anyways just seemed kind of funny. Well, for $10, I'll splurge to possibly learn something new. Umm, the next thing I was about to say would be very unethical, not to mention illegal. :-O (Although, I must say, this guy looks like he's got quite the racket going--lots of little $10, 50 page books. Maybe this is the future of publishing, eh?) Marc Help! I'm an AI running around in someone's f*cked up universe simulator.
            Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus
            Every line of code is a liability - Taka Muraoka
            Microsoft deliberately adds arbitrary layers of complexity to make it difficult to deliver Windows features on non-Windows platforms--Microsoft's "Halloween files"

            T Offline
            T Offline
            tidge
            wrote on last edited by
            #10

            this guy? You've never heard of Dan Appleman? Pretty big in the vb world. He's written a pretty good whitepaper (and book too) on regex.

            M 1 Reply Last reply
            0
            • B Brit

              Brian Delahunty wrote: I really like the: #define private public #define protected public way of doing it in C++... does this work.. can't try it here. Yes, it does work in VS 6. ------------------------------------------ "What happened in that Rhode Island club is shocking. To think that over a hundred people would attend a Great White concert." - The Onion

              B Offline
              B Offline
              Brian Delahunty
              wrote on last edited by
              #11

              Brit wrote: Yes, it does work in VS 6. Cool :-D Regards, Brian Dela :-)

              1 Reply Last reply
              0
              • T tidge

                this guy? You've never heard of Dan Appleman? Pretty big in the vb world. He's written a pretty good whitepaper (and book too) on regex.

                M Offline
                M Offline
                Marc Clifton
                wrote on last edited by
                #12

                tidge wrote: this guy? You've never heard of Dan Appleman? I must confess my ignorance. But then again, I am happy to remain ignorant of everything, especially having to do with the VB world. :-D Marc Help! I'm an AI running around in someone's f*cked up universe simulator.
                Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus
                Every line of code is a liability - Taka Muraoka
                Microsoft deliberately adds arbitrary layers of complexity to make it difficult to deliver Windows features on non-Windows platforms--Microsoft's "Halloween files"

                T 1 Reply Last reply
                0
                • M Marc Clifton

                  tidge wrote: this guy? You've never heard of Dan Appleman? I must confess my ignorance. But then again, I am happy to remain ignorant of everything, especially having to do with the VB world. :-D Marc Help! I'm an AI running around in someone's f*cked up universe simulator.
                  Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus
                  Every line of code is a liability - Taka Muraoka
                  Microsoft deliberately adds arbitrary layers of complexity to make it difficult to deliver Windows features on non-Windows platforms--Microsoft's "Halloween files"

                  T Offline
                  T Offline
                  tidge
                  wrote on last edited by
                  #13

                  Marc Clifton wrote: I am happy to remain ignorant of everything, especially having to do with the VB world You lucky guy. :)

                  1 Reply Last reply
                  0
                  • J Jim Crafton

                    I just noticed a book review[^] on slashdot regarding techniques that allow you to access private members of classes. Anyone here know or has heard anything about this? Thought it was interesting, not sure how big a deal it is, though the book review seems to imply that it is not very difficult to do at all. Seems weird. ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!

                    A Offline
                    A Offline
                    Arjan Einbu
                    wrote on last edited by
                    #14

                    It is done through reflection... But you also need to give your code the rights to query for private members... Use the "Administrative Tools/Microsoft .NET Framework Configuration" utility to create permission sets and assign them to code groups (assemblies) When running your code from the VS.NET IDE you might actually have those rights, even though your code don't have those right when run as standalone. I dunno why this is, but one should keep it in mind when developing/using this ability... Even though one would expect privates to remain private whatsoever, this feature can come in quite handy when it comes to creating your own generic classes for serialization/deserialization. (Been there, done that...)

                    1 Reply Last reply
                    0
                    • J Jim Crafton

                      I just noticed a book review[^] on slashdot regarding techniques that allow you to access private members of classes. Anyone here know or has heard anything about this? Thought it was interesting, not sure how big a deal it is, though the book review seems to imply that it is not very difficult to do at all. Seems weird. ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!

                      R Offline
                      R Offline
                      Roger Wright
                      wrote on last edited by
                      #15

                      I consider it rude, not to mention an invasion of privacy, to access anyone's private members on the 'net. There oughtta be a law!:mad:

                      "Ask not for whom the bell tolls;
                      It tolls for thee..."

                      V A 2 Replies Last reply
                      0
                      • J Jim Crafton

                        I just noticed a book review[^] on slashdot regarding techniques that allow you to access private members of classes. Anyone here know or has heard anything about this? Thought it was interesting, not sure how big a deal it is, though the book review seems to imply that it is not very difficult to do at all. Seems weird. ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!

                        D Offline
                        D Offline
                        David Stone
                        wrote on last edited by
                        #16

                        It's obvious that they haven't spent all that much time with .NET. They're going at it a completely roundabout way. You can do it very easily through Reflection.


                        Hawaian shirts and shorts work too in Summer. People assume you're either a complete nut (in which case not a worthy target) or so damn good you don't need to worry about camouflage... -Anna-Jayne Metcalfe on Paintballing

                        C 1 Reply Last reply
                        0
                        • D David Stone

                          It's obvious that they haven't spent all that much time with .NET. They're going at it a completely roundabout way. You can do it very easily through Reflection.


                          Hawaian shirts and shorts work too in Summer. People assume you're either a complete nut (in which case not a worthy target) or so damn good you don't need to worry about camouflage... -Anna-Jayne Metcalfe on Paintballing

                          C Offline
                          C Offline
                          Chris Maunder
                          wrote on last edited by
                          #17

                          Reflection allows you to easily list the members of a class (even private) but can you actually call those members easily? cheers, Chris Maunder

                          1 Reply Last reply
                          0
                          • J Jim Crafton

                            I just noticed a book review[^] on slashdot regarding techniques that allow you to access private members of classes. Anyone here know or has heard anything about this? Thought it was interesting, not sure how big a deal it is, though the book review seems to imply that it is not very difficult to do at all. Seems weird. ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!

                            C Offline
                            C Offline
                            Chris Maunder
                            wrote on last edited by
                            #18

                            The comments under this are truly great: "OMG .NET sucks and is so secure. Perl is SO much better because you can do this anyway. Man - Microsoft really screwed up letting this bug through QA. Lucky that Java sandboxes everything so you can't do this so it's more secure. Blah blah blah blah blah". yaawwwwwwn cheers, Chris Maunder

                            1 Reply Last reply
                            0
                            • R Roger Wright

                              I consider it rude, not to mention an invasion of privacy, to access anyone's private members on the 'net. There oughtta be a law!:mad:

                              "Ask not for whom the bell tolls;
                              It tolls for thee..."

                              V Offline
                              V Offline
                              Vikram A Punathambekar
                              wrote on last edited by
                              #19

                              Roger Wright wrote: to access anyone's private members on the 'net :laugh: How about "In C++, only your friends can handle your private parts" ?
                              Vikram. ----------------------------- My site due for a massive update Radioactive cats have 18 half-lives. "Do not give redundant error messages again and again." - A classmate of mine, while giving a class talk on error detection in compiler design.

                              1 Reply Last reply
                              0
                              • R Roger Wright

                                I consider it rude, not to mention an invasion of privacy, to access anyone's private members on the 'net. There oughtta be a law!:mad:

                                "Ask not for whom the bell tolls;
                                It tolls for thee..."

                                A Offline
                                A Offline
                                Anna Jayne Metcalfe
                                wrote on last edited by
                                #20

                                Good one! :laugh: I don't keep much private these days, but I do like to feel protected. ;) Anna :rose: Homepage | My life in tears "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work. Trouble with resource IDs? Try the Resource ID Organiser Visual C++ Add-In

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups