Jump to content
Sign in to follow this  
SpotCheckBilly

Same Project in Question

Recommended Posts

SpotCheckBilly

Hey all,

Back again. I'm still working on the same project. With some assistance, I was able to populate my listbox from a text file using the _FileReadToArray along with the update Listbox UDF's.

In addition to being able to open log files that I have saved, I need to be able to paste them into the Listbox after copying them from a website. The problem is that I can't seem to get linebreaks, leaving the file displaying as one long line. The source code when I copied from a website page looks like this:

Logfile of Trend Micro HijackThis v2.0.2<br>Scan saved at 21:57:44, on 13/05/2009<br>Platform: Windows XP SP3 (WinNT 5.01.2600)<br>MSIE: Internet Explorer v7.00 (7.00.6000.16827)<br>Boot mode: Normal

which appears in my GUI as one long line minus the HTML tags. Of course, what it should look like is:

"Logfile of Trend Micro HijackThis v2.0.2

Scan saved at 21:57:44, on 13/05/2009

Platform: Windows XP SP3 (WinNT 5.01.2600)

MSIE: Internet Explorer v7.00 (7.00.6000.16827)

Boot mode: Normal"

Here's the code for my GUI:

;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#include <GuiListBox.au3>
#include <Misc.au3>
#include <String.au3>
#include <EditConstants.au3>
#include <Clipboard.au3>
#include<Array.au3>

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Main = GUICreate("DB Scanner", 641, 443)
GUISetFont(10, 400, 0, "Tahoma")
GUISetOnEvent($GUI_EVENT_CLOSE, "MainClose")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "MainMinimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "MainMaximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "MainRestore")
$Scan = GUICtrlCreateButton("Scan", 28, 359, 90, 35, 0)
GUICtrlSetFont(-1, 14, 400, 0, "Tahoma")
GUICtrlSetOnEvent(-1, "ScanClick")
GUICtrlSetTip(-1, "Scans Database for items in current Log")
$Add = GUICtrlCreateButton("Add", 185, 368, 75, 25, 0)
GUICtrlSetFont(-1, 12, 400, 0, "Tahoma")
GUICtrlSetOnEvent(-1, "AddClick")
GUICtrlSetTip(-1, "Add selection to Database")
$Clear = GUICtrlCreateButton("Clear", 302, 369, 75, 25, 0)
GUICtrlSetFont(-1, 12, 400, 0, "Tahoma")
GUICtrlSetOnEvent(-1, "ClearClick")
GUICtrlSetTip(-1, "Clears selected line")
$Button4 = GUICtrlCreateButton("Create Solution", 451, 360, 150, 35, 0)
GUICtrlSetFont(-1, 14, 400, 0, "Tahoma")
GUICtrlSetOnEvent(-1, "Button4Click")
GUICtrlSetTip(-1, "Generates Formatted Post")
$List1 = GUICtrlCreateList("", 4, 14, 625, 326, BitOR($WS_BORDER, $LBS_NOTIFY, $LBS_DISABLENOSCROLL, $WS_HSCROLL, $WS_VSCROLL))
GUICtrlSetBkColor(-1, 0xFFFBF0)
GUICtrlSetFont(-1, 12, 400, 0, "Tahoma")
GUICtrlSetOnEvent(-1, "List1Click")
$Log1 = GUICtrlCreateMenu("&Log")
GUICtrlSetOnEvent(-1, "Log1Click")
$Open = GUICtrlCreateMenuItem("Open (Ctrl+O)", $Log1)
GUICtrlSetOnEvent(-1, "OpenClick")
$Save = GUICtrlCreateMenuItem("Save (Ctrl+S)", $Log1)
GUICtrlSetOnEvent(-1, "SaveClick")
$SavAS = GUICtrlCreateMenuItem("Save As...", $Log1)
GUICtrlSetOnEvent(-1, "SavAsClick")
$Close = GUICtrlCreateMenuItem("Close Log", $Log1)
GUICtrlSetOnEvent(-1, "CloseClick")
$MenuItem1 = GUICtrlCreateMenuItem("Exit", $Log1)
GUICtrlSetOnEvent(-1, "MenuItem1Click")
$Edit = GUICtrlCreateMenu("&Edit")
GUICtrlSetOnEvent(-1, "EditClick")
$Copy = GUICtrlCreateMenuItem("Copy (Ctrl+C)", $Edit)
GUICtrlSetOnEvent(-1, "CopyClick")
$Paste = GUICtrlCreateMenuItem("Paste (Ctrl+V)", $Edit)
GUICtrlSetOnEvent(-1, "PasteClick")
$Delete = GUICtrlCreateMenuItem("Delete (Del)", $Edit)
GUICtrlSetOnEvent(-1, "DeleteClick")
$Database = GUICtrlCreateMenu("&Database")
GUICtrlSetOnEvent(-1, "DatabaseClick")
$Update = GUICtrlCreateMenuItem("Update Database", $Database)
GUICtrlSetOnEvent(-1, "UpdateClick")
$Solution = GUICtrlCreateMenu("&Solution")
GUICtrlSetOnEvent(-1, "Solutionclick")
$CREditor = GUICtrlCreateMenuItem("Cannes Fix Editor", $Solution)
GUICtrlSetOnEvent(-1, "CREditorClick")
$Translator = GUICtrlCreateMenuItem("Translator", $Solution)
GUICtrlSetOnEvent(-1, "TranslatorClick")
$Help = GUICtrlCreateMenu("&Help")
GUICtrlSetOnEvent(-1, "HelpClick")
$MenuItem2 = GUICtrlCreateMenuItem("Help Topics", $Help)
GUICtrlSetOnEvent(-1, "MenuItem2Click")
$About = GUICtrlCreateMenuItem("About DB Scanner", $Help)
GUICtrlSetOnEvent(-1, "AboutClick")
$List1context = GUICtrlCreateContextMenu($List1)
$Cop = GUICtrlCreateMenuItem("Copy Ctrl+C", $List1context)
GUICtrlSetOnEvent(-1, "CopClick")
$Past = GUICtrlCreateMenuItem("Paste Ctrl+V", $List1context)
GUICtrlSetOnEvent(-1, "PastClick")
$Google = GUICtrlCreateMenuItem("Google Ctrl+G", $List1context)
GUICtrlSetOnEvent(-1, "GoogleClick")
GUISetState(@SW_SHOW)
Dim $Main_AccelTable[8][2] = [["^o", $Open],["^s", $Save],["^c", $Copy],["^w", $Paste],["{DEL}", $Delete],["^c", $Cop],["^w", $Past],["^g", $Google]]
GUISetAccelerators($Main_AccelTable)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func ScanClick()

