Valhalla Legends Forums Archive | Visual Basic Programming | Can Someone Verify This

AuthorMessageTime
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
May 18, 2006, 7:01 PM
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.
May 18, 2006, 8:09 PM
warz
Ew. I'd suggest dll injection.
May 18, 2006, 11:07 PM
laurion
[quote author=warz link=topic=15009.msg152711#msg152711 date=1147993628]
Ew. I'd suggest dll injection.
[/quote]
Which is very difficult in vb. If you choose to use DLL injection, I suggest using a dll made in C/C++.
May 18, 2006, 11:59 PM
Topaz
[quote author=Tazo link=topic=15009.msg152714#msg152714 date=1147996782]
[quote author=warz link=topic=15009.msg152711#msg152711 date=1147993628]
Ew. I'd suggest dll injection.
[/quote]
Which is very difficult in vb. If you choose to use DLL injection, I suggest using a dll made in C/C++.
[/quote]

Depends how you meter difficulty... it's not very hard for me
May 19, 2006, 12:25 AM
TheMinistered
[quote]
Depends how you meter difficulty... it's not very hard for me
[/quote]

All the COM involved is a slight bit difficult if you ask me...
May 19, 2006, 1:10 AM
warz
[quote author=Tazo link=topic=15009.msg152714#msg152714 date=1147996782]
[quote author=warz link=topic=15009.msg152711#msg152711 date=1147993628]
Ew. I'd suggest dll injection.
[/quote]
Which is very difficult in vb. If you choose to use DLL injection, I suggest using a dll made in C/C++.
[/quote]

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++.
May 19, 2006, 1:12 AM
JoeTheOdd
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 ".")

[code]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[/code]
May 19, 2006, 1:14 AM
warz
[quote author=J link=topic=15009.msg152725#msg152725 date=1148001247]
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 ".")

[code]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[/code]
[/quote]

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
May 19, 2006, 2:56 AM
JoeTheOdd
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 [tt]this.varName[/tt] so you can tell right away if it's local or class.
May 19, 2006, 12:18 PM
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.

[code]
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
[/code]
May 19, 2006, 1:42 PM
Myndfyr
[quote author=warz link=topic=15009.msg152772#msg152772 date=1148046125]
[code]
Private Sub getHandle() as long
[/code]
[/quote]
As something with a return value, isn't it appropriate to declare it as a Function rather than as a Sub?
May 19, 2006, 4:22 PM
ShaDoWDeM
got yer dun
May 19, 2006, 10:33 PM
Quarantine
[quote author=MyndFyre[vL] link=topic=15009.msg152783#msg152783 date=1148055750]
[quote author=warz link=topic=15009.msg152772#msg152772 date=1148046125]
[code]
Private Sub getHandle() as long
[/code]
[/quote]
As something with a return value, isn't it appropriate to declare it as a Function rather than as a Sub?
[/quote]

Correct, I don't think that's legal in VB either.
May 20, 2006, 12:27 AM
FrOzeN
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:
[code]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[/code]
May 20, 2006, 3:37 AM
dRAgoN
[quote author=J link=topic=15009.msg152725#msg152725 date=1148001247]
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 ".")

[code]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[/code]
[/quote]

You shoulden't use Err as a linefeed in VB6.
May 20, 2006, 8:41 AM
rabbit
If you're going to capture errors, CAPTURE them.  Using "On Error Goto label" and having nothing after "label" is almost as bad as using "On Error Resume Next".
May 20, 2006, 3:29 PM
ShaDoWDeM
yupper
May 21, 2006, 3:25 AM
warz
What is this program supposed to do?
May 21, 2006, 1:57 PM
ShaDoWDeM
anti-hack which i got done
May 22, 2006, 1:53 AM

Search