Jump to content

Can't describe it.


Geeky
 Share

Recommended Posts

Hi, there.

I'm working an a small script to clean a half-life 2 mod folder, for "viruses". Unfortunately it doesn't work as i want it to :nuke:

Whenever i run it, it just says that it found and deleted all the viruses, even though the viruses doesn't exist, in the folder.

Its a long one, but most of it is just copied and pasted :P

The code:

#include <GUIConstants.au3>
GUICreate( "Gmod Virus-Killah", 400, 300)
$path = GUICtrlCreateInput( "Path...", 30, 20, 250, 21)
$browse = GUICtrlCreateButton( "Browse...", 300, 20, 70, 21)
$results = GUICtrlCreateEdit( "", 30, 60, 340, 200, $ES_READONLY)
$Search = GUICtrlCreateButton( "Search & Destroy", 130, 270, 140, 21)


GUISetState(@SW_SHOW)


While 1
    $msg = GUIGetMsg()

    Select
        
            Case $msg = $browse
            $browsepath = FileSelectFolder( "Select your Gmod9 folder", "", 2)
        
        GUICtrlSetData($path, $browsepath)
        
        Case $msg = $Search
            
            GUICtrlSetData ($results, "Scanning for lua viruses...",1)

            $1 = FileExists( $path &"/lua/init/ULM.lua")
            If $1 = "ULM.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: ULM.lua",1)
            FileDelete($path &"/lua/init/ULM.lua")
        EndIf
        
                    $2 = FileExists( $path &"/lua/init/UFM.lua")
            If $2 = "UFM.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: UFM.lua",1)
            FileDelete($path &"/lua/init/UFM.lua")
        EndIf
        
                    $3 = FileExists( $path &"/lua/init/UCM.lua")
            If $3 = "UCM.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: UCM.lua",1)
            FileDelete($path &"/lua/init/UCM.lua")
        EndIf
        
                    $4 = FileExists( $path &"/lua/init/UEM.lua")
            If $4 = "UEM.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: UEM.lua",1)
                    FileDelete($path &"/lua/init/UEM.lua")
        EndIf
        
                    $5 = FileExists( $path &"/lua/init/USM.lua")
            If $5 = "USM.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: USM.lua",1)
                        FileDelete($path &"/lua/init/USM.lua")
        EndIf
        
                    $6 = FileExists( $path &"/lua/init/URM.lua")
            If $6 = "URM.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: URM.lua",1)
            FileDelete($path &"/lua/init/URM.lua")
