New child language - (Function member address (structure))

Pages: 1... 17181920
merging C++ with assembly
What exactly does that mean, anyway?
Ah.. Just try translating and replacing about 50% C++ code with assembly....
In my opinion assembly is the fastest, and optimizing them by assembly is a great choice... :)

I'm trying getting function addresses from structures. But, something blocks me, and here is an example :

1
2
void * begin = std::vector::begin;
void * value = Stack::value;


Anyways it only gives crazy compling errors... Am I doing anything wrong? :(
Last edited on
Unless your compiler is braindead, it will probably write better, faster, smaller, and more efficient assembly than you ever will, even with optimizations disabled.
Yes; std::vector::begin() is a function, not a variable.
You just need to give up with the questions you ask you are just making stuff up i guess
I am making & writing documentation. So now no need to post long updates... :)
About documentation : Which file format is best? CHM, HTML, or anything else?

Macro library is almost done. I only try to complete code replacing, that means it will compile the string inside the macro instead (If it supports). An example "DECIMAL" contains "double", so certainly the parser will find and compile the inside string "double" of the macro. "Macro" also has a higher level of precedence than functions and numbers. :)

What is intelligent compiler-interpreter?
Last edited on
HelpNDoc is great for CHM documentation: http://www.helpndoc.com/
You had better post your interpreter thing in the Articles section when it's done!
(Yeah, right.)
EDIT : Thanks L B & Catfish3... :)

chrisname wrote:
Yes; std::vector::begin() is a function, not a variable.


No. But actually a function also is an address, right? Every function contains its address information so that the program can locate and then call them exactly.

So what I really need is "function address". It's not a common function variable, it's "structure -> function". Come back to the example :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//EDIT2 : I converted successfully template functions to addresses...
//Second example :

struct NUMBER{
	int a;
	int b;
inline void fprint(){
	a = 15;
	printf("value a = %d - (value) b = %d\n",a,b);

}
};
//////////////////////////////////////////////////////////////////////////
void * fprint_address;

fprint_address = NUMBER::fprint; //FAILED
fprint_address = (void*)NUMBER::fprint; //FAILED

__asm mov eax, NUMBER::fprint; //COMPILING ERROR
__asm mov fprint_address, eax

Another example : Many structures (DIRECTX) have their inside functions.

