summaryrefslogtreecommitdiff
path: root/LibTSforge/Modifiers/TamperedFlagsDelete.cs
blob: 55ba1ecc2861463627813852e11d88ff3bef23a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
namespace LibTSforge.Modifiers
{
    using System;
    using System.Linq;
    using LibTSforge.PhysicalStore;
    using LibTSforge.SPP;

    public static class TamperedFlagsDelete
    {
        public static void DeleteTamperFlags(PSVersion version, bool production)
        {
            SPPUtils.KillSPP(version);

            Logger.WriteLine("Writing TrustedStore data...");

            using (IPhysicalStore store = SPPUtils.GetStore(version, production))
            {
                if (version != PSVersion.Win7)
                {
                    string recreatedFlag = "__##USERSEP-RESERVED##__$$RECREATED-FLAG$$";
                    string recoveredFlag = "__##USERSEP-RESERVED##__$$RECOVERED-FLAG$$";

                    DeleteFlag(store, recreatedFlag);
                    DeleteFlag(store, recoveredFlag);
                }
                else
                {
                    SetFlag(store, 0xA0001);
                }

                Logger.WriteLine("Successfully cleared the tamper state.");
            }
        }

        private static void DeleteFlag(IPhysicalStore store, string flag)
        {
            store.FindBlocks(flag).ToList().ForEach(block => store.DeleteBlock(block.KeyAsStr, block.ValueAsStr));
        }

        private static void SetFlag(IPhysicalStore store, uint flag)
        {
            store.FindBlocks(flag).ToList().ForEach(block => store.SetBlock(block.KeyAsStr, block.ValueAsInt, new byte[8]));
        }
    }
}