Posted April 20, 200916 yr I am trying to emulate this assembly in C++ (to make it more readable then a hacky inline assembly).MOV EAX,DWORD PTR DS:[5D91B4]PUSH ESILEA ECX,DWORD PTR DS:[EAX+89C08]CALL 0047F3F8So I have this psuedo code class MAIN { public: class FUNCLIST { public: bool (* FuncListContains)(int idx,bool) = (bool (*)(int,bool))0x0047EE03; int FuncListGetItem(int idx) { return idx*2; } }; FUNCLIST* FuncList = (FUNCLIST*)(this+0x00089C08); }; MAIN* Main = (MAIN*)0x005D91B4;Of course this doesn't work because the function pointer isn't static.Is there anyway to set the function pointer as a constant but keeping it as a member?Summary:I am injecting a dll and I want to have that assembly above as C++ so I can easily call it from my dll without a hacky inline assembly segment.
April 20, 200916 yr If I understood you correctly, this should work: class FUNCLIST { public: bool (* FuncListContains)(int idx,bool); // .... };FUNCLIST::FuncListContains = (bool (*)(int,bool))0x0047EE03;Why can't you set it to static anyway?I'm not sure if the above actually works, I think it only does with statics.However, you can init vars in the constructor: class FUNCLIST { public: bool (* FuncListContains)(int idx,bool)= (bool (*)(int,bool))0x0047EE03; int FuncListGetItem(int idx) { return idx*2; } FUNCLIST() : FuncListContains((bool (*)(int,bool))0x0047EE03) {}; };
April 20, 200916 yr Author "Why can't you set it to static anyway?"Because, I need it to set "ECX" ("this" in C++) to the address of the classes data.Is there any way to not use contructors? And ya the top snippet only works if it is static.
April 20, 200916 yr Author Still not satisfied with this way but I think it will work.static const int FuncListContainsAddr = 0x0047EE03;bool FuncListContains(int a, int B){ return ((bool (*)(int,bool))FuncListContainsAddr)(a,B);} Edited April 20, 200916 yr by high6
April 20, 200916 yr Author I guess I will have to do it like that unless I can declare a constant function pointer in a class. Forgot that a function pointer stores the destination so changing the location of "this" would break it.
April 21, 200916 yr Author Almost works, just need to figure out how to set FuncListContains to 0x0047EE03. class MAIN { public: char bump1[0x00089C08]; class FUNCLIST { public: bool FuncListContains(int idx,bool b) { return ((bool (*)(int,bool))0x0047EE03)(idx,b); } int FuncListGetItem(int idx) { return idx*2; } }; FUNCLIST* FuncList; }; static MAIN* Main = (MAIN*)0x005D91B4;Would making "FuncListContains" virtual allow me to set it's address?
April 22, 200916 yr Author why does this workbool FuncListContains(int idx,bool b) { return ((bool (*)(int,bool))0x0047EE03)(idx,b); }But not thisbool FuncListContains(int idx,bool b) { return ((bool (FUNCLIST::*)(int,bool))0x0047EE03)(idx,b); }?It says that it cannot typecast an int to "bool (FUNCLIST::*)(int,bool)".Basically I want to call an address as a member without having a function pointer stored that takes up space in the classes memory.
Create an account or sign in to comment