raptor25 Posted October 27, 2011 Share Posted October 27, 2011 Hi. I am trying to use a malwarebytes logfile to add up all the infected items and get a total. It seems like they are always found on lines 16-22 in the log: Memory Processes Infected: 0 Memory Modules Infected: 0 Registry Keys Infected: 0 Registry Values Infected: 0 Registry Data Items Infected: 0 Folders Infected: 0 Files Infected: 0 Is there a function that will get the last number of each lines 16-22 so that they can be added up for a total? Thanks Link to comment Share on other sites More sharing options...
rcmaehl Posted October 27, 2011 Share Posted October 27, 2011 (edited) FIleReadLine followed by a StringRegExp should work for you EDIT: Thanks kaotbliss for noticing the StringRight. StringRegExp is much better in this case however I don't think anyone would really have more than 99 of each Infected Processes/Keys/etc, then again... Edited October 27, 2011 by rcmaehl My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.My Projects WhyNotWin11Cisco Finesse, Github, IRC UDF, WindowEx UDF Link to comment Share on other sites More sharing options...
kaotkbliss Posted October 27, 2011 Share Posted October 27, 2011 StringRight is a bad choice because the number can be any number of digits long StringRegExp would be the better choice 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
JohnOne Posted October 27, 2011 Share Posted October 27, 2011 Here is a very basic example of what you want, there are many other ways to achieve the same result. Look at examples of some other functions mentioned and adapt them. #include <String.au3> ; Include the String UDFs library #include <Array.au3> ; Include the Array UDFs library for visual purpose $str = "Memory Processes Infected: 10" & @CRLF _ ; Create a string representation of your file & "Memory Modules Infected: 2" & @CRLF _ & "Registry Keys Infected: 100" & @CRLF _ & "Registry Values Infected: 6" & @CRLF _ & "Registry Data Items Infected: 0" & @CRLF _ & "Folders Infected: 5" & @CRLF _ & "Files Infected: 2" $astr = _StringBetween($str, ": ", @CRLF) ; Create an array of matches _ArrayDisplay($astr) ; Just to show what you are dealing with Local $result = 0 ; Create a variable to hold the result For $i = 0 To UBound($astr) -1 ; Add array matches via a loop $result += Int($astr[$i]) Next MsgBox(0,0,$result) ; Show result AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
kaotkbliss Posted October 27, 2011 Share Posted October 27, 2011 I stand corrected, stringbetween would be a lot simpler than stringregexp 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
raptor25 Posted October 27, 2011 Author Share Posted October 27, 2011 Okay. Well I have a log called mbam.txt in the script directory and have tried using stringregexp to get anything with a digit at the end of each line and return an array to just to learn how to use it but I get nothing on this. $hFile = FileOpen(@ScriptDir & "\mbam.txt", 0) While 1 $line = FileReadLine($hFile) If @error = -1 Then ExitLoop $text = StringRegExp($line, "[:digit:]$", 3) For $i = 0 To UBound($text) - 1 MsgBox(0, 'Info', $text[$i]) Next Wend FileClose($hFile) Any suggestions on what I am doing wrong on this? Link to comment Share on other sites More sharing options...
JohnOne Posted October 27, 2011 Share Posted October 27, 2011 Try this#include <String.au3> $hFile = FileOpen(@ScriptDir & "\mbam.txt", 0) $lines = '' For $i = 16 to 22 $lines &= FileReadLine($hFile,$i) Wend FileClose($hFile) $astr = _StringBetween($lines, ": ", @CRLF) ; Create an array of matches Local $result = 0 ; Create a variable to hold the result For $i = 0 To UBound($astr) -1 ; Add array matches via a loop $result += Int($astr[$i]) Next MsgBox(0,0,$result) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
raptor25 Posted October 27, 2011 Author Share Posted October 27, 2011 Nope. I just get a 0 when I run that one even though there are numbers to add up in the log. (I had to change that Wend to Next for the for loop). Thanks for you help so far though. Link to comment Share on other sites More sharing options...
raptor25 Posted October 27, 2011 Author Share Posted October 27, 2011 I wonder if the $lines &= FileReadLine($hFile,$i) isn't putting a @CRLF to find to parse it..? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 27, 2011 Moderators Share Posted October 27, 2011 raptor25, By using StringRegExp directly you avoid that problem: #include <Array.au3> ; Include the Array UDFs library for visual purpose $str = "Memory Processes Infected: 10" & @CRLF _ ; Create a string representation of your file & "Memory Modules Infected: 2" & @CRLF _ & "Registry Keys Infected: 100" & @CRLF _ & "Registry Values Infected: 6" & @CRLF _ & "Registry Data Items Infected: 0" & @CRLF _ & "Folders Infected: 5" & @CRLF _ & "Files Infected: 2" $astr = StringRegExp($str, "\d+", 3) ; Create an array of matches _ArrayDisplay($astr) Local $result = 0 ; Create a variable to hold the result For $i = 0 To UBound($astr) - 1 ; Add array matches via a loop $result += Int($astr[$i]) Next MsgBox(0, "Result", $result) ; Show result Any better? M23 P.S. stringbetween would be a lot simpler than stringregexpWhat do you think _StringBetween uses internally? Take a look inside String.au3! Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
kaotkbliss Posted October 27, 2011 Share Posted October 27, 2011 Ahh. I've never used StringBetween before and I'm horrible with stringregexp, so my thinking is just entering the 2 characters that surround what you want is a lot easier than formulating an expression to grab the numbers after a : 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 27, 2011 Moderators Share Posted October 27, 2011 kaotkbliss, I'm horrible with stringregexMy normal response to that is suggest ressions.info/tutorial.html'>this site - the best SRE tutorial I have come across. Seriously, it is worth getting to grips with SREs - even to the basic level I have managed so far. They can prove extremely useful - and at times they are absolutely essential. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JohnOne Posted October 27, 2011 Share Posted October 27, 2011 I keep threatening to get stuck into regexp, but just wind up staring at the screen like its enigma matrix wrapped in a double helix. One day.. One day. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now