EndIf
                    
                    $7 = FileExists( $path &"/lua/init/UNM.lua")
            If $7 = "UNM.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: UNM.lua",1)
                        FileDelete($path &"/lua/init/UNM.lua")
        EndIf
                            $8 = FileExists( $path &"/lua/init/UPM.lua")
            If $8 = "UPM.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: UPM.lua",1)
                        FileDelete($path &"/lua/init/UPM.lua")
        EndIf
                            $9 = FileExists( $path &"/lua/init/ah.lua")
            If $9 = "ah.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: ah.lua",1)
                        FileDelete($path &"/lua/init/ah.lua")
        EndIf
                            $10 = FileExists( $path &"/lua/init/ERAT.lua")
            If $10 = "ERAT.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: ERAT.lua",1)
                        FileDelete($path &"/lua/init/ERAT.lua")
        EndIf
                            $11 = FileExists( $path &"/lua/init/oma2r3fxc6g.lua")
            If $11 = "om2r3fxc6g.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: oma2r3fxc6g.lua",1)
                        FileDelete($path &"/lua/init/oma2r3fxc6g.lua")
        EndIf
                            $12 = FileExists( $path &"/lua/init/racehook*.lua")
            If $12 = "racehook.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: racehook#.lua",1)
                        FileDelete($path &"/lua/init/racehook#.lua")
        EndIf
                            $13 = FileExists( $path &"/lua/init/racehook3.lua")
            If $13 = "racehook3.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: racehook3.lua",1)
                        FileDelete($path &"/lua/init/racehook3.lua")
        EndIf
                            $14 = FileExists( $path &"/lua/init/Z.lua")
            If $14 = "Z.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: Z.lua",1)
                        FileDelete($path &"/lua/init/Z.lua")
        EndIf
                            $15 = FileExists( $path &"/lua/init/urn.lua")
            If $15 = "urn.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: urn.lua",1)
                        FileDelete($path &"/lua/init/urn.lua")
        EndIf
                            $16 = FileExists( $path &"/lua/init/initialize.lua")
            If $16 = "initialize.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: initialize.lua",1)
                        FileDelete($path &"/lua/init/initialize.lua")
        EndIf
                            $17 = FileExists( $path &"/lua/init/luaupdate10.lua")
            If $17 = "luaupdate10.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: luaupdate10.lua",1)
                        FileDelete($path &"/lua/init/luaupdate.lua")
        EndIf
                            $18 = FileExists( $path &"/lua/init/makecode.lua")
            If $18 = "makecode.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: makecode.lua",1)
                        FileDelete($path &"/lua/init/makecode.lua")
        EndIf
        
                            $19 = FileExists( $path &"/lua/init/omgwtfbbq.lua")
            If $19 = "omgwtfbbq.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: omgwtfbbq.lua",1)
                        FileDelete($path &"/lua/init/wtfbbq.lua")
        EndIf
                                    $20 = FileExists( $path &"/lua/init/GMXinit.lua")
            If $20 = "GMXinit.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: gmxinit.lua",1)
                        FileDelete($path &"/lua/init/gmxinit.lua")
        EndIf
                                    $21 = FileExists( $path &"/lua/init/test.lua")
            If $21 = "test.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: test.lua",1)
                        FileDelete($path &"/lua/init/test.lua")
        EndIf
                                    $22 = FileExists( $path &"/lua/init/vmfloaderclient.lua")
            If $22 = "vmfloaderclient.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: vmfloaderclient.lua",1)
                        FileDelete($path &"/lua/init/vmfloaderclient.lua")
        EndIf
                                    $23 = FileExists( $path &"/lua/init/ulxboost.lua")
            If $23 = "ulxboost.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: ulxboost.lua",1)
                        FileDelete($path &"/lua/init/ulxboost.lua")
        EndIf
                                    $24 = FileExists( $path &"/lua/init/antivirus_update.lua")
            If $24 = "antivirus_update.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: antivirus_update.lua",1)
                        FileDelete($path &"/lua/init/antivirus_update.lua")
        EndIf
                                    $25 = FileExists( $path &"/lua/init/ULM2.lua")
            If $25 = "ULM2.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: ULM2.lua",1)
                        FileDelete($path &"/lua/init/ULM2.lua")
        EndIf
                                    $26 = FileExists( $path &"/lua/init/zzz.lua")
            If $26 = "zzz.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: zzz.lua",1)
                        FileDelete($path &"/lua/init/zzz.lua")
        EndIf
                                    $27 = FileExists( $path &"/lua/init/lw.lua")
            If $27 = "lw.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: lw.lua",1)
                        FileDelete($path &"/lua/init/lw.lua")
        EndIf
                                    $28 = FileExists( $path &"/lua/init/lw_2.lua")
            If $28 = "lw_2.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: lw_2.lua",1)
                        FileDelete($path &"/lua/init/lw_2.lua")
        EndIf
                                    $29 = FileExists( $path &"/lua/init/spoon.lua")
            If $29 = "spoon.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: spoon.lua",1)
                        FileDelete($path &"/lua/init/spoon.lua")
        EndIf
                                    $30 = FileExists( $path &"/lua/init/teaspoon.lua")
            If $30 = "teaspoon.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: teaspoon.lua",1)
                        FileDelete($path &"/lua/init/teaspoon.lua")
        EndIf
                                    $31 = FileExists( $path &"/lua/init/Facehook.lua")
            If $31 = "Facehook.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: facehook.lua",1)
                        FileDelete($path &"/lua/init/facehook.lua")
        EndIf
                                    $32 = FileExists( $path &"/lua/init/vtfplugin.lua")
            If $32 = "vtfplugin.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: vtfplugin.lua",1)
                        FileDelete($path &"/lua/init/vtfplugin.lua")
            Filedelete( $path &"")
        EndIf
                                    $33 = FileExists( $path &"/lua/init/gm_hockeywrite.lua")
            If $33 = "gm_hockeywrite.lua" Then
            GUICtrlSetData ($results, @CRLF &"Found and deleted: gm_hockeywrite.lua",1)
                        FileDelete($path &"/lua/init/gm_hockeywrite.lua")
        EndIf

        If $1 and $2 and $3 and $4 and $5 and $6 and $7 and $8 and $9 and $10 and $11 and $12 and $13 and $14 and $15 and $16 and $17 and $18 and $19 and $20 and $21 and $22 and $23 and $24 and $25 and $26 and $27 and $28 and $29 and $30 and $31 and $32 and $33 = -1 Then
        GUICtrlSetData ($results, "No virus found")

    EndIf
    GUICtrlSetData ($results, @CRLF &"Placed antivirus log in lua/init", 1)
    $log = FileOpen( $path &"\Antivirus_log.txt", 1)
        FileWriteLine( $path &"\Antivirus_log.txt", @CRLF & "---------------")
        FileWriteLine( $path &"\Antivirus_log.txt", @CRLF & "Antivirus Scan.")
        FileWriteLine( $path &"\Antivirus_log.txt", @CRLF & "---------------")
        FileWriteLine( $path &"\Antivirus_log.txt", @CRLF & "Scan Complete:")
        FileWriteLine( $path &"\Antivirus_log.txt", @CRLF & "Results:" & $results)
        FileClose($log)

    EndSelect

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