EndFunc  ;==>ScanClick
Func AboutClick()
    Run("AboutTEST.exe", @WorkingDir)
EndFunc  ;==>AboutClick
Func AddClick()

EndFunc  ;==>AddClick
Func Button4Click()

EndFunc  ;==>Button4Click
Func ClearClick()

EndFunc  ;==>ClearClick

Func CloseClick()
    GUICtrlSetData(7, "")
EndFunc  ;==>CloseClick
Func CopClick()

EndFunc  ;==>CopClick
Func CopyClick()

EndFunc  ;==>CopyClick
Func CREditorClick()

EndFunc  ;==>CREditorClick
Func DatabaseClick()

EndFunc  ;==>DatabaseClick
Func DeleteClick()

EndFunc  ;==>DeleteClick
Func EditClick()

EndFunc  ;==>EditClick
Func GoogleClick()

EndFunc  ;==>GoogleClick
Func HelpClick()

EndFunc  ;==>HelpClick
Func List1Click()

EndFunc  ;==>List1Click
Func Log1Click()

EndFunc  ;==>Log1Click
Func MainClose()
    Exit
EndFunc  ;==>MainClose
Func MainMaximize()

EndFunc  ;==>MainMaximize
Func MainMinimize()

EndFunc  ;==>MainMinimize
Func MainRestore()

EndFunc  ;==>MainRestore
Func MenuItem1Click()
    Exit
EndFunc  ;==>MenuItem1Click
Func MenuItem2Click()

EndFunc  ;==>MenuItem2Click

Func OpenClick()
    Dim $aRecords
    $hListbox = $List1
    $handle = FileOpenDialog("", "@workingDirOpenClick()", "Text Files (*.log; *.txt)")

    If Not _FileReadToArray($handle, $aRecords) Then
        MsgBox(4096, "Error", " Error reading log to Array   error:" & @error)
        Exit
    EndIf

