Private Access
-
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
-
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
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
-
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
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
-
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
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 followingclass 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
-
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
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
-
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
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
-
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
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
-
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
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