3
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.

WripWrath
  • 51
  • 1
  • 1
  • 7
  • 1
    Does this answer your question? [CS0120: An object reference is required for the nonstatic field, method, or property 'foo'](https://stackoverflow.com/questions/498400/cs0120-an-object-reference-is-required-for-the-nonstatic-field-method-or-prop) – Johnathan Barclay May 28 '20 at 07:27
  • EasyExploits.Module module = new EasyExploits.Module(); needs to be in the Main() method. – Kishan Vaishnav May 28 '20 at 07:44

2 Answers2

4

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();
Peter Csala
  • 17,736
  • 16
  • 35
  • 75
2

There are 2 issues here

  1. Module is a class, but LaunchExploit() is not static, that is, it needs to run from an object. You probably meant to use the object module
  2. module should be static as well, if you want to use it inside a static function main

I would also mention a less pressing issue: goto are rarely a good idea. Your code can become nicer if you:

  1. Create a static function begin, and wherever you have go to Begin do:
begin()
return;
  1. Create a static function label, do the same for it

This will make your code much more readable and debuggable.

Shahar Bental
  • 991
  • 6
  • 16