; Add strings
    _GUICtrlListBox_BeginUpdate($hListbox)
    For $x = 1 To $aRecords[0]
        _GUICtrlListBox_AddString($hListbox, $aRecords[$x] & @CR)
    Next

    _GUICtrlListBox_UpdateHScroll($hListbox)
    _GUICtrlListBox_EndUpdate($hListbox)

EndFunc  ;==>OpenClick

Func PastClick()
$hListbox = $List1
    
$text = ClipGet()
$array = StringSplit($text , "<br>", 1)

; Add strings
    _GUICtrlListBox_BeginUpdate($hListbox)

_GUICtrlListBox_AddString($hListbox, $text & @CR)
    
    _GUICtrlListBox_UpdateHScroll($hListbox)
    _GUICtrlListBox_EndUpdate($hListbox)
EndFunc ;==>PastClick
Func PasteClick()

EndFunc  ;==>PasteClick
Func SavAsClick()

EndFunc  ;==>SavAsClick
Func SaveClick()

EndFunc  ;==>SaveClick
Func Solutionclick()

EndFunc  ;==>Solutionclick
Func TranslatorClick()

EndFunc  ;==>TranslatorClick
Func UpdateClick()

EndFunc  ;==>UpdateClick

As you can see, I tried to modify the code for the Open File function to make it work with tasting as well. I've tried every combination of UDF's and examples from theAutoIt help guide that seemed relevant to no avail.

If someone could get me pointed in the right direction, I would truly appreciate it. Thanks so much in advance. -- SCB


[font="Tahoma"]"I was worried 'bout rich and skinny, 'til I wound up poor and fat."-- Delbert McClinton[/font]

Share this post


Link to post
Share on other sites
GEOSoft

Use StringReplace() or StringRegExpReplace() to replace the <br> tags with @LF or @CRLF.

$sStr = StringRegExpReplace($sStr, "<br\s*/?>", @CRLF)
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
SpotCheckBilly

Thanks. I'll Work on that. :D

BTW--I always say there can never be enough Georges in the world. :D

George a.k.a. SpotCheckBilly


[font="Tahoma"]"I was worried 'bout rich and skinny, 'til I wound up poor and fat."-- Delbert McClinton[/font]

Share this post


Link to post
Share on other sites
SpotCheckBilly

I don't think I asked the correct question in my earlier post. I do have to paste the contents of the clipboard into my listbox, but it also has to end up in the same array format as is created by the first part of the "OpenClick()" command:

Dim $aRecords
    $hListbox = $List1
    $handle = FileOpenDialog("", "@workingDirOpenClick()", "Text Files (*.log; *.txt)")

    If Not _FileReadToArray($handle, $aRecords) Then
        MsgBox(4096, "Error", " Error reading log to Array   error:" & @error)
        Exit
    EndIf
because the same operations are going to be performed on it. So basically, if I'm not mistaken, the contents of the clipboard would be replacing what is returned by:

$handle = FileOpenDialog("", "@workingDirOpenClick()", "Text Files (*.log; *.txt)")

correct?

In truth, I could copy/paste the log file to an empty Notepad window, save it, then open it from within my GUI, but every unnecessary copying/pasting sequence just introduces more chances of information being left out.

Sorry that I didn't get it right (the question) the first time. That's what I get for trying to do things in too much of a hurry. -- SCB :D


[font="Tahoma"]"I was worried 'bout rich and skinny, 'til I wound up poor and fat."-- Delbert McClinton[/font]

Share this post


Link to post
Share on other sites
GEOSoft

Not sure if I have it straight yet or not. Instead of what I gave you try this.

$sStr = StringRegExpReplace($sStr, "<br\s*/?>", "~")

and change the PastClick function to

Func PastClick()
$hListbox = $List1
    
$text = ClipGet()
$array = StringSplit($text , "~", 1)

; Add strings
    _GUICtrlListBox_BeginUpdate($hListbox)

_GUICtrlListBox_AddString($hListbox, $text & @CR)
    
    _GUICtrlListBox_UpdateHScroll($hListbox)
    _GUICtrlListBox_EndUpdate($hListbox)
EndFunc;==>PastClick

That leaves a still unresolved problem, just what are you attempting to do with this line?

$handle = FileOpenDialog("", "@workingDirOpenClick()", "Text Files (*.log; *.txt)")

