public void DiscRead(uint offset, byte[] data, uint length) { if (data != null) { if (length == 0) { return; } if (file.Read(data, ((long)offset) << 2, (int)length) < 0) { //Nada } } if (SectorUsageTable != null) { uint blockno = offset >> 13; do { SectorUsageTable[blockno] = 1; blockno++; if (length > 0x8000) { length -= 0x8000; } } while (length > 0x8000); } }
public IORet Read(Array buffer, int count) //Precisa ser uma matriz de bytes { if (count <= 0) { return(IORet.RET_IO_OK); } int read = 0; IORet ret; while (count > 0) { int toRead = (int)Math.Min(count, sectorSize - offset); int absoluteRead = (int)((((offset + toRead - 1) / sectorSize) + 1) * sectorSize); Byte[] absoluteBuffer = new byte[absoluteRead]; if ((ret = context.Read(absoluteBuffer, absoluteRead)) != IORet.RET_IO_OK) { return(ret); } Array.Copy(absoluteBuffer, offset, buffer, read, toRead); read += toRead; count -= toRead; discPosition += toRead; Seek(discPosition); } return(IORet.RET_IO_OK); }
//--------------------------- Retorna as informações da iso de Wii public static Int32 GetIsoInformation(String file, out string code, out string name, out int region, out long used) { code = ""; name = ""; region = -1; used = 0; IIOContext context = IOManager.CreateIOContext("ISWIIISO", file, FileAccess.Read, FileShare.ReadWrite, 0, FileMode.Open, EFileAttributes.None); if (context.Result != (int)IORet.RET_IO_OK) { //Loga erro return(context.Result); } int r = 0; WiiDisc d = new WiiDisc(context, false); d.Open(); r = d.BuildDisc(PartitionSelection.OnlyGamePartition); if (r == 0) { name = d.name; code = d.code; used = d.UsedSectors; Byte[] bregion = new byte[4]; if (context.Read(bregion, WBFSDevice.IsoRegionPos, 4) != IORet.RET_IO_OK) { //Loga erro region = -1; } else { region = (int)System.Net.IPAddress.NetworkToHostOrder((int)BitConverter.ToUInt32(bregion, 0)); } bregion = null; d.Close(); context.Close(); return(0); } else { d.Close(); context.Close(); return(r); } }
//--------------------------- Verifica se o arquivo é uma iso de Wii public static Int32 IsWiiIso(String file) { IIOContext context = IOManager.CreateIOContext("ISWIIISO", file, FileAccess.Read, FileShare.ReadWrite, 0, FileMode.Open, EFileAttributes.None); if (context.Result != (int)IORet.RET_IO_OK) { //Loga erro return(context.Result); } else { int r = (int)context.Lock(); if (r != (int)IORet.RET_IO_OK) { //Loga erro context.Close(); return(r); } Byte[] header = new Byte[256]; if (context.Read(header, 256) != IORet.RET_IO_OK) { //Loga erro r = context.Result; context.Unlock(); context.Close(); return(r); } r = IsWiiIso(header); context.Unlock(); context.Close(); return(r); } }
public IORet Read(Array buffer, int count) //Precisa ser uma matriz de bytes { if (count <= 0) { return(IORet.RET_IO_OK); } int read = 0; IORet ret; while (count > 0) { int toRead = (int)Math.Min(count, device.wbfsSectorSize - ((deviceLBA - wbfsSectorLBA) << device.hdSectorSize_s) - offset); if (deviceLBA == 0) { Array.Clear(buffer, read, toRead); } else { int absoluteRead = (int)((((offset + toRead - 1) / device.hdSectorSize) + 1) << device.hdSectorSize_s); Byte[] absoluteBuffer = new byte[absoluteRead]; if ((ret = context.Read(absoluteBuffer, absoluteRead)) != IORet.RET_IO_OK) { return(ret); } Array.Copy(absoluteBuffer, offset, buffer, read, toRead); } read += toRead; count -= toRead; discPosition += toRead; Seek(discPosition); } return(IORet.RET_IO_OK); }
//---------------------------- Rotinas public MBRReader(string device) { IIOContext pdrive = IOManager.CreateIOContext("PDRIVE\\" + device, device, FileAccess.Read, FileShare.Read, 0, FileMode.Open, EFileAttributes.NoBuffering); if (pdrive.Result != 0) { result = pdrive.Result; return; } if (pdrive.Lock() != IORet.RET_IO_OK) { //Loga a informação result = pdrive.Result; return; } Byte[] mbr = new byte[512]; if (pdrive.Read(mbr, 512) != IORet.RET_IO_OK) { result = pdrive.Result; pdrive.Unlock(); pdrive.Close(); return; } //----------------- //MBRReader(byte[] mbr) //----------------- pdrive.Unlock(); pdrive.Close(); }
//--------------------------- Retorna as informações da iso de Wii public static Int32 SetIsoInformation(String file, string code, string name) { IIOContext context = IOManager.CreateIOContext("ISWIIISO", file, FileAccess.ReadWrite, FileShare.Read, 0, FileMode.Open, EFileAttributes.None); if (context.Result != (int)IORet.RET_IO_OK) { //Loga erro return(context.Result); } else { int r = (int)context.Lock(); if (r != (int)IORet.RET_IO_OK) { //Loga erro context.Close(); return(r); } Byte[] header = new Byte[256]; if (context.Read(header, 256) != IORet.RET_IO_OK) { //Loga erro r = context.Result; context.Unlock(); context.Close(); return(r); } uint magic = _be32(header, 24); if (magic != 0x5D1C9EA3) { context.Unlock(); context.Close(); header = null; return((int)WBFSRet.RET_WBFS_NOTAWIIDISC); } header = null; // if (code.Length != 0) { if (code.Length != WBFSDevice.IsoCodeLen) { if (code.Length < WBFSDevice.IsoCodeLen) { while (code.Length < WBFSDevice.IsoCodeLen) { code += '0'; } } else { code = code.Substring(0, WBFSDevice.IsoCodeLen); //Eu preciso fazer isso para o GetDiscByCode() } } context.Seek(WBFSDevice.IsoCodePos); context.Write(code, false); } if (name.Length != 0) { if (name.Length > WBFSDevice.IsoNameLen) { name = name.Substring(0, WBFSDevice.IsoNameLen); } context.Seek(WBFSDevice.IsoNamePos); context.Write(name, false); for (int i = name.Length; i < WBFSDevice.IsoNameLen; i++) { context.Write((byte)0); } } // context.Unlock(); context.Close(); return(0); } }
//--------------------------- Retorna as informações da iso de Wii public static Int32 GetIsoInformation(String file, out string code, out string name, out int region) { code = ""; name = ""; region = -1; IIOContext context = IOManager.CreateIOContext("ISWIIISO", file, FileAccess.Read, FileShare.ReadWrite, 0, FileMode.Open, EFileAttributes.None); if (context.Result != (int)IORet.RET_IO_OK) { //Loga erro return(context.Result); } else { int r = (int)context.Lock(); if (r != (int)IORet.RET_IO_OK) { //Loga erro context.Close(); return(r); } Byte[] header = new Byte[256]; if (context.Read(header, 256) != IORet.RET_IO_OK) { //Loga erro r = context.Result; context.Unlock(); context.Close(); header = null; return(r); } uint magic = _be32(header, 24); if (magic != 0x5D1C9EA3) { context.Unlock(); context.Close(); header = null; return((int)WBFSRet.RET_WBFS_NOTAWIIDISC); } //Lê o código do jogo de 6 caracteres int j = WBFSDevice.IsoCodePos; byte c = 0; for (j = WBFSDevice.IsoCodePos; j < WBFSDevice.IsoCodePos + WBFSDevice.IsoCodeLen; j++) { code += (char)header[j]; } //Lê o nome do jogo j = WBFSDevice.IsoNamePos; while (((c = header[j++]) != 0) && (j < WBFSDevice.IsoNamePos + WBFSDevice.IsoNameLen)) { name += (char)c; } if (context.Read(header, WBFSDevice.IsoRegionPos, 4) != IORet.RET_IO_OK) { //Loga erro r = context.Result; context.Unlock(); context.Close(); header = null; return(r); } region = (int)System.Net.IPAddress.NetworkToHostOrder((int)BitConverter.ToUInt32(header, 0)); context.Unlock(); context.Close(); header = null; return(0); } }