Results 1 to 4 of 4
  1. #1
    Fowl3628800's Avatar
    Join Date
    Feb 2014
    Gender
    male
    Posts
    78
    Reputation
    10
    Thanks
    2,971

    Titanium Alternative - call C# DLL from injected C++ DLL

    I'm trying to make my hack independent from Titanium by calling it's Loader.Load() method in an injectable C++ DLL.

    Currently I am using the following code:
     
    Code:
    #include "MSCorEE.h"
    #include <windows.h>
    #include <metahost.h>
    #include <corerror.h>
    
    #pragma once
    
    using namespace System;
    
    void CallLoad()
    {
    	ICLRMetaHost *pMetaHost = NULL;
    	ICLRRuntimeInfo *pRuntimeInfo = NULL;
    	ICLRRuntimeHost *pClrHost = NULL;
    
    	HRESULT hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_PPV_ARGS(&pMetaHost)); // returns 0 (S_OK)
    
    	hr = pMetaHost->GetRuntime(L"v4.0.30319", IID_PPV_ARGS(&pRuntimeInfo)); // returns 0 (S_OK)
    
    	hr = pRuntimeInfo->GetInterface(CLSID_CLRRuntimeHost, IID_PPV_ARGS(&pClrHost)); // returns 0 (S_OK)
    
    	hr = pClrHost->Start(); // returns 1 (S_FALSE), maybe because the Runtime is already running??
    
    	DWORD dwRet = 99;
    	hr = pClrHost->ExecuteInDefaultAppDomain(L"Absolute\\Path\\To\\FowlsHack.dll", L"FowlsHack.Loader", L"LoadHacks", L"", &dwRet); // returns -2146233078 (seems to be COR_E_SECURITY)
    	// dwRet is still 99
    }
    
    #pragma unmanaged
    
    DWORD WINAPI ThreadProc(LPVOID lpParam)
    {
    	CallLoad();
    	return 0;
    }
    
    }
    
    BOOL APIENTRY DllMain(HINSTANCE hinstDll, DWORD Reason, LPVOID Reserved)
    {
    	switch (Reason){
    	case DLL_PROCESS_ATTACH:
    		CreateThread(0, NULL, ThreadProc, (LPVOID)L"", NULL, NULL);
    		break;
    	case DLL_PROCESS_DETACH:
    		break;
    	}
    	return TRUE;
    }
    
    #pragma managed

     
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using UnityEngine;
    
    namespace FowlsHack
    {
        public class Loader
        {
            public static GameObject load_object;
            
            public static void Load()
            {
                load_object = new GameObject();
                load_object.AddComponent<Hacks>();
                UnityEngine.Object.DontDestroyOnLoad(load_object);
            }
            static int LoadHacks(String ignored)
            {
                Load();
                return 0;
            }
        }
    }

    I put the from the hack required libraries from
    ...\SteamApps\common\Unturned\Unturned_Data\Manage d\
    to the folder, where both DLLs (the C# and the C++) are (they are in the same folder)

    and injected the C++ DLL into Unturned.exe using Extreme Injector v3.3,

    but it's not working.

    Start returns 1 (S_FALSE) and
    ExecuteInDefaultAppDomain returns -2146233078 (seems to be COR_E_SECURITY).

    Any ideas why?

  2. #2
    Blueblood1's Avatar
    Join Date
    Aug 2012
    Gender
    male
    Posts
    711
    Reputation
    132
    Thanks
    7,125
    My Mood
    Mellow
    Probably because your over complicating it. Just add your hack as a reference and attach it inside the assembly's Database start().

  3. The Following User Says Thank You to Blueblood1 For This Useful Post:

    Fowl3628800 (08-14-2014)

  4. #3
    Fowl3628800's Avatar
    Join Date
    Feb 2014
    Gender
    male
    Posts
    78
    Reputation
    10
    Thanks
    2,971
    Quote Originally Posted by Blueblood1 View Post
    Probably because your over complicating it. Just add your hack as a reference and attach it inside the assembly's Database start().
    Thank you for the idea. It works perfectly for me.

  5. #4
    Color's Avatar
    Join Date
    Aug 2012
    Gender
    male
    Posts
    19,896
    Reputation
    2588
    Thanks
    7,864
    My Mood
    Lurking
    //Answered..

    Member Since 8/05/2012
    Editor 4/04/13 - 4/21/13
    Middleman 7/14/13 - 11/4/13

    Battlefield Minion 6/13/14-3/20/15
    Steam Minion 7/16/14-3/20/15

    Minion+ 10/1/14-3/20/15
    M.A.T. Minion 10/19/14-3/20/15
    ROTMG Minion 1/14/15-3/20/15

    Donator Since 2/26/15 (Thanks @Cursed!)
    Steam Minion 5/9/15 - 11/5/15
    OSFPS Minion 9/15/15 - 11/5/15


Similar Threads

  1. [Help Request] Dll whichs inject a Dll.
    By denniskai1234 in forum C++/C Programming
    Replies: 4
    Last Post: 12-01-2013, 05:14 AM
  2. [Help]Inject DLL from Website?
    By mastermods in forum Visual Basic Programming
    Replies: 7
    Last Post: 09-07-2010, 05:14 AM
  3. [Help]Call .dll From Visual Basic
    By GameTrainerMaker in forum Visual Basic Programming
    Replies: 7
    Last Post: 09-06-2010, 11:46 PM
  4. Could i get some help for an Injector that injects a dll from ftp?
    By Sydney in forum Visual Basic Programming
    Replies: 9
    Last Post: 06-29-2010, 07:03 AM
  5. how to inject dll from web
    By pr0h4x0r in forum Combat Arms Hack Coding / Programming / Source Code
    Replies: 7
    Last Post: 04-14-2010, 09:06 PM

Tags for this Thread