aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Frontend/Hacking/HackableProvider.cs
blob: d661147836e629320d974b56c4dbf51a886f7028 (plain) (blame)
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ShiftOS.Objects;
using ShiftOS.Engine;
using Newtonsoft.Json;

namespace ShiftOS.Frontend
{
    public class HackableProvider : IHackableProvider
    {
        public byte[] FindLootBytes(string id)
        {
            foreach(var res in typeof(Properties.Resources).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static))
            {
                if(res.Name == id)
                {
                    var obj = res.GetValue(null);
                    if(obj is System.Drawing.Image)
                    {
                        var img = (obj as System.Drawing.Bitmap);
                        using(var memstr = new System.IO.MemoryStream())
                        {
                            img.Save(memstr, System.Drawing.Imaging.ImageFormat.Png);
                            return memstr.ToArray();
                        }
                    }
                    else if(obj is System.IO.UnmanagedMemoryStream)
                    {
                        var ms = obj as System.IO.MemoryStream;
                        return ms.ToArray();
                    }
                    else if(obj is string)
                    {
                        var bytes = Encoding.UTF8.GetBytes(obj.ToString());
                        return bytes;
                    }
                }
            }
            return null;
        }

        public Hackable[] GetHackables()
        {
            return JsonConvert.DeserializeObject<Hackable[]>(Properties.Resources.Hackables);
        }

        public Exploit[] GetExploits()
        {
            return JsonConvert.DeserializeObject<Exploit[]>(Properties.Resources.Exploits);
        }

        public Payload[] GetPayloads()
        {
            return JsonConvert.DeserializeObject<Payload[]>(Properties.Resources.Payloads);
        }

        public Port[] GetPorts()
        {
            return JsonConvert.DeserializeObject<Port[]>(Properties.Resources.Ports);
        }

        public byte[] GetLootFromResource(string resId)
        {
            return new byte[] { 0xDE, 0xAD, 0xBE, 0xEF }; //nyi
        }

        public Loot[] GetLoot()
        {
            return JsonConvert.DeserializeObject<Loot[]>(Properties.Resources.LootInfo);
        }
    }
}