ok, so i essentially have a .c file from anubis' process injection code, that i need converted to c++, which is the format of the rest of my product.

on compiling, i am getting one annoying error error (when i compile as a .cpp file):

1>.\inject.cpp(27) : error C2440: '=' : cannot convert from 'LPVOID' to 'HMODULE'
1>        Conversion from 'void*' to pointer to non-'void' requires an explicit cast

the problem code

BOOL InjectExecutable(DWORD dwPid, LPTHREAD_START_ROUTINE lpStartProc, LPVOID lpParam)
{
HMODULE hModule, hNewModule;
DWORD dwSize;
HANDLE hProcess;

hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPid);

if (hProcess == NULL)
{
return FALSE;
}

hModule = GetModuleHandle(NULL);

hNewModule = VirtualAllocEx(hProcess, hModule, dwSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);

if (hNewModule == NULL)
{
return FALSE;
}

WriteProcessMemory(hProcess, hNewModule, hModule, dwSize, NULL);

CreateRemoteThread(hProcess, 0, 0, lpStartProc, lpParam,	 0, NULL);

return TRUE;
}

help?

3
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by shea279

Sorry but anubis' process injection code, is normally used to put code into running windows processes for the purpose of running a rootkit. As far as I can tell.

So why should we help given the site rules and likely purpose. The only good news is you don't seem to know much.

If that isn't the case, then please explain further or we are all very unlikely to help. Please note the last section in:
http://www.daniweb.com/forums/faq.php?faq=daniweb_policies.

c++ is a lot stricter about typcasting than C. For example, in C it is not necessary to typecase the return value of malloc(), but in C++ it is required.

Which one of the lines you posted is line 27?

um well i don't see what part of "keep it legal" a process injection script is breaking. this section talks about copyrights, pornography, and not posting pirated software.

windows.h can be used to create a program like firefox, or it can be used to make a virus. that doesn't mean that we shouldn't be allowed to talk about it.

I don't care what people are "usually" doing with anubis' process injection code, but I have a completely legal use for it. I'm making a script for the network I administer which prevents the computers from disconnecting from network, and this code gives it persistence from being killed (this is none of your business but I have no reason not to share). that way a user can't just go into taskmgr and kill it. when a user disconnects, the script gives them 30 seconds to reconnect (with a warning), then shuts down the computer.

and no i can't just make the users limited accounts because they have to be able to install software on the machines.

and line 27 would be
hNewModule = VirtualAllocEx(hProcess, hModule, dwSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);

um well i don't see what part of "keep it legal" a process injection script is breaking. this section talks about copyrights, pornography, and not posting pirated software.

Don't worry -- IMO you are not violating that rule (yet).

and line 27 would be
hNewModule = VirtualAllocEx(hProcess, hModule, dwSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);

As I stated previously, just typecast the return value to HMODULE and it will compile just fine.

im stupid. i just added a typcast (hmodule) by the problem code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.