return To index | download demo package!
Mono: Enumerate .EXE Files In Ubuntu Linux (From Roots To Tips) -------------------------------------------------------------- alcopaul/brigada ocho june 05, 2011 So I logged into my Ubuntu partition to finally resolve an issue that I encountered when I was testing the functions of my .NET virus in Mono. I found out that the directory recursion hangs when finding .exe files. Today, I was able to solve that problem. The culprit? /proc and /sys directories. The trick is to exclude them from the directory search. note: filenamex is the full path of the .exe file. ---------------------------------------------------------------------- using System; using System.IO; using System.Reflection; namespace FindEXEUbuntuLinux { class Program { static void Main(string[] args) { Module gxc = Assembly.GetExecutingAssembly().GetModules()[0]; string self = gxc.FullyQualifiedName; string currLoc = Path.GetDirectoryName(self); string root = Directory.GetDirectoryRoot(currLoc); DirectoryInfo dirs = new DirectoryInfo(@root); AndLetsRock(dirs); Console.WriteLine("End here.."); Console.ReadKey(); } private static void AndLetsRock(DirectoryInfo dir) { FileInfo[] filesx = dir.GetFiles("*.exe"); foreach (FileInfo filex in filesx) { string filenamex = filex.FullName; try { Console.WriteLine(filenamex); } catch { continue; } } DirectoryInfo[] dirs = dir.GetDirectories("*.*"); foreach (DirectoryInfo xdir in dirs) { try { if (xdir.FullName == "/proc" || xdir.FullName == "/sys") { continue; } AndLetsRock(xdir); } catch { continue; } } } } } --------------------------------------------------------------------