⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bluedumpspythread.java

📁 this a dump j2me source code
💻 JAVA
字号:
//------------------------------------------------------------------
// Copyright (c) 2004 Jyperion SARL
//                    France
//  
// This software is provided "AS IS," without a warranty of any kind. 
// ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, 
// INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A 
// PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
//
//------------------------------------------------------------------
package example.bluetooth.dump;

import java.io.IOException;

import javax.bluetooth.L2CAPConnection;
import javax.bluetooth.ServiceRecord;
import javax.microedition.io.Connector;

/**
/**
 * This class is the worker thread that will be launched to make a Bluetooth connection dump
 * The dump will be in infinite loop, so it must be ran inside a Thread 
 *
 * @author Guillaume COMPAGNON
 * @version 1.0
 */
public class BlueDumpSpyThread implements Runnable {
 
	
	L2CAPConnection conn = null;
	
	public void run() {
		try{
			if( BlueDump.singleton.record == null ) return;
		
			String conURL = BlueDump.singleton.record.getConnectionURL(ServiceRecord.AUTHENTICATE_NOENCRYPT, false);

			conn = (L2CAPConnection)Connector.open(conURL);
			int length = conn.getReceiveMTU();
		
			BlueDump.singleton.setStateConnected();
			BlueDump.display("Connected to "+conURL,BlueDumpGUI.BLUE);

			byte data[] = new byte[length];

			// start to dump the content on the GUI 
			while (BlueDump.singleton.record != null && (length =conn.receive(data))!=1) {
				String content = toHex(data);
				BlueDump.display(content);
			}
	}
	catch (Exception e) {
		if( BlueDump.DEBUG ) e.printStackTrace();
	}
	finally {
		close();
	}

} 


/**
 * Close the connection
 * state is now disconnected.
 */
public void close() {
	try{
		if (BlueDump.singleton.record == null) {
			return;
		}
		BlueDump.singleton.record = null;
		if(conn != null ) conn.close();
		conn = null;
		BlueDump.singleton.setStateDisconnected();
	}catch(IOException e){
		if( BlueDump.DEBUG) e.printStackTrace();
	}
}


private static final String symbols = "0123456789ABCDEF";

private static String toHex(byte[] n) {
	 
	 StringBuffer s = new StringBuffer("0x");
	 
	 for (int i = 0; i < n.length; i++) {
	 	int nd = n[i];
		char c  = symbols.charAt(nd % 16); 

		nd = nd / 16;
		s.append( symbols.charAt(nd % 16) );
		s.append(c);
	 }
		 
	 return s.toString();
 }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -