Giter VIP home page Giter VIP logo

unityhook's Introduction

UnityHook

UnityHook is a simple platform for hooking managed function calls, targeting specifically assemblies compiled for Unity3d games.

Installed hooks allow overriding hooked functions' return values, essentially granting complete control over managed code execution in a targeted game.

Hooker

Hooker is the project that actually injects code into original game assemblies/libraries (= .dll files). It can be used to 'hook' and 'restore' assemblies. Run hooker.exe help for information about the options to pass. To hook game-assemblies you need to tell it the location of the game folder and the path to a compiled HookRegistry binary.

HookRegistry

HookRegistry is the project that contains code to be executed when a hooked method/function has been called while the game is running. The project compiles to 1 binary file that must be passed to Hooker. Currently implemented hooks are following:

  • Hearthstone - with dependancy on HS game libraries
    • Disable SSL connection between client/server;
    • Duplicate packets transferred between client/server to other TCP streams. These streams try to attach to the HearthStone PacketAnalyzer.
  • General
    • Hooking into the Unity logger.

Hooker will attempt to copy all referenced (by HookRegistry) library files to the library folder of the game. Make sure to validate all necessary library files are copied by inspecting the Hooker log output.

Hooks file

The file which declares all methods, located inside the game libraries, to be hooked. See /Hooker/example_hooks for more information about it's syntax. The example_hooks file is used in the next section's example.

NOTE: The hooker will always hook all methods entered in the Hooks file, if found. Hooking a specific method when the HooksRegistry binary has no code to inject will have NO side effect on the game! The game will run a bit slower though..

Build

Visual Studio 2017 has to be installed to build both projects. Required components are C# - and Unity development tools! Visual Studio 2017 Community edition is free to download and capable to perform the build.

  1. Clone the repo;
  2. Create a junction link between the solution folder and the game install path. See /createJunction.bat;
  3. Open UnityHook solution file with Visual Studio;
  4. Build project Hooker;
  5. Build project HookRegistry;
  6. All binary files can be found inside the bin folder of each project.

Usage Example

The example expects the example_hooks file to be used as of the latest commit, also the latest HookRegistry binary.

Effects of the example

  • The game creates a non secure connection to the server (NOT through a TLS tunnel);
  • All transferred network packets are being duplicated to another TCP 'dump'-stream.

What you need

  • The PATH to Hooker compiled binaries. Refered to as {HOOKERPATH};
  • The compiled binary FILE from HookRegistry. Referred to as {REGISTRY};
  • The PATH to the game installation folder. Referred to as {GAMEDIR};
  • The path to a hooks FILE, example_hooks as mentioned above. Referred to as {HOOKS}.

Steps

  1. Call Hooker.exe;
{HOOKERPATH}\Hooker.exe hook -d "{GAMEDIR}" -h "{HOOKS}" -l "{REGISTRY}"
  1. Verify that that Hooker did not encounter a problem;
    • Check the log output;
    • Requested methods are hooked;
    • Game assemblies are duplicated next to the original as {name}.original.dll -> Backup;
    • Patched assemblies are written to the game directory as {name}.out.dll;
    • Patched assemblies replaced the original assemblies as {name}.dll;
    • HookRegistry assembly, and referenced assemblies, are copied next to the game assemblies;
  2. Run the game -> Watch the game log for lines starting with [HOOKER].

To restore, run the command {HOOKERPATH}\Hooker.exe restore -d "{GAMEDIR}"

Remarks

  • This project is intended to run within the context of the Unity Engine. If Unity Engine is not initialised when HookRegistry is initialised, then no hooks will run. Each method will perform as if unhooked when outside of the Unity Engine context.

unityhook's People

Contributors

bert-proesmans avatar jakibaki avatar jleclanche avatar robert-nix avatar synap5e avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unityhook's Issues

I need help building the project

I am using UnityHook for my a-level computer science project in which i will use this project to determine when you play a card in hearthstone, which card is played and on which side of the board then calculate real time statistics from the data but i cannot get unityhook to build at all can someone just walk me through the steps they took to make it work?

Add an example hook to recover arena draft rewards logging

See this diff from 9786:

@@ -544,20 +395,7 @@ public class ArenaRewardDisplay : MonoBehaviour

    public void ActivateKey()
    {
-       if (this.m_Rewards.get_Count() == 0)
-       {
-           Debug.LogError("ArenaRewardDisplay: m_rewards.Count == 0!");
-           return;
-       }
-       Log.Rachelle.Print("DRAFT REWARDS:", new object[0]);
-       for (int i = 0; i < this.m_Rewards.get_Count(); i++)
-       {
-           RewardData rewardData = this.m_Rewards.get_Item(i);
-           Log.Rachelle.Print(string.Format("\treward {0}={1}", i, rewardData), new object[0]);
-       }
-       SceneUtils.SetLayer(this.m_TheKeyMesh.get_transform().get_parent().get_gameObject(), GameLayer.IgnoreFullScreenEffects);
        SceneUtils.EnableColliders(this.m_TheKeyMesh, true);
-       this.FadeVignetteIn();
        this.m_TheKeySelectionGlow.get_renderer().set_enabled(true);
        Color color = this.m_TheKeySelectionGlow.get_renderer().get_sharedMaterial().get_color();
        color.a = 0f;

Need help with usage of this tool

I'm just working with this wonderful tool, but something makes me confused.

With the example code inside, I create a class with onCall method to execute my own logic firstly. Seems that hooker module works fine, but the call to method in hookregistry performs as it is not executed at all.

Then with some simple tests, hookregistry.dll was dynamically loaded successfully, but cannot be found in my process memory detection tool, though origin file was locked by the system. Of course none of the debug logic was executed.

I suspect that something was wrong, and should I pay special attention to anything here?

code.txt

Need a bit help please

Hey,

so, i tried to work with your Program, which is very pretty, but I have some issues.

I compiled the "Hooker" and the "HookerRegistry" and set the "Hooker" correctly with valid path's. At next I compiled your "Proto-Extractor" and tried to extract the functtions. I got two File-Path Errors. I thought I fixed them, but theres still an File-Path Error in the ProgramTest.cs File in Line 178.

I went on and looked with .Net-Reflector in the Assembly-CSharp.dll File's and found the functions I need, I think. But at least I'am a bit confused how to go on.

For testing this I want to write a Script that automaticly click the "Play"-Button in Hearthstone, and then hook this Script to execute it.

Am I missed something important about the functionality about your Hooker/Extractro? ^^

If not, someone wants to help me with the script? Or give me a hint in the right direction? Would be Nice :)

PS: I am using Windows 10 as OS, The newest Version of Hearthstone and Visual Studio Express 2017 for compiling.

  • Cheers!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.