-
Jun 22nd, 2018, 08:06 AM
#1
Thread Starter
Member
I want to use a Function inside a sub, how is this done?
I have a Private Function called GetMD5String. All this function does, is it scans for files that are being opened, and if their MD5 matches with a database, an alert is shown saying
Everything works well, however, I have one issue.
I need to refresh the GetMD5String function so that my program continues to have GetMD5String monitoring the files being opened. The way I think is the most practical way of doing it, is putting my GetMD5String function into a Timer1_Tick sub so my program can check every set interval. I've tried this, but I'm getting this error:
Argument not specified for parameter 'strFilename' of 'Private Function GetMD5String(strFilename As String) As String
I get this error when I try to pass GetMD5String() into Timer1_Tick
Is there any way I can refresh GetMD5String without needing to use a Timer? Or, by using a Timer but a different way of doing so?
GetMD5String code:
Code:
Private Function GetMD5String(ByVal strFilename As String) As String
Dim MD5 As String = GetMD5String(strFilename)
Dim cMD5 = Security.Cryptography.MD5.Create
Dim bytHash As Byte()
Dim sb As New System.Text.StringBuilder
Dim scanbox As New TextBox
scanbox.Text = My.Computer.FileSystem.ReadAllText("viruslist.txt").ToString
Me.OpenFileDialog1.FileName = strFilename
Using cStream As New IO.FileStream(strFilename, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
bytHash = cMD5.ComputeHash(cStream)
End Using
For Each c In bytHash
sb.Append(c.ToString("X2"))
Next
If scanbox.Text.Contains(sb.ToString) Then
Detect.ShowDialog()
WriteToLog("Malicious exploit detected.")
Quarantinevb.ListBox1.Items.Add(strFilename)
End If
Return sb.ToString
End Function
Thanks
-
Jun 22nd, 2018, 08:41 AM
#2
Lively Member
Re: I want to use a Function inside a sub, how is this done?
Code:
Private Function GetMD5String(ByVal strFilename As String) As String
Dim MD5 As String = GetMD5String(strFilename)
Dim cMD5 = Security.Cryptography.MD5.Create
Dim bytHash As Byte()
Dim sb As New System.Text.StringBuilder
Dim scanbox As New TextBox
scanbox.Text = My.Computer.FileSystem.ReadAllText("viruslist.txt").ToString
Me.OpenFileDialog1.FileName = strFilename
Using cStream As New IO.FileStream(strFilename, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
bytHash = cMD5.ComputeHash(cStream)
End Using
For Each c In bytHash
sb.Append(c.ToString("X2"))
Next
If scanbox.Text.Contains(sb.ToString) Then
Detect.ShowDialog()
WriteToLog("Malicious exploit detected.")
Quarantinevb.ListBox1.Items.Add(strFilename)
End If
Return sb.ToString
End Function
I want to use a Function inside a sub, how is this done?
This is not a Sub it IS the function.
PS: When you declare the function with (ByVal strFilename As String) you are creating a NEW var called strFilename.
You should assign a value before using it it.
KBConsole
Last edited by KBConsole; Jun 22nd, 2018 at 08:45 AM.
-
Jun 22nd, 2018, 08:43 AM
#3
Re: I want to use a Function inside a sub, how is this done?
Your previous thread in which you basically asked the same question had a very complete explanation of the error you are receiving.
http://www.vbforums.com/showthread.p...ing)-As-String
Your idea of a timer with a 1 second interval is not necessarily the most practical way of doing it. That would result in programs being allowed to execute for an average of at least 0.5 seconds before your program can terminate them, which may be long enough for some payload to take place.
A more practical way of doing it is for your program to hook into the operating system so that your program sits in between the user initiating the execution of the program and the program actually executing, so that your program can scan the file and control whether it is executed or not. That might well be above and beyond your current coding capabilities.
If your goal is just tinkering for the sake of learning, then the absolute best of luck to you, and have fun with it.
-
Jun 22nd, 2018, 08:38 PM
#4
Thread Starter
Member
Re: I want to use a Function inside a sub, how is this done?
How do I hook it to the OS?
-
Jun 22nd, 2018, 09:41 PM
#5
Re: I want to use a Function inside a sub, how is this done?
Originally Posted by Modulus
How do I hook it to the OS?
You could run it as a Scheduled Task to fire every so often, could have it run at Windows Startup via the Windows Registry, or you could install it as a Service with startup with the OS.
-
Jun 23rd, 2018, 02:24 AM
#6
Thread Starter
Member
Re: I want to use a Function inside a sub, how is this done?
Originally Posted by JuggaloBrotha
You could run it as a Scheduled Task to fire every so often, could have it run at Windows Startup via the Windows Registry, or you could install it as a Service with startup with the OS.
Do you have any references on how to do this?
-
Jun 23rd, 2018, 09:51 AM
#7
Re: I want to use a Function inside a sub, how is this done?
No offense, but since you now have three different threads where you are still reportedly struggling with the same concept of calling a function that requires a parameter be passed, I don't believe you are currently skilled to do anything like what you are asking about.
The only thing providing you answers to your questions above would do is result in more questions, since those answers would involve concepts that are likely beyond your current scope of programming knowledge.
First, figure out how to call a function and pass a parameter. Then, stick with your current plan of using a timer and at least get the program functional. Then, do more reading and research and coding and keep improving your program as you learn new things.
Good luck.
Last edited by OptionBase1; Jun 23rd, 2018 at 09:55 AM.
-
Jun 23rd, 2018, 10:02 AM
#8
Re: I want to use a Function inside a sub, how is this done?
I have to agree with OptionBase here. You're asking questions that are, on their face, a bit nonsensical and then, when people make basic suggestions about what you should do, the concepts seem to mean nothing to you. I would suggest that you need to learn the basics of VB.NET programming first. There's a tutorial link in my signature below and I would suggest that you follow it and work through the entire tutorial before doing anything else. Calling methods is one of the absolute fundamentals of VB.NET programming and it's something you should know how to do before posting anything here. If you have a question about something that is difficult to do, we should be able to tell you to call a method as part of the solution and you should be able to do that, which is obviously not the case at the moment.
-
Jun 23rd, 2018, 11:31 AM
#9
Re: I want to use a Function inside a sub, how is this done?
Originally Posted by Modulus
Do you have any references on how to do this?
Google
-
Jun 26th, 2018, 09:22 AM
#10
Re: I want to use a Function inside a sub, how is this done?
Originally Posted by jmcilhinney
I would suggest that you need to learn the basics of VB.NET programming first. There's a tutorial link in my signature below and I would suggest that you follow it and work through the entire tutorial before doing anything else.
jmcilhinney, your tutorial links don't always work, but they've been archived by the Wayback Machine:
Microsoft Visual Basic .NET tutorials for beginners
Visual C# .NET for complete beginners
-
Jun 26th, 2018, 09:25 AM
#11
Re: I want to use a Function inside a sub, how is this done?
Originally Posted by Peter Porter
jmcilhinney, your tutorial links don't always work
That's odd. They've never not worked for me and they are working for me now.
-
Jun 26th, 2018, 10:07 AM
#12
Re: I want to use a Function inside a sub, how is this done?
They work for me, too. What are you seeing when they don't work? Do you get something like a 404, or an error?
My usual boring signature: Nothing
-
Jun 26th, 2018, 10:15 AM
#13
Re: I want to use a Function inside a sub, how is this done?
The site has been having issues. First I couldn't connect, and when I was able to, some of the tutorials were 404 pages, but everything seems to be working now.
-
Jun 26th, 2018, 01:59 PM
#14
Re: I want to use a Function inside a sub, how is this done?
Originally Posted by Peter Porter
The site has been having issues. First I couldn't connect, and when I was able to, some of the tutorials were 404 pages, but everything seems to be working now.
Were you logged into the forum at the time of clicking?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|