public static ReadByteArray ( Stream fs ) : byte[] | ||
fs | Stream | |
Résultat | byte[] |
public static RegChange ReadFromStream(Stream fs) { RegChange regChange = new RegChange(); bool flag = false; byte b = (byte)fs.ReadByte(); while (!ReadFiles.ReachedEndByte(fs, b, 158)) { switch (b) { case 1: regChange.RegOperation = (RegOperations)ReadFiles.ReadInt(fs); break; case 2: regChange.RegBasekey = (RegBasekeys)ReadFiles.ReadInt(fs); break; case 3: regChange.RegValueKind = (RegistryValueKind)ReadFiles.ReadInt(fs); break; case 4: regChange.SubKey = ReadFiles.ReadDeprecatedString(fs); break; case 5: regChange.ValueName = ReadFiles.ReadDeprecatedString(fs); break; case 6: if (regChange.RegValueKind != RegistryValueKind.ExpandString && regChange.RegValueKind != RegistryValueKind.String) { regChange.RegValueKind = RegistryValueKind.String; } regChange.ValueData = ReadFiles.ReadDeprecatedString(fs); break; case 128: flag = true; break; case 129: regChange.Is32BitKey = true; break; case 7: switch (regChange.RegValueKind) { case RegistryValueKind.Binary: if (flag) { regChange.ValueData = ReadFiles.ReadDeprecatedString(fs); } else { regChange.ValueData = ReadFiles.ReadByteArray(fs); } break; case RegistryValueKind.DWord: regChange.ValueData = ReadFiles.ReadInt(fs); break; case RegistryValueKind.QWord: regChange.ValueData = ReadFiles.ReadLong(fs); break; case RegistryValueKind.String: case RegistryValueKind.ExpandString: case RegistryValueKind.MultiString: regChange.ValueData = ReadFiles.ReadDeprecatedString(fs); break; } break; default: ReadFiles.SkipField(fs, b); break; } b = (byte)fs.ReadByte(); } return(regChange); }
public static ServerFile Load(string fileName, string updatePathVar, string customUrlArgs) { ServerFile serv = new ServerFile(); byte[] fileIDBytes = new byte[7]; Stream fs = null; try { fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); // Read the first 7 bytes of identification data fs.Read(fileIDBytes, 0, 7); } catch (Exception) { if (fs != null) { fs.Close(); } throw; } // check for compression (see if PKZip header is there) if (fileIDBytes[0] == 0x50 && fileIDBytes[1] == 0x4B && fileIDBytes[2] == 0x03 && fileIDBytes[3] == 0x04) { // decompress the "actual" server file to memory fs.Close(); using (ZipFile zip = ZipFile.Read(fileName)) { fs = new MemoryStream(); zip["0"].Extract(fs); } fs.Position = 0; // Read the first 7 bytes of identification data fs.Read(fileIDBytes, 0, 7); } // see if the file is in the correct server format string fileID = Encoding.UTF8.GetString(fileIDBytes); if (fileID != "IUSDFV2") { //free up the file so it can be deleted fs.Close(); throw new Exception("The downloaded server file does not have the correct identifier. This is usually caused by file corruption."); } serv.VersionChoices.Add(new VersionChoice()); byte bType = (byte)fs.ReadByte(); while (!ReadFiles.ReachedEndByte(fs, bType, 0xFF)) { switch (bType) { case 0x01: //Read New Version serv.NewVersion = ReadFiles.ReadDeprecatedString(fs); break; case 0x07: //Min Client version serv.MinClientVersion = ReadFiles.ReadDeprecatedString(fs); break; case 0x0B: //The version to update from if (serv.VersionChoices.Count > 1 || serv.VersionChoices[0].Version != null) { serv.VersionChoices.Add(new VersionChoice()); } serv.VersionChoices[serv.VersionChoices.Count - 1].Version = ReadFiles.ReadDeprecatedString(fs); break; case 0x03: //Add update file site string updateSite = ReadFiles.ReadDeprecatedString(fs); if (updatePathVar != null) { updateSite = updateSite.Replace("%updatepath%", updatePathVar); } updateSite = updateSite.Replace("%urlargs%", customUrlArgs ?? string.Empty); ClientFile.AddUniqueString(updateSite, serv.VersionChoices[serv.VersionChoices.Count - 1].FileSites); break; case 0x80: //the changes text is in RTF format serv.VersionChoices[serv.VersionChoices.Count - 1].RTFChanges = true; break; case 0x04: //Read Changes serv.VersionChoices[serv.VersionChoices.Count - 1].Changes = ReadFiles.ReadDeprecatedString(fs); break; case 0x09: //update's filesize serv.VersionChoices[serv.VersionChoices.Count - 1].FileSize = ReadFiles.ReadLong(fs); break; case 0x08: //update's Adler32 checksum serv.VersionChoices[serv.VersionChoices.Count - 1].Adler32 = ReadFiles.ReadLong(fs); break; case 0x14: // signed SHA1 hash serv.VersionChoices[serv.VersionChoices.Count - 1].SignedSHA1Hash = ReadFiles.ReadByteArray(fs); break; case 0x0A: //Installing to which directories? serv.VersionChoices[serv.VersionChoices.Count - 1].InstallingTo = (InstallingTo)ReadFiles.ReadInt(fs); break; case 0x8E: //the RegChanges (built with wyBuid 2.6.11.4 and below) if (RegChange.ReadFromStream(fs).RegBasekey != RegBasekeys.HKEY_CURRENT_USER) { serv.VersionChoices[serv.VersionChoices.Count - 1].InstallingTo |= InstallingTo.NonCurrentUserReg; } break; case 0x20: serv.NoUpdateToLatestLinkText = ReadFiles.ReadDeprecatedString(fs); break; case 0x21: serv.NoUpdateToLatestLinkURL = ReadFiles.ReadDeprecatedString(fs); break; case 0x0F: //skip over the integer (4 bytes) length //this is just used to trick pre-1.0 Final versions //of wyUpdate to correctly read the server file correctly fs.Position += 4; break; default: ReadFiles.SkipField(fs, bType); break; } bType = (byte)fs.ReadByte(); } fs.Close(); return(serv); }
public static RegChange ReadFromStream(Stream fs) { RegChange tempReg = new RegChange(); bool isBinaryString = false; byte bType = (byte)fs.ReadByte(); //read until the end byte is detected while (!ReadFiles.ReachedEndByte(fs, bType, 0x9E)) { switch (bType) { case 0x01: //RegOperation tempReg.RegOperation = (RegOperations)ReadFiles.ReadInt(fs); break; case 0x02: //load basekey tempReg.RegBasekey = (RegBasekeys)ReadFiles.ReadInt(fs); break; case 0x03: //load valuekind tempReg.RegValueKind = (RegistryValueKind)ReadFiles.ReadInt(fs); break; case 0x04: //subkey tempReg.SubKey = ReadFiles.ReadDeprecatedString(fs); break; case 0x05: //value name tempReg.ValueName = ReadFiles.ReadDeprecatedString(fs); break; case 0x06: //Depreciated: Use 0x07. All 0x06 will be converted to a string "ValueKind" if (tempReg.RegValueKind != RegistryValueKind.ExpandString && tempReg.RegValueKind != RegistryValueKind.String) { //Read in the entry,if it's tempReg.RegValueKind = RegistryValueKind.String; } tempReg.ValueData = ReadFiles.ReadDeprecatedString(fs); break; case 0x80: isBinaryString = true; break; case 0x81: tempReg.Is32BitKey = true; break; case 0x07: //Value data switch (tempReg.RegValueKind) { case RegistryValueKind.Binary: if (isBinaryString) { tempReg.ValueData = ReadFiles.ReadDeprecatedString(fs); } else { tempReg.ValueData = ReadFiles.ReadByteArray(fs); } break; case RegistryValueKind.DWord: tempReg.ValueData = ReadFiles.ReadInt(fs); break; case RegistryValueKind.QWord: tempReg.ValueData = ReadFiles.ReadLong(fs); break; case RegistryValueKind.ExpandString: case RegistryValueKind.MultiString: case RegistryValueKind.String: tempReg.ValueData = ReadFiles.ReadDeprecatedString(fs); break; } break; default: ReadFiles.SkipField(fs, bType); break; } bType = (byte)fs.ReadByte(); } return(tempReg); }