private void AddToTable(string HexString, TableString tableString) { for (int k = 0; k < HexString.Length; k += 2) { tableString.bytes.Add(Convert.ToByte(HexString.Substring(k, 2), 16)); } }
private void AddToTable (string HexString, TableString tableString) { for (int k = 0; k < HexString.Length; k +=2) { tableString.bytes.Add(Convert.ToByte(HexString.Substring(k, 2), 16)); } }
/// <summary> /// Encodes a string. /// </summary> /// <param name="scriptBuf">The string to encode.</param> /// <param name="BadCharOffset">The Bad char offset.</param> /// <returns>The size of the encoded stream.</returns> public int EncodeStream(string scriptBuf, ref int BadCharOffset) { TableString tablestring = new TableString(); string hexstr = string.Empty; string subtextstr = string.Empty; int i = 0; int EncodedSize = 0; int BufOffset = 0; BadCharOffset = 0; if (string.IsNullOrEmpty(scriptBuf)) { return(0); } if (StringTable.Count > 0) { TableString restoreString = StringTable[StringTable.Count - 1]; if (string.IsNullOrEmpty(restoreString.EndToken)) { StringTable.RemoveAt(StringTable.Count - 1); tablestring.bytes = restoreString.bytes; } } while (BufOffset < scriptBuf.Length) { int longestText = Table.LongestText[scriptBuf[BufOffset]]; for (i = longestText; i > 0; --i) { if (BufOffset + i >= scriptBuf.Length) { subtextstr = scriptBuf.Substring(BufOffset); } else { subtextstr = scriptBuf.Substring(BufOffset, i); } if (Table.LookupValue.ContainsKey(subtextstr)) { hexstr = Table.LookupValue[subtextstr]; EncodedSize += hexstr.Length; if (Table.EndTokens.Contains(subtextstr)) { if (AddEndToken) { AddToTable(hexstr, tablestring); } tablestring.EndToken = subtextstr; StringTable.Add(tablestring); tablestring = new TableString(); } else { AddToTable(hexstr, tablestring); } BufOffset += i; break; } } if (i == 0) { BadCharOffset = BufOffset; return(-1); } } if (tablestring.bytes.Count > 0) { StringTable.Add(tablestring); } return(EncodedSize); }
/// <summary> /// Encodes a string. /// </summary> /// <param name="scriptBuf">The string to encode.</param> /// <param name="BadCharOffset">The Bad char offset.</param> /// <returns>The size of the encoded stream.</returns> public int EncodeStream (string scriptBuf, ref int BadCharOffset) { TableString tablestring = new TableString(); string hexstr = string.Empty; string subtextstr = string.Empty; int i = 0; int EncodedSize = 0; int BufOffset = 0; BadCharOffset = 0; if (string.IsNullOrEmpty(scriptBuf)) { return 0; } if (StringTable.Count > 0) { TableString restoreString = StringTable[StringTable.Count - 1]; if (string.IsNullOrEmpty(restoreString.EndToken)) { StringTable.RemoveAt(StringTable.Count - 1); tablestring.bytes = restoreString.bytes; } } while (BufOffset < scriptBuf.Length) { int longestText = Table.LongestText[scriptBuf[BufOffset]]; for (i = longestText; i > 0; --i) { if (BufOffset + i >= scriptBuf.Length) { subtextstr = scriptBuf.Substring(BufOffset); } else { subtextstr = scriptBuf.Substring(BufOffset, i); } if (Table.LookupValue.ContainsKey(subtextstr)) { hexstr = Table.LookupValue[subtextstr]; EncodedSize += hexstr.Length; if (Table.EndTokens.Contains(subtextstr)) { if (AddEndToken) { AddToTable(hexstr, tablestring); } tablestring.EndToken = subtextstr; StringTable.Add(tablestring); tablestring = new TableString(); } else { AddToTable(hexstr, tablestring); } BufOffset += i; break; } } if (i == 0) { BadCharOffset = BufOffset; return -1; } } if (tablestring.bytes.Count > 0) { StringTable.Add(tablestring); } return EncodedSize; }