Thank you.

Link to comment
Share on other sites

Study the documetation for FileExists and see if you can find out what exactly it is

returning when a file exists and when it isn't. It's not the filename, that's for sure.

What you're doing right now is something like this :

If 0 = "tiss" Then MsgBox(64, "", "That's weird")
Edited by Helge
Link to comment
Share on other sites

My script worked before. I just found out why, I think i used FileFindFirstFile before, and thats why i made it like that.

I'll try and change it back to see what happens. Thanks for the help :P

Edited by Geeky
Link to comment
Share on other sites

It will work if you actually do as I told you to, which was to read what FileExists actually

is returning. Look at the example in the helpfile, modify it for your use, and it will work.

I'm giving you the answer for the problem you wanted to solve and you just ignore it.

Yay.

Link to comment
Share on other sites

My script worked before. I just found out why, I think i used FileFindFirstFile before, and thats why i made it like that.

I'll try and change it back to see what happens. Thanks for the help :P

You have more problems than that. You seem to use control IDs thinking they will contain the data from the control, like your use of $path without doing GuiCtrlRead($path).

This is reworked to use an array of files to check, but I only added the first five. It's untested, but should at least move you forward:

#include <GUIConstants.au3>
#include <array.au3>

; Create array of files to check for
Global $aFileList[1] = [0]
_ArrayAdd($aFileList, "/lua/init/ULM.lua")
_ArrayAdd($aFileList, "/lua/init/UFM.lua")
_ArrayAdd($aFileList, "/lua/init/UCM.lua")
_ArrayAdd($aFileList, "/lua/init/UEM.lua")
_ArrayAdd($aFileList, "/lua/init/USM.lua")

Global $sFoundList = ""

