Skip to content

Commit 9451e3e

Browse files
Create vbscript-analyzer.bak
Signed-off-by: LUIZ HAMILTON ROBERTO DA SILVA <[email protected]>
1 parent c830fc9 commit 9451e3e

1 file changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: VBScript Syntax Validation
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
paths:
7+
- '**/*.vbs'
8+
- '**/*.hta'
9+
pull_request:
10+
branches: [main, develop]
11+
paths:
12+
- '**/*.vbs'
13+
- '**/*.hta'
14+
workflow_dispatch:
15+
16+
jobs:
17+
vbscript-syntax-check:
18+
name: 🔍 VBScript Lint with Line Detection
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: 📦 Checkout repository (short path to avoid filename issues)
23+
uses: actions/checkout@v4
24+
with:
25+
path: repo
26+
27+
- name: 🍷 Setup Wine
28+
run: |
29+
sudo apt-get update
30+
sudo apt-get install -y wine64
31+
32+
- name: 🔎 Locate .vbs and .hta Files
33+
working-directory: ./repo
34+
run: |
35+
find . -type f \( -iname "*.vbs" -o -iname "*.hta" \) > vbscript-files.txt
36+
cat vbscript-files.txt || echo "No .vbs or .hta files found."
37+
38+
- name: 🧪 VBScript Syntax Validation with SARIF
39+
working-directory: ./repo
40+
run: |
41+
echo '{"version":"2.1.0","runs":[{"tool":{"driver":{"name":"VBScript Syntax Check","informationUri":"https://learn.microsoft.com/en-us/previous-versions//d1wf56tt(v=vs.85)","rules":[]}},"results":[' > vbscript-results.sarif
42+
43+
exit_code=0
44+
first=true
45+
46+
while IFS= read -r file; do
47+
echo "🔍 Checking: $file"
48+
49+
# Skip HTA files that start with HTML or lack VBScript blocks
50+
if [[ "$file" == *.hta ]]; then
51+
if grep -iqE '^\s*<(html|!doctype)' "$file"; then
52+
echo "::notice file=$file::Skipped HTA (HTML content)"
53+
continue
54+
fi
55+
if ! grep -iq '<script[^>]*language=["'\''"]vbscript["'\''"]' "$file"; then
56+
echo "::notice file=$file::Skipped HTA (no VBScript block)"
57+
continue
58+
fi
59+
fi
60+
61+
# Run VBScript under Wine
62+
if ! wine cscript.exe //nologo "$file" 2> error.log; then
63+
echo "::error file=$file::Syntax error in VBScript."
64+
[[ "$first" == false ]] && echo "," >> vbscript-results.sarif
65+
first=false
66+
67+
# Extract first useful line number using grep -n
68+
match_line=$(grep -in "Error" error.log | head -n 1)
69+
line_number=$(echo "$match_line" | cut -d: -f1)
70+
message=$(echo "$match_line" | cut -d: -f2- | sed 's/"/'\''/g')
71+
72+
# fallback if grep fails
73+
if [[ -z "$line_number" ]]; then
74+
line_number=1
75+
message="Syntax error in VBScript"
76+
fi
77+
78+
echo "❌ Line $line_number: $message"
79+
80+
echo '{' >> vbscript-results.sarif
81+
echo ' "level": "error",' >> vbscript-results.sarif
82+
echo ' "message": { "text": "'"${message}"'" },' >> vbscript-results.sarif
83+
echo ' "locations": [{' >> vbscript-results.sarif
84+
echo ' "physicalLocation": {' >> vbscript-results.sarif
85+
echo ' "artifactLocation": { "uri": "'"${file#./}"'" },' >> vbscript-results.sarif
86+
echo ' "region": { "startLine": '"$line_number"' }' >> vbscript-results.sarif
87+
echo ' }' >> vbscript-results.sarif
88+
echo ' }]' >> vbscript-results.sarif
89+
echo '}' >> vbscript-results.sarif
90+
91+
exit_code=1
92+
fi
93+
done < vbscript-files.txt
94+
95+
echo ']}]}' >> vbscript-results.sarif
96+
exit $exit_code
97+
98+
- name: 📁 Upload SARIF Artifact
99+
uses: actions/upload-artifact@v4
100+
with:
101+
name: vbscript-lint-report
102+
path: repo/vbscript-results.sarif
103+
104+
- name: 🛰️ Upload SARIF to GitHub Code Scanning
105+
uses: github/codeql-action/upload-sarif@v3
106+
with:
107+
sarif_file: repo/vbscript-results.sarif

0 commit comments

Comments
 (0)