Giter VIP home page Giter VIP logo

juno's Introduction

Juno

Build status

A Windows managed function detouring library written in C# that supports both x86 and x64 detours.


Features

  • x86 and x64 detours

Limitations

  • Both detoured and original classes must have the same layout of class variables if you wish to access them
  • Both detoured and orginal functions can not be inlined
  • Detoured functions must match the signature of the original function i.e same parameters and return type

Installation

  • Download and install Juno using NuGet

Useage

You have the option of using one of two function detouring methods

  • GenericFunctionDetour
  • NonGenericFunctionDetour

GenericFunctionDetour should be used when the class type is availible at compiletime.

NonGenericFunctionDetour should be used when a type is only availible at runtime.

Creating instances of these classes is as follows

using Juno;

var genericFunctionDetour = new GenericFunctionDetour<OriginalClass, TargetClass>("OriginalFunction", "TargetFunction");

var nonGenericFunctionDetour = new NonGenericFunctionDetour(OriginalClassType, TargetClassType, "OriginalFunction", "TargetFunction");

Basic detour

using Juno;

public class TestClass1
{
    public void TestMethod1()
    {
        Console.WriteLine("Original Function Called");
    }
}

public class TestClass2
{
    public void TestMethod2()
    {
        Console.WriteLine("Detoured Function Called");
    }
}

public class Program
{
    public static void Main()
    {
        var functionDetour = new GenericFunctionDetour<TestClass1, TestClass2>("TestMethod1", "TestMethod2");
        
        // Initialize a test class
        
        var testClass = new TestClass1();
        
        // This calls the original function as expected
        
        testClass.TestMethod1(); 
        
        // Add the function detour
        
        functionDetour.AddDetour();
        
        // This calls the detoured function TestClass2.TestMethod2
        
        testClass.TestMethod1();
        
        // Remove the detour
        
        functionDetour.RemoveDetour();
        
        // This calls the original function again
        
        testClass.TestMethod1();
    }
}

Accessing parameters of detoured functions

using Juno;

public class TestClass1
{
    public void TestMethod1(int a, int b)
    {
        Console.WriteLine(a + b);
    }
}

public class TestClass2
{
    public void TestMethod2(int a, int b)
    {
        Console.WriteLine(a * b);
    }
}

public class Program
{
    public static void Main()
    {
        var functionDetour = new GenericFunctionDetour<TestClass1, TestClass2>("TestMethod1", "TestMethod2");
        
        // Initialize a test class
        
        var testClass = new TestClass1();
        
        // This calls the original function as expected producing 5 to the console
        
        testClass.TestMethod1(2, 3); 
        
        // Add the function detour
        
        functionDetour.AddDetour();
        
        // This calls the detoured function TestClass2.TestMethod2 producing 6 to the console
        
        testClass.TestMethod1(2, 3);
        
        // Remove the detour
        
        functionDetour.RemoveDetour();
        
        // This calls the original function again producing 5 to the console
        
        testClass.TestMethod1();
    }
}

Accessing returns of detoured functions

using Juno;

public class TestClass1
{
    public int TestMethod1()
    {
        return 5;
    }
}

public class TestClass2
{
    public void TestMethod2()
    {
        return 10;
    }
}

public class Program
{
    public static void Main()
    {
        var functionDetour = new GenericFunctionDetour<TestClass1, TestClass2>("TestMethod1", "TestMethod2");
        
        // Initialize a test class
        
        var testClass = new TestClass1();
        
        // This calls the original function as expected returning 5
        
        var testValue1 = testClass.TestMethod1(); 
        
        // Add the function detour
        
        functionDetour.AddDetour();
        
        // This calls the detoured function TestClass2.TestMethod2 returning 10
        
        var testValue2 = testClass.TestMethod1();
        
        // Remove the detour
        
        functionDetour.RemoveDetour();
        
        // This calls the original function as expected returning 5
        
        var testValue3 = testClass.TestMethod1();
    }
}

Accessing original class variables from detoured functions

using Juno;

public class TestClass1
{
    private int classVariable = 8;

    public void TestMethod1()
    {
        Console.WriteLine($"Class variable was {classVariable}");
    }
}

public class TestClass2
{
    private int classVariable = 0;

    public void TestMethod2()
    {
       Console.WriteLine($"Class variable was {classVariable}");
    }
}

public class Program
{
    public static void Main()
    {
        var functionDetour = new GenericFunctionDetour<TestClass1, TestClass2>("TestMethod1", "TestMethod2");
        
        // Initialize a test class
        
        var testClass = new TestClass1();
        
        // This calls the original function as expected producing 8 to the console
        
        testClass.TestMethod1(); 
        
        // Add the function detour
        
        functionDetour.AddDetour();
        
        // This calls the detoured function TestClass2.TestMethod2 producing 8 to the console
        
        testClass.TestMethod1();
        
        // Remove the detour
        
        functionDetour.RemoveDetour();
        
        // This calls the original function as expected producing 8 to the console
        
        testClass.TestMethod1();
    }
}

Contributing

Pull requests are welcome.

For large changes, please open an issue first to discuss what you would like to add.

juno's People

Watchers

 avatar

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.