A simple memory patch

Source: Internet
Author: User

Memory patch Example 1: Use a memory patch for test.exe

. 386
. Model flat, stdcall
Option Casemap: None

Include windows. inc
Include user32.inc
Include kernel32.inc
Includelib user32.lib
Includelib kernel32.lib

Patch_position equ 00401004 h; linear address of patch position
Patch_bytes equ 2; patch memory bytes

. Data?
Dboldbytes dB patch_bytes DUP (?) ; Read buffer
Ststartup startupinfo <?>
Stprocinfo process_information <?>

. Const
Dbpatch dB 74 h, 15 h; original content
Dbpatched dB 90 h, 90 h; patch content
Szexecfilename dB 'test.exe ', 0; file name
The execution file cannot be loaded in szerrexec db! ', 0
The version of the szerrversion db' execution file is incorrect and cannot be corrected! ', 0

. Code
Start:
; Create a process
Invoke getstartupinfo, ADDR ststartup
Invoke CreateProcess, offset szexecfilename, null ,/
Normal_priority_class or create_suincluded, null, null ,/
Offset ststartup, offset stprocinfo; pause the process when it is created, rewrite it, and run it again
. If eax; read the process memory and verify that the content is correct
Invoke readprocessmemory, stprocinfo. hprocess, patch_position,/; read
ADDR dboldbytes, patch_bytes, null
. If eax
MoV ax, word PTR dboldbytes
. If AX = word PTR dbpatch; Verification
Invoke writeprocessmemory, stprocinfo. hprocess,/; write
Patch_position, ADDR dbpatched, patch_bytes, null
Invoke resumethread, stprocinfo. hthread;
. Else
Invoke terminateprocess, stprocinfo. hprocess,-1
Invoke MessageBox, null, ADDR szerrversion, null, mb_ OK or mb_iconstop
. Endif
. Endif
Invoke closehandle, stprocinfo. hprocess
Invoke closehandle, stprocinfo. hthread
. Else
Invoke MessageBox, null, ADDR szerrexec, null, mb_ OK or mb_iconstop
. Endif

Invoke exitprocess, null
End start

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.