• Welcome to Valhalla Legends Archive.
 

Can Someone Verify This

Started by ShaDoWDeM, May 18, 2006, 02:01 PM

Previous topic - Next topic

ShaDoWDeM

I would like someone to verify if I am correct or not and if im wrong can you tell me the right address

============================================= Function
Private Sub GetHandle()
On Error GoTo Err
Dim hwnd As Long
Dim pid As Long
Dim str As String * 1
    hwnd = FindWindow("SWarClass", vbNullString)
If (hwnd = 0) Then
    pHandle = 0
Exit Sub
End If
    GetWindowThreadProcessId hwnd, pid
    pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If (pHandle = 0) Then
    pHandle = 0
Exit Sub
End If
Err:
End Sub
============================================= Function

============================================= Function

Dim sValue As String * 1, sValue2 As String * 1
    GetHandle
If pHandle = 0 Then Exit Sub

============================================= Verify This If Wrong
    ReadProcessMemory pHandle, "&H6A489C", sValue2, 1, 0& 'unit
    ReadProcessMemory pHandle, "&H651834", sValue, 1, 0& ' cursor
    ReadProcessMemory pHandle, "&H6B6D9C", sValue2, 1, 0& 'text
============================================= Verify This If Wrong

============================================= Function

rabbit

&H6A489C etc are longs, why are you passing them as strings?
And you're not capturing your errors, take that out and find out if it's wrong yourself.
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

warz

Ew. I'd suggest dll injection.

Tazo

Quote from: warz on May 18, 2006, 06:07 PM
Ew. I'd suggest dll injection.
Which is very difficult in vb. If you choose to use DLL injection, I suggest using a dll made in C/C++.

topaz

Quote from: Tazo on May 18, 2006, 06:59 PM
Quote from: warz on May 18, 2006, 06:07 PM
Ew. I'd suggest dll injection.
Which is very difficult in vb. If you choose to use DLL injection, I suggest using a dll made in C/C++.

Depends how you meter difficulty... it's not very hard for me
RLY...?

TheMinistered

Quote
Depends how you meter difficulty... it's not very hard for me

All the COM involved is a slight bit difficult if you ask me...

warz

Quote from: Tazo on May 18, 2006, 06:59 PM
Quote from: warz on May 18, 2006, 06:07 PM
Ew. I'd suggest dll injection.
Which is very difficult in vb. If you choose to use DLL injection, I suggest using a dll made in C/C++.

The actual dll injection is very easy, in visual basic. It's just a few API calls. See my visual basic demo source code at www.rafm.org - but the dll being injected would most likely work best if in C/C++.

Joe[x86]

#7
I revamped the first function for you, fixing a few things. Due to my lack of VB installed, or even Windows for that matter, it's untested, but it should work.

Fixes:

1. Variable declarations - str is declared and not used.
2. If statements - instead of doing four lines (start, action, action, end), why not just use your label and jump to that in one line?
3. Default values - remember that numbers are initalized to 0, booleans to false (at least, in Java), and Strings to "". You don't need to assign a 0 value to a number when it already has that value.
4. Last but not least, indent. Unless of course SMF killed your code (place it within [code.][/.code] tags, minus the ".")

Private Sub getHandle()
    On Error Goto Err
    Dim HWnd As Long, PID As Long

    HWnd = FindWindow("SWarClass", vbNullString)
    If HWnd = 0 Then Goto Err 'Window not found

    Call GetWindowThreadProcessId(HWnd, PID)
    pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, PID)

Err:
    '// No action is needed
End Sub
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

warz

Quote from: J on May 18, 2006, 08:14 PM
I revamped the first function for you, fixing a few things. Due to my lack of VB installed, or even Windows for that matter, it's untested, but it should work.

Fixes:

1. Variable declarations - str is declared and not used. pHandle is used and not declared.
2. If statements - instead of doing four lines (start, action, action, end), why not just use your label and jump to that in one line?
3. Default values - remember that numbers are initalized to 0, booleans to false (at least, in Java), and Strings to "". You don't need to assign a 0 value to a number when it already has that value.
4. Last but not least, indent. Unless of course SMF killed your code (place it within [code.][/.code] tags, minus the ".")

Private Sub getHandle()
    On Error Goto Err
    Dim HWnd As Long, PID As Long, pHandle As Long

    HWnd = FindWindow("SWareClass", vbNullString)
    If HWnd = 0 Then Goto Err 'Window not found

    Call GetWindowThreadProcessId(HWnd, PID)
    pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, PID)

Err:
    '// No action is needed
End Sub


Ofcourse, you'd probably want pHandle to be a global variable, or return the value of pHandle when the function ends. Because, this function really doesn't accomplish anything otherwise. Also, 'SWareClass'? :-p

Joe[x86]

Fixed. SWareClass was a typo, and I didn't realize that pHandle was global until later and forgot to go back to change it.

EDIT -
That's a nice advantage of Java - it's class variables are accessed by this.varName so you can tell right away if it's local or class.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

warz

Well, I wouldn't make pHandle global. Since this functions purpose is to get a handle, according to the function name, I'd just make it "as long" and return the value.


Private Sub getHandle() as long
    On Error Goto Err
    Dim hWnd As Long, PID As Long, retValue as long

    hWnd = FindWindow("SWarClass", vbNullString)
    If (hWnd = 0) then
       exit function
    end if

    retValue = GetWindowThreadProcessId(hWnd, PID)
    if (retValue = 0) then
       exit function
    end if
   
     getHandle = OpenProcess(PROCESS_ALL_ACCESS, False, PID)
End Sub

MyndFyre

Quote from: warz on May 19, 2006, 08:42 AM

Private Sub getHandle() as long

As something with a return value, isn't it appropriate to declare it as a Function rather than as a Sub?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

ShaDoWDeM

#12
got yer dun

Warrior

Quote from: MyndFyre[vL] on May 19, 2006, 11:22 AM
Quote from: warz on May 19, 2006, 08:42 AM

Private Sub getHandle() as long

As something with a return value, isn't it appropriate to declare it as a Function rather than as a Sub?

Correct, I don't think that's legal in VB either.
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

FrOzeN

#14
Sub's in VB6 have no return value, thus you can't declare a type for a non-existent return value. That is what a function is for.

It would be:
Private Function getHandle() as long
    On Error Goto Err
    Dim hWnd As Long, PID As Long, retValue as long

    hWnd = FindWindow("SWarClass", vbNullString)
    If hWnd <> 0 Then
        retValue = GetWindowThreadProcessId(hWnd, PID)
        If retValue <> 0 Then
            getHandle = OpenProcess(PROCESS_ALL_ACCESS, False, PID)
            Exit Function
        End If
    End If
Err:
    getHandle = 0
End Function
~ FrOzeN