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. class structure

class structure

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
13 Posts 7 Posters 1 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.
  • C Cedric Moonen

    Amr Shahin wrote:

    getting the private and public data and functions in the class without having the source code of the class; only the binary !!

    :confused: Binary data for a class ?? What do you mean ? It is saved in a file and you want to 'reverse-engineer' the file ? Then I think this will be a little bit difficult because it depends a lot of the guy who wrote the class.

    A Offline
    A Offline
    Amr Shahin
    wrote on last edited by
    #3

    well ya; i meant that only the object code of the class is available; just like the CString class for example. i dont want to reverse engineer the class, i just want to get its structure, i can get the public interface through the documentation of course, but i wanna know if there is a way to know what are the private stuff in the class, not the implementation, only the type of variables, and segnature in case of functions

    C V 2 Replies Last reply
    0
    • A Amr Shahin

      well ya; i meant that only the object code of the class is available; just like the CString class for example. i dont want to reverse engineer the class, i just want to get its structure, i can get the public interface through the documentation of course, but i wanna know if there is a way to know what are the private stuff in the class, not the implementation, only the type of variables, and segnature in case of functions

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #4

      But... :confused: Fot the CString class you can see the members of the class if you want to. If you have the header file (which is needed to be able to use the class), then you have all the members of the class. Just right click on the class name and select go to definition.

      A 1 Reply Last reply
      0
      • C Cedric Moonen

        But... :confused: Fot the CString class you can see the members of the class if you want to. If you have the header file (which is needed to be able to use the class), then you have all the members of the class. Just right click on the class name and select go to definition.

        A Offline
        A Offline
        Amr Shahin
        wrote on last edited by
        #5

        man! i said CString as an example of a class that u dont have its source code; and the RC->go to defenition gives only the public stuff!

        T C 2 Replies Last reply
        0
        • A Amr Shahin

          man! i said CString as an example of a class that u dont have its source code; and the RC->go to defenition gives only the public stuff!

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #6

          CString[^] :rolleyes:;P


          TOXCCT >>> GEII power

          [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

          1 Reply Last reply
          0
          • A Amr Shahin

            man! i said CString as an example of a class that u dont have its source code; and the RC->go to defenition gives only the public stuff!

            C Offline
            C Offline
            Cedric Moonen
            wrote on last edited by
            #7

            Amr Shahin wrote:

            i said CString as an example of a class that u dont have its source code

            Man ! I know that was just an example :). But this is the same for ALL the classes. If you use a class in your program, then you need to have its header file. If you have it's header file, you can look to the members. Maybe your problem is because it uses a kind of interface ? And you just have access to public functions and the rest is defined in a derived class ? Is that the case ? Or maybe you don't explain correctly the problem. What is this class ? Where does it comes from ? What do you have in the header file ? Please provide some more info then.

            1 Reply Last reply
            0
            • A Amr Shahin

              well ya; i meant that only the object code of the class is available; just like the CString class for example. i dont want to reverse engineer the class, i just want to get its structure, i can get the public interface through the documentation of course, but i wanna know if there is a way to know what are the private stuff in the class, not the implementation, only the type of variables, and segnature in case of functions

              V Offline
              V Offline
              vikramlinux
              wrote on last edited by
              #8

              C++ supports only syntactic kind of encapsulaion. Also those visibility or access keywords(private,protected and public ) comes into picture only at compile time. At run time the whole object is just a memory block. Access rules are the grammer defined by language and can force user to model the code in some defined fashion.I dont think it's directly possible to get all those details with binary image. I am not sure about object file. Is object file formats that each platform uses are published? VikramS -- modified at 9:10 Wednesday 10th May, 2006

              1 Reply Last reply
              0
              • A Amr Shahin

                hello guys is there a way in c++ to analyze a class structure?? i.e: getting the private and public data and functions in the class without having the source code of the class; only the binary !! maybe using the RTTI

                M Offline
                M Offline
                Maximilien
                wrote on last edited by
                #9

                no. RTTI will NOT be usefull.


                Maximilien Lincourt Your Head A Splode - Strong Bad

                V 1 Reply Last reply
                0
                • M Maximilien

                  no. RTTI will NOT be usefull.


                  Maximilien Lincourt Your Head A Splode - Strong Bad

                  V Offline
                  V Offline
                  vikramlinux
                  wrote on last edited by
                  #10

                  Just for Info guys: CString class source code is available. I meant STL/MFC library source code is available with any VC++ IDE.

                  1 Reply Last reply
                  0
                  • A Amr Shahin

                    hello guys is there a way in c++ to analyze a class structure?? i.e: getting the private and public data and functions in the class without having the source code of the class; only the binary !! maybe using the RTTI

                    N Offline
                    N Offline
                    Nick_Kisialiou
                    wrote on last edited by
                    #11

                    There is, but it is no longer C++. It is compiler implementation code which is not in C++ standard. Class (memory) structure is something like this: this_pointer -> [vtable_pointer, dataField1, dataField2, ...] where vtable_pointer points to the table of virtual functions: vtable_pointer -> [func1, func2, ...] So, in theory, you can get access to class (public/private do not make sense in binary) members like this: data1 = *((char*)(*this) + 4); data2 = *((char*)(*this) + 8); // or 12 or 16 depending on the type of data1 Notice, I said in theory, because in practice the compiler aligns data fields the way it wants, even the order matters. So, if you have an integer data field and a double data field you may get something like this: [4 bytes for vtable_pointer, 4 bytes garbage, 4 bytes int, 8 bytes double] There is no simple way to figure out the order and the types of data fields unless you disasm the binary to see which memory locations are accessed from public functions that you know. That's not much, but I hope it'll be helpful. -- modified at 12:28 Wednesday 10th May, 2006

                    N 1 Reply Last reply
                    0
                    • N Nick_Kisialiou

                      There is, but it is no longer C++. It is compiler implementation code which is not in C++ standard. Class (memory) structure is something like this: this_pointer -> [vtable_pointer, dataField1, dataField2, ...] where vtable_pointer points to the table of virtual functions: vtable_pointer -> [func1, func2, ...] So, in theory, you can get access to class (public/private do not make sense in binary) members like this: data1 = *((char*)(*this) + 4); data2 = *((char*)(*this) + 8); // or 12 or 16 depending on the type of data1 Notice, I said in theory, because in practice the compiler aligns data fields the way it wants, even the order matters. So, if you have an integer data field and a double data field you may get something like this: [4 bytes for vtable_pointer, 4 bytes garbage, 4 bytes int, 8 bytes double] There is no simple way to figure out the order and the types of data fields unless you disasm the binary to see which memory locations are accessed from public functions that you know. That's not much, but I hope it'll be helpful. -- modified at 12:28 Wednesday 10th May, 2006

                      N Offline
                      N Offline
                      NiceNaidu fo
                      wrote on last edited by
                      #12

                      Good work Mr.Nick.

                      N 1 Reply Last reply
                      0
                      • N NiceNaidu fo

                        Good work Mr.Nick.

                        N Offline
                        N Offline
                        NiceNaidu fo
                        wrote on last edited by
                        #13

                        when a class uses the methods of a library file(dll). Since the binary file(dll) does not contain the type of access specifier(public,private)a method is assocaited with,How can the class identify whether the method is public or private ???

                        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