aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/Loaders/Executables/Nro.cs
blob: 6015da2132135e7a3016d55486dc57303df5392b (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
using System.IO;

namespace Ryujinx.HLE.Loaders.Executables
{
    class Nro : IExecutable
    {
        public string FilePath { get; private set; }

        public byte[] Text { get; private set; }
        public byte[] RO   { get; private set; }
        public byte[] Data { get; private set; }

        public int Mod0Offset { get; private set; }
        public int TextOffset { get; private set; }
        public int ROOffset   { get; private set; }
        public int DataOffset { get; private set; }
        public int BssSize    { get; private set; }

        public long SourceAddress { get; private set; }
        public long BssAddress    { get; private set; }

        public Nro(Stream Input, string FilePath, long SourceAddress = 0, long BssAddress = 0)
        {
            this.FilePath      = FilePath;
            this.SourceAddress = SourceAddress;
            this.BssAddress    = BssAddress;

            BinaryReader Reader = new BinaryReader(Input);

            Input.Seek(4, SeekOrigin.Begin);

            int Mod0Offset = Reader.ReadInt32();
            int Padding8   = Reader.ReadInt32();
            int Paddingc   = Reader.ReadInt32();
            int NroMagic   = Reader.ReadInt32();
            int Unknown14  = Reader.ReadInt32();
            int FileSize   = Reader.ReadInt32();
            int Unknown1c  = Reader.ReadInt32();
            int TextOffset = Reader.ReadInt32();
            int TextSize   = Reader.ReadInt32();
            int ROOffset   = Reader.ReadInt32();
            int ROSize     = Reader.ReadInt32();
            int DataOffset = Reader.ReadInt32();
            int DataSize   = Reader.ReadInt32();
            int BssSize    = Reader.ReadInt32();

            this.Mod0Offset = Mod0Offset;
            this.TextOffset = TextOffset;
            this.ROOffset   = ROOffset;
            this.DataOffset = DataOffset;
            this.BssSize    = BssSize;

            byte[] Read(long Position, int Size)
            {
                Input.Seek(Position, SeekOrigin.Begin);

                return Reader.ReadBytes(Size);
            }

            Text = Read(TextOffset, TextSize);
            RO   = Read(ROOffset,   ROSize);
            Data = Read(DataOffset, DataSize);
        }
    }
}