readProcessMemory의 출력에서 문자열을 얻는 방법
-
08-07-2019 - |
문제
이것은 내 코드의 스 니펫입니다.
Declare Function ReadProcessMemory Lib "kernel32" _
(ByVal hProcess As Long, _
ByVal lpBaseAddress As Long, _
lpBuffer As Any, _
ByVal nSize As Long, _
lpNumberOfBytesRead As Long) As Long
Dim bytearray As String * 65526
Dim GetWindowsFormsID
ReadProcessMemory(processHandle, bufferMem, ByVal bytearray, size, lp)
GetWindowsFormsID = ByteArrayToString(bytearray, retLength)
Function ByteArrayToString(bytes As String, length As Long) As String
Dim retValStr As String
Dim l As Long
retValStr = String$(length + 1, Chr(0))
l = WideCharToMultiByte(CP_ACP, 0, bytes, -1, retValStr, length + 1, Null, Null)
ByteArrayToString = retValStr
End Function
WideChartomultibyte를 호출하는 동안 '94 NULL '오류가 발생했습니다. 그러나 나는 바이트가 비어 있지 않다고 확신합니다.
이것이이 출력을 문자열로 변환하는 정확한 절차입니까?
해결책
좋아, 이것은 해결된다 (그리고 또한 이 질문). 문제는 실제로 WideChar 문자열을 ANSI 문자열로 변환하는 것입니다. 나는 widechartomultibyte 대신 copymemory를 사용합니다.
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Function ByteArrayToString(bytes As String, Length As Long) As String
Dim retValStr As String
retValStr = String(Length - 1, Chr$(0))
CopyMemory ByVal StrPtr(retValStr), ByVal bytes, Length * 2
ByteArrayToString = retValStr
End Function
제휴하지 않습니다 StackOverflow