"Original" C # Super Game Plug-in Help class, encapsulated a lot of methods, including multi-level pointer data reading and writing methods.

Source: Internet
Author: User

The code is as follows:

Using system;using system.diagnostics;using system.runtime.interopservices;using system.windows.forms;//qq 844125365 Green Pepper Technology Memory Help Class C # thousand people QQ Group: 137 696 483 Welcome to join Daniel!        Namespace Master {class Processmemoryreaderapi {public const UINT Process_vm_read = (0x0010);        Public const UINT Process_vm_write = (0x0020);        Public const UINT Process_vm_operation = (0x0008);        Public const UINT PAGE_READWRITE = 0x0004;        public const int wm_syscommand = 0x0112;        public const int wm_activate = 0x6;        public const int wm_hotkey = 0x0312; [DllImport ("user32.dll", CharSet = CharSet.Auto, callingconvention = callingconvention.stdcall)] public static Exte        RN void Mouse_event (long dwFlags, long dx, long dy, long cbuttons, long dwextrainfo); [DllImport ("kernel32.dll")] public static extern IntPtr OpenProcess (UInt32 dwdesiredaccess, Int32 binherithandle, U        Int32 dwprocessid); [DllImport ("kernel32.dll")] public static extern Int32 ClosehandLe (IntPtr hobject); [DllImport ("kernel32.dll")] public static extern Int32 ReadProcessMemory (IntPtr hprocess, IntPtr lpbaseaddress, [in        , out] byte[] buffer, UInt32 size, out IntPtr lpnumberofbytesread); [DllImport ("kernel32.dll")] public static extern Int32 WriteProcessMemory (IntPtr hprocess, IntPtr lpbaseaddress, [I        N, out] byte[] buffer, UInt32 size, out IntPtr lpnumberofbyteswritten); [DllImport ("kernel32", SetLastError = true)] public static extern IntPtr VirtualAllocEx (IntPtr hprocess, IntPtr LpA        Ddress, UInt32 dwsize, uint flallocationtype, uint flprotect);  [DllImport ("kernel32.dll", SetLastError = true)] public static extern bool Virtualprotectex (IntPtr hprocess, IntPtr        Lpaddress, UInt32 dwsize, uint flnewprotect, out uint lpfloldprotect);        [DllImport ("user32.dll", SetLastError = true)] public static extern bool Unregisterhotkey (INTPTR hWnd, int id); [DllImport ("User32.dll")] public static extern inT getkeystate (int vkey); } public class Processmemoryreader {public Processmemoryreader () {} public Process Rea            dprocess {get {return m_readprocess;            } set {m_readprocess = value;        }} private Process m_readprocess = null;        Private IntPtr m_hprocess = IntPtr.Zero; public void OpenProcess () {m_hprocess = Processmemoryreaderapi.openprocess (processmemoryreaderapi.proce Ss_vm_read | Processmemoryreaderapi.process_vm_write |        Processmemoryreaderapi.process_vm_operation, 1, (UINT) m_readprocess.id);            } public void CloseHandle () {int iretvalue;            Iretvalue = Processmemoryreaderapi.closehandle (m_hprocess);        if (Iretvalue = = 0) throw new Exception ("CloseHandle failed"); } #region readmem public int readmem (int memoryaddress, UINT Bytestoread, out byte[] buffer) {IntPtr Prochandle = processmemoryreaderapi.openprocess (processmemor Yreaderapi.process_vm_read | Processmemoryreaderapi.process_vm_write |            Processmemoryreaderapi.process_vm_operation, 1, (UINT) m_readprocess.id);                if (Prochandle = = IntPtr.Zero) {buffer = new byte[0];            return 0;            } buffer = new Byte[bytestoread];            IntPtr ptrbytesreaded; Processmemoryreaderapi.readprocessmemory (Prochandle, (INTPTR) memoryaddress, buffer, Bytestoread, out ptrbytesreaded            );            Processmemoryreaderapi.closehandle (Prochandle);        return Ptrbytesreaded.toint32 (); }//we use the to public int readmultilevelpointer (int memoryaddress, uint bytestoread, int32[] Offsetlist ) {IntPtr Prochandle = processmemoryreaderapi.openprocess (Processmemoryreaderapi.process_vm_read | Processmemoryreaderapi.process_vm_write | ProcesSmemoryreaderapi.process_vm_operation, 1, (UINT) m_readprocess.id);            IntPtr pointer = (INTPTR) 0x0; If the PROCESS isnt available we return nothing if (Prochandle = = IntPtr.Zero) {RE            Turn 0;            } byte[] Btbuffer = new Byte[bytestoread];            IntPtr lpoutstorage = IntPtr.Zero;            int pointeraddy = memoryaddress;            int pointertemp = 0;                    for (int i = 0; i < (offsetlist.length); i++) {if (i = = 0) { Processmemoryreaderapi.readprocessmemory (Prochandle, (INTPTR) (Pointeradd Y), Btbuffer, (UINT) btbuffer.length, out Lpoutstorage                );                } Pointeraddy = (Bitconverter.toint32 (btbuffer, 0) + offsetlist[i]);                String pointeraddyhex = pointeraddy.tostring ("X");Processmemoryreaderapi.readprocessmemory (Prochandle, (INTPTR) (Pointeraddy),            Btbuffer, (UINT) btbuffer.length, out lpoutstorage);        } return Pointeraddy;            } public byte readbyte (int memoryaddress) {byte[] buffer;            int read = Readmem (memoryaddress, 1, out buffer);            if (read = = 0) return new byte ();        else return buffer[0];            } public int ReadInt (int memoryaddress) {byte[] buffer;            int read = Readmem (memoryaddress, 4, out buffer);            if (read = = 0) return 0;        else return bitconverter.toint32 (buffer, 0);            } public UINT Readuint (int memoryaddress) {byte[] buffer;            int read = Readmem (memoryaddress, 4, out buffer);             if (read = = 0)   return 0;        else return bitconverter.touint32 (buffer, 0);            } public float readfloat (int memoryaddress) {byte[] buffer;            int read = Readmem (memoryaddress, 4, out buffer);            if (read = = 0) return 0;        else return bitconverter.tosingle (buffer, 0); } public byte[] Readamem (IntPtr memoryaddress, uint bytestoread, out int bytesreaded) {byte[] bu            Ffer = new Byte[bytestoread];            IntPtr ptrbytesreaded;            Processmemoryreaderapi.readprocessmemory (m_hprocess, memoryaddress, buffer, Bytestoread, out ptrbytesreaded);            bytesreaded = Ptrbytesreaded.toint32 ();        return buffer; } internal byte[] readamem (int p, int p_2, out int bytesreadsize) {throw new Notimplementedexcep        tion (); } #endregion #region writemem public int writemem (int memoryaddress, byte[] buf) {IntPtr prochandle = processmemoryreaderapi.openprocess (Processmemoryreaderapi.process_vm_read | Processmemoryreaderapi.process_vm_write |            Processmemoryreaderapi.process_vm_operation, 1, (UINT) m_readprocess.id);            if (Prochandle = = IntPtr.Zero) return 0;            UINT Oldprotect; Processmemoryreaderapi.virtualprotectex (Prochandle, (INTPTR) memoryaddress, (UINT) buf.            Length, Processmemoryreaderapi.page_readwrite, out oldprotect);            IntPtr Ptrbyteswritten; Processmemoryreaderapi.writeprocessmemory (Prochandle, (INTPTR) memoryaddress, buf, (UINT) buf.            Length, out Ptrbyteswritten);            Processmemoryreaderapi.closehandle (Prochandle);        return Ptrbyteswritten.toint32 ();        } public void WriteByte (int memoryaddress, byte b) {Writemem (memoryaddress, new byte[] {b}); } public void Writeint (int memoryaddress, int w) {byte[] buf = BitconverteR.getbytes (w);        Writemem (memoryaddress, buf);            } public void Writeuint (int memoryaddress, uint u) {byte[] buf = bitconverter.getbytes (u);        Writemem (memoryaddress, buf);            } public void Writefloat (int memoryaddress, float f) {byte[] buf = Bitconverter.getbytes (f);        Writemem (memoryaddress, buf);            } public void writedouble (int memoryaddress, double d) {byte[] buf = bitconverter.getbytes (d);        Writemem (memoryaddress, buf);            } public void Writeamem (IntPtr memoryaddress, byte[] bytestowrite, out int byteswritten) {            IntPtr Ptrbyteswritten; Processmemoryreaderapi.writeprocessmemory (m_hprocess, Memoryaddress, Bytestowrite, (UINT) bytesToWrite.Length, out            Ptrbyteswritten);        Byteswritten = Ptrbyteswritten.toint32 (); } #endregion #region Keys [DllImport ("User32.dll")] PubliC static extern short getkeystate (Keys nvirtkey); public enum Virtualkeystates:int {Vk_lbutton = 0x01, Vk_rbutton = 0x02, Vk_canc            EL = 0x03, Vk_mbutton = 0x04,//Vk_xbutton1 = 0x05, Vk_xbutton2 = 0x06, Vk_back = 0x08, Vk_tab = 0x09,//Vk_clear = 0x0C, Vk_retu RN = 0x0D,//Vk_shift = 0x10, Vk_control = 0x11, Vk_menu = 0x12, V K_pause = 0x13, vk_capital = 0x14,//Vk_kana = 0x15, Vk_hangeul = 0x15,/* o  LD Name-should is here for compatibility */Vk_hangul = 0x15, Vk_junja = 0x17, vk_final            = 0x18, Vk_hanja = 0x19, Vk_kanji = 0x19,//Vk_escape = 0x1B,// Vk_convert = 0x1C, Vk_nonconvert = 0x1D, vk_accept = 0x1E, Vk_modechange = 0x1F,//Vk_space = 0x20, Vk_prior = 0x21, Vk_ne            XT = 0x22, Vk_end = 0x23, Vk_home = 0x24, Vk_left = 0x25, vk_up = 0x26, Vk_right = 0x27, Vk_down = 0x28, Vk_select = 0x29, Vk_print = 0x2A, vk_ex Ecute = 0x2B, Vk_snapshot = 0x2C, Vk_insert = 0x2D, Vk_delete = 0x2e, vk_help            = 0x2F,//Vk_lwin = 0x5b, Vk_rwin = 0x5C, Vk_apps = 0x5d,// Vk_sleep = 0x5f,//vk_numpad0 = 0x60, Vk_numpad1 = 0x61, vk_numpad2 = 0 x62, vk_numpad3 = 0x63, vk_numpad4 = 0x64, Vk_numpad5 = 0x65, Vk_numpad6 = 0x6 6, Vk_numpad7 = 0x67, Vk_numpad8 = 0x68, vk_numpad9 = 0x69, vk_multiply = 0x6A , Vk_add = 0x6B, Vk_separator = 0x6c, vk_subtract = 0x6d, Vk_decimal = 0x6e, vk_divide = 0x  6F, vk_f1 = 0x70, Vk_f2 = 0x71, vk_f3 = 0x72, Vk_f4 = 0x73, Vk_f5 = 0x74, Vk_f6 = 0x75, Vk_f7 = 0x76, Vk_f8 = 0x77, vk_f9 = 0x78, Vk_f            Ten = 0x79, vk_f11 = 0x7A, vk_f12 = 0x7B, vk_f13 = 0x7C, Vk_f14 = 0x7d,             Vk_f15 = 0x7E, Vk_f16 = 0x7F, vk_f17 = 0x80, vk_f18 = 0x81, vk_f19 = 0x82,  Vk_f20 = 0x83, Vk_f21 = 0x84, vk_f22 = 0x85, vk_f23 = 0x86, Vk_f24 = 0x87,//Vk_numlock = 0x90, Vk_scroll = 0x91,//Vk_oem_nec_equa L = 0x92,//' = ' key on Numpad//Vk_oem_fj_jisho = 0x92,//' Dictionary ' key vk_oem_ Fj_masshou = 0x93,//' Unregister word ' key Vk_oem_fj_touroku = 0x94,//' Register word ' key Vk_oem_fj_loya = 0x95,//            ' Left Oyayubi ' key Vk_oem_fj_roya = 0x96,//' right Oyayubi ' key//Vk_lshift = 0xA0,            Vk_rshift = 0xa1, Vk_lcontrol = 0xa2, Vk_rcontrol = 0xa3, Vk_lmenu = 0xa4,            Vk_rmenu = 0xa5,//Vk_browser_back = 0xa6, Vk_browser_forward = 0xa7, Vk_browser_refresh = 0xa8, Vk_browser_stop = 0xa9, Vk_browser_search = 0xAA, Vk_browser_ FAVORITES = 0xAB, Vk_browser_home = 0xAC,//Vk_volume_mute = 0xAD, vk_volume_             Down = 0xAE, vk_volume_up = 0xAF, Vk_media_next_track = 0xb0, Vk_media_prev_track = 0xb1, Vk_media_stop = 0xb2, Vk_media_play_pause = 0xb3, Vk_launch_mail = 0xb4, vk_l Aunch_media_select = 0xB5, Vk_launch_app1 = 0xb6, vk_launch_app2 = 0xb7,//vk_oem_1 = 0xBA,//';: '            For US Vk_oem_plus = 0xBB,//' + ' any country Vk_oem_comma = 0xBC,//', ' any country Vk_oem_minus = 0xBD,//'-' any country vk_oem_period = 0xBE,//'. ' Any country vk_oem_2 = 0x BF,//'/? ' for us vk_oem_3 = 0xC0,//"~ ' for us//Vk_oem_4 = 0xDB,//' [{' for  US vk_oem_5 = 0xDC,//' \| ' for us vk_oem_6 = 0xDD,//'} ' for us vk_oem_7 = 0xDE,            ' "' for US vk_oem_8 = 0xDF,//Vk_oem_ax = 0xe1,//' ax ' key on Japanese ax KBD            vk_oem_102 = 0xe2,//"<>" or "\|" on RT 102-key kbd. Vk_ico_help = 0xe3,//Help key on ico vk_ico_00 = 0xE4,////-Key on ICO//Vk_proce     Sskey = 0xe5,//vk_ico_clear = 0xe6,       Vk_packet = 0xE7,//Vk_oem_reset = 0xe9, Vk_oem_jump = 0xEA,            VK_OEM_PA1 = 0xEB, VK_OEM_PA2 = 0xEC, vk_oem_pa3 = 0xED, Vk_oem_wsctrl = 0xEE,            Vk_oem_cusel = 0xEF, Vk_oem_attn = 0xF0, Vk_oem_finish = 0xF1, vk_oem_copy = 0xF2, Vk_oem_auto = 0xf3, VK_OEM_ENLW = 0xf4, Vk_oem_backtab = 0xf5,//V K_ATTN = 0xf6, Vk_crsel = 0xf7, Vk_exsel = 0xF8, vk_ereof = 0xf9, Vk_play = 0x        FA, Vk_zoom = 0xFB, Vk_noname = 0xFC, vk_pa1 = 0xFD, vk_oem_clear = 0xFE            } public bool Keystate (Keys key) {int state = Getkeystate (key);            if (state = = -127 | | state = = -128) {return true;        } return false; } #endregion}}

  

"Original" C # Super Game Plug-in Help class, encapsulated a lot of methods, including multi-level pointer data reading and writing methods.

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.