这段代码中的错误是什么? (它无法识别kernel32等)

时间:2012-05-16 00:18:54

标签: vb.net structure

我是这项业务的新手

代码:

    Dim info As StructLib.MEMORY_BASIC_INFORMATION
    Dim size = CUInt(Marshal.SizeOf(GetType(StructLib.MEMORY_BASIC_INFORMATION)))
    Dim address = IntPtr.Zero
    Dim handle = Api.kernel32.OpenProcess(EnumLib.ProcessAccessFlags.All, False, Helper.EnumProcess.Process().First(Function(res) res.szExeFile = "chrome.exe").th32ProcessID)
    Dim lookFor As Object = "google.co.il", replaceWith As Object = "boogle.co.il"
    Dim done As UInteger
    Dim lookData As Byte() = Nothing
    If TypeOf lookFor Is String Then
        lookData = Encoding.Unicode.GetBytes(DirectCast(lookFor, String))
    ElseIf TypeOf lookFor Is Byte Then
        lookData = New Byte(0) {}
        lookData(0) = CByte(lookFor)
    ElseIf TypeOf lookFor Is Short Then
        lookData = BitConverter.GetBytes(CShort(lookFor))
    ElseIf TypeOf lookFor Is Integer Then
        lookData = BitConverter.GetBytes(CInt(lookFor))
    ElseIf TypeOf lookFor Is Long Then
        lookData = BitConverter.GetBytes(CLng(lookFor))
    End If
    While Api.kernel32.VirtualQueryEx(handle, address, info, size) > 0
        If info.Valid Then
            Dim data = info.getData(handle)
            For i As var = 0 To data.Length - 1
                Dim index = -1
                While System.Threading.Interlocked.Increment(index) < lookData.Length
                    Try
                        If data(i + index) = lookData(index) Then
                            If index = lookData.Length - 1 Then
                                If TypeOf replaceWith Is String Then
                                    Api.kernel32.WriteProcessMemory(handle, address + i, Marshal.StringToHGlobalUni(DirectCast(replaceWith, String)), Convert.ToUInt32(DirectCast(replaceWith, String).Length * 2), done)
                                    i += (index + DirectCast(replaceWith, String).Length)
                                Else
                                    Dim replace As Byte() = Nothing
                                    If TypeOf replaceWith Is Long Then
                                        replace = BitConverter.GetBytes(CLng(replaceWith))
                                    ElseIf TypeOf replaceWith Is Integer Then
                                        replace = BitConverter.GetBytes(CInt(replaceWith))
                                    ElseIf TypeOf replaceWith Is Short Then
                                        replace = BitConverter.GetBytes(CShort(replaceWith))
                                    ElseIf TypeOf replaceWith Is Byte Then
                                        replace = New Byte() {CByte(replaceWith)}
                                    End If
                                    If True Then
                                        Dim gc = GCHandle.Alloc(replace, GCHandleType.Pinned)
                                        Api.kernel32.WriteProcessMemory(handle, address + i, gc.AddrOfPinnedObject(), 1, done)
                                        gc.Free()
                                    End If
                                    If TypeOf replaceWith Is Long Then
                                        i += (index + 8)
                                    ElseIf TypeOf replaceWith Is Integer Then
                                        i += (index + 4)
                                    ElseIf TypeOf replaceWith Is Short Then
                                        i += (index + 2)
                                    ElseIf TypeOf replaceWith Is Byte Then
                                        i += (index + 1)
                                    End If
                                End If
                                Exit Try
                            End If
                        Else
                            i += index
                            Exit Try
                        End If
                    Catch
                        i += index
                        Exit Try
                    End Try
                End While
            Next
        End If
        If CLng(address) <= &H7FFFFFFF Then
            If info.[Next] = address Then
                Exit While
            End If
            address = info.[Next]
        Else
            Exit While
        End If
    End While

无法识别:

Api.kernel32
   For i As var
      StructLib.MEMORY_BASIC_INFORMATION
      Dim size = CUInt(Marshal.SizeOf(GetType(**StructLib.MEMORY_BASIC_INFORMATION**)))

      EnumLib.ProcessAccessFlags.All
      helper.EnumProcess.Process().First(Function(res) res.szExeFile = "chrome.exe"
  • 什么是结构?
  • 什么是libs?

1 个答案:

答案 0 :(得分:0)

从事物的外观来看,Api是某人写的一个类。据我所知,没有名为Api的.Net类型。您将需要该对象所属的任何库并引用它。您复制代码的类/模块是否具有:

Imports xxx.Api

...还是有任何你不认识的进口产品?

代码是否在编译时失败?还是运行时间?如果在运行时,在哪里?我猜想,如果在运行时,你应该在第一行或第四行中抛出异常:

Dim info As StructLib.MEMORY_BASIC_INFORMATION
Dim size = CUInt(Marshal.SizeOf(GetType(StructLib.MEMORY_BASIC_INFORMATION)))
Dim address = IntPtr.Zero
Dim handle = Api.kernel32.OpenProcess(EnumLib.ProcessAccessFlags.All, False, Helper.EnumProcess.Process().First(Function(res) res.szExeFile = "chrome.exe").th32ProcessID)  

我猜你甚至可能都没有编译。

相关问题