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. General Programming
  3. C / C++ / MFC
  4. Private Access

Private Access

Scheduled Pinned Locked Moved C / C++ / MFC
business
8 Posts 2 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.
  • S Offline
    S Offline
    Shouvik Das
    wrote on last edited by
    #1

    Say if we ve certain private methods along with private data members and public methods. other than friend functions is thr any other way we access these members(they being private only) directly. its one of the requirements in a project of mine. plz hlp


    There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) SH:)UVIK

    J 1 Reply Last reply
    0
    • S Shouvik Das

      Say if we ve certain private methods along with private data members and public methods. other than friend functions is thr any other way we access these members(they being private only) directly. its one of the requirements in a project of mine. plz hlp


      There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) SH:)UVIK

      J Offline
      J Offline
      Jorgen Sigvardsson
      wrote on last edited by
      #2

      Yes. If you know the binary layout of the objects, you can always access the data. If you are protecting sensitive data by making it private, it will not be sufficient.

      class Class {
      private:
      int mySecretInt;
      ....
      };

      Class obj;
      int* ptrToSecretInt = (int*)(((unsigned char*)&obj) + offset);
      *ptrToSecretInt = 1234; // Gotcha!

      From a language point of view, there is no standard and portable way to access the data.

      -- Verletzen zerfetzen zersetzen zerstören Doch es darf nicht mir gehören Ich muss zerstören

      S 4 Replies Last reply
      0
      • J Jorgen Sigvardsson

        Yes. If you know the binary layout of the objects, you can always access the data. If you are protecting sensitive data by making it private, it will not be sufficient.

        class Class {
        private:
        int mySecretInt;
        ....
        };

        Class obj;
        int* ptrToSecretInt = (int*)(((unsigned char*)&obj) + offset);
        *ptrToSecretInt = 1234; // Gotcha!

        From a language point of view, there is no standard and portable way to access the data.

        -- Verletzen zerfetzen zersetzen zerstören Doch es darf nicht mir gehören Ich muss zerstören

        S Offline
        S Offline
        Shouvik Das
        wrote on last edited by
        #3

        if we are given n .obj file n header file is tht u mean i can carry out the above. I mght nt have the source code.


        There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) SH:)UVIK

        1 Reply Last reply
        0
        • J Jorgen Sigvardsson

          Yes. If you know the binary layout of the objects, you can always access the data. If you are protecting sensitive data by making it private, it will not be sufficient.

          class Class {
          private:
          int mySecretInt;
          ....
          };

          Class obj;
          int* ptrToSecretInt = (int*)(((unsigned char*)&obj) + offset);
          *ptrToSecretInt = 1234; // Gotcha!

          From a language point of view, there is no standard and portable way to access the data.

          -- Verletzen zerfetzen zersetzen zerstören Doch es darf nicht mir gehören Ich muss zerstören

          S Offline
          S Offline
          Shouvik Das
          wrote on last edited by
          #4

          Wat abt functions... In case we've a void return type is it possible to type cast it to the **(void *)** and can get an access. ur code was givin access violation error so instead we did the following

          class A {
          private:
          int a;
          int b;
          
          public:
          	A()
          	{
          		a=0;
          		b=10;
          	}
          	void show()
          	{
          		cout<
          

          * * * There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. **Oscar Wilde (1854-1900)** Regards... Shouvik

          1 Reply Last reply
          0
          • J Jorgen Sigvardsson

            Yes. If you know the binary layout of the objects, you can always access the data. If you are protecting sensitive data by making it private, it will not be sufficient.

            class Class {
            private:
            int mySecretInt;
            ....
            };

            Class obj;
            int* ptrToSecretInt = (int*)(((unsigned char*)&obj) + offset);
            *ptrToSecretInt = 1234; // Gotcha!

            From a language point of view, there is no standard and portable way to access the data.

            -- Verletzen zerfetzen zersetzen zerstören Doch es darf nicht mir gehören Ich muss zerstören

            S Offline
            S Offline
            Shouvik Das
            wrote on last edited by
            #5

            The real prob comes when accessing function. say we've classes ported to us in .obj format. then going for DMA using pointers is a risky n unreliable job.

            class x
            {
            private:
            	void meth1()
            	{
            		cout<<"Meth1";
            	}
            
            	void meth2()
            	{
            		cout<<"meth 2";
            	}
            };
            
            class xduplicate
            {
            public:
            	void virtual meth1();
            	void virtual meth2();
            };
            
            main()
            {
            	x obj;
            	xduplicate *obj1;
            	obj1=(xduplicate *)&obj;
            	obj1->meth1();
            }
            

            we can access meth1 only if in class x it is virtual. i.e. the entry is in the virtual table. But now i cant jst change the native code ported to us. i've to anyhow access the private methods without any change in native code. wht we're plannin is x will be the producer class n xduplicate the consumer class. x will be available as .obj along with .h file so how can 1.


            There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik

            1 Reply Last reply
            0
            • J Jorgen Sigvardsson

              Yes. If you know the binary layout of the objects, you can always access the data. If you are protecting sensitive data by making it private, it will not be sufficient.

              class Class {
              private:
              int mySecretInt;
              ....
              };

              Class obj;
              int* ptrToSecretInt = (int*)(((unsigned char*)&obj) + offset);
              *ptrToSecretInt = 1234; // Gotcha!

              From a language point of view, there is no standard and portable way to access the data.

              -- Verletzen zerfetzen zersetzen zerstören Doch es darf nicht mir gehören Ich muss zerstören

              S Offline
              S Offline
              Shouvik Das
              wrote on last edited by
              #6

              most unproffesional way would be

              #define private public
              

              ;) bt disadv is all not required private members become open. hope u can understand the scenario now.


              There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik

              J 1 Reply Last reply
              0
              • S Shouvik Das

                most unproffesional way would be

                #define private public
                

                ;) bt disadv is all not required private members become open. hope u can understand the scenario now.


                There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik

                J Offline
                J Offline
                Jorgen Sigvardsson
                wrote on last edited by
                #7

                You have to define your security boundaries, and who you trust. Can the class trust the code? If so, then all is fine. If not, well, then you'll have to resort to other means of storage of sensitive data. It's very very hard to perfectly protect data as you can imagine. "How well do you want to protect your data, and against whom?" - that is the question you have to ask yourself. If it's hackers you are going to protect yourself from, then you can at most buy yourself some time. Anyone with enough time and wit will get to your data eventually...

                -- Verletzen zerfetzen zersetzen zerstören Doch es darf nicht mir gehören Ich muss zerstören

                S 1 Reply Last reply
                0
                • J Jorgen Sigvardsson

                  You have to define your security boundaries, and who you trust. Can the class trust the code? If so, then all is fine. If not, well, then you'll have to resort to other means of storage of sensitive data. It's very very hard to perfectly protect data as you can imagine. "How well do you want to protect your data, and against whom?" - that is the question you have to ask yourself. If it's hackers you are going to protect yourself from, then you can at most buy yourself some time. Anyone with enough time and wit will get to your data eventually...

                  -- Verletzen zerfetzen zersetzen zerstören Doch es darf nicht mir gehören Ich muss zerstören

                  S Offline
                  S Offline
                  Shouvik Das
                  wrote on last edited by
                  #8

                  this isn't a very critical data sensitive issue but to access the code in the form of ported .obj format whr i cant chng the code itself. hence it is of utmost importance tht i have a method in my appl to acces the member methods. at the same time the source .obj file remains unaltered. hope u could get the scenario


                  There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik

                  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