コード例 #1
0
        public static string SID_SPLevel        = "S-1-16-28672"; //	Secure Process Mandatory Level

        public static bool TakeOwn(string path)
        {
            bool ret = true;

            try
            {
                TokenManipulator.AddPrivilege(TokenManipulator.SE_TAKE_OWNERSHIP_NAME);

                FileSecurity ac = File.GetAccessControl(path);
                ac.SetOwner(new SecurityIdentifier(FileOps.SID_Admins));
                File.SetAccessControl(path, ac);
            }
            catch (Exception err)
            {
                AppLog.Exception(err);
                ret = false;
            }
            finally
            {
                TokenManipulator.RemovePrivilege(TokenManipulator.SE_TAKE_OWNERSHIP_NAME);
            }
            return(ret);
        }
コード例 #2
0
ファイル: MiscFunc.cs プロジェクト: safino9/priv10
 public static bool Exec(string cmd, string args, bool hidden = true)
 {
     try
     {
         Process process = new Process();
         process.StartInfo.UseShellExecute = false;
         if (hidden)
         {
             process.StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
             process.StartInfo.CreateNoWindow = true;
         }
         process.StartInfo.FileName  = cmd;
         process.StartInfo.Arguments = args;
         process.StartInfo.Verb      = "runas"; // run as admin
         process.Start();
         process.WaitForExit();
         return(true);
     }
     catch (Exception err)
     {
         AppLog.Exception(err);
     }
     return(false);
 }
コード例 #3
0
        private UwpFunc.AppInfo GetInfo(Windows.ApplicationModel.Package package, string sid)
        {
            string path;

            try
            {
                path = package.InstalledLocation.Path;
            }
            catch
            {
                return(null);
            }

            string manifest = Path.Combine(path, "AppxManifest.xml");

            if (!File.Exists(manifest))
            {
                return(null);
            }

            XElement xelement;

            try
            {
                string manifestXML = File.ReadAllText(manifest);

                int startIndex = manifestXML.IndexOf("<Properties>", StringComparison.Ordinal);
                int num        = manifestXML.IndexOf("</Properties>", StringComparison.Ordinal);
                xelement = XElement.Parse(manifestXML.Substring(startIndex, num - startIndex + 13).Replace("uap:", string.Empty));
            }
            catch (Exception err)
            {
                AppLog.Exception(err);
                return(null);
            }

            string displayName = null;
            string logoPath    = null;

            try
            {
                displayName = xelement.Element((XName)"DisplayName")?.Value;
                logoPath    = xelement.Element((XName)"Logo")?.Value;
            }
            catch (Exception err)
            {
                AppLog.Exception(err);
            }

            if (displayName == null)
            {
                return(null);
            }

            try
            {
                Uri result;
                if (Uri.TryCreate(displayName, UriKind.Absolute, out result))
                {
                    string pathToPri         = Path.Combine(package.InstalledLocation.Path, "resources.pri");
                    string resourceKey1      = "ms-resource://" + package.Id.Name + "/resources/" + ((IEnumerable <string>)result.Segments).Last <string>();
                    string stringFromPriFile = MiscFunc.GetResourceStr(pathToPri, resourceKey1);
                    if (!string.IsNullOrEmpty(stringFromPriFile.Trim()))
                    {
                        displayName = stringFromPriFile;
                    }
                    else
                    {
                        string str          = string.Concat(((IEnumerable <string>)result.Segments).Skip <string>(1));
                        string resourceKey2 = "ms-resource://" + package.Id.Name + "/" + str;
                        stringFromPriFile = MiscFunc.GetResourceStr(pathToPri, resourceKey2);
                        if (!string.IsNullOrEmpty(stringFromPriFile.Trim()))
                        {
                            displayName = stringFromPriFile;
                        }
                    }
                }

                if (logoPath != null)
                {
                    string path1 = Path.Combine(package.InstalledLocation.Path, logoPath);
                    if (File.Exists(path1))
                    {
                        logoPath = path1;
                    }
                    else
                    {
                        string path2 = Path.Combine(package.InstalledLocation.Path, Path.ChangeExtension(path1, "scale-100.png"));
                        if (File.Exists(path2))
                        {
                            logoPath = path2;
                        }
                        else
                        {
                            string path3 = Path.Combine(Path.Combine(package.InstalledLocation.Path, "en-us"), logoPath);
                            string path4 = Path.Combine(package.InstalledLocation.Path, Path.ChangeExtension(path3, "scale-100.png"));
                            if (File.Exists(path4))
                            {
                                logoPath = path4;
                            }
                            else
                            {
                                logoPath = null;
                            }
                        }
                    }
                }
            }
            catch (Exception err)
            {
                AppLog.Exception(err);
            }

            return(new UwpFunc.AppInfo()
            {
                Name = displayName, Logo = logoPath, ID = package.Id.FamilyName, SID = sid
            });
        }
コード例 #4
0
ファイル: AppManager.cs プロジェクト: safino9/priv10
        private UwpFunc.AppInfo GetInfo(Windows.ApplicationModel.Package package)
        {
            string path;
            string manifest;

            try
            {
                path = package.InstalledLocation.Path; // that call takes a long time

                manifest = Path.Combine(path, !package.IsBundle ? @"AppxManifest.xml" : @"AppxMetadata\AppxBundleManifest.xml");
                if (!File.Exists(manifest))
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }

            XElement xelement;

            try
            {
                string manifestXML = File.ReadAllText(manifest);

                int startIndex = manifestXML.IndexOf("<Properties>", StringComparison.Ordinal);
                int num        = manifestXML.IndexOf("</Properties>", StringComparison.Ordinal);
                xelement = XElement.Parse(manifestXML.Substring(startIndex, num - startIndex + 13).Replace("uap:", string.Empty));
            }
            catch (Exception err)
            {
                AppLog.Exception(err);
                return(null);
            }

            string displayName = null;
            string logoPath    = null;

            try
            {
                displayName = xelement.Element((XName)"DisplayName")?.Value;
                logoPath    = xelement.Element((XName)"Logo")?.Value;
            }
            catch (Exception err)
            {
                AppLog.Exception(err);
            }

            if (displayName == null)
            {
                return(null);
            }

            try
            {
                Uri result;
                if (Uri.TryCreate(displayName, UriKind.Absolute, out result))
                {
                    string pathToPri         = Path.Combine(path, "resources.pri");
                    string resourceKey1      = "ms-resource://" + package.Id.Name + "/resources/" + ((IEnumerable <string>)result.Segments).Last <string>();
                    string stringFromPriFile = MiscFunc.GetResourceStr(pathToPri, resourceKey1);
                    if (!string.IsNullOrEmpty(stringFromPriFile.Trim()))
                    {
                        displayName = stringFromPriFile;
                    }
                    else
                    {
                        string str          = string.Concat(((IEnumerable <string>)result.Segments).Skip <string>(1));
                        string resourceKey2 = "ms-resource://" + package.Id.Name + "/" + str;
                        stringFromPriFile = MiscFunc.GetResourceStr(pathToPri, resourceKey2);
                        if (!string.IsNullOrEmpty(stringFromPriFile.Trim()))
                        {
                            displayName = stringFromPriFile;
                        }
                    }
                }

                if (logoPath != null)
                {
                    List <string> extensions = new List <string> {
                        "", "scale-100.png", "scale-125.png", "scale-150.png", "scale-200.png", "scale-400.png"
                    };
                    List <string> sub_dirs = new List <string> {
                        "", "en-us"
                    };

                    string foundPath = null;
                    foreach (string extension in extensions)
                    {
                        foreach (string sub_dir in sub_dirs)
                        {
                            string testPath = path;
                            if (sub_dir.Length > 0)
                            {
                                testPath = Path.Combine(testPath, sub_dir);
                            }

                            string testName = logoPath;
                            if (extension.Length > 0)
                            {
                                testName = Path.ChangeExtension(testName, extension);
                            }

                            testPath = Path.Combine(testPath, testName);
                            if (File.Exists(testPath))
                            {
                                foundPath = testPath;
                                goto done;
                            }
                        }
                    }

done:
                    logoPath = foundPath;
                }
            }
            catch (Exception err)
            {
                AppLog.Exception(err);
            }

            return(new UwpFunc.AppInfo()
            {
                Name = displayName, Logo = logoPath, ID = package.Id.FamilyName, Path = path
            });
        }