{"id":17877097,"url":"https://github.com/zjx20/stealer","last_synced_at":"2026-02-21T20:30:53.562Z","repository":{"id":23952850,"uuid":"27334706","full_name":"zjx20/stealer","owner":"zjx20","description":"A macro helps accessing private fields and methods of c++ objects.","archived":false,"fork":false,"pushed_at":"2016-08-14T15:42:05.000Z","size":39,"stargazers_count":17,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-24T14:49:37.484Z","etag":null,"topics":["cpp","hack","private-field","private-method"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zjx20.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-30T12:20:56.000Z","updated_at":"2025-01-04T05:31:46.000Z","dependencies_parsed_at":"2022-07-30T05:07:54.935Z","dependency_job_id":null,"html_url":"https://github.com/zjx20/stealer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zjx20/stealer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjx20%2Fstealer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjx20%2Fstealer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjx20%2Fstealer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjx20%2Fstealer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zjx20","download_url":"https://codeload.github.com/zjx20/stealer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjx20%2Fstealer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29692521,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T18:18:25.093Z","status":"ssl_error","status_checked_at":"2026-02-21T18:18:22.435Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","hack","private-field","private-method"],"created_at":"2024-10-28T11:45:13.481Z","updated_at":"2026-02-21T20:30:53.546Z","avatar_url":"https://github.com/zjx20.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Stealer: stealing privates of c++ object\n\nThe main purpose of stealer is for testing: that makes it possible to test privates of a class without changing its design.\n\nIt was tested in:\n\n* Apple LLVM version 6.1.0 (clang-602.0.49)\n* VS2012\n\n## Usage\n\nNo installation is needed, just copy and include the *stealer.h*. Here is a small tutorial shows how to use it.\n\n1. **Assume there is an existing class named `private_t`, the definition is:**\n\n    ```cpp\n    class private_t\n    {\n    public:\n        private_t(const std::string\u0026 initial_value)\n        {\n            _private_string = initial_value;\n            _private_int = 123456789;\n        }\n    \n        void print()\n        {\n            std::cout \u003c\u003c \"_private_string: \" \u003c\u003c _private_string \u003c\u003c std::endl \u003c\u003c\n                    \"_private_int: \" \u003c\u003c _private_int \u003c\u003c std::endl;\n        }\n    \n    private:\n        void private_method()\n        {\n            std::cout \u003c\u003c \"in private_method()!\" \u003c\u003c std::endl;\n        }\n    \n        int private_method3(int a, double b, const std::string\u0026 str)\n        {\n            std::cout \u003c\u003c \"in private_method3(), a = \" \u003c\u003c a \u003c\u003c \", b = \" \u003c\u003c b \u003c\u003c\n                    \", str = \" \u003c\u003c str \u003c\u003c std::endl;\n            return a;\n        }\n    \n        void private_const_method() const\n        {\n            std::cout \u003c\u003c \"in private_const_method()!\" \u003c\u003c std::endl;\n        }\n    \n        void private_volatile_method() volatile\n        {\n            std::cout \u003c\u003c \"in private_volatile_method()!\" \u003c\u003c std::endl;\n        }\n    \n    private:\n        std::string _private_string;\n        int _private_int;\n    };\n    ```\n\n2. **Then declare a stealer wrapper class of `private_t`:**\n\n    ```cpp\n    STEALER(stealer_private_t, private_t,\n            /* STEAL_FIELD(type_of_the_field, field_name) */\n            STEAL_FIELD(int, _private_int),\n            STEAL_FIELD(std::string, _private_string),\n            \n            /* STEAL_METHOD(return_type_of_the_method, method_name, arg1, arg2, ...) */\n            STEAL_METHOD(void, private_method),\n            STEAL_METHOD(int, private_method3, int, double, const std::string\u0026),\n            \n            /* STEAL_METHOD() family */\n            STEAL_CONST_METHOD(void, private_const_method),\n            STEAL_QUALIFIED_METHOD(volatile, void, private_volatile_method),\n    );\n    ```\n    \n    the macro will be expanded to this like:\n    \n    ```cpp\n    /*...*/\n    class stealer_private_t\n    {\n        private_t* _obj;\n    public:\n        stealer_private_t(private_t* obj) _obj(obj) {/*...*/}\n        stealer_private_t(private_t\u0026 obj) _obj(\u0026obj) {/*...*/}\n        \n        void private_method() {/*...*/}\n        int private_method3(int a1, double a2, const std::string\u0026 a3) {/*...*/}\n        void private_const_method() const {/*...*/}\n        void private_volatile_method() volatile {/*...*/}\n        \n        int\u0026 _private_int;\n        std::string\u0026 _private_string;\n    };\n    ```\n    \n3. **Use the wrapper class for stealing:**\n\n    ```cpp\n    int main()\n    {\n        private_t inst(\"private!\");\n        inst.print();\n    \n        std::cout \u003c\u003c std::endl;\n    \n        stealer_private_t steal(inst);\n    \n        // read private fields\n        std::cout \u003c\u003c\n                \"steal _private_string: \" \u003c\u003c steal._private_string \u003c\u003c std::endl \u003c\u003c\n                \"steal _private_int: \" \u003c\u003c steal._private_int \u003c\u003c std::endl;\n    \n        std::cout \u003c\u003c std::endl;\n    \n        // call private methods\n        steal.private_method();\n        steal.private_method3(100, 123.4, \"foo\");\n        steal.private_const_method();\n        steal.private_volatile_method();\n    \n        std::cout \u003c\u003c std::endl;\n    \n        // modify private fields\n        steal._private_string = \"stole!\";\n        steal._private_int = 0;\n        steal._private_map[1] = 'a';\n    \n        inst.print();\n    \n        return 0;\n    }\n    ```\n    \n    the output:\n    \n    ```\n    _private_string: private!\n    _private_int: 123456789\n    _private_map.size(): 0\n    \n    steal _private_string: private!\n    steal _private_int: 123456789\n    \n    in private_method()!\n    in private_method3(), a = 100, b = 123.4, str = foo\n    in private_const_method()!\n    in private_volatile_method()!\n    \n    _private_string: stole!\n    _private_int: 0\n    _private_map.size(): 1\n    ```\n\n# Technique Detail\n\nTwo blog posts explain how it works:\n* [Access to private members. That's easy!](http://bloglitb.blogspot.com/2010/07/access-to-private-members-thats-easy.html)\n* [Access to private members: Safer nastiness.](http://bloglitb.blogspot.com/2011/12/access-to-private-members-safer.html)\n\n# Limitations\n\n* Although the technique used by strealer is blessed by the c++ standard, not all compilers support that feature. And gcc is recommended.\n* Complex types of fields such as `std::map\u003cint, int\u003e` are not supported by stealer directly due to the comma breaks the macro. A workaround is typedef, so commas will be eliminated.\n* Overloaded methods are not supported. There is no way to specify which version of overloads should be used (casting doesn't work, it may be a bug of the compiler).\n* Private template member methods are also not supported, the compiler just not allows.\n\n# License\n\nThis project is released under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzjx20%2Fstealer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzjx20%2Fstealer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzjx20%2Fstealer/lists"}