Get class member function address __ function with Consortium

Source: Internet
Author: User

Recently learned the principle of plug, mainly some memory operation. And then I found one in the process--the address of a class member function seems to get out of the class directly (except for static functions).
I've found an ingenious way to get a class member function address with a consortium

Template<typename dst_type,typename src_type>
dst_type union_cast (src_type src)
{
    union{
        src _type s;
        Dst_type D;
    } u;
    U.S = src;
    return u.d;
}

This is a type conversion function
You can call this:

    typedef void (A::* Good) (void);
    typedef void (*golobal) (void);
    Cout<<union_cast<golobal,good> (&a::good);

This will allow the global address to be obtained. can use OD to open look at the output of the address location is what instructions, open OD can find this address is such an instruction jmp XXXXX
And that piece of instruction is this, not difficult to guess is the function of the Address table. Although this is the callable address of the function, it is not the real address of the function.
~ ~~~~~~~ Editor ~ ~~~~~~~~~~~
I later found out that this was the real address with release version. If it's a debug version, you'll get a lot of debugging information.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.