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

📄 dismantlebytecode.java

📁 一个查找java程序里bug的程序的源代码,该程序本身也是java写的,对提高java编程水平很有用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
						int npairs = byteStream.readInt();						i += 4;						switchOffsets = new int[npairs];						switchLabels = new int[npairs];						for (int o = 0; o < npairs; o++) {							switchLabels[o] = byteStream.readInt();							switchOffsets[o] = byteStream.readInt();							i += 8;						}						;						sortByOffset(switchOffsets, switchLabels);					} else if (opcode == TABLESWITCH) {						int pad = 4 - (i & 3);						if (pad == 4) pad = 0;						byteStream.skipBytes(pad);						i += pad;						defaultSwitchOffset = byteStream.readInt();						branchOffset = defaultSwitchOffset;						branchTarget = branchOffset + PC;						i += 4;						switchLow = byteStream.readInt();						i += 4;						switchHigh = byteStream.readInt();						i += 4;						int npairs = switchHigh - switchLow + 1;						switchOffsets = new int[npairs];						switchLabels = new int[npairs];						for (int o = 0; o < npairs; o++) {							switchLabels[o] = o + switchLow;							switchOffsets[o] = byteStream.readInt();							i += 4;						}						;						sortByOffset(switchOffsets, switchLabels);					} else if (opcode == WIDE) {						opcodeIsWide = true;						opcode = byteStream.readUnsignedByte();						i++;						switch (opcode) {						case ILOAD:						case FLOAD:						case ALOAD:						case LLOAD:						case DLOAD:						case ISTORE:						case FSTORE:						case ASTORE:						case LSTORE:						case DSTORE:						case RET:							registerOperand = byteStream.readUnsignedShort();							i += 2;							break;						case IINC:							registerOperand = byteStream.readUnsignedShort();							i += 2;							intConstant = byteStream.readShort();							i += 2;							break;						default:							throw new IllegalStateException("bad wide bytecode: " + OPCODE_NAMES[opcode]);						}					} else						throw new IllegalStateException("bad unpredicatable bytecode: " + OPCODE_NAMES[opcode]);				} else {					if (byteStreamArgCount < 0) throw new IllegalStateException("bad length for bytecode: " + OPCODE_NAMES[opcode]);					for (int k = 0; k < TYPE_OF_OPERANDS[opcode].length; k++) {						int v;						int t = TYPE_OF_OPERANDS[opcode][k];						int m = MEANING_OF_OPERANDS[opcode][k];						boolean unsigned = (m == M_CP || m == M_R || m == M_UINT);						switch (t) {						case T_BYTE:							if (unsigned)								v = byteStream.readUnsignedByte();							else								v = byteStream.readByte();							/*							System.out.print("Read byte " + v);							System.out.println(" with meaning" + m);							*/							i++;							break;						case T_SHORT:							if (unsigned)								v = byteStream.readUnsignedShort();							else								v = byteStream.readShort();							i += 2;							break;						case T_INT:							v = byteStream.readInt();							i += 4;							break;						default:							throw new IllegalStateException();						}						switch (m) {						case M_BR:							branchOffset = v;							branchTarget = v + PC;							branchFallThrough = i;							break;						case M_CP:							constantRefOperand = getConstantPool().getConstant(v);							if (constantRefOperand instanceof ConstantClass) {								ConstantClass clazz = (ConstantClass) constantRefOperand;								classConstantOperand = getStringFromIndex(clazz.getNameIndex()).intern();								dottedClassConstantOperand = replaceSlashesWithDots(classConstantOperand);							}							if (constantRefOperand instanceof ConstantInteger)								intConstant = ((ConstantInteger) constantRefOperand).getBytes();							else if (constantRefOperand instanceof ConstantLong)								longConstant = ((ConstantLong) constantRefOperand).getBytes();							else if (constantRefOperand instanceof ConstantFloat)								floatConstant = ((ConstantFloat) constantRefOperand).getBytes();							else if (constantRefOperand instanceof ConstantDouble)								doubleConstant = ((ConstantDouble) constantRefOperand).getBytes();							else if (constantRefOperand instanceof ConstantString) {								int s = ((ConstantString) constantRefOperand).getStringIndex();								stringConstantOperand = getStringFromIndex(s);							} else if (constantRefOperand instanceof ConstantCP) {								ConstantCP cp = (ConstantCP) constantRefOperand;								ConstantClass clazz								        = (ConstantClass) getConstantPool().getConstant(cp.getClassIndex());								classConstantOperand = getStringFromIndex(clazz.getNameIndex()).intern();								dottedClassConstantOperand = replaceSlashesWithDots(classConstantOperand);								ConstantNameAndType sig								        = (ConstantNameAndType) getConstantPool().getConstant(cp.getNameAndTypeIndex());								nameConstantOperand = getStringFromIndex(sig.getNameIndex());								sigConstantOperand = getStringFromIndex(sig.getSignatureIndex()).intern();								dottedSigConstantOperand = replaceSlashesWithDots(sigConstantOperand);								StringBuffer ref = new StringBuffer(5 + dottedClassConstantOperand.length()								        + nameConstantOperand.length()								        + dottedSigConstantOperand.length());								ref.append(dottedClassConstantOperand)								        .append(".")								        .append(nameConstantOperand)								        .append(" : ")								        .append(dottedSigConstantOperand);								refConstantOperand = ref.toString();							}							break;						case M_R:							registerOperand = v;							break;						case M_UINT:						case M_INT:							intConstant = v;						}					}				}				switch (opcode) {				case ILOAD:				case FLOAD:				case ALOAD:				case LLOAD:				case DLOAD:					registerKind = opcode - ILOAD;					break;				case ISTORE:				case FSTORE:				case ASTORE:				case LSTORE:				case DSTORE:					registerKind = opcode - ISTORE;					break;				case RET:					registerKind = R_REF;					break;				case GETSTATIC:				case PUTSTATIC:					refFieldIsStatic = true;					break;				case GETFIELD:				case PUTFIELD:					refFieldIsStatic = false;					break;				}				sawOpcode(opcode);				if (opcode == TABLESWITCH) {					sawInt(switchLow);					sawInt(switchHigh);					int prevOffset = i - PC;					for (int o = 0; o <= switchHigh - switchLow; o++) {						sawOffset(switchOffsets[o] - prevOffset);						prevOffset = switchOffsets[o];					}					sawOffset(defaultSwitchOffset - prevOffset);				} else if (opcode == LOOKUPSWITCH) {					sawInt(switchOffsets.length);					int prevOffset = i - PC;					for (int o = 0; o < switchOffsets.length; o++) {						sawOffset(switchOffsets[o] - prevOffset);						prevOffset = switchOffsets[o];						sawInt(switchLabels[o]);					}					sawOffset(defaultSwitchOffset - prevOffset);				} else					for (int k = 0; k < TYPE_OF_OPERANDS[opcode].length; k++) {						int m = MEANING_OF_OPERANDS[opcode][k];						switch (m) {						case M_BR:							if (branchOffset > 0)								sawOffset(branchOffset - (i - PC));							else								sawOffset(branchOffset);							break;						case M_CP:							if (constantRefOperand instanceof ConstantInteger)								sawInt(intConstant);							else if (constantRefOperand instanceof ConstantLong)								sawLong(longConstant);							else if (constantRefOperand instanceof ConstantFloat)								sawFloat(floatConstant);							else if (constantRefOperand instanceof ConstantDouble)								sawDouble(doubleConstant);							else if (constantRefOperand instanceof ConstantString)								sawString(stringConstantOperand);							else if (constantRefOperand instanceof ConstantFieldref)								sawField();							else if (constantRefOperand instanceof ConstantMethodref)								sawMethod();							else if (constantRefOperand instanceof ConstantInterfaceMethodref)								sawIMethod();							else if (constantRefOperand instanceof ConstantClass)								sawClass();							break;						case M_R:							sawRegister(registerOperand);							break;						case M_INT:							sawInt(intConstant);							break;						}					}			}		} catch (IOException e) {			System.out.println("Got IO Exception:");			e.printStackTrace();		}		try {			byteStream.close();		} catch (IOException e) {			assert false;		}	}	public void sawDouble(double seen) {	}	public void sawFloat(float seen) {	}	public void sawRegister(int r) {	}	public void sawInt(int seen) {	}	public void sawLong(long seen) {	}	public void sawOffset(int seen) {	}	public void sawOpcode(int seen) {	}	public void sawString(String seen) {	}	public void sawField() {	}	public void sawMethod() {	}	public void sawIMethod() {	}	public void sawClass() {	}}

⌨️ 快捷键说明

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