SolvedLoad When Injected (C++)

Posts 115 of 15 · Page 1 of 1
Load When Injected (C++)
I've been fooling around with VS lately and I'm just wondering how do I load (run, without require) all my shit when it gets injected (shInject, Extreme Injector, etc.) into Garry's Mod. Thanks. I'm still new to o C++.
If your talking about how to run your C++ code when injected, put your code in DllMain. If you mean loading your lua then you gotta get gmods lua vtables, by either dumping them urself from luashared or just using the ones HerpDerpenstine posted (if your ok with fixing the errors), then you gotta dllimport GetLuaInterface and do a whole bunch of shit (you can paste it from Herp's post) to get down to CLuaShared(i think thats the one with RunString) then load your files and cLuaShared->RunString them, although this will mean you will have to uninject and inject every time u want to run your code |:
Quote Originally Posted by Gorzoid View Post
If your talking about how to run your C++ code when injected, put your code in DllMain. If you mean loading your lua then you gotta get gmods lua vtables, by either dumping them urself from luashared or just using the ones HerpDerpenstine posted (if your ok with fixing the errors), then you gotta dllimport GetLuaInterface and do a whole bunch of shit (you can paste it from Herp's post) to get down to CLuaShared(i think thats the one with RunString) then load your files and cLuaShared->RunString them, although this will mean you will have to uninject and inject every time u want to run your code |:
Or you could be smart and attach a console. load files on input from the user
Quote Originally Posted by Gorzoid View Post
If your talking about how to run your C++ code when injected, put your code in DllMain. If you mean loading your lua then you gotta get gmods lua vtables, by either dumping them urself from luashared or just using the ones HerpDerpenstine posted (if your ok with fixing the errors), then you gotta dllimport GetLuaInterface and do a whole bunch of shit (you can paste it from Herp's post) to get down to CLuaShared(i think thats the one with RunString) then load your files and cLuaShared->RunString them, although this will mean you will have to uninject and inject every time u want to run your code |:
Do you have any way I can contact you besides PMs?

Quote Originally Posted by IAmPhage View Post
Or you could be smart and attach a console. load files on input from the user
Thought about this a bit ago.
Quote Originally Posted by IAmPhage View Post
Or you could be smart and attach a console. load files on input from the user
hey don't give me that logic, i can be stupid if i want |:

Quote Originally Posted by oBLOOo View Post
Do you have any way I can contact you besides PMs?
/id/gorzoid but I am by far no expert on this, I made one dll that RunStrings a file for gmod phage's DunkedFramework also shows how to get LuaShared from GetLuaInterface if u want to check out his github
Quote Originally Posted by Gorzoid View Post
hey don't give me that logic, i can be stupid if i want |:


/id/gorzoid but I am by far no expert on this, I made one dll that RunStrings a file for gmod phage's DunkedFramework also shows how to get LuaShared from GetLuaInterface if u want to check out his github
Just added you.
Quote Originally Posted by Gorzoid View Post
If your talking about how to run your C++ code when injected, put your code in DllMain. If you mean loading your lua then you gotta get gmods lua vtables, by either dumping them urself from luashared or just using the ones HerpDerpenstine posted (if your ok with fixing the errors), then you gotta dllimport GetLuaInterface and do a whole bunch of shit (you can paste it from Herp's post) to get down to CLuaShared(i think thats the one with RunString) then load your files and cLuaShared->RunString them, although this will mean you will have to uninject and inject every time u want to run your code |:
Just for tips sake. Don't do your code in DllMain. Run your code in a new thread created from DllMain.
Running code inside DllMain can cause issues with your DLL.
Quote Originally Posted by Herp Derpinstine View Post
Just for tips sake. Don't do your code in DllMain. Run your code in a new thread created from DllMain.
Running code inside DllMain can cause issues with your DLL.
my high school comp sci teacher told me that i run all of my functions in int main(int argc, char* arghv[]). you're such a bad troll herp /s

On a real note, he doesn't know enough to truly explain what he's doing. He probably already uses CreateThread (you should be using _beginthreadex but that's an argument for another time) but didn't include it in his post because the solution was pasted.
Quote Originally Posted by IAmPhage View Post
my high school comp sci teacher told me that i run all of my functions in int main(int argc, char* arghv[]). you're such a bad troll herp /s

On a real note, he doesn't know enough to truly explain what he's doing. He probably already uses CreateThread (you should be using _beginthreadex but that's an argument for another time) but didn't include it in his post because the solution was pasted.
what do you think CreateThread does lol
Depending on injection method and also what you intend to do, there should be no real problem with running the code on the same thread, E.g. hooking functions.

--Edit: I say this as if it's a fact, although I could be completely wrong
Quote Originally Posted by IAmPhage View Post
my high school comp sci teacher told me that i run all of my functions in int main(int argc, char* arghv[]). you're such a bad troll herp /s

On a real note, he doesn't know enough to truly explain what he's doing. He probably already uses CreateThread (you should be using _beginthreadex but that's an argument for another time) but didn't include it in his post because the solution was pasted.
Quote Originally Posted by Gorzoid View Post
Depending on injection method and also what you intend to do, there should be no real problem with running the code on the same thread, E.g. hooking functions.

--Edit: I say this as if it's a fact, although I could be completely wrong
Executable's main != Dll's DllMain (I know you were joking Phage but for explanation's sake they are not alike.)

DllMain gets called when a loader-lock is active and held.
There are restrictions to what functions can be called from DllMain because of this.
Calling any of the restricted functions from DllMain can cause deadlocks and crashes.

You can still run your code in DllMain without worry but only if you aren't using any of the restricted functions.
Creating a new thread (CreateThread or _beginthreadex) and then running your code from there is overall a safer option.
Quote Originally Posted by D3M0L1T10N View Post
what do you think CreateThread does lol
It's a wrapper for CreateThread, I know, I've had some bad memory leaks using CreateThread.
Quote Originally Posted by IAmPhage View Post
It's a wrapper for CreateThread, I know, I've had some bad memory leaks using CreateThread.
going out on a limb and guessing by CreateThread you mean _beginthreadex, but i've never heard of someone getting memory leaks from it

are you just talking about the handle created from it and you didn't close it, or what?
Quote Originally Posted by D3M0L1T10N View Post
going out on a limb and guessing by CreateThread you mean _beginthreadex, but i've never heard of someone getting memory leaks from it

are you just talking about the handle created from it and you didn't close it, or what?
Yeah, _beginthreadex is just a wrapper for CreateThread. There were a few different posts on StackOverflow arguing which is considered 'more proper'. I'm sure you've probably read this by now. These just list the known/main benefits to using _beginthreadex over CreateThread.


The memory leak is a lot smaller than I thought but it's still a memory leak.

EDIT: And yeah I do call CloseHandle so it's def not from that.
Code:
hThread = reinterpret_cast<void*>(_beginthreadex(nullptr, 0, &g_ThreadStart, nullptr, 0, nullptr));
CloseHandle(hThread);
Been over a week since last update/bump after answers, assuming solved.

/Closed.
Posts 115 of 15 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?