Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2005

Tip: Looking for answers? Try searching our database.

Help! - Reading playlist files from winamp through Windows & Winamp APIs & .NET - Decoding memory contents

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pangel83@gmail.com - 24 Jul 2005 18:35 GMT
I've been trying for days to write a piece of VB.NET code that will
read from winamp's memory space the paths of the files from the current
winamp playlist.

The GETPLAYLISTFILE command of the winamp API will only return a
pointer to the position of the asked path. An article available on
http://msmvps.com/ch21st/archive/2004/02/26.aspx provides a VB6
implementation of this, using the ReadProcessMemory Windows API
command. Through digging and asking around, I managed to read the
memory contents that winamp points to, but I can't seem to be able to
decode them!

In the attached code below that contains all you need to recreate my
problem. The function always returns the following giberish:
"UVßwXjÝw

====================================================================Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MsgBox(Me.GetPlaylistFile(0))
End Sub

Private Const PROCESS_VM_READ As Long = &H10
Private Const IPC_GETPLAYLISTFILE = 211

Private Declare Auto Function FindWindow Lib "user32" (ByVal
lpClassName As String, ByVal lpWindowName As String) As IntPtr

Private Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As
IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As
Integer) As IntPtr

Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal
hwnd As IntPtr, ByRef lpdwProcessId As IntPtr) As IntPtr

Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Integer, _
ByVal bIneritHandle As Boolean, _
ByVal dwProcessId As IntPtr) As IntPtr

Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal
hProcess As IntPtr, ByRef lpBase As IntPtr, ByVal lpBuffer() As Byte,
ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As
Boolean

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As
IntPtr) As Boolean

Private Function FindWinamp() As IntPtr
Return FindWindow("Winamp v1.x", vbNullString)
End Function

Public Function GetPlaylistFile(ByVal TrackNo As Integer) As String
Dim winampWindow As IntPtr = FindWinamp()
Dim fileName As String = String.Empty

If Not IsNullPtr(winampWindow) Then

Dim lp As IntPtr = SendMessage(winampWindow, &H400, TrackNo,
IPC_GETPLAYLISTFILE)

If Not IsNullPtr(lp) Then

Dim pid As IntPtr

Call GetWindowThreadProcessId(winampWindow, pid)
If Not IsNullPtr(pid) Then

Dim hWinampProcess As IntPtr = OpenProcess(PROCESS_VM_READ, False, pid)

If Not IsNullPtr(hWinampProcess) Then

Dim buffer(1000) As Byte
Dim bytesWritten As Integer

If ReadProcessMemory(hWinampProcess, lp, buffer, buffer.Length,
bytesWritten) Then

fileName = System.Text.Encoding.Default.GetString(buffer)
End If

CloseHandle(hWinampProcess)
End If

End If

End If

End If

Return fileName

End Function

Private Function IsNullPtr(ByVal ptr As IntPtr) As Boolean
Return ptr.Equals(IntPtr.Zero)
End Function
Stefan De Schepper - 24 Jul 2005 20:43 GMT
The error lies in the fact that the lpBase argument of the ReadProcessMemory
declaration should be declared ByVal, not ByRef.

Hope this helps,
Stefan

I've been trying for days to write a piece of VB.NET code that will
read from winamp's memory space the paths of the files from the current
winamp playlist.

The GETPLAYLISTFILE command of the winamp API will only return a
pointer to the position of the asked path. An article available on
http://msmvps.com/ch21st/archive/2004/02/26.aspx provides a VB6
implementation of this, using the ReadProcessMemory Windows API
command. Through digging and asking around, I managed to read the
memory contents that winamp points to, but I can't seem to be able to
decode them!

In the attached code below that contains all you need to recreate my
problem. The function always returns the following giberish:
"UVßwXjÝw

======================================================================

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MsgBox(Me.GetPlaylistFile(0))
End Sub

Private Const PROCESS_VM_READ As Long = &H10
Private Const IPC_GETPLAYLISTFILE = 211

Private Declare Auto Function FindWindow Lib "user32" (ByVal
lpClassName As String, ByVal lpWindowName As String) As IntPtr

Private Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As
IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As
Integer) As IntPtr

Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal
hwnd As IntPtr, ByRef lpdwProcessId As IntPtr) As IntPtr

Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Integer, _
ByVal bIneritHandle As Boolean, _
ByVal dwProcessId As IntPtr) As IntPtr

Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal
hProcess As IntPtr, ByRef lpBase As IntPtr, ByVal lpBuffer() As Byte,
ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As
Boolean

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As
IntPtr) As Boolean

Private Function FindWinamp() As IntPtr
Return FindWindow("Winamp v1.x", vbNullString)
End Function

Public Function GetPlaylistFile(ByVal TrackNo As Integer) As String
Dim winampWindow As IntPtr = FindWinamp()
Dim fileName As String = String.Empty

If Not IsNullPtr(winampWindow) Then

Dim lp As IntPtr = SendMessage(winampWindow, &H400, TrackNo,
IPC_GETPLAYLISTFILE)

If Not IsNullPtr(lp) Then

Dim pid As IntPtr

Call GetWindowThreadProcessId(winampWindow, pid)
If Not IsNullPtr(pid) Then

Dim hWinampProcess As IntPtr = OpenProcess(PROCESS_VM_READ, False, pid)

If Not IsNullPtr(hWinampProcess) Then

Dim buffer(1000) As Byte
Dim bytesWritten As Integer

If ReadProcessMemory(hWinampProcess, lp, buffer, buffer.Length,
bytesWritten) Then

fileName = System.Text.Encoding.Default.GetString(buffer)
End If

CloseHandle(hWinampProcess)
End If

End If

End If

End If

Return fileName

End Function

Private Function IsNullPtr(ByVal ptr As IntPtr) As Boolean
Return ptr.Equals(IntPtr.Zero)
End Function

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.