冰楓論壇

 找回密碼
 立即註冊
搜索
查看: 2754|回覆: 1
打印 上一主題 下一主題

[分享] [VB.NET] MapleFunction 一個方便 VB.NET 使用的楓之谷模組

[複製鏈接]

468

主題

0

好友

522

積分

高級會員

Rank: 4

UID
70473
帖子
471
主題
468
精華
0
積分
522
楓幣
738
威望
521
存款
0
贊助金額
0
推廣
0
GP
43
閱讀權限
50
性別
保密
在線時間
28 小時
註冊時間
2014-7-14
最後登入
2015-5-16
跳轉到指定樓層
1
發表於 2014-7-14 09:43:29 |只看該作者 |倒序瀏覽
MapleFunction.vb
  1. Module MapleFunction
  2.     '----------------------------------系統API宣告-----------------------------------'
  3.     Private Declare Function OpenProcess Lib "kernel32" (ByVal Access As Integer, ByVal Handle As Boolean, ByVal ProcessId As Integer) As IntPtr
  4.     Private Declare Function WriteProcessMemory Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As Integer, ByVal lpBuffer() As Byte, ByVal nSize As Integer, ByVal lpNumberOfBytesWritten As Integer) As Integer
  5.     Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByVal lpNumberOfBytesWritten As Integer) As Integer
  6.     '----------------------------------啟用所有CheckBox-----------------------------------'
  7.     Public Sub AllCrackMemoryFunctionCheckBoxEnable(ByVal ParentControls As System.windows.Forms.Control.ControlCollection)
  8.         For Each i As Control In ParentControls
  9.             If i.Name.Contains("CheckBox") Then i.Enabled = True
  10.         Next
  11.     End Sub
  12.     Structure MapleStoryProcess
  13.         Shared WriteMapleStoryIntptr As IntPtr = IntPtr.Zero
  14.         Shared MProcess As Process = Nothing
  15.         'Public ID As Integer = Nothing '如VB2008編譯上出錯,請把這行的註解拿掉.
  16.         '----------------------------------自定義指標格式-----------------------------------'
  17.         Structure Pointer
  18.             Public Address As Integer
  19.             Public Offset
  20.         End Structure
  21.         '----------------------------------讀取楓之谷遊戲-----------------------------------'
  22.         Public Function LoadMemory() As Boolean
  23.             Try
  24.                 Dim MapleStoryProcess As Process = Process.GetProcessesByName("MapleStory")(0)
  25.                 If MapleStoryProcess.MainWindowHandle.Equals(IntPtr.Zero) = False Then
  26.                     WriteMapleStoryIntptr = OpenProcess(&H1F0FFF, False, MapleStoryProcess.Id)
  27.                     MProcess = MapleStoryProcess
  28.                     Return True
  29.                 End If
  30.                 Return False
  31.             Catch ex As Exception
  32.                 Return False
  33.             End Try
  34.         End Function
  35.         '--------------------------------讀取楓之谷遊戲(可指定Handle)------------------------'
  36.         Public Function LoadMemory(ByVal Handle As IntPtr) As Boolean
  37.             Try
  38.                 Dim AllProcessInHandle As Process() = Process.GetProcesses
  39.                 For Each P As Process In AllProcessInHandle
  40.                     If P.MainWindowHandle = Handle Then
  41.                         WriteMapleStoryIntptr = OpenProcess(&H1F0FFF, False, P.Id)
  42.                         MProcess = P
  43.                         Return True
  44.                     End If
  45.                 Next
  46.                 Return False
  47.             Catch ex As Exception
  48.                 Return False
  49.             End Try
  50.         End Function
  51.         Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
  52.         Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Integer, ByRef lpdwProcessId As Integer) As Integer
  53.         '--------------------------------讀取楓之谷遊戲(指定視窗)------------------------'
  54.         Public Function OpenProcessByWindow(ByVal lpWindowName As String, Optional ByVal lpClassName As String = vbNullString) As Boolean
  55.             Try
  56.                 Dim Pid As Integer
  57.                 GetWindowThreadProcessId(FindWindow(lpClassName, lpWindowName), Pid)
  58.                 Dim MapleStoryProcess As Process = Process.GetProcessById(Pid)
  59.                 If MapleStoryProcess.MainWindowHandle.Equals(IntPtr.Zero) = False Then
  60.                     WriteMapleStoryIntptr = OpenProcess(&H1F0FFF, False, MapleStoryProcess.Id)
  61.                     MProcess = MapleStoryProcess
  62.                     Return True
  63.                 End If
  64.                 Return False
  65.             Catch ex As Exception
  66.                 Return False
  67.             End Try

  68.         End Function
  69.         '----------------------------------寫入遊戲記憶體-----------------------------------'
  70.         Public Function WriteByte(ByVal Address As Integer, ByVal ArrayOfByte As Byte())
  71.             On Error Resume Next
  72.             If WriteMapleStoryIntptr.Equals(IntPtr.Zero) Then
  73.                 MsgBox("Application Can't Catch MapleStory Process.", MsgBoxStyle.Critical, "Error")
  74.                 Return False
  75.             End If
  76.             WriteProcessMemory(WriteMapleStoryIntptr, Address, ArrayOfByte, ArrayOfByte.Length, False)
  77.             Return True
  78.         End Function
  79.         Private Declare Function WriteProcessMemoryAPI Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByVal lpNumberOfBytesWritten As Integer) As Integer
  80.         Public Function WriteLong(ByVal lpAddress As Integer, ByVal lpValue As Integer) As Integer
  81.             Try
  82.                 Return WriteProcessMemoryAPI(WriteMapleStoryIntptr, lpAddress, lpValue, Len(lpValue), False)
  83.             Catch ex As Exception
  84.                 Return 0
  85.             End Try
  86.         End Function

  87.         Public Function MakeJmp(ByVal lpAddress As Long, ByVal lpJmpAddress As Long, Optional ByVal lpNops As Long = 0) As Long
  88.             Dim JmpByte As Byte() = {&HE9}
  89.             MakeJmp = CBool(WriteByte(lpAddress, JmpByte)) And CBool(WriteLong(lpAddress + 1, lpJmpAddress - lpAddress - 5))
  90.             If lpNops = 0 Then Exit Function
  91.             Return MakeJmp
  92.         End Function

  93.         Public Function MakeCall(ByVal lpAddress As Long, ByVal lpCallAddress As Long, Optional ByVal lpNops As Long = 0) As Long
  94.             Dim CallByte As Byte() = {&HE8}
  95.             MakeCall = CBool(WriteByte(lpAddress, CallByte)) And CBool(WriteLong(lpAddress + 1, lpCallAddress - lpAddress - 5))
  96.             If lpNops = 0 Then Exit Function
  97.             Return MakeCall
  98.         End Function
  99.         '----------------------------------讀取地址的Value-----------------------------------'
  100.         Public Function GetValue(ByVal Address As Integer) As Integer
  101.             On Error Resume Next
  102.             If WriteMapleStoryIntptr.Equals(IntPtr.Zero) Then
  103.                 MsgBox("Application Can't Catch MapleStory Process.", MsgBoxStyle.Critical, "Error")
  104.                 Return False
  105.             End If
  106.             Dim GetRetValue As Integer = vbNullString
  107.             ReadProcessMemory(WriteMapleStoryIntptr, Address, GetRetValue, 4, False)
  108.             Return GetRetValue
  109.         End Function

  110.         Public Function ReadLong(ByVal lpAddress As Long) As Long
  111.             Dim Value As Integer = vbNullString
  112.             ReadProcessMemory(WriteMapleStoryIntptr, lpAddress, Value, 4, False)
  113.             Return Value
  114.         End Function

  115.         '----------------------------------讀取指標的Value-----------------------------------'
  116.         Public Function GetPointerValue(ByVal Pointer As MapleStoryProcess.Pointer) As Integer
  117.             On Error Resume Next
  118.             If WriteMapleStoryIntptr.Equals(IntPtr.Zero) Then
  119.                 MsgBox("Application Can't Catch MapleStory Process.", MsgBoxStyle.Critical, "Error")
  120.                 Return False
  121.             End If
  122.             Dim GetPointerMain, GetTheTrueValue As Integer
  123.             ReadProcessMemory(WriteMapleStoryIntptr, "&H" + Pointer.Address, GetPointerMain, 4, False)
  124.             ReadProcessMemory(WriteMapleStoryIntptr, GetPointerMain + "&H" + Pointer.Offset, GetTheTrueValue, 4, False)
  125.             Return GetTheTrueValue
  126.         End Function

  127.         Public Function ReadPointer(ByVal lpAddress As Long, ByVal lpOffset As Long) As Long
  128.             Return ReadLong(ReadLong(lpAddress) + lpOffset)
  129.         End Function
  130.         '----------------------------------十進位轉換16進位(Hex)-----------------------------------'
  131.         Public Function IntegerHex(ByVal InPutInt As String) As Integer
  132.             On Error Resume Next
  133.             Return Microsoft.VisualBasic.Hex(InPutInt)
  134.         End Function
  135.         '----------------------------------16進位轉十進位(UnHex)-----------------------------------'
  136.         Public Function IntegerUnHex(ByVal InPutInt As String) As Integer
  137.             On Error Resume Next
  138.             Return CLng("&H" & InPutInt)
  139.             End
  140.         End Function
  141.         '----------------------------------結束遊戲<強制>-------------------------------------------'
  142.         Public Function KillMapleStory() As Boolean
  143.             Try
  144.                 MProcess.Kill()
  145.                 Return True
  146.             Catch ex As Exception
  147.                 Return False
  148.             End Try
  149.         End Function
  150.         '---------------------------------結束遊戲<普通>--------------------------------------------'
  151.         Public Function EndMapleStory() As Boolean
  152.             Try
  153.                 MProcess.CloseMainWindow()
  154.                 Return True
  155.             Catch ex As Exception
  156.                 Return False
  157.             End Try
  158.         End Function
  159.         '-------------------------------確認遊戲是否存在---------------------------------------------'
  160.         Public Function MapleStoryCloseOrNot() As Boolean
  161.             Return MProcess.HasExited
  162.         End Function
  163.         '------------------------------- Auto Key Press ---------------------------------------------'
  164.         Private Declare Auto Function PostMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Boolean
  165.         Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Integer, ByVal wMapType As Integer) As Integer
  166.         Private Declare Function ExitWindowsEx Lib "user32 " (ByVal uFlags As Integer, ByVal dwReserved As Integer) As Integer
  167.         Private Const WM_KEYDOWN As Integer = &H100
  168.         Dim hModuleNoFree As Integer

  169.         Public Function RingPst(ByVal HWnd As Integer, ByVal KeyType As String, ByVal KeyCode As String)
  170.             If KeyCode = "關閉電腦" Then ExitWindowsEx(1, 0)
  171.             Dim myKeyValue As Integer = toKeyValue(KeyCode)
  172.             Select Case KeyType
  173.                 Case "Press"
  174.                     PostMessage(HWnd, &H100, myKeyValue, MakeKeyLparam(myKeyValue, &H100))
  175.                     PostMessage(HWnd, &H101, myKeyValue, MakeKeyLparam(myKeyValue, &H101))
  176.                     Return 1
  177.                 Case "Down"
  178.                     PostMessage(HWnd, &H100, myKeyValue, MakeKeyLparam(myKeyValue, &H100))
  179.                     Return 1
  180.                 Case "Up"
  181.                     PostMessage(HWnd, &H101, myKeyValue, MakeKeyLparam(myKeyValue, &H101))
  182.                     Return 1
  183.                 Case Else
  184.                     Return 0
  185.             End Select
  186.         End Function

  187.         Private Function toKeyValue(ByVal KeyCode As String) As Integer
  188.             Dim strKey() As String = {"None", "Enter", "Shift", "Ctrl", "Alt", "Space", "PageUp", "PageDown", "Insert", "Delete", "Home", "End", "Left", "Up", "Right", "Down", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "ESCAPE"}
  189.             Dim intKey() As Integer = {0, &HD, &H10, &H11, &H12, &H20, &H21, &H22, &H2D, &H2E, &H24, &H23, &H25, &H26, &H27, &H28, &H30, &H31, &H32, &H33, &H34, &H35, &H36, &H37, &H38, &H39, &H41, &H42, &H43, &H44, &H45, &H46, &H47, &H48, &H49, &H4A, &H4B, &H4C, &H4D, &H4E, &H4F, &H50, &H51, &H52, &H53, &H54, &H55, &H56, &H57, &H58, &H59, &H5A, &H70, &H71, &H72, &H73, &H74, &H75, &H76, &H77, &H78, &H79, &H7A, &H7B, &H1B}
  190.             For i = 0 To strKey.Length - 1
  191.                 If strKey(i) = KeyCode Then Return intKey(i)
  192.             Next
  193.             Return False
  194.         End Function
  195.         Private Function MakeKeyLparam(ByVal VirtualKey As Integer, ByVal flag As Integer) As Integer
  196.             '參數VirtualKey表示按鍵虛擬碼,flag表示是按下鍵還是釋放鍵,用WM_KEYDOWN和WM_KEYUP這兩個常數表示
  197.             Dim s As String
  198.             Dim Firstbyte As String 'lparam參數的24-31位
  199.             If flag = WM_KEYDOWN Then '如果是按下鍵
  200.                 Firstbyte = "00"
  201.             Else
  202.                 Firstbyte = "C0" '如果是釋放鍵
  203.             End If
  204.             Dim Scancode As Long
  205.             '獲得鍵的掃描碼
  206.             Scancode = MapVirtualKey(VirtualKey, 0)
  207.             Dim Secondbyte As String 'lparam參數的16-23位元,即虛擬鍵掃描碼
  208.             Secondbyte = Right("00" & Hex(Scancode), 2)
  209.             s = Firstbyte & Secondbyte & "0001" '0001為lparam參數的0-15位,即發送次數和其他擴展資訊
  210.             MakeKeyLparam = Val("&H" & s)
  211.         End Function
  212.         '------------------------------- 申請記憶體 ---------------------------------------------'
  213.         Private Declare Function VirtualAllocEx Lib "kernel32.dll" (ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As IntPtr, ByVal flAllocationType As Integer, ByVal flProtect As Integer) As IntPtr
  214.         Public Function Alloc(ByVal lpSize As Integer, Optional ByVal lpAddress As Integer = 0) As Integer
  215.             Const MEM_COMMIT As Integer = &H1000
  216.             Const PAGE_EXECUTE_READWRITE As Integer = &H40
  217.             Dim pBlob As IntPtr = VirtualAllocEx(WriteMapleStoryIntptr, New IntPtr(lpAddress), New IntPtr(lpSize), MEM_COMMIT, PAGE_EXECUTE_READWRITE)
  218.             If pBlob = IntPtr.Zero Then Throw New Exception
  219.             Return pBlob.ToInt32
  220.         End Function
  221.         '------------------------------- Address2Aob ---------------------------------------------'
  222.         Public Function Adr2Aob(ByVal Address As Integer) As String
  223.             Dim tmpAOB As String = Hex(Address).PadLeft(8, "0")
  224.             Dim reAOB As String = Nothing
  225.             For i = 1 To 7
  226.                 If (i Mod 2) = 1 Then
  227.                     reAOB = Mid(tmpAOB, i, 2) & " " & reAOB
  228.                 End If
  229.             Next
  230.             Return Trim(reAOB)
  231.         End Function
  232.     End Structure
  233. End Module