GUICreate( "Gmod Virus-Killah", 400, 300)
$path = GUICtrlCreateInput( "Path...", 30, 20, 250, 21)
$browse = GUICtrlCreateButton( "Browse...", 300, 20, 70, 21)
$results = GUICtrlCreateEdit("", 30, 60, 340, 200, $ES_READONLY)
$Search = GUICtrlCreateButton( "Search & Destroy", 130, 270, 140, 21)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE 
            ExitLoop
            
        Case $msg = $browse
            $browsepath = FileSelectFolder( "Select your Gmod9 folder", "", 2)
            GUICtrlSetData($path, $browsepath)
            
        Case $msg = $Search
            GUICtrlSetData($results, "Scanning for lua viruses...", 1)
            $FolderPath = GUICtrlRead($path)
            For $n = 1 To UBound($aFileList) - 1
                If FileExists($FolderPath & $aFileList[$n]) Then
                    FileDelete($FolderPath & $aFileList[$n])
                    $FoundList &= @CRLF & "Found and deleted: " & $FolderPath & $aFileList[$n]
                    GUICtrlSetData($results, $FoundList)
                EndIf
            Next
            
            If $FoundList = "" Then GUICtrlSetData($results, "No virus found")
                
            GUICtrlSetData($results, @CRLF & "Placed antivirus log in lua/init", 1)
            $log = FileOpen($FolderPath & "\Antivirus_log.txt", 1)
            FileWriteLine($log, @CRLF & "---------------")
            FileWriteLine($log, @CRLF & "Antivirus Scan.")
            FileWriteLine($log, @CRLF & "---------------")
            FileWriteLine($log, @CRLF & "Scan Complete:")
            FileWriteLine($log, @CRLF & "Results:" & $FoundList)
            FileClose($log)
    EndSelect   
WEnd

:nuke:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I've never used Arrays before, but i'll try and take a look at it.

As far as i can see what i need to do to make the script you posted work like i wanted mine to do, i need to add all the names to arrays, like you started?

Link to comment
Share on other sites

Okay, i've found a way (i think) to make updating the antivirus alot easier. Instead of having all the names in the script itself, i thought it would be better to have it in an external .txt document that everybody understands, and can add/remove viruses from. Now my question is; will this work?

$file = FileOpen( "Virusdb.txt", 0)

Global $aFileList[1] = [0]

Do
   $line = FileReadLine($file)
   
        If Not $line = "" Then


            _ArrayAdd($aFileList, "/lua/init/" & $line)
        EndIf

Until $line = ""

Global $sFoundList = ""
Edited by Geeky
Link to comment
Share on other sites

Ok, now i've spend a few hours on the script, and i can't find the damn error. My script looks like this now:

#include <GUIConstants.au3>
#include <array.au3>

; Create array of files to check for
Global $aFileList[1] = [0]

$file = FileOpen( "virusdb.txt", 0)
Do
   $line = FileReadLine($file)
   
        If Not $line = "" Then
            _ArrayAdd($aFileList, "/lua/init/"& $line &".lua")
        EndIf
Until $line = ""

Global $sFoundList = ""

GUICreate( "Gmod Virus-Killah", 400, 300)
$path = GUICtrlCreateInput( "Path...", 30, 20, 250, 21)
$browse = GUICtrlCreateButton( "Browse...", 300, 20, 70, 21)
$results = GUICtrlCreateEdit("", 30, 60, 340, 200, $ES_READONLY)
$Search = GUICtrlCreateButton( "Search & Destroy", 130, 270, 140, 21)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
           
        Case $msg = $browse
            $browsepath = FileSelectFolder( "Select your Gmod9 folder", "", 2)
            GUICtrlSetData($path, $browsepath)
           
        Case $msg = $Search
            GUICtrlSetData($results, "Scanning for lua viruses...", 1)
            $FolderPath = GUICtrlRead($path)
            For $n = 1 To UBound($aFileList) - 1
                If FileExists($FolderPath & $aFileList[$n]) Then
                    FileDelete($FolderPath & $aFileList[$n])
                    $FoundList = @CRLF & "Found and deleted: " & $FolderPath & $aFileList[$n]
                    GUICtrlSetData($results, $FoundList)
                EndIf
            Next
           
            If $FoundList = "" Then GUICtrlSetData($results, "No virus found")
               
            GUICtrlSetData($results, @CRLF & "Placed antivirus log in lua/init", 1)
            $log = FileOpen($FolderPath & "\Antivirus_log.txt", 1)
            FileWriteLine($log, @CRLF & "---------------")
            FileWriteLine($log, @CRLF & "Antivirus Scan.")
            FileWriteLine($log, @CRLF & "---------------")
            FileWriteLine($log, @CRLF & "Scan Complete:")
            FileWriteLine($log, @CRLF & "Results:" & $FoundList)
            FileClose($log)
    EndSelect   
WEnd

When i press the Search & Destroy button, it says that $Foundlist wasn't declared :S

Anyone who can help me?

(sorry for triple post :P)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...