Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Looping through a String

$
0
0
I am sniffing packets sent to a printer. My problem is there are 2 distinct encodings in the packet utf16-be and utf16-le. Half the info is encoded in one lang and the other half is encoded in the second. I am a novice and I have tried several different loops and buffers but am not getting the results I want. I am looking to read through the packet twice then append it back to a single string. Any advice or help would be much appreciated.

for(int t=0; t<2;){
                String data1 = new String(packet.data, Charset.forName("UTF-16BE"));
			data1 = data1.replaceAll ("[^A-Za-z0-9#://>/>/>/s() ]", "");
                       t++;
		String data2 = new String(packet.data, Charset.forName("UTF-16LE"));
                data2 = data2.replaceAll ("[^A-Za-z0-9#://>/>/>/s() ]", "");
                       t++
			}
			
            start.append(data1);
            start.append(data2);
			
			data = start.toString() ;


and tried this

 if ((((IPPacket) packet).dst_ip.toString().equals("/xxx.xx.xx.xxx")) || (((IPPacket)     packet).src_ip.toString().equals("/xxx.xx.xx.xxx"))) {
			
			do{
			String data1 = new String(packet.data, Charset.forName("UTF-16BE"));
			data1 = data1.replaceAll ("[^A-Za-z0-9#://>/>/>/s() ]", "");
			String data2 = new String(packet.data, Charset.forName("UTF-16LE"));
			data2 = data2.replaceAll ("[^A-Za-z0-9#://>/>/>/s() ]", "");
			
			start.append(data1);
                        start.append(data2);}
            while(packet.data!= null);
			
			data = start.toString() ;

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>