scanning strings

BlitzPlus Forums/BlitzPlus Programming/scanning strings

Paul A. B.(Posted 2006) [#1]
hey. i am making a program that searches through source code for vulnerabilities in php scripts. Since I already have BlitzPlus, I was wondering if it was possible to scan code for certain characters, then copy the line that the character appeared on, an output it to a file?


Adam Novagen(Posted 2006) [#2]
Try this:

Global errors

Dim filelinearray(1000000);This should store the entire file contents - enlarge as needed
Dim filevulnarray(1000000);This holds any "vulnerabilities" found


Function ScanFile(sourcefile,outputfile)


file = ReadFile(sourcefile);The file to be scanned

i = 0

While Not Eof(file);Keep going until the file ends

filelinearray(i) = readline(file)
i = i + 1;Next iteration & array element

Wend

CloseFile file

For i = 0 to 1000000;Check the entire file line array
    For letter = 1 To Len(filelinearray(i));Scan each line letter by letter
        If Mid(filelinearray(i),letter,1) = Chr([num]);Replace [num] with the character to scan for
            filevulnarray(errors) = filelinearray(i)
            errors = errors + 1
        EndIf
    Next
Next

file = WriteFile(outputfile)

For i = 0 To errors
    WriteLine(file,filevulnarray(i))
Next

CloseFile file


End Function

This is just a ten-minute thing off the top of my head, I've never actually even thought of it before now - hope it works for ya!