Author Topic: DEVELOPERS: (mod info) WM_COPYDATA command interface  (Read 37773 times)

Pwntastic

  • Roffles The Mighty
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1910
    • MSN Messenger - rofflesthemighty@hotmail.com
    • AOL Instant Messenger - LordDosk
    • View Profile
    • Pwntastic.Net
Re: developers: WM_COPYDATA command interface
« Reply #15 on: April 10, 2008, 02:02:23 pm »
imho you should just go for filename. Audiosurf will always be using Questviewer.exe so that should always be open when audiosurf is open. there have been a few occasions where the audiosurf title does not show up correctly
you can do something like
public IntPtr FindProcessByName(string strProcessName)
        {
            IntPtr HandleOfToProcess = IntPtr.Zero;
            Process[] p = Process.GetProcesses();
            foreach (Process p1 in p)
            {
                Debug.WriteLine(p1.ProcessName.ToUpper());
                if (p1.ProcessName.ToUpper() == strProcessName)
                {
                    HandleOfToProcess = p1.MainWindowHandle;
                    break;
                }
            }
            return HandleOfToProcess;
        }
to get the handle of the questviewer process. just pass it something like IntPtr ProcessHandle = FindProcessByName("QUESTVIEWER");

ANOON

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: developers: WM_COPYDATA command interface
« Reply #16 on: April 10, 2008, 02:10:38 pm »
Or you just use double check like me :P
Code: [Select]
If ProcessExists("Questviewer.exe") And WinExists("[TITLE:Audiosurf; CLASS:START]") Then

Dylan

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1266
    • View Profile
    • Audiosurf
    • Email
Re: developers: WM_COPYDATA command interface
« Reply #17 on: April 10, 2008, 03:03:50 pm »
Bump. New commands now listed in the first post.

Faxmachinen

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: developers: WM_COPYDATA command interface
« Reply #18 on: April 10, 2008, 03:41:38 pm »
The folder doesn't make a difference... It's found by the title text, and if you just set that to "Audiosurf", then it doesn't use any wildcards, and Audiosurf is the only thing to return that exact title.
I was trying to hint that XP's file browser uses the current folder name as the window title.

ANOON's suggestion seems adequate though. Pwntastic looks like he's using Java; not quite sure how that translates to the C Windows API, but it might be worth checking out.

Pwntastic

  • Roffles The Mighty
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1910
    • MSN Messenger - rofflesthemighty@hotmail.com
    • AOL Instant Messenger - LordDosk
    • View Profile
    • Pwntastic.Net
Re: developers: WM_COPYDATA command interface
« Reply #19 on: April 10, 2008, 03:45:04 pm »
Lol im using C#. It translates perfectly over to the C windows API :P

ascommand stopsong and ascommand next/prevsong would be nifty
« Last Edit: April 10, 2008, 04:18:57 pm by Pwntastic »

Lo/Rez

  • Hero Member
  • *****
  • Posts: 716
  • High Priest
    • View Profile
Re: developers: WM_COPYDATA command interface
« Reply #20 on: April 11, 2008, 02:28:41 am »
why it no work for html?   how i mine 4 fish?

Community Restoration in Progress

Cody900

  • Hero Member
  • *****
  • Posts: 953
    • View Profile
    • Email
Re: developers: WM_COPYDATA command interface
« Reply #21 on: April 11, 2008, 03:22:41 am »
why it no work for html?   how i mine 4 fish?

How do I shot web?

Dylan

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1266
    • View Profile
    • Audiosurf
    • Email
Re: developers: WM_COPYDATA command interface
« Reply #22 on: April 11, 2008, 04:23:56 am »
Bump.

First thread updated with new commands that require the 4.11.08 beta patch. Duplicated here:

EDIT: More! (4.11.08)
ascommand restorenormalwindowstyle
There's now two commands it will accept while loading. Sending either one puts Audiosurf in quickstart mode where it will progress to the character selection screen with no clicks.
1) ascommand quickstartregisterwindow MyWindowName
--It'll send you a "asreport successfullyquickstartregistered" to confirm registration
--Then it will send "asreport oncharacterscreen" when ready for further commands
2) ascommand quickstartqueuecommand CommandToRunWhenDoneLoadingGoesHere
--Example: ascommand quickstartqueuecommand ascommand playsongfreeride c:\music\some song.mp3
--Once it gets to the character selection screen it will run CommandToRunWhenDoneLoadingGoesHere

tnl

  • Full Member
  • ***
  • Posts: 110
  • tweaker
    • View Profile
Re: developers: WM_COPYDATA command interface
« Reply #23 on: April 11, 2008, 09:47:44 am »
Here's another way to do WM_COPYDATA in Python, that preserves unicode strings:

from ctypes import *

class CopyDataStruct(Structure):
  _fields_ = [('dwData', c_int),
              ('cbData', c_int),
              ('lpData', c_void_p)]

def SendASCommand(cmd):
  hwnd = FindWindow(None, 'Audiosurf')
  if hwnd:
    s = create_string_buffer(cmd)
    cds = CopyDataStruct(len(s), len(s), cast(s, c_void_p))
    SendMessage(hwnd, WM_COPYDATA, 0, addressof(cds))


Faxmachinen

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: developers: WM_COPYDATA command interface
« Reply #24 on: April 11, 2008, 04:14:29 pm »
I assume that's user32.SendMessageW? Or does it matter?
And aren't string buffers only for when the called function writes to the string?

ANOON

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: developers: WM_COPYDATA command interface
« Reply #25 on: April 11, 2008, 04:28:05 pm »
Maybe this is useful??
http://ASExample1.notlong.com

Pwntastic

  • Roffles The Mighty
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1910
    • MSN Messenger - rofflesthemighty@hotmail.com
    • AOL Instant Messenger - LordDosk
    • View Profile
    • Pwntastic.Net
Re: developers: WM_COPYDATA command interface
« Reply #26 on: April 11, 2008, 04:45:13 pm »
I hate you. I should have thought of that first

tnl

  • Full Member
  • ***
  • Posts: 110
  • tweaker
    • View Profile
Re: developers: WM_COPYDATA command interface
« Reply #27 on: April 11, 2008, 05:33:08 pm »
I assume that's user32.SendMessageW? Or does it matter?
And aren't string buffers only for when the called function writes to the string?

I tried using c_char_p with no luck.  String buffers are used for writes, but I don't care about that since they can be read, too.

Since I'm using win32com for my script, I end up using other bindings from pywin32:

from win32gui import FindWindow, SetForegroundWindow
from win32con import WM_COPYDATA, WM_SYSCOMMAND
from win32api import SendMessage

I don't know much about COM and am unsure if/how it can be done without pywin32.

Faxmachinen

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: developers: WM_COPYDATA command interface
« Reply #28 on: April 11, 2008, 05:42:28 pm »
Ah, I thought you were just writing pseudocode. You can do it with only ctypes, see this post. Also look up the ctypes man.
DLL functions ending ending with an 'A' use ASCII strings, whereas those ending in a 'W' use unicode strings. I'm not sure if that actually makes a difference with SendMessage though.

Edit: It does make a difference. If you use SendMessageW you can pass it a c_wchar_p.
« Last Edit: April 11, 2008, 05:57:12 pm by Faxmachinen »

e_-

  • Newbie
  • *
  • Posts: 41
    • AOL Instant Messenger - hohoho
    • View Profile
Re: developers: WM_COPYDATA command interface
« Reply #29 on: April 11, 2008, 06:09:46 pm »
Me and a friend have been trying to get this working in VB.NET for a few days now, we've tried pretty much everything we could think of, and it just wont work. Any idea whats causing it to not work?:

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Private Shared Function FindWindow( _
        ByVal lpClassName As String, _
        ByVal lpWindowName As String) As IntPtr
    End Function

    <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    Public Shared Function SendMessage( _
        ByVal hwnd As IntPtr, _
        ByVal msg As Integer, _
        ByVal wparam As IntPtr, _
        ByVal lparam As IntPtr) As IntPtr
    End Function

    <StructLayout(LayoutKind.Sequential)> _
    Private Structure CopyData
        Public dwData As IntPtr
        Public cbData As Integer
        Public lpData As IntPtr
    End Structure

    Private Const WM_COPYDATA As Integer = &H4A

    Public Function SendString(ByVal s As String) As Integer
        Try
            Dim CDS As CopyData, Result As Integer
            Dim Str As String = s

            CDS.dwData = AudiosurfHandle
            Str &= Chr(0)

            CDS.cbData = Str.Length + 1
            CDS.lpData = Marshal.AllocHGlobal(Str.Length)
            CDS.lpData = Marshal.StringToHGlobalAnsi(Str)
            Dim iPtr As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(CDS))
            Marshal.StructureToPtr(CDS, iPtr, True)

            Result = SendMessage(AudiosurfHandle, WM_COPYDATA, IntPtr.Zero, iPtr).ToInt32

            Marshal.FreeHGlobal(CDS.lpData)
            Marshal.FreeHGlobal(iPtr)

            Return Result
        Catch ex As Exception
            MessageBox.Show(ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Application.Exit()
            Return 0
        End Try
    End Function

Also, we used this reference page too.
« Last Edit: April 11, 2008, 07:31:57 pm by e_- »