操纵程序存储器。 (记忆黑客)

时间:2012-04-21 06:05:51

标签: c# memory

好吧,我最近在C#中创建了一个改变程序内存的程序,它会起作用,但是每次关闭程序并重新打开程序时,我都要再次找到内存值,是否有我可以阻止程序的内存在关闭后改变吗?

public partial class Form1 : Form
{

    public Form1()
    {
        InitializeComponent();
    }

    [DllImport("kernel32.dll")]
    static extern IntPtr OpenProcess(ProcessAccessFlags dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, int dwProcessId);

    [DllImport("kernel32.dll", SetLastError = true)]
    static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, out int lpNumberOfBytesWritten);

    [DllImport("kernel32.dll")]
    public static extern Int32 CloseHandle(IntPtr hProcess);

    [Flags]
    public enum ProcessAccessFlags : uint
    {
        All = 0x001F0FFF,
        Terminate = 0x00000001,
        CreateThread = 0x00000002,
        VMOperation = 0x00000008,
        VMRead = 0x00000010,
        VMWrite = 0x00000020,
        DupHandle = 0x00000040,
        SetInformation = 0x00000200,
        QueryInformation = 0x00000400,
        Synchronize = 0x00100000
    }

    public static void WriteMem(Process p, int address, long v)
    {
        var hProc = OpenProcess(ProcessAccessFlags.All, false, (int)p.Id);
        var val = new byte[] { (byte)v };

        int wtf = 0;
        WriteProcessMemory(hProc, new IntPtr(address), val, (UInt32)val.LongLength, out wtf);

        CloseHandle(hProc);
    }

    private void notify(string not)
    {
        if (textBox1.Text != "")
        {
            textBox1.Text += Environment.NewLine;
        }

        textBox1.Text += not;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        var p = Process.GetProcessesByName("SAFlashPlayer").FirstOrDefault();
        WriteMem(p, 0x07A6A0C1, 1000);
        notify("A lot of Ability Points added.");
    }
    private void button2_Click(object sender, EventArgs e)
    {
        var p = Process.GetProcessesByName("SAFlashPlayer").FirstOrDefault();
        //WriteMem(p, 0x008373CC, 0);
        notify("Power set to 0.");
    }

    private void Checker_Tick(object sender, EventArgs e)
    {
        Process[] pname = Process.GetProcessesByName("SAFlashPlayer");

        if (pname.Length == 0)
        {
            button1.Enabled = false;
            button2.Enabled = false;
            status.ForeColor = System.Drawing.Color.Red;
            status.Text = "Flash Player not running!";
        }
        else
        {
            button1.Enabled = true;
            button2.Enabled = true;
            status.ForeColor = System.Drawing.Color.Green;
            status.Text = "Flash Player running!";
        }
    }
}

2 个答案:

答案 0 :(得分:3)

您无法估算或决定程序在运行时的加载位置。操作系统决定,但我认为你可以在运行时动态地找到进程的内存位置,而无需对应用程序进行硬编码。

您是否尝试过ReadProcessMemory WinAPI call

答案 1 :(得分:1)

是的,作弊很难 - 付钱的黄金农民更容易。在每次程序重启后,您很可能需要扫描其他进程以查找要更新的值/模式,因为内存布局很有可能更改,特别是在Win7上。

在旧时代,人们只会更新可执行文件......阅读印刷杂志上的一些文章......

现在所有的JIT,ASLR,压缩/编码的执行程序和脚本甚至远程加载的模块/ SWF都要困难得多。所以责怪互联网需要在作弊时花更多的精力。