because it appears to be totally incorrect as far as the "@workingDirOpenClick()" part is concerned. First of all Directory Macros do not include a railing backslash so perheaps you wanted @WorkingDir & "\some\path". The macro portion shouldn't be quoted. Thern we arrive at the next part of that which is the "OpenClick()" part. What are you attempting to accomplish with that?


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
SpotCheckBilly

Hi George,

First, I'd like to thank you for your continued assistance. This project is probably too big for someone who's a complete newbie to programming, but I've spent too much time working on it to stop now. Maybe a little outline of the project will help. You may even be able to suggest a better way to go about it.

I spend most of my time helping people clean their machines of malware at several security sites. The diagnostic tools that we use produce log files that can get quite long and I am moderately vision impaired, making it difficult to wade through them.

What this tool will do is compare individual lines in the three basic log files that we use to a very large database. The return will be a list of the entries matching those of known "bad" files. The bad files list will be compared to a database of the specific infection(s) those files are related to. The list of specific infections is then compared to a list of "canned speeches" used to remove each type of infection. Any unknown log entry can then be Googled and either cleared from the list or add it to the fix. At this point, the tool will script a formatted (BBC or HTML) ready to post text file.

That's the basic outline. The actual nuts and bolts will contain a few other, related tasks, but hopefully you get the gist. Other, more detailed information should probably be exchanged via PM to save bandwidth on the forums. :D

As far as the OpenClick() code you were mentioning:

$handle = FileOpenDialog("", "@workingDirOpenClick()", "Text Files (*.log; *.txt)")
I'm not exactly sure how that ended up looking like that. The only thing I can think of is that I use an iGeature touchpad and for some reason things occasionally get transposed during a copy/paste cycle (I suspect operator error). It originally looked like this:
$handle = FileOpenDialog("", @workingDir, "Text Files (*.log; *.txt)")

Funny thing is, it actually works with the incorrect code. It probably wouldn't have after the script was compiled into an executable, but I fixed it so it should be OK now. I do a lot of copying and pasting of code because the text size in the AutoIt help file is too small for me to read comfortably so I always paste it into a Notepad window so I can crank up the font to a readable size. Feel free to point out anything like that if you happen to see it in my script. I use Dragon NaturallySpeaking to do my typing for me and I often lose the cursor position which also sometimes ends up in pasting errors.

Anyway, I'll get to work on your latest suggestions and let you know how I get on. Thanks again. -- SCB :D


[font="Tahoma"]"I was worried 'bout rich and skinny, 'til I wound up poor and fat."-- Delbert McClinton[/font]

Share this post


Link to post
Share on other sites
GEOSoft

Just a quick suggestion about the help file font size, You can click the Font button to enlarge it or you can use the Online help pages in my signature which should allow you to set the font size in your browser.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
SpotCheckBilly

Hi George,

Unfortunately, even at its largest, the font in the AutoIt help file is still too small. I've also used the online help on occasion. The thing that I run into online is horizontal scrolling. Just for reference, I use "No Squint" in Firefox (if you're familiar with that add in) set at Full Zoom@170%, Text Zoom@130% which means a lot of horizontal scrolling. The reason I use Notepad is because with word wrap turned on, I don't have to do any horizontal scrolling, which is nice for text such as the help files. It's not so nice for reading the log files I use in my security work, which are largely registry keys. ***Big sigh*** We deal with what we must, 'eh?

I've been playing around with your suggested code for my paste function. Seems like no matter what I do, the only thing that AutoIt sees is $text=ClipGet(). It's as if this: $sStr = StringRegExpReplace($sStr, "<br\s*/?>", "~") and this: $array = StringSplit($text , "~", 1 don't even exist. I can completely remove them from the code and it makes no difference whatsoever. I'm at a complete loss as to how $sStr is having any effect on $text since neither one is included in the other. I think I understand how the array is created using the StringSplit but then I'm not seeing where or how that array variable is being used.

I spent most of the afternoon trying different combinations of the variables, even trying to include one into another but the end results are always the same. I get error messages, no error messages but nothing happens or the text does paste into the listbox but is still one big long line.

Well, I'm done for the day but I'll be ready for another go-round tomorrow. Thanks for your patience with this rookie. :D -- SCB


[font="Tahoma"]"I was worried 'bout rich and skinny, 'til I wound up poor and fat."-- Delbert McClinton[/font]

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.