複製代碼
[size=100%]來源: knowlet3389.blogspot.tw


[發帖際遇]: ai1118 的房子遭到劉政鴻拆除,損失 27 楓幣 幸運榜 / 衰神榜
收藏收藏0 推0 噓0


把本文推薦給朋友或其他網站上,每次被點擊增加您在本站積分: 1彩票
複製連結並發給好友,以賺取推廣點數
簡單兩步驟,註冊、分享網址,即可獲得獎勵! 一起推廣文章換商品、賺$$

5

主題

0

好友

-1

積分

限制會員

UID
92540
帖子
81
主題
5
精華
0
積分
-1
楓幣
-7
威望
-4
存款
0
贊助金額
0
推廣
0
GP
4
閱讀權限
0
性別
保密
在線時間
58 小時
註冊時間
2015-2-18
最後登入
2015-10-18
2
發表於 2015-2-27 19:51:14 |只看該作者
感謝
點評回覆

使用道具 舉報

高級模式
B Color Image Link Quote Code Smilies |上傳

廣告刊登意見回饋關於我們管群招募本站規範DMCA隱私權政策

Copyright © 2011-2024 冰楓論壇, All rights reserved

免責聲明:本網站是以即時上載留言的方式運作,本站對所有留言的真實性、完整性及立場等,不負任何法律責任。

而一切留言之言論只代表留言者個人意見,並非本網站之立場,用戶不應信賴內容,並應自行判斷內容之真實性。

小黑屋|手機版|冰楓論壇

GMT+8, 2024-11-22 06:20

回頂部