예제 #1
0
        private static int DecompressSection(NsoReader reader, NsoReader.SegmentType segmentType, int offset, byte[] Program)
        {
            reader.GetSegmentSize(segmentType, out uint uncompressedSize).ThrowIfFailure();

            var span = Program.AsSpan().Slice(offset, (int)uncompressedSize);

            reader.ReadSegment(segmentType, span).ThrowIfFailure();

            return((int)uncompressedSize);
        }
예제 #2
0
        private static byte[] DecompressSection(NsoReader reader, NsoReader.SegmentType segmentType)
        {
            reader.GetSegmentSize(segmentType, out uint uncompressedSize).ThrowIfFailure();

            byte[] result = new byte[uncompressedSize];

            reader.ReadSegment(segmentType, result).ThrowIfFailure();

            return(result);
        }
예제 #3
0
        private uint DecompressSection(NsoReader reader, NsoReader.SegmentType segmentType, uint offset)
        {
            reader.GetSegmentSize(segmentType, out uint uncompressedSize).ThrowIfFailure();

            var span = Program.AsSpan((int)offset, (int)uncompressedSize);

            reader.ReadSegment(segmentType, span).ThrowIfFailure();

            return(uncompressedSize);
        }
예제 #4
0
        public NsoExecutable(IStorage inStorage, string name = null)
        {
            NsoReader reader = new NsoReader();

            reader.Initialize(inStorage.AsFile(OpenMode.Read)).ThrowIfFailure();

            TextOffset = (int)reader.Header.Segments[0].MemoryOffset;
            RoOffset   = (int)reader.Header.Segments[1].MemoryOffset;
            DataOffset = (int)reader.Header.Segments[2].MemoryOffset;
            BssSize    = (int)reader.Header.BssSize;

            reader.GetSegmentSize(NsoReader.SegmentType.Data, out uint uncompressedSize).ThrowIfFailure();
            Program = new byte[DataOffset + uncompressedSize];

            TextSize = DecompressSection(reader, NsoReader.SegmentType.Text, TextOffset, Program);
            RoSize   = DecompressSection(reader, NsoReader.SegmentType.Ro, RoOffset, Program);
            DataSize = DecompressSection(reader, NsoReader.SegmentType.Data, DataOffset, Program);

            Name    = name;
            BuildId = reader.Header.ModuleId;
        }