Example #1
0
        public List <Win32Directory> GetDirectoryByPath(string anypath)
        {
            Win32Directory ps;
            string         aWSql = this.WSql + " where Path='" + anypath.Replace(@"\", @"\\") + "'";

            System.Console.WriteLine(aWSql);
            ManagementObjectCollection moc = this.GetAllInfo(aWSql);
            List <Win32Directory>      dc  = new List <Win32Directory>();

            foreach (ManagementObject mo in moc)
            {
                ps = new Win32Directory();
                if (mo != null)
                {
                    ps.AccessMask          = GetManagementObject <uint>(mo, "AccessMask");
                    ps.Archive             = GetManagementObject <bool>(mo, "Archive");
                    ps.Caption             = GetManagementObject <string>(mo, "Caption");
                    ps.Compressed          = GetManagementObject <bool>(mo, "Compressed");
                    ps.CompressionMethod   = GetManagementObject <string>(mo, "CompressionMethod");
                    ps.CreationClassName   = GetManagementObject <string>(mo, "CreationClassName");
                    ps.Cim_CreationDate    = GetManagementObject <string>(mo, "CreationDate");
                    ps.CSCreationClassName = GetManagementObject <string>(mo, "CSCreationClassName");
                    ps.CSName                = GetManagementObject <string>(mo, "CSName");
                    ps.Description           = GetManagementObject <string>(mo, "Description");
                    ps.Drive                 = GetManagementObject <string>(mo, "Drive");
                    ps.EightDotThreeFileName = GetManagementObject <string>(mo, "EightDotThreeFileName");
                    ps.Encrypted             = GetManagementObject <bool>(mo, "Encrypted");
                    ps.EncryptionMethod      = GetManagementObject <string>(mo, "EncryptionMethod");
                    ps.Extension             = GetManagementObject <string>(mo, "Extension");
                    ps.FileName              = GetManagementObject <string>(mo, "FileName");
                    ps.FileSize              = GetManagementObject <ulong>(mo, "FileSize");
                    ps.FileType              = GetManagementObject <string>(mo, "FileType");
                    ps.FSCreationClassName   = GetManagementObject <string>(mo, "FSCreationClassName");
                    ps.FSName                = GetManagementObject <string>(mo, "FSName");
                    ps.Hidden                = GetManagementObject <bool>(mo, "Hidden");
                    ps.Cim_InstallDate       = GetManagementObject <string>(mo, "InstallDate");
                    ps.InUseCount            = GetManagementObject <ulong>(mo, "InUseCount");
                    ps.Cim_LastAccessed      = GetManagementObject <string>(mo, "LastAccessed");
                    ps.Cim_LastModified      = GetManagementObject <string>(mo, "LastModified");
                    ps.Name      = GetManagementObject <string>(mo, "Name");
                    ps.Path      = GetManagementObject <string>(mo, "Path");
                    ps.Readable  = GetManagementObject <bool>(mo, "Readable");
                    ps.Status    = GetManagementObject <string>(mo, "Status");
                    ps.System    = GetManagementObject <bool>(mo, "System");
                    ps.Writeable = GetManagementObject <bool>(mo, "Writeable");

                    dc.Add(ps);
                }
            }
            moc.Dispose();
            return(dc);
        }
Example #2
0
    public void AutoTamperResponseBefore(Session oSession)
    {
        if (/*oSession.oResponse.headers.ExistsAndContains("Content-Type", "application/x-shockwave-flash")*/ true)
        {
            String path = oSession.host + oSession.PathAndQuery;

            //path = path.Substring(0, path.IndexOf('?'));
            path = path.Split('?')[0];
            path = path
                   .Replace("/", "\\")
                   .Replace("?", ",")
                   .Replace("&", "-")
                   .Replace(":", "%3A")
                   .Replace("*", "%2A")
                   .Replace("\"", "%22")
                   .Replace("<", "%3C")
                   .Replace(">", "%3E")
                   .Replace("|", "%7C");
            path = "C:\\Temp\\FiddlerCapture\\" + path;

            while (path.Contains("\\\\"))
            {
                path = path.Replace("\\\\", "\\ \\");
            }

            if (path[path.Length - 1] == '\\')
            {
                path = path + "index.html";
            }

            string[] segments = path.Split('\\');
            for (int j = 0; j < segments.Length; j++)
            {
                for (int i = 200; i < segments[j].Length; i += 200)
                {
                    segments[j] = segments[j].Substring(0, i) + '\\' + segments[j].Substring(i);
                }
            }
            path = String.Join("\\", segments);

            for (int i = 0; i < path.Length; i++)
            {
                if (path[i] == '\\' && Win32File.Exists(path.Substring(0, i)))
                {
                    string dirName      = path.Substring(0, i);
                    string tempFileName = dirName + ".temp-index";
                    Win32File.Move(dirName, tempFileName);
                    Win32Directory.CreateDirectory(dirName);
                    Win32File.Move(tempFileName, dirName + "\\index.html");
                }
            }

            try {
                if (Win32Directory.Exists(path))
                {
                    path = path + "\\";
                }
            } catch (Exception e) { throw new Exception("Directory.Exists failure: " + path, e); }

            if (path[path.Length - 1] == '\\')
            {
                path = path + "index.html";
            }

            //String dir = Path.GetDirectoryName(path);
            String dir = path.Substring(0, path.LastIndexOf('\\'));

            try {
                //if (!Directory.Exists(dir))
                //	Directory.CreateDirectory(dir);
                Win32Directory.CreateDirectory(dir);
            } catch (Exception e) { throw new Exception("Directory.CreateDirectory failure: " + dir, e); }

            oSession.utilDecodeResponse();

            //oSession.SaveResponseBody(path);
            byte[]     data = oSession.responseBodyBytes;
            FileStream s;
            try {
                s = Win32File.Open(path, FileMode.Create);
            } catch (Exception e) { throw new Exception("Open failure: " + path, e); }
            try {
                s.Write(data, 0, data.Length);
            } catch (Exception e) { throw new Exception("Write failure: " + path, e); }
            try {
                s.Close();
            } catch (Exception e) { throw new Exception("Close failure: " + path, e); }
        }
    }