尝试返回时访问冲突

时间:2018-02-24 22:26:27

标签: c#

我有一个返回长值的问题,当我点击一个按钮我想让它返回长值时,相反它会抛出这个异常。

  

System.AccessViolationException:'尝试读取或写入受保护的   记忆。这通常表明其他内存已损坏。'

我正在尝试获取模块的基地址,因为它在消息框中输出正确的值。

以下是获取基地址的代码。

     public long GetbMod(long bModaddress)
    {
        MessageBox.Show("Got the trash value " + bModaddress);
        long ohno = 0x000001;

        foreach (Process proc in Process.GetProcessesByName("Target Process"))
        {

            foreach (ProcessModule module in proc.Modules)
            {

                if (module.ModuleName == "target.dll")
                {
                    MessageBox.Show("Found module!");
                    bModaddress = (long)module.BaseAddress;
                    MessageBox.Show("Proof = " + bModaddress); // Output address
                    return bModaddress; //Return address
                }
            }


        }
        MessageBox.Show("Was unable to find process, making errors now.");
        return ohno;
    }

我尝试在点击按钮时检索该值,代码如下。

        private void buttonAB_Click(object sender, EventArgs e)
    {
        long trashaddress = 0x000001;
        long bModaddress02 = GetbMod(trashaddress); // This is where I get the error
        //use address for stuff

    }

0 个答案:

没有答案