ShaneGowland

WinappDebug Source Code

Jan 15th, 2012
131
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.IO
  2. Module Module1
  3.  
  4.     Sub Main()
  5.  
  6.         'Check if the winapp2.ini file is in the current directory. End program if it isn't.
  7.         If File.Exists(Environment.CurrentDirectory & "\winapp2.ini") = False Then
  8.             Console.WriteLine("winapp2.ini file could not be located in the current working directory (" & Environment.CurrentDirectory & ")")
  9.             Console.ReadKey()
  10.             End
  11.         End If
  12.  
  13.         'Create some variables for later use
  14.         Dim linecount As Integer = 0
  15.         Dim command As String
  16.         Dim number_of_errors As Integer = 0
  17.  
  18.         'Create a list of supported environmental variables
  19.         Dim envir_vars As New List(Of String)
  20.         envir_vars.AddRange(New String() {"%userprofile%", "%ProgramFiles%", "%rootdir%", "%windir%", "%appdata%", "%systemdrive%"})
  21.  
  22.  
  23.         'Read the winapp2.ini file line-by-line
  24.         Dim r As IO.StreamReader
  25.         Try
  26.  
  27.             r = New IO.StreamReader(Environment.CurrentDirectory & "\winapp2.ini")
  28.             Do While (r.Peek() > -1)
  29.  
  30.                 'Update the line that is being tested
  31.                 command = (r.ReadLine.ToString)
  32.  
  33.                 'Increment the lineocunt value
  34.                 linecount = linecount + 1
  35.  
  36.                 'Whitespace checks
  37.                 If command = "" = False And command.StartsWith(";") = False Then
  38.  
  39.                     'Check for trailing whitespace
  40.                     If command.EndsWith(" ") Then
  41.                         Console.WriteLine("Line: " & linecount & " Error: Detected unwanted whitespace at end of line." & Environment.NewLine & "Command: " & command & Environment.NewLine)
  42.                         number_of_errors = number_of_errors + 1
  43.                     End If
  44.  
  45.                     'Check for ending whitespace
  46.                     If command.StartsWith(" ") Then
  47.                         Console.WriteLine("Line: " & linecount & " Error: Detected unwanted whitespace at beginning of line." & Environment.NewLine & "Command: " & command & Environment.NewLine)
  48.                         number_of_errors = number_of_errors + 1
  49.                     End If
  50.  
  51.                 End If
  52.  
  53.                 'Check for spelling errors in "LangSecRef"
  54.                 If command.StartsWith("Lan") Then
  55.                     If command.Contains("LangSecRef=") = False Then
  56.                         Console.WriteLine("Line: " & linecount & " Error: 'LangSecRef' entry is incorrectly spelled or formatted." & Environment.NewLine & "Command: " & command & Environment.NewLine)
  57.                         number_of_errors = number_of_errors + 1
  58.                     End If
  59.                 End If
  60.  
  61.                 'Check for environmental variable spacing errors
  62.                 If command.Contains("%Program Files%") Then
  63.                     Console.WriteLine("Line: " & linecount & " Error: '%ProgramFiles%' variable should not have spacing." & Environment.NewLine & "Command: " & command & Environment.NewLine)
  64.                     number_of_errors = number_of_errors + 1
  65.                 End If
  66.  
  67.                 'Check for cleaning command spelling errors (files)
  68.                 If command.StartsWith("Fi") Then
  69.                     If command.Contains("FileKey") = False Then
  70.                         Console.WriteLine("Line: " & linecount & " Error: 'FileKey' entry is incorrectly spelled or formatted. Spelling should be CamelCase." & Environment.NewLine & "Command: " & command & Environment.NewLine)
  71.                         number_of_errors = number_of_errors + 1
  72.                     End If
  73.                 End If
  74.  
  75.                 'Check for cleaning command spelling errors (registry keys)
  76.                 If command.StartsWith("Re") Then
  77.                     If command.Contains("RegKey") = False Then
  78.                         Console.WriteLine("Line: " & linecount & " Error: 'RegKey' entry is incorrectly spelled or formatted. Spelling should be CamelCase." & Environment.NewLine & "Command: " & command & Environment.NewLine)
  79.                         number_of_errors = number_of_errors + 1
  80.                     End If
  81.                 End If
  82.  
  83.                 'Check for missing numbers next to cleaning commands
  84.                 If command.StartsWith("FileKey=") Or command.StartsWith("RegKey=") Then
  85.                     Console.WriteLine("Line: " & linecount & " Error: Cleaning path entry needs to have a trailing number." & Environment.NewLine & "Command: " & command & Environment.NewLine)
  86.                     number_of_errors = number_of_errors + 1
  87.                 End If
  88.  
  89.                 'Check for Detect that contains a filepath instead of a registry path
  90.                 If command.StartsWith("Detect=%") Or command.StartsWith("Detect=C:\") Then
  91.                     Console.WriteLine("Line: " & linecount & " Error: 'Detect' can only be used for registry key paths." & Environment.NewLine & "Command: " & command & Environment.NewLine)
  92.                 End If
  93.  
  94.                 'Check for detectfile that contains a registry path
  95.                 If command.StartsWith("DetectFile=HKLM") Or command.StartsWith("DetectFile=HKCU") Or command.StartsWith("DetectFile=HKC") Or command.StartsWith("DetectFile=HKCR") Then
  96.                     Console.WriteLine("Line: " & linecount & " Error: 'DetectFile' can only be used for filesystem paths." & Environment.NewLine & "Command: " & command & Environment.NewLine)
  97.                 End If
  98.  
  99.                 'Check for missing backslashes on environmental variables
  100.                 For Each var As String In envir_vars
  101.                     If command.Contains(var) = True Then
  102.                         If command.Contains(var & "\") = False Then
  103.                             Console.WriteLine("Line: " & linecount & " Error: Environmental variables must have a trailing backslash." & Environment.NewLine & "Command: " & command & Environment.NewLine)
  104.                             number_of_errors = number_of_errors + 1
  105.                         End If
  106.                     End If
  107.                 Next
  108.  
  109.  
  110.             Loop
  111.                 Catch ex As Exception
  112.             Console.WriteLine(ex.Message)
  113.         End Try
  114.  
  115.         'Close unmanaged code calls
  116.         r.Close()
  117.  
  118.         'Stop the program from closing on completion
  119.         Console.WriteLine("***********************************************" & Environment.NewLine & "Completed analysis of winapp2.ini. " & number_of_errors & " errors were detected. Press any key to close.")
  120.         Console.ReadKey()
  121.  
  122.  
  123.     End Sub
  124.  
  125. End Module
RAW Paste Data