Scan MD5 in Process Running vb.net - vb.net

I Have Antivirus Form
i want scan the application running and found the md5 hash and not the process (only MD5) and i want do some action if the md5 same with my TextBox, anyone can help me how to do that?
Thank you before
Sorry for my bad english.

you can get the filename by making an array of the running processes
Then you can build a function that does an MD5 of all processes found.
Maybe if you split your idea into many small chunks you will get forward easier.
I'd try to create an array of the processes and their paths (see my snippet).
Then you can write that to another Array where you add the checksum that you calculated in the line and use a split-character like ";"
So one line of your array could be "C:\windows\system32\cmd.exe;afd4383f8d8fd"
Then you can loop through the processes, do an MD5 of your process and then look it up in the array you wrote, it will lookup the Filepath as ID and then it will compare the MD5 in the array with the one you calculated again.
When you put that on a timer with a tick of like 5 seconds you could kind of "seal " your application-sums and let a warning appear if there is a mismatch or something else.
Dim Processfinder() As Process = System.Diagnostics.Process.GetProcesses()
For Each pr In Processfinder
Dim Prstring As String = pr.StartInfo.FileName.ToString
Next
Since i built something similar a while ago:
You have to be aware that you cannot see all processes if your program is 32 bit and your OS is 64 bit.

Related

Why is numpy save not immediate, and can it be forced to save immediately?

I thought this question would have been asked already, but I can't find it, so here goes: I've noticed that numpy.save commands only trigger, i.e. the file to-be-created is actually created, after the entire code has finished running. This is bad when the code takes days or weeks to run, and I want to pin down exactly which function, and what arguments into the function, are causing the bottleneck.
There is a similar issue with the print() command; it doesn't write to the output file immediately but rather waits until the entire code is finished before writing. I can force it to write immediately with this code:
def printnow(*messages):
w=open("output.log","a")
for message in messages:
w.write(str(message))
w.write(" ")
w.write("\n")
w.close()
I was wondering whether it's possible to do an analogous thing, i.e. force an immediate save, for numpy arrays. No need for appending; overwriting with the current value of the numpy array is fine.
If it makes a difference, I'm not running the code on my personal computer but a group server, which I issue commands to and check on using Putty and WinSCP.
Thanks
Edit: I tried another package, shelve, and it encounters the same problem. I create a global variable called function_calls and initialize it to 0. Then, at the start of the function that I suspect is causing the bottleneck, I put in the following code:
global function_calls
file='function_inputs'+str(function_calls)
function_shelf=shelve.open(file,'n')
for key in dir():
function_shelf[key]=locals()[key]
function_calls+=1
This code is intended to create a new file that saves the function inputs, each time the function is called. Unfortunately, 9 hours into starting the run, no files have been created. So I suspect Python is just waiting until the whole run is finished before creating the files I asked it to.

Is there a method for arudino to store values into different variables as soon as they come over a serial connection?

I have built an android app that will send a string of values (using getbyte()_) across a serial connection. I would like each of these values to be stored in a seperate variable/
For example:
a list of numbers like this:
10004056700003
are sent across the connection.
there are a bunch of variables on the arduino side:
A,B,C,D.... etc
i would like to be able to do this:
A = 1
B = 0
C = 0
D = 0
E = 4
F= 0
.... and so on. i will then use these variables to run a certain sequence of functions on the arduino. In this sense the android application is just to control the arduino.
Thanks for the help! :D
Serial communication usually happens byte-wise.
So if you want to transfer a sequence of numbers (>255) the easiest way is to send each digit as a byte.
On the receiving end you basically have two options.
a) you read each byte and do something with it befor reading the next byte.
b) you read the bytes into a buffer array and do something with it later.
If you want to minimize the number of bytes transferred you of course can split the number value into several bytes instead of transferring each digit.
Try sending the data as String, and then you can access each character of the String using the method: StringVariableName.charAt(pos);
With this approach, your code will be more readable.
Check out charAt function here.

VB.NET, best practice for sorting concurrent results of threadpooling?

