/// <summary> /// This method replaces IP addresses based on some identifier /// </summary> /// <param name="payload">Payload to be translated</param> /// <param name="old_ss_ip">Old source IP address</param> /// <param name="old_sd_ip">Old destination IP</param> /// <param name="new_ss_ip">New source IP address</param> /// <param name="new_sd_ip">New destination IP address</param> /// <param name="packet_id">A packet identifier</param> /// <returns>A MemBlock of the translated payload</returns> public static MemBlock TextTranslate(MemBlock payload, string old_ss_ip, string old_sd_ip, string new_ss_ip, string new_sd_ip, string packet_id) { string sdata = payload.GetString(System.Text.Encoding.UTF8); if(sdata.Contains(packet_id)) { sdata = sdata.Replace(old_ss_ip, new_ss_ip); sdata = sdata.Replace(old_sd_ip, new_sd_ip); payload = MemBlock.Reference(System.Text.Encoding.UTF8.GetBytes(sdata)); } return payload; }
public static string ReadString(MemBlock b, int offset, out int bytelength) { int null_idx = b.IndexOf(0, offset); int raw_length = null_idx - offset; bytelength = raw_length + 1; //One for the null Encoding e; /* * Benchmarks of mono show this to be about twice as fast as just * using UTF8. That really means UTF8 could be optimized in mono */ if( b.IsAscii(offset, raw_length) ) { e = Encoding.ASCII; } else { e = Encoding.UTF8; } return b.GetString(e, offset, raw_length); }