【问题标题】:Generate a random value生成随机值
【发布时间】:2014-03-19 13:56:31
【问题描述】:

首先,我有一个这样的内存写入模块:

    Module Lul

#Region "Declarations"

        Private Declare Function OpenProcess Lib "kernel32" Alias "OpenProcess" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
        Private Declare Function WriteProcessMemory Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
        Private Declare Function WriteFloatMemory Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Single, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
        Private Declare Function ReadFloat Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByRef buffer As Single, ByVal size As Int32, ByRef lpNumberOfBytesRead As Int32) As Boolean
        Private Declare Function ReadProcessMemory Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
        Private Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As Integer) As Integer

        Private string1 As Long
        Private string2 As Integer
        Private RBuff1 As Long
        Private RBuff2 As Single
        Private RBuff3 As Integer

#End Region

        Public Function IsProcessOpen(ByVal name As String) As Boolean

            For Each clsProcess As Process In Process.GetProcesses

                If clsProcess.ProcessName.Contains(name) Then


                    Return True

                End If
            Next
            ' Do nothing
            Return False
        End Function

#Region "Hacks"

        'WriteMemory
        Private Function WriteMemory(ByVal Address As Integer, ByVal Value As Long, ByVal Bytes As Integer)
            Dim ACRSPLookUp As Process() = Process.GetProcessesByName("S4Client")
            If ACRSPLookUp.Length = 0 Then
                End
            End If
            Dim processHandle As IntPtr = OpenProcess(&H1F0FFF, 0, ACRSPLookUp(0).Id)
            WriteProcessMemory(processHandle, Address, Value, Bytes, Nothing)
            CloseHandle(processHandle)

            Return Nothing
        End Function

        'WriteFloat
        Private Function WriteFloat(ByVal Address As Integer, ByVal Value As Single)
            Dim ACRSPLookUp As Process() = Process.GetProcessesByName("S4Client")
            If ACRSPLookUp.Length = 0 Then
                End
            End If
            Dim processHandle As IntPtr = OpenProcess(&H1F0FFF, 0, ACRSPLookUp(0).Id)
            WriteFloatMemory(processHandle, Address, Value, 4, Nothing)
            CloseHandle(processHandle)

            Return Nothing
        End Function

        'NOP
        Private Function NOP(ByVal Address As Integer, ByVal value As Integer)
            Dim ACRSPLookUp As Process() = Process.GetProcessesByName("S4Client")
            If ACRSPLookUp.Length = 0 Then
                End
            End If
            Dim processHandle As IntPtr = OpenProcess(&H1F0FFF, 0, ACRSPLookUp(0).Id)
            WriteProcessMemory(processHandle, Address, value, 1, Nothing)
            CloseHandle(processHandle)

            Return Nothing
        End Function

#End Region

#Region "Functions"

        Public Function memoryh4x(ByVal address As String, ByVal value As Long, ByVal bytes As Byte)
            If IsProcessOpen("S4Client") Then
                string2 = "&H" & Hex(string1 + address)
                WriteMemory(string2, value, bytes)
            End If
            Return Nothing
        End Function

        Public Function floath4x(ByVal address As String, ByVal value As Long)
            If IsProcessOpen("S4Client") Then
                string2 = "&H" & Hex(string1 + address)
                WriteFloat(string2, value)
            End If
            Return Nothing
        End Function

        Public Function noph4x(ByVal address As String, ByVal value As Long)
            If IsProcessOpen("S4Client") Then
                string2 = "&H" & Hex(string1 + address)
                NOP(string2, value)


            End If
            Return Nothing
        End Function

#End Region
    End Module

我正在像这样写入进程的内存:

memoryh4x(&H482719, 8, 4)

我希望它在每次选中复选框而不是 8 时放置一个随机值。 我怎样才能做到这一点 ?谢谢。

【问题讨论】:

  • 您对关键字End 的使用被滥用。这不是结束函数的正确方式——它会结束你的应用——而且方式不正确!
  • 我猜你弄错了。我只是希望它生成一个随机值来写入。
  • 不,我想告诉你这是一件坏事,不应该被使用。让我知道你的软件的名称是什么,这样我就可以避免它 - 谢谢
  • 这是一个客户端破解。 :P @Miky Dinescu 的回答奏效了,谢谢。

标签: vb.net random


【解决方案1】:

您可以使用 .NET 随机数生成器来生成随机值:

 ' You should only declare and initialize this once for your class
 '   otherwise the values you'll get won't be very random
 Dim rGenerator As System.Random = New System.Random()


 Dim val As Integer = 0        

 val = rGenerator.Next(1, 8)         ' generate a random integer between 1 and 8

 memoryh4x(&H482719, val, 4)

【讨论】:

  • @user3423677 - 很高兴为您提供帮助.. 如答案中所述,请确保只初始化随机数生成器一次,而不是每次调用 .Next 就可以了!
  • 有点吹毛求疵:val = rGenerator.Next(1, 8) 行将生成一个从 1 到 7 的随机数。它不包括 8。
【解决方案2】:

如果你在乎数字是随机的,请不要使用 System.Random()

我对创建随机数的可怕程度感到震惊!

查看我的帖子Here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-05
    • 2011-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-04
    • 1970-01-01
    相关资源
    最近更新 更多