Visual Studio线程语句给出错误?

问题描述 投票:-3回答:1

我反编译.NET应用程序来编写自己的注入软件。线程错误不希望被删除。我尝试了一切,但它一直告诉我有些事情是错的......

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# multithreading lua code-injection
1个回答
0
投票

我认为你得到The call is ambiguous between the following methods or properties: 'Thread.Thread(ThreadStart)' and 'Thread.Thread(ParameterizedThreadStart)'错误。

正如您所正确指出的那样,编译器无法区分Thread构造函数参数的类型。如果在调用ParameterizedThreadStart方法时将参数传递给代理,则使用Thread.Start。您的代码不会这样做。因此,你需要一个ThreadStart代表。它的语法是

public delegate void ThreadStart();

即它不接受任何参数,也不返回值。所以,你可以通过一个同样的lambda function

new Thread(() => {
    // ...
}).Start();
© www.soinside.com 2019 - 2024. All rights reserved.