Created
December 29, 2025 14:45
-
-
Save rkttu/b2203aeedbd2cd1c4efd916d51b6d11f to your computer and use it in GitHub Desktop.
Modernizing the AutoIt-based USSF script to C# File-based App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env dotnet | |
| // Copyright 2025 Alexandru Avadanii | |
| // | |
| // Licensed under the Apache License, Version 2.0 (the "License"); | |
| // you may not use this file except in compliance with the License. | |
| // You may obtain a copy of the License at | |
| // | |
| // http://www.apache.org/licenses/LICENSE-2.0 | |
| // | |
| // Unless required by applicable law or agreed to in writing, software | |
| // distributed under the License is distributed on an "AS IS" BASIS, | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| // See the License for the specific language governing permissions and | |
| // limitations under the License. | |
| // | |
| // Converted from AutoIt to C# Console Application. | |
| // Converted and developed by Jung-Hyun Nam. | |
| // Original project: https://github.com/alexandruavadanii/USSF | |
| using System; | |
| using System.Collections.Generic; | |
| using System.IO; | |
| using System.Linq; | |
| using System.Text; | |
| class Program | |
| { | |
| static Dictionary<int, (string Extension, string Type, string Usage, string Notes)> Messages = new Dictionary<int, (string, string, string, string)> | |
| { | |
| {1, (".inf", "Information or Installation file", "rundll32.exe setupapi,InstallHinfSection DefaultInstall 132 {filename}", "N/A")}, | |
| {2, (".reg", "Registry file", "regedit.exe /s \"{filename}\"", "")}, | |
| {3, (".exe", "NSIS Package", "\"{filename}\" /S", "")}, | |
| {4, (".exe", "Inno Setup Package", "\"{filename}\" /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-", "")}, | |
| {5, (".exe", "Installshield AFW Package", "", "Extract the installation file with UniExtract or another unpacker. The unpacked archive should be either .CAB or .MSI based. Next only for .CAB based files: Create an installation with this command: {filename} /r /f1\"X:\\setup.iss\" Now you can perform a silent installation using the ISS file: {filename} /s /f1\"X:\\setup.iss\" Next only for .MSI based files: msiexec.exe /i setup.msi /qb")}, | |
| {6, (".exe", "InstallShield 2003 Package", "\"{filename}\" /s /v\"/qb\"", "You can also try to get the .MSI file from the Temp directory during installation, then install with: msiexec.exe /i setup.msi /qb")}, | |
| {7, (".exe", "Wise Installer Package", "\"{filename}\" /s", "")}, | |
| {8, (".exe", "Self-Extracting RAR Archive", "\"{filename}\" /s", "The RAR comment contains the installation script.")}, | |
| {9, (".exe", "Self-Extracting Microsoft CAB Archive", "", "Extract the archive with UniExtract or another unpacker.")}, | |
| {10, (".exe", "Self-Extracting ZIP Archive", "\"{filename}\" /s", "")}, | |
| {11, (".exe", "7-Zip Installer Package", "\"{filename}\" /s", "")}, | |
| {12, (".exe", "Unknown 7-Zip Archive", "", "Extract with 7-Zip")}, | |
| {13, (".exe", "Unknown ZIP Archive", "", "Extract with unzip")}, | |
| {14, (".exe", "Self-Extracting WinZip Archive", "\"{filename}\" /s", "")}, | |
| {15, (".exe", "UPX Packed", "", "Unpack with UPX")}, | |
| {16, (".msi", "MSI File", "msiexec.exe /i \"{filename}\" /qb", "")} | |
| }; | |
| static void Main(string[] args) | |
| { | |
| if (args.Length == 0) | |
| { | |
| Console.WriteLine("Usage: USSF <file_path>"); | |
| return; | |
| } | |
| string filePath = args[0]; | |
| if (!File.Exists(filePath)) | |
| { | |
| Console.WriteLine("File does not exist."); | |
| return; | |
| } | |
| string extension = Path.GetExtension(filePath).ToLower(); | |
| string fileName = Path.GetFileName(filePath); | |
| Console.WriteLine($"File: {filePath}"); | |
| Console.WriteLine($"Extension: {extension}"); | |
| int messageNumber = DetectFileType(filePath, extension); | |
| if (messageNumber > 0 && Messages.ContainsKey(messageNumber)) | |
| { | |
| var msg = Messages[messageNumber]; | |
| Console.WriteLine($"Type: {msg.Type}"); | |
| Console.WriteLine($"Usage: {msg.Usage.Replace("{filename}", fileName)}"); | |
| if (!string.IsNullOrEmpty(msg.Notes)) | |
| { | |
| Console.WriteLine($"Notes: {msg.Notes.Replace("{filename}", fileName)}"); | |
| } | |
| } | |
| else | |
| { | |
| Console.WriteLine("Unknown file type."); | |
| } | |
| } | |
| static int DetectFileType(string filePath, string extension) | |
| { | |
| switch (extension) | |
| { | |
| case ".msi": | |
| if (CheckHeader(filePath, "D0CF11E0A1B11AE1000000000000000000000000000000003E000300FEFF090006")) | |
| return 16; | |
| return -2; // Corrupted MSI | |
| case ".exe": | |
| if (!CheckHeader(filePath, "4D5A")) | |
| return -1; // Corrupted EXE | |
| // For simplicity, assume NSIS or Inno, but in reality, need more detection | |
| // Here we can add more logic or just return a default | |
| return 3; // Assume NSIS for demo | |
| case ".inf": | |
| return 1; | |
| case ".reg": | |
| if (CheckRegFile(filePath)) | |
| return 2; | |
| return -3; // Invalid REG | |
| default: | |
| return -6; // Not supported | |
| } | |
| } | |
| static bool CheckHeader(string filePath, string expectedHex) | |
| { | |
| try | |
| { | |
| using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) | |
| { | |
| int length = expectedHex.Length / 2; | |
| byte[] buffer = new byte[length]; | |
| fs.Read(buffer, 0, length); | |
| string hex = BitConverter.ToString(buffer).Replace("-", ""); | |
| return hex.Equals(expectedHex, StringComparison.OrdinalIgnoreCase); | |
| } | |
| } | |
| catch | |
| { | |
| return false; | |
| } | |
| } | |
| static bool CheckRegFile(string filePath) | |
| { | |
| try | |
| { | |
| string content = File.ReadAllText(filePath, Encoding.UTF8); | |
| if (content.StartsWith("Windows Registry Editor Version 5.00") || content.StartsWith("REGEDIT4")) | |
| return true; | |
| } | |
| catch | |
| { | |
| // Try Unicode | |
| try | |
| { | |
| string content = File.ReadAllText(filePath, Encoding.Unicode); | |
| if (content.StartsWith("Windows Registry Editor Version 5.00") || content.StartsWith("REGEDIT4")) | |
| return true; | |
| } | |
| catch { } | |
| } | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment