首页 > 解决方案 > Visual Studio Thread Statement gives Error?

问题描述

I decompiled a .NET Application to write my own Injection Software. A Thread Error don't want to get removed. I tried everything but it keeps telling me that something is wrong...

Code (Screenshot)

{
    using System;
    using System.IO;
    using System.IO.Pipes;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Threading;
    using System.Windows.Forms;

    internal class NamedPipes
    {
        public static string luapipename = "IDUNNOPIPE123";

        public static void LuaPipe(string script)
        {
            if (NamedPipeExist(luapipename))
            {
                new Thread (delegate {
                    try
                    {
                        using (NamedPipeClientStream stream = new NamedPipeClientStream(".", luapipename, PipeDirection.Out))
                        {
                            stream.Connect();
                            using (StreamWriter writer = new StreamWriter(stream, Encoding.Default, 0xf423f))
                            {
                                writer.Write(script);
                                writer.Dispose();
                            }
                            stream.Dispose();
                        }
                    }
                    catch (IOException)
                    {
                        MessageBox.Show("Error occured connecting to the pipe.", "Connection Failed!", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    catch (Exception exception1)
                    {
                        MessageBox.Show(exception1.Message.ToString());
                    }
                }).Start();
            }
            else
            {
                MessageBox.Show("Please Inject " + Functions.exploitdllname + " before Using this!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        public static bool NamedPipeExist(string pipeName)
        {
            bool flag;
            try
            {
                int timeout = 0;
                if (!WaitNamedPipe(Path.GetFullPath($"\\\\.\\pipe\\{pipeName}"), timeout))
                {
                    bool flag4;
                    int num2 = Marshal.GetLastWin32Error();
                    if (num2 != 0)
                    {
                        if (num2 != 2)
                        {
                            goto TR_0005;
                        }
                        else
                        {
                            flag4 = false;
                        }
                    }
                    else
                    {
                        flag4 = false;
                    }
                    return flag4;
                }
            TR_0005:
                flag = true;
            }
            catch (Exception)
            {
                flag = false;
            }
            return flag;
        }

        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
        private static extern bool WaitNamedPipe(string name, int timeout);
    }
}

标签: c#multithreadingluacode-injection

解决方案


I think you are getting the The call is ambiguous between the following methods or properties: 'Thread.Thread(ThreadStart)' and 'Thread.Thread(ParameterizedThreadStart)' error with this.

As you correctly noted, the compiler can't distinguish what type the Thread constructor parameter is. ParameterizedThreadStart is used if you pass a parameter to your delegate when calling the Thread.Start method. Your code does not do this. Thus, you need a ThreadStart delegate here. Its syntax is

public delegate void ThreadStart();

I.e. it does not accept any parameter and does not return a value. So, you can just pass a lambda function that does the same.

new Thread(() => {
    // ...
}).Start();

推荐阅读