(The problem here, the compiler doesn't accept it.)

error C2440: 'initializing' : cannot convert from 'void (__thiscall NUMBER::*)(void)' to 'void *'


Without structure & function, the interpreter probably will never be done.

Now absolutely I want to get a function address which is hidden behind a structure. What should I do now?
Last edited on
Every function contains its address information
Not necessarily.
fprint_address = (void*)NUMBER::fprint; //FAILED
It's because fprint is not a static function.

You remind the topic about the 'this' pointer?
Well I explained you the 'this' pointer goes in ecx, then you will be able to call NUMBER::fprint.

Also in ASM you need no ';' at the end of a line, check that out.

Try
1
2
3
4
5
6
NUMBER nr;
NUMBER * pNR = &nr;
__asm {
    mov ecx, pNR
    call NUMBER::fprint
};


I didn't test it but that should work.
You need an instance of vector, and get a function pointer to its member function.

I don't know if this works.

1
2
3
4
std::vector<int> v;
std::vector<int>::iterator (v::*A)(void);
A = &v::begin;
(v.*A)();
Last edited on
Yeah, this is my goal :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 ////////////////////////////////////////////////////////////////
    template <class F, [...]> //Generic version
       void * GetFunctionAddress() {

       //CODE...
       //return FUNCTION_MEMBER_ADDRESS;

    }
    ////////////////////////////////////////////////////////////////
    //NUMBER structure sample
    struct NUMBER
            {
            int a;
            int b;
     
            void PRINT() //Syntax : void FUNC(void);
            {printf("value a = %d - (value) b = %d\n",a,b);}
     
            void SETA(int A)
            {a = A;}
     
            void SETB(int B)
            {b = B;}
     
            int GETA()
            {return a;}
     
            int GETB()
            {return b;}
     
    };
    ////////////////////////////////////////////////////////////////
    int main()
    {
    //Currently impossible - MY GOAL
    //Generic version - Only uses a single function : GetFunctionAddress!!!

                void *address_PRINT = GetFunctionAddress<NUMBER,&NUMBER::PRINT>();
                void *address_GETA = GetFunctionAddress<NUMBER,&NUMBER::GETA>();
                void *address_GETB = GetFunctionAddress<NUMBER,&NUMBER::GETB>();
                void *address_SETA = GetFunctionAddress<NUMBER,&NUMBER::SETA>();
                void *address_SETB = GetFunctionAddress<NUMBER,&NUMBER::SETB>();
     
         printf("The NUMBER::PRINT address : 0x%X\n",address_PRINT);
         printf("The NUMBER::GETA address : 0x%X\n",address_GETA);
         printf("The NUMBER::GETB address : 0x%X\n",address_GETB);
         printf("The NUMBER::SETA address : 0x%X\n",address_SETA);
         printf("The NUMBER::SETB address : 0x%X\n",address_SETB);
    return 0;
    }

Last edited on
Wow! With template function I successfully converted a function member to an address!!!!
Because C++ does not support __thiscall definition, so I had a new idea : Defining a template function instead. It's much simpler I think :)

-> Firstly, see my goal above :D

And here, this is a trick which can get function member address easily :
1
2
3
4
5
6
7
8
9
10
11
12
13
template <class F,void (F::*Function)()>  //Only for syntax "void FUNC(void)"
void * GetFunctionAddress() {
 
    union ADDRESS  
    {
        void (F::*func)();  //Similar definition
        void * function_address;
    }address_data;  
 
    address_data.func = Function;  
    return address_data.function_address; //Address found!!! 

}  


With NUMBER structure example above, for example :

- This is an example code which is used to get address of the function NUMBER::PRINT :

 
void *address_PRINT = GetFunctionAddress<NUMBER,&NUMBER::PRINT>();


- Finally try implementing PRINT function using the output address :
1
2
__asm mov ecx, ADDRESS_OF_STRUCTURE (e.g : NUMBER)
__asm call address_PRINT //Done!!! 


It's so awesome!!! Wow, The hardest problem has been solved!!!!!!!!!!!!!!!!!!!

How does it work?

In this example the union variable ADDRESS::void (F::*func)() stores the address of the member function NUMBER::PRINT and then next, ADDRESS::function_address returns the function address...



But, what is the hell? (I HAVE TO CREATE A NEW TEMPLATE FOR EVERY SET OF ARGUMENT TYPES) :(

Like I mentioned before, the comment //Only for syntax "void FUNC(void)" , you will see it's extremely specific. Imagine it looks like "LOCK" - "KEY". Each template can only handle a single specific case. If you pick a wrong converter, the process will fall which result in compiling errors.

1
2
3
4
5
void *address_PRINT = GetFunctionAddress<NUMBER,&NUMBER::PRINT>();
// Converter : void FUNC(void) == void FUNC(void) -> OK

void *address_GETA = GetFunctionAddress<NUMBER,&NUMBER::GETA>();
// Converter : void FUNC(void) != void FUNC(int) -> Compiling error!!! (Different syntax) 

Finally four remaining functions NUMBER::GETA, NUMBER::SETA, NUMBER::GETB, NUMBER::SETB : Cry!!!
address_data.func = Function;
cannot convert from 'void (__thiscall NUMBER::*)(int)' to 'void (__thiscall NUMBER::*)(void)'
Details : Their addresses are unknown, just because they have their different syntax.

-> So with structure example, at least I have to make two other versions of converter to get their addresses properly!!


Does anyone have any idea "the generic version of the converter which is able to convert any function member to address"? Any help would be very helpful XDXD
Last edited on
jesus christ what a clusterfuck
Someone tells me his/her level of C++ knowledge. So, you don't know for's but you know templates? What the hell?
@coder777
Wow. I never have seen this. It's very new to me. Very interesting!!! XDXD

But, I have some questions : Can the boost function member variable be converted into a *void address value? Is it structure or regular value? And could you show me an example how to get, store the result into a void* then print the output address of a member function properly? :)


EssGeEich - it is just because I want to know more information - check others before implementing :)
Last edited on
@gtm
I agree.

I picked this thread as being complete BS near the start, and I was criticised for not being tolerant enough.

So then we had about 500 posts of more BS. Then Jackson Marie had her? account restricted (not sure what led to that, but presumably warned by admin), then renamed to Imadatobanisa. I didn't believe one word of the excuses posted in the OP's Bio at that time. Account reinstated, now more of the same BS.

I can only think that it keeps continuing because people continue to reply.

Also, I think that it may be one of the strategies of a troll to take on a female role to try to endear themselves to the male members on this site. I wouldn't be the least surprised if the OP was really a middle aged man on the same psychological plane as those who write viruses.

@EssGeEich

I agree with you too. Questions about loops and cout, but code with templates & asm?

Of course the real proof would be for the OP to post all the code, but I very much doubt that will happen. Others have requested it, and it hasn't happened yet. If code was posted I think it would be rather easy to spot the difference between your original code, and the OP's

I think time-wasters like the OP should have a permanent ban. If you are not happy - send a message to admin.

Any way this is all my opinion, but I would urge others to help stop this continued non sense.
closed account (3qX21hU5)
I told myself I would stop replying to this thread and hopefully JM would stop giving "Updates", but I wanted to break that rule to just say this.

Amen TheIdeasMan Amen

Now I'm gone again :)
Pages: 1... 17181920