Manifest.cs 3.36 KB
Newer Older
Archnoc's avatar
Archnoc committed
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;
using System.Linq;
using System.IO;

namespace sunrise_launcher
{
    public class ManifestMetadata
    {
        [JsonPropertyName("title")]
        public string Title { get; set; }
        [JsonPropertyName("hash")]
        public string Hash { get; set; }
        [JsonPropertyName("launch_path")]
        public string LaunchPath { get; set; }
        [JsonPropertyName("launch_env")]
        public string LaunchEnv { get; set; }
        [JsonPropertyName("launch_args")]
        public string LaunchArgs { get; set; }

        public bool Verify()
        {
            if (Path.IsPathFullyQualified(LaunchPath))
            {
                Console.WriteLine("launch path is fully qualified");
                return false;
            }

            return true;
        }
    }

    public class ManifestFile
    {
        [JsonPropertyName("path")]
        public string Path { get; set; }
        [JsonPropertyName("size")]
        public long Size { get; set; }
        [JsonPropertyName("sha256")]
        public string Sha256 { get; set; }
        [JsonPropertyName("md5")]
        public string MD5 { get; set; }
        [JsonPropertyName("sources")]
        public List<FileSource> Sources { get; set; }

        public bool Verify()
        {
            if (Path.Contains(".."))
            {
                Console.WriteLine("illegal sequence in manifest file path: '..' in {0}", Path);
                return false;
            }
                
            if (Path.Contains("~"))
            {
                Console.WriteLine("illegal sequence in manifest file path: '~' in {0}", Path);
                return false;
            }

            if (Path.Contains("$"))
            {
                Console.WriteLine("illegal sequence in manifest file path: '$' in {0}", Path);
                return false;
            }

            if (Path.Contains("%"))
            {
                Console.WriteLine("illegal sequence in manifest file path: '%' in {0}", Path);
                return false;
            }

            if (System.IO.Path.IsPathFullyQualified(Path))
            {
                Console.WriteLine("file path is fully qualified: {0}", Path);
                return false;
            }

            if (Path.Contains("main.js"))
            {
                Console.WriteLine("illegal sequence in manifest file path: 'main.js' in {0}", Path);
                return false;
            }

            if (Path.Contains("main.qml"))
            {
                Console.WriteLine("illegal sequence in manifest file path: 'main.qml' in {0}", Path);
                return false;
            }

            if (Path.Contains("sunrise-launcher"))
            {
                Console.WriteLine("illegal sequence in manifest file path: 'sunrise-launcher' in {0}", Path);
                return false;
            }

            return Sources.All(x => x.Verify());
        }
    }

    public class FileSource
    {
        [JsonPropertyName("url")]
        public string URL { get; set; }

        public bool Verify()
        {
            if (URL.ToLower().Contains("file:"))
            {
                Console.WriteLine("illegal sequence in manifest source url: 'file:' in source {0}", URL);
                return false;
            }

            return true;
        }
    }
}