Example #1
0
        public static Title processNro(string filename)
        {
            Title title = new Title();

            using (var filestream = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                Nro nro;

                try
                {
                    nro = new Nro(filestream.AsStorage());

                    title.distribution = Title.Distribution.Homebrew;

                    log?.WriteLine("Processing NRO {0}", filename);

                    using (var control = nro.OpenNacp().AsStream())
                    {
                        processControlNacp(control, ref title);
                    }
                }
                catch (InvalidDataException)
                {
                    return(null);
                }
            }

            log?.WriteLine("NRO information for {0}: [{1}] {2}", filename, title.titleName, title.displayVersion);

            return(title);
        }
        private void _btnSortear_Click(object sender, EventArgs e)
        {
            try
            {
                List <int> numeros = new List <int>();

                Random R = new Random();

                for (int i = 0; i < 15; i++)
                {
                    int numero = R.Next(0, 50);

                    bool existe = false;
                    foreach (int nro in numeros)
                    {
                        if (nro == numero)
                        {
                            existe = true;
                        }
                    }

                    if (!existe)
                    {
                        numeros.Add(numero);
                    }
                    else
                    {
                        i--;
                    }
                }

                _numeros = numeros;

                string mensaje = "Los nĂºmeros sorteados son:\n | ";
                foreach (int Nro in numeros)
                {
                    mensaje += Nro.ToString() + " | ";
                }

                _lblMensaje.Text = mensaje;

                SorteoRealizado(this, new EventArgs());
            }

            catch (Exception ex)
            {
                _lblMensaje.Text = ex.Message;
            }
        }
Example #3
0
 public override string ToString()
 {
     return(Suit.ToString() + "," + Colour + "," + Nro.ToString() + "," + IsFaceDown.ToString());
 }
Example #4
0
 public NroInfo(Nro Executable, byte[] Hash, long TotalSize)
 {
     this.Executable = Executable;
     this.Hash       = Hash;
     this.TotalSize  = TotalSize;
 }
Example #5
0
        public long ParseNro(out NroInfo Res, ServiceCtx Context, long NroHeapAddress, long NroSize, long BssHeapAddress, long BssSize)
        {
            Res = null;

            if (NroInfos.Count >= MaxNro)
            {
                return(MakeError(ErrorModule.Loader, LoaderErr.MaxNro));
            }
            else if (NroSize == 0 || NroHeapAddress + NroSize <= NroHeapAddress || (NroSize & 0xFFF) != 0)
            {
                return(MakeError(ErrorModule.Loader, LoaderErr.BadSize));
            }
            else if (BssSize != 0 && (BssHeapAddress + BssSize) <= BssHeapAddress)
            {
                return(MakeError(ErrorModule.Loader, LoaderErr.BadSize));
            }
            else if ((NroHeapAddress & 0xFFF) != 0)
            {
                return(MakeError(ErrorModule.Loader, LoaderErr.UnalignedAddress));
            }

            uint Magic       = Context.Memory.ReadUInt32(NroHeapAddress + 0x10);
            uint NroFileSize = Context.Memory.ReadUInt32(NroHeapAddress + 0x18);

            if (Magic != NroMagic || NroSize != NroFileSize)
            {
                return(MakeError(ErrorModule.Loader, LoaderErr.InvalidNro));
            }

            byte[] NroData = Context.Memory.ReadBytes(NroHeapAddress, NroSize);
            byte[] NroHash = null;

            MemoryStream Stream = new MemoryStream(NroData);

            using (SHA256 Hasher = SHA256.Create())
            {
                NroHash = Hasher.ComputeHash(Stream);
            }

            if (!IsNroHashPresent(NroHash))
            {
                return(MakeError(ErrorModule.Loader, LoaderErr.NroHashNotPresent));
            }

            if (IsNroLoaded(NroHash))
            {
                return(MakeError(ErrorModule.Loader, LoaderErr.NroAlreadyLoaded));
            }

            Stream.Position = 0;

            Nro Executable = new Nro(Stream, "memory", NroHeapAddress, BssHeapAddress);

            // check if everything is page align.
            if ((Executable.Text.Length & 0xFFF) != 0 || (Executable.RO.Length & 0xFFF) != 0 ||
                (Executable.Data.Length & 0xFFF) != 0 || (Executable.BssSize & 0xFFF) != 0)
            {
                return(MakeError(ErrorModule.Loader, LoaderErr.InvalidNro));
            }

            // check if everything is contiguous.
            if (Executable.ROOffset != Executable.TextOffset + Executable.Text.Length ||
                Executable.DataOffset != Executable.ROOffset + Executable.RO.Length ||
                NroFileSize != Executable.DataOffset + Executable.Data.Length)
            {
                return(MakeError(ErrorModule.Loader, LoaderErr.InvalidNro));
            }

            // finally check the bss size match.
            if (Executable.BssSize != BssSize)
            {
                return(MakeError(ErrorModule.Loader, LoaderErr.InvalidNro));
            }

            Res = new NroInfo(Executable, NroHash, Executable.Text.Length + Executable.RO.Length + Executable.Data.Length + Executable.BssSize);

            return(0);
        }
Example #6
0
 public override string ToString()
 {
     return(Nro.ToString());
 }