C # use Windows API functions to modify memory data

Source: Internet
Author: User

This problem comes from the yundun robot with water.
If you are interested in the purpose of this article, please read the post with water roughly. In this post, I used this method to write scissors No. 5
The record is good. Of course it is a cheating method.

The idea of scissors No. 5 is to try to win each other and scan the saved address of the game wins in the memory based on an address segment, after finding this information, you can get rid of the memory data when you get the game results. This is similar to the modification tool FPE used in previous standalone games. Of course, if the other party intentionally fouls and won't win in a single game, you won't be able to find his address, so that you can win through the normal channel.

After the core code of scissors 5 is simplified, it mainly serves 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
Leleapplication4

...
{


//
Enable Unsafe code: Right-click a project and choose Properties> Generate to allow Insecure 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
);
//
Obtain memory data


Console. writeline (read [
0
]);
//
999 output


Writeprocessmemory (H, paddress, write,
4
, (Intptr)
0
);
//
Modify memory data


Console. writeline (mm );
//
100 output


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.