Search code examples
c#console-applicationdll-injection

An object reference is required for a non-static field, method, or property


using System;
using System.Diagnostics;
using System.Reflection.Emit;
using System.Threading;
using EasyExploits;

namespace ConsoleApp1
{
    class Program
    {
        EasyExploits.Module module = new EasyExploits.Module();

        static void Main(string[] args)
        {
            Module.LaunchExploit();
            Console.ForegroundColor = ConsoleColor.Green;
            Label:
            Console.WriteLine("Please Type 'Inject'");
            string proccess1 = Console.ReadLine();
            if (proccess1 == "Inject")
            {
                Console.WriteLine("");
                Console.WriteLine("Injected!");
                goto Begin;
            }
            else
            {
                goto Label;
            }
            Begin:
            Console.WriteLine("");
            Console.WriteLine("Enter a script and press enter to execute it.");
            string answer = Console.ReadLine();
            Module.ExecuteScript(answer);
            goto Begin





        }
    }
}

So, I tried finding a solution to this problem but I could not find one so I came to stack overflow. Anyway, my Console Application is supposed to Inject the EasyExploits.DLL and Execute a Lua script when a script is pasted into the input. However, I am getting and error saying, "An object reference is required for the non-static field, method, or property 'Module.LaunchExploit()'" and "An object reference is required for the non-static field, method, or property 'Module.ExecuteScript(string)'" I am a beginner to c# and do not really understand this error so if someone could walk me through it with easy steps that are beginner friendly that would be great.


Solution

  • Your Main method is static and you can access only static members of the same class from a static method. All you need to do to make your EasyExploits.Module static as well:

    private static readonly EasyExploits.Module module = new EasyExploits.Module();