private static void CompleteDownload(LocalStorageFileState state) { bool flag = true; LocalStorageAPI.s_log.LogDebug("Download completed for State={0}", new object[] { state }); HTTPHeader hTTPHeader = LocalStorageAPI.ParseHTTPHeader(state.FileData); if (hTTPHeader != null) { byte[] numArray = new byte[hTTPHeader.ContentLength]; Array.Copy(state.FileData, hTTPHeader.ContentStart, numArray, 0, hTTPHeader.ContentLength); if (LocalStorageAPI.ComputeSHA256(numArray) == state.CH.Sha256Digest) { flag = false; LocalStorageAPI.DecompressStateIfPossible(state, numArray); } else { LocalStorageAPI.s_log.LogWarning("Integrity check failed for State={0}", new object[] { state }); } } else { LocalStorageAPI.s_log.LogWarning("Parsinig of HTTP header failed for State={0}", new object[] { state }); } if (flag || state.FileData == null) { LocalStorageAPI.ExecuteFailedDownload(state); } else { LocalStorageAPI.ExecuteSucessfulDownload(state); } }
private static HTTPHeader ParseHTTPHeader(byte[] data) { try { int num = LocalStorageAPI.SearchForBytePattern(data, new byte[] { 13, 10, 13, 10 }); HTTPHeader result; if (num == -1) { result = null; return(result); } int num2 = num + 1; if (num2 >= data.Length) { result = null; return(result); } string @string = Encoding.get_ASCII().GetString(data, 0, num); if (@string.IndexOf("200 OK") == -1) { result = null; return(result); } Regex regex = new Regex("(?<=Content-Length:\\s)\\d+", 1); Match match = regex.Match(@string); if (!match.get_Success()) { result = null; return(result); } int num3 = (int)uint.Parse(match.get_Value()); int num4 = data.Length - num2; if (num3 != num4) { result = null; return(result); } result = new HTTPHeader { ContentLength = num3, ContentStart = num2 }; return(result); } catch (Exception ex) { LocalStorageAPI.s_log.LogWarning("EXCEPTION (ParseHTTPHeader): {0}", new object[] { ex.get_Message() }); } return(null); }
private static HTTPHeader ParseHTTPHeader(byte[] data) { HTTPHeader hTTPHeader; try { int num = LocalStorageAPI.SearchForBytePattern(data, new byte[] { 13, 10, 13, 10 }); if (num != -1) { int num1 = num + 1; if (num1 < (int)data.Length) { string str = Encoding.ASCII.GetString(data, 0, num); if (str.IndexOf("200 OK") != -1) { Match match = (new Regex("(?<=Content-Length:\\s)\\d+", RegexOptions.IgnoreCase)).Match(str); if (match.Success) { int num2 = (int)uint.Parse(match.Value); if (num2 == (int)data.Length - num1) { HTTPHeader hTTPHeader1 = new HTTPHeader() { ContentLength = num2, ContentStart = num1 }; hTTPHeader = hTTPHeader1; } else { hTTPHeader = null; } } else { hTTPHeader = null; } } else { hTTPHeader = null; } } else { hTTPHeader = null; } } else { hTTPHeader = null; } } catch (Exception exception1) { Exception exception = exception1; LocalStorageAPI.s_log.LogWarning("EXCEPTION (ParseHTTPHeader): {0}", new object[] { exception.Message }); return(null); } return(hTTPHeader); }