In short, I'm trying to "sort" incoming results of using threadpooling as they finish. I have a functional solution, but there's no way in the world it's the best way to do it (it's prone to huge pauses). So here I am! I'll try to hit the bullet points of what's going on/what needs to happen and then post my current solution.
The intent of the code is to get information about files in a directory, and then write that to a text file.
I have a list (Counter.ListOfFiles) that is a list of the file paths sorted in a particular way. This is the guide that dictates the order I need to write to the text file.
I'm using a threadpool to collect the information about each file, create a stringbuilder with all of the text ready to write to the text file. I then call a procedure(SyncUpdate, inlcluded below), send the stringbuilder(strBld) from that thread along with the name of the path of the file that particular thread just wrote to the stringbuilder about(Xref).
The procedure includes a synclock to hold all the other threads until it finds a thread passing the correct information. That "correct" information being when the xref passed by the thread matches the first item in my list (FirstListItem). When that happens, I write to the text file, delete the first item in the list and do it again with the next thread.
The way I'm using the monitor is probably not great, in fact I have little doubt I'm using it in an offensively wanton manner. Basically while the xref (from the thread) <> the first item in my list, I'm doing a pulseall for the monitor. I originally was using monitor.wait, but it would eventually just give up trying to sort through the list, even when using a pulse elsewhere. I may have just been coding something awkwardly. Either way, I don't think it's going to change anything.
Basically the problem comes down to the fact that the monitor will pulse through all of the items it has in the queue, when there's a good chance the item I am looking for probably got passed to it somewhere earlier in the queue or whatever and it's now going to sort through all of the items again before looping back around to find a criteria that matches. The result of this is that my code will hit one of these and take a huge amount of time to complete.
I'm open to believing I'm just using the wrong tool for the job, or just not using tool I have correctly. I would strongly prefer some sort of threaded solution (unsurprisingly, it's much faster!). I've been messing around a bit with the Parallel Task functionality today, and a lot of the stuff looks promising, but I have even less experience with that vs. threadpool, and you can see how I'm abusing that! Maybe something with queue? You get the idea. I am directionless. Anything someone could suggest would be much appreciated. Thanks! Let me know if you need any additional information.
Private Sub SyncUpdateResource(strBld As Object, Xref As String)
SyncLock (CType(strBld, StringBuilder))
Dim FirstListitem As String = counter.ListOfFiles.First
Do While Xref <> FirstListitem
FirstListitem = Counter.ListOfFiles.First
'This makes the code much faster for reasons I can only guess at.
Thread.Sleep(5)
Monitor.PulseAll(CType(strBld, StringBuilder))
Loop
Dim strVol As String = Form1.Volname
Dim strLFPPath As String = Form1.txtPathDir
My.Computer.FileSystem.WriteAllText(strLFPPath & "\" & strVol & ".txt", strBld.ToString, True)
Counter.ListOfFiles.Remove(Xref)
End SyncLock
End Sub
This is a pretty typical multiple producer, single consumer application. The only wrinkle is that you have to order the results before they're written to the output. That's not difficult to do. So let's let that requirement slide for a moment.
The easiest way in .NET to implement a producer/consumer relationship is with BlockingCollection, which is a thread-safe FIFO queue. Basically, you do this:
In your case, the producer threads get items, do whatever processing they need to, and then put the item onto the queue. There's no need for any explicit synchronization--the BlockingCollection class implementation does that for you.
Your consumer pulls things from the queue and outputs them. You can see a really simple example of this in my article Simple Multithreading, Part 2. (Scroll down to the third example if you're just interested in the code.) That example just uses one producer and one consumer, but you can have N producers if you want.
Your requirements have a little wrinkle in that the consumer can't just write items to the file as it gets them. It has to make sure that it's writing them in the proper order. As I said, that's not too difficult to do.
What you want is a priority queue of some sort onto which you can place an item if it comes in out of order. Your priority queue can be a sorted list or even just a sequential list if the number of items you expect to get out of order isn't very large. That is, if you typically have only a half dozen items at a time that could be out of order, then a sequential list could work just fine.
I'd use a heap because it performs well. The .NET Framework doesn't supply a heap, but I have a simple one that works well for jobs like this. See A Generic BinaryHeap Class.
So here's how I'd write the consumer (the code is in pseudo-C#, but you can probably convert it easily enough).
The assumption here is that you have a BlockingCollection called sharedQueue that contains the items. The producers put items on that queue. Consumers do this:
var heap = new BinaryHeap<ItemType>();
foreach (var item in sharedQueue.GetConsumingEnumerable())
{
if (item.SequenceKey == expectedSequenceKey)
{
// output this item
// then check the heap to see if other items need to be output
expectedSequenceKey = expectedSequenceKey + 1;
while (heap.Count > 0 && heap.Peek().SequenceKey == expectedSequenceKey)
{
var heapItem = heap.RemoveRoot();
// output heapItem
expectedSequenceKey = expectedSequenceKey + 1;
}
}
else
{
// item is out of order
// put it on the heap
heap.Insert(item);
}
}
// if the heap contains items after everything is processed,
// then some error occurred.
One glaring problem with this approach as written is that the heap could grow without bound if one of your consumers crashes or goes into an infinite loop. But then, your other approach probably would suffer from that as well. If you think that's an issue, you'll have to add some way to skip an item that you think won't ever be forthcoming. Or kill the program. Or something.
If you don't have a binary heap or don't want to use one, you can do the same thing with a SortedList<ItemType>. SortedList will be faster than List, but slower than BinaryHeap if the number of items in the list is even moderately large (a couple dozen). Fewer than that and it's probably a wash.
I know that's a lot of info. I'm happy to answer any questions you might have.

How do i start Process iteratively in VB.NET? or change argument dynamically

i have used following code to repeat a process creation/close iteratively
dim vProcessInfo as new ProcessInfo
For i= 1 to 100
dim p as new Process
vProcessInfo.Arguments = "some"+i.toString()
p.StartInfo = vProcessInfo
p.Start()
p.WaitForExit()
p.Close()
Next i
the above code worked for me successfully. but it takes too much time for process creation and dispose. i had to change process argument dynamically in the iteration. is there any way to change the process argument dynamically. or is there any better method to reduce time. pls help me
"Is there any way to change the process argument dynamically" - do you mean you want to start one process, and change its command line arguments after it's started? No, you can't do that - but you could communicate with it in other ways, for example:
Using standard input/output (e.g. write lines of text to its standard input)
Using files (e.g. you write to a file, it monitors the directory, picks up the file and processes it)
Using named pipes or sockets
Creating a process is a relatively slow operation. You can't easily speed that up - but if you can change your process in some way like the above, and just launch it once, that should make it a lot faster.

Get most frequently used applications in VB.NET

Is there a way that I can get the most used applications via VB.NET? I'm developing a sort of hobby project as a quick launcher kind of thing and thought this would sit perfectly on the main form.
If possible, would somebody be able to explain to me how add/remove applications manages to get the frequency of used applications? It would be good if I could get it in a list like the XP/Vista start menu as well.
Any guidance would be greatly appreciated. :)
It looks like you can find information on how often a program is run in the registry key:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\
There's more explanation here and a .NET program here that you could reverse engineer to get at the count values using VB.Net.
This might be a decent place to start. It seems like windows does a crappy job of determining frequency of applications use.
http://blogs.msdn.com/oldnewthing/archive/2004/07/09/178342.aspx
According to this posting the information is stored in the first 28 bytes of the SlowInfoCache Registry value found at the following key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Management\ARPCache
The format of the value is (in VB.Net):
Structure SlowInfoCache
Dim cLen As Integer ' size of the SlowInfoCache (552 bytes)
Dim Flag As Boolean ' has a name
Dim Size As Long ' program size in bytes
Dim LastUsed As Long ' API-style FILETIME
Dim Frequency As Integer ' 0-2 = rarely; 3-9 = occassionaly; 10+ = frequently
Dim Path As String ' remaining 524 bytes (max path of 260 + null) in unicode
End Structure
If you are interested in the other information displayed in Control Panel -> Add or Remove Programs you will find it listed for each product under the following Registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
Or course these solutions only track when the shell (explorer.exe) is used to start a program via a shortcut (all start menu items are shortcuts). That's why it is so inaccurate.
FWIW I'm not aware of any microcomputer operating system that tracks the execution frequency of program images.
I suggest for your launcher tool that you initially popule it with the shortcuts from the quicklaunch bar and just make it really easy for the user to configure rather than trying to do anything automatic - automatic stuff that doesn't work in the way the user expects is one of the most annoying aspects of user interface design.
One question you should ask yourself is how are you going to determine frequency?
Are you going to base it on the number of times and application is run, or based on the length of time that an application is run for?