【问题标题】:Visual Studio Thread Statement gives Error?Visual Studio 线程语句给出错误?
【发布时间】:2019-07-26 02:53:59
【问题描述】:

我反编译了一个 .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);
    }
}

【问题讨论】:

  • 它告诉你什么是错的——如果我们不知道问题就帮不上忙
  • 这不可能是“完整代码”,因为没有代码以{ 开头,其余的在哪里?
  • 将鼠标悬停在错误上,它说什么?
  • 我将鼠标悬停在它上面。这是结果(对不起它的德语):prntscr.com/mt6686
  • @Hogan 没有休息。命名空间定义仅一行(命名空间注入工具)

标签: c# multithreading lua code-injection


【解决方案1】:

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

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

public delegate void ThreadStart();

即它不接受任何参数,也不返回值。所以,你可以传递一个 lambda function 来做同样的事情。

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

【讨论】:

  • 我修复了所有问题,我的程序几乎可以运行了。但是现在我遇到了另一个问题:资源标识符“标识符”已在此程序集中使用。如果我尝试构建项目,我会收到 2 次此错误。你知道有什么解决办法吗?
  • 好的。解决了一切。无论如何,非常感谢:)!
猜你喜欢
  • 2022-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-01
  • 2020-05-11
  • 2015-01-04
相关资源
最近更新 更多