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

📄 sendimpacket.java

📁 用java实现的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	    	if(!sub.equals("")) {
	    	    b = Utils.getBytes(sub, QQ.QQ_CHARSET_DEFAULT);
			    buf.put(b);
	    	}
		    buf.put((byte)0x14);
		    buf.put((byte)(message.charAt(j + 1) & 0xFF));
		    i = j + 2;
	    }
	    if(i < message.length()) {
	    	String sub = message.substring(i);
	    	b = Utils.getBytes(sub, QQ.QQ_CHARSET_DEFAULT);	
		    buf.put(b);	    	
	    }
	    buf.put((byte)0x20); // 空格,不要也没事,但是能尽量和QQ一致就一致
	    buf.put((byte)0);    // 0x0
	    // 消息尾部,字体修饰属性
	    buf.put(fontFlag);
	    // 字体颜色红绿篮
	    buf.put(red);
	    buf.put(green);
	    buf.put(blue);
	    // 一个未知字节
	    buf.put((byte)0);
	    // 消息编码
	    buf.putChar(encoding);
	    // 字体
	    buf.put(fontName.getBytes());
	    // 最后一个回车符
	    buf.put((byte)0x0D);   
	}

	/**
     * 调试方法,从QQ的抓包中里面解析出内容,看看有没有问题,实际中请勿使用
     */
    public byte[] forDebug(byte[] packetBuf) {
        // 提取加密内容
        byte[] buf = new byte[packetBuf.length - 12];
        System.arraycopy(packetBuf, 11, buf, 0, buf.length);
        // 解密
        buf = crypter.decrypt(buf, user.getSessionKey());
        // 创建流
        ByteArrayInputStream bais = new ByteArrayInputStream(buf);
        DataInputStream dis = new DataInputStream(bais);
        
        try {
            log.debug("接收者: " + dis.readInt());
            log.debug("发送者: " + dis.readInt());
            log.debug("发送者QQ版本: " + Utils.getClientString(dis.readChar()));
            log.debug("接收者: " + dis.readInt());
            log.debug("发送者: " + dis.readInt());
            log.debug("跳过16字节MD5");
            dis.skipBytes(16);
            log.debug("消息类型: " + Utils.getIMTypeString(dis.readChar()));
            log.debug("消息序号: " + (int)dis.readChar());
            log.debug("发送时间: " + new Date((long)dis.readInt() * 1000L).toString());
            log.debug("跳过1字节");
            dis.skipBytes(1);
            log.debug("发送者头像: " + (dis.readByte() & 0xFF));
            log.debug("跳过8字节");
            dis.skipBytes(8);
            log.debug("消息回复类型: " + Utils.getIMReplyType(dis.readByte()));
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(baos);
            while(true) {
                byte b = dis.readByte();
                if(b == 0) break;
                dos.writeByte(b);
            }
            message = new String(baos.toByteArray(), QQ.QQ_CHARSET_DEFAULT);
            log.debug("消息正文: " + message);
            dos.close();
            byte flag = dis.readByte();
            log.debug("字体大小: " + (int)(flag & 0x1F));
            log.debug("粗体: " + ((flag & 0x20) != 0));
            log.debug("斜体: " + ((flag & 0x40) != 0));
            log.debug("下划线: " + ((flag & 0x80) != 0));
            log.debug("红: " + (dis.readByte() & 0xFF));
            log.debug("绿: " + (dis.readByte() & 0xFF));
            log.debug("蓝: " + (dis.readByte() & 0xFF));
            log.debug("跳过1字节");
            dis.skipBytes(1);
            log.debug("消息编码: " + Utils.getEncodingString(dis.readChar()));
            byte[] f = new byte[dis.available()];
            dis.read(f);
            log.debug("字体: " + new String(f, QQ.QQ_CHARSET_DEFAULT));
            
            return message.getBytes();
        } catch (IOException e) {
            log.debug("解析出错");
            return null;
        }        
    }

    /**
     * @return Returns the blue.
     */
    public byte getBlue() {
        return blue;
    }
    
    /**
     * @param blue The blue to set.
     */
    public void setBlue(byte blue) {
        this.blue = blue;
    }
    
    /**
     * @return Returns the bold.
     */
    public boolean isBold() {
        return bold;
    }
    
    /**
     * @param bold The bold to set.
     */
    public void setBold(boolean bold) {
        this.bold = bold;
        fontFlag &= 0xDF;
        fontFlag |= bold ? 0x20 : 0x00;
    }
    
    /**
     * @return Returns the encoding.
     */
    public char getEncoding() {
        return encoding;
    }
    
    /**
     * @param encoding The encoding to set.
     */
    public void setEncoding(char encoding) {
        this.encoding = encoding;
    }
    
    /**
     * @return Returns the fontName.
     */
    public String getFontName() {
        return fontName;
    }
    
    /**
     * @param fontName The fontName to set.
     */
    public void setFontName(String fontName) {
        this.fontName = fontName;
    }
    
    /**
     * @return Returns the green.
     */
    public byte getGreen() {
        return green;
    }
    
    /**
     * @param green The green to set.
     */
    public void setGreen(byte green) {
        this.green = green;
    }
    
    /**
     * @return Returns the italic.
     */
    public boolean isItalic() {
        return italic;
    }
    
    /**
     * @param italic The italic to set.
     */
    public void setItalic(boolean italic) {
        this.italic = italic;
        fontFlag &= 0xBF;
        fontFlag |= italic ? 0x40 : 0x00;
    }
    
    /**
     * @return Returns the receiverQqNum.
     */
    public int getReceiver() {
        return receiver;
    }
    
    /**
     * @param receiverQqNum The receiverQqNum to set.
     */
    public void setReceiver(int receiverQqNum) {
        this.receiver = receiverQqNum;
    }
    
    /**
     * @return Returns the red.
     */
    public byte getRed() {
        return red;
    }
    
    /**
     * @param red The red to set.
     */
    public void setRed(byte red) {
        this.red = red;
    }
    
    /**
     * @return Returns the underline.
     */
    public boolean isUnderline() {
        return underline;
    }
    
    /**
     * @param underline The underline to set.
     */
    public void setUnderline(boolean underline) {
        this.underline = underline;
        fontFlag &= 0x7F;
        fontFlag |= underline ? 0x80 : 0x00;
    }
    
    /**
     * @return Returns the message.
     */
    public String getMessage() {
        return message;
    }
    
    /**
     * @param message The message to set.
     */
    public void setMessage(String message) {
        this.message = message;
    }
    
    /**
     * @return Returns the messageType.
     */
    public char getMessageType() {
        return messageType;
    }
    
    /**
     * @param messageType The messageType to set.
     */
    public void setMessageType(char messageType) {
        this.messageType = messageType;
    }
    
    /**
     * @return Returns the replyType.
     */
    public byte getReplyType() {
        return replyType;
    }
    
    /**
     * @param replyType The replyType to set.
     */
    public void setReplyType(byte replyType) {
        this.replyType = replyType;
    }
    
    /**
     * @return Returns the fontSize.
     */
    public byte getFontSize() {
        return fontSize;
    }
    
    /**
     * @param fontSize The fontSize to set.
     */
    public void setFontSize(byte fontSize) {
        this.fontSize = fontSize;
        fontSize &= 0x1F;
        fontFlag &= 0xE0;
        fontFlag |= fontSize;
    }
    
	/**
	 * @param filePath The filePath to set.
	 */
	public void setFileName(String filePath) {
		this.fileName = filePath;
	}
	
	/**
	 * @param fileSize The fileSize to set.
	 */
	public void setFileSize(int size) {
		this.fileSize = String.valueOf(size) + " 字节";
	}
	
	/**
	 * @param port The port to set.
	 */
	public void setDirectPort(int port) {
		this.directPort = (char)port;
	}
    
	/**
	 * @return Returns the requestSequence.
	 */
	public char getRequestSequence() {
		return requestSequence;
	}
	
	/**
	 * @param requestSequence The requestSequence to set.
	 */
	public void setRequestSequence(char requestSequence) {
		this.requestSequence = requestSequence;
	}
	
    /**
     * @return Returns the localIp.
     */
    public byte[] getLocalIp() {
        return localIp;
    }
    
    /**
     * @param localIp The localIp to set.
     */
    public void setLocalIp(byte[] localIp) {
        this.localIp = localIp;
    }
    
    /**
     * @return Returns the localPort.
     */
    public char getLocalPort() {
        return localPort;
    }
    
    /**
     * @param localPort The localPort to set.
     */
    public void setLocalPort(int localPort) {
        this.localPort = (char)localPort;
    }
}

⌨️ 快捷键说明

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