Using Windows API functions to modify memory data in C #

Source: Internet
Author: User

This problem comes from the water "Huaquan robot", for the purpose of this article interested friends please roughly read the thread, in the post I used this method to write scissors fifth, the record is good, of course, the method of cheating.

Scissors fifth train of thought is every time out fist, try to let the other party to win, and then according to an address section to scan the memory of each other won the number of the save address, find the game results when the memory data to get rid of. This is similar to the previous use of a stand-alone game fpe, such as the modification tool. Of course, if the other party deliberately fouls, not a game to win, you can not find his address, so that the normal way to obtain victory.

After simplifying the scissors fifth core code, the main three API functions

Openprocess,readprocessmemory,writeprocessmemory

The code is roughly as follows:

Using System;
Using System.Collections.Generic;
Using System.Text;
Using System.Runtime.InteropServices;
Namespace ConsoleApplication4
... {
Open unsafe code switch: item-Right-properties-build-Allow unsafe code
Class Program
... {
[DllImport ("kernel32.dll")]
public static extern
IntPtr openprocess (UInt32 dwdesiredaccess, Int32 binherithandle, UInt32 dwprocessid);
[DllImport ("kernel32.dll")]
public static extern
Int32 writeprocessmemory (IntPtr hprocess, IntPtr lpbaseaddress, uint[] lpbuffer, UInt32 nsize, INTPTR Lpnumberofbyteswritten);
[DllImport ("kernel32.dll")]
public static extern
Int32 readprocessmemory (IntPtr hprocess, IntPtr lpbaseaddress, uint[] lpbuffer, UInt32 nsize, IntPtr-Lpnumberofbytesread );
static IntPtr paddress = (IntPtr) 0x12bdad8;
Static uint[] Read = new Uint[1];
Static uint[] Write = new uint[] ... {0x64};
static private int mm = 999;

static void Main (string[] args)
... {
Unsafe ... {fixed (int* i = &mm) ... {paddress = (IntPtr) i;} }
IntPtr h = openprocess (0x1f0fff, 0, (UInt32) System.Diagnostics.Process.GetCurrentProcess (). ID);
ReadProcessMemory (H, Paddress, Read, 4, (INTPTR) 0);//Get Memory data
Console.WriteLine (read[0]);//Output 999
WriteProcessMemory (H, Paddress, Write, 4, (INTPTR) 0);//Modify memory data
Console.WriteLine (mm);//Output 100
Console.read ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.