SHARE
TWEET

Untitled

a guest May 22nd, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void GenerateContexts(string Root, string OutputFile)
  2.         {
  3.             LogInstance.Log(LogLineHead + "Generating correct file contexts");
  4.             if (File.Exists(Root + "\\system\\etc\\selinux\\plat_file_contexts") && File.Exists(Root + "\\vendor\\etc\\selinux\\nonplat_file_contexts"))
  5.             {
  6.                 StreamReader platreader = new StreamReader(Root + "\\system\\etc\\selinux\\plat_file_contexts");
  7.                 StreamReader nonplatreader = new StreamReader(Root + "\\vendor\\etc\\selinux\\nonplat_file_contexts");
  8.                 StreamWriter contextwriter = new StreamWriter(OutputFile);
  9.                 contextwriter.Write(platreader.ReadToEnd() + nonplatreader.ReadToEnd());
  10.                 contextwriter.Close();
  11.                 contextwriter.Dispose();
  12.                 nonplatreader.Close();
  13.                 nonplatreader.Dispose();
  14.                 platreader.Close();
  15.                 platreader.Dispose();
  16.             }
  17.             else if (File.Exists(Root + "\\boot\\ramdisk\\file_contexts")) File.Copy(Root + "\\boot\\ramdisk\\file_contexts", OutputFile);
  18.             else if (File.Exists(Root + "\\boot\\ramdisk\\file_contexts.bin"))
  19.             {
  20.                 File.Copy(Root + "\\boot\\ramdisk\\file_contexts.bin", Path.GetDirectoryName(OutputFile) + "\\file_contexts.bin");
  21.                 ConvertContexts(Root + "\\boot\\ramdisk\\file_contexts.bin", OutputFile);
  22.             }
  23.             else if (File.Exists(Root + "\\boot\\ramdisk\\plat_file_contexts") && File.Exists(Root + "\\boot\\ramdisk\\nonplat_file_contexts"))
  24.             {
  25.                 StreamReader platreader = new StreamReader(Root + "\\boot\\ramdisk\\plat_file_contexts");
  26.                 StreamReader nonplatreader = new StreamReader(Root + "\\boot\\ramdisk\\nonplat_file_contexts");
  27.                 StreamWriter contextwriter = new StreamWriter(OutputFile);
  28.                 contextwriter.Write(platreader.ReadToEnd() + nonplatreader.ReadToEnd());
  29.                 contextwriter.Close();
  30.                 contextwriter.Dispose();
  31.                 nonplatreader.Close();
  32.                 nonplatreader.Dispose();
  33.                 platreader.Close();
  34.                 platreader.Dispose();
  35.             }
  36.             if (!File.Exists(OutputFile))
  37.             {
  38.                 if (File.Exists(Root + "\\recovery\\ramdisk\\file_contexts")) File.Copy(Root + "\\recovery\\ramdisk\\file_contexts", OutputFile);
  39.                 else if (File.Exists(Root + "\\recovery\\ramdisk\\file_contexts.bin"))
  40.                 {
  41.                     File.Copy(Root + "\\recovery\\ramdisk\\file_contexts.bin", Path.GetDirectoryName(OutputFile) + "\\file_contexts.bin");
  42.                     ConvertContexts(Root + "\\recovery\\ramdisk\\file_contexts.bin", OutputFile);
  43.                 }
  44.                 else if (File.Exists(Root + "\\recovery\\ramdisk\\plat_file_contexts") && File.Exists(Root + "\\recovery\\ramdisk\\nonplat_file_contexts"))
  45.                 {
  46.                     StreamReader platreader = new StreamReader(Root + "\\recovery\\ramdisk\\plat_file_contexts");
  47.                     StreamReader nonplatreader = new StreamReader(Root + "\\recovery\\ramdisk\\nonplat_file_contexts");
  48.                     StreamWriter contextwriter = new StreamWriter(OutputFile);
  49.                     contextwriter.Write(platreader.ReadToEnd() + nonplatreader.ReadToEnd());
  50.                     contextwriter.Close();
  51.                     contextwriter.Dispose();
  52.                     nonplatreader.Close();
  53.                     nonplatreader.Dispose();
  54.                     platreader.Close();
  55.                     platreader.Dispose();
  56.                 }
  57.             }
  58.             if (File.Exists(OutputFile)) LogInstance.Log(LogLineHead + "Success");
  59.             else LogInstance.Log(LogLineHead + "[ERROR] : Failed to generate correct contexts");
  60.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top