high6 Posted April 20, 2009 Posted April 20, 2009 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.
Killboy Posted April 20, 2009 Posted April 20, 2009 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) {}; };
high6 Posted April 20, 2009 Author Posted April 20, 2009 "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.
high6 Posted April 20, 2009 Author Posted April 20, 2009 (edited) 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, 2009 by high6
high6 Posted April 20, 2009 Author Posted April 20, 2009 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.
high6 Posted April 21, 2009 Author Posted April 21, 2009 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?
high6 Posted April 22, 2009 Author Posted April 22, 2009 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.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now