private int getFixedAccess(int access, Modifier target) { target.oldAccess = access; int t = target.targetAccess; int ret = (access & ~7); switch (access & 7) { case ACC_PRIVATE: ret |= t; break; case 0: // default ret |= (t != ACC_PRIVATE ? t : 0 /* default */); break; case ACC_PROTECTED: ret |= (t != ACC_PRIVATE && t != 0 /* default */ ? t : ACC_PROTECTED); break; case ACC_PUBLIC: ret |= (t != ACC_PRIVATE && t != 0 /* default */ && t != ACC_PROTECTED ? t : ACC_PUBLIC); break; default: throw new RuntimeException("The f**k?"); } // Clear the "final" marker on fields only if specified in control field if (target.changeFinal && target.desc == "") { if (target.markFinal) { ret |= ACC_FINAL; } else { ret &= ~ACC_FINAL; } } target.newAccess = ret; return ret; }
public BlockWall() { this.id = Global.MODIFIER_ID.BLOCK_WALL; this.paint = new Paint(); this.paint.setColor(this.color2); this.wall = new GOModifier[Math.round(GameCanvas.WIDTH / BLOCK_SIZE)]; for (int n = 0; n < this.wall.length; n++) { final Modifier sbm = new SolidBlockMod(); // if (n % 2 == 0) { // sbm.paint.setColor(this.color2); // } else { // sbm.paint.setColor(this.color1); // } sbm.useDefaultLogoPaint(); final RectF box = new RectF(0, 0, BLOCK_SIZE, BLOCK_SIZE); this.wall[n] = new GOModifier(0, box, false, sbm); this.wall[n].destroyAfterColision = true; if (Global.gEngine != null) { Global.gEngine.addGameObject(this.wall[n]); } } this.useDefaultLogoPaint(); this.leftLogoOffset = 0.03f; this.bottonLogoOffset = -0.04f; this.logoSize = 1.45f; this.logoString = "\u2509"; }
public static int getModifiersFrom(IAttributedFeatureInfo afi) { int iModifiers = 0; iModifiers = Modifier.setBit(iModifiers, afi.isPublic(), PUBLIC); iModifiers = Modifier.setBit(iModifiers, afi.isPrivate(), PRIVATE); iModifiers = Modifier.setBit(iModifiers, afi.isProtected(), PROTECTED); iModifiers = Modifier.setBit(iModifiers, afi.isInternal(), INTERNAL); iModifiers = Modifier.setBit(iModifiers, afi.isStatic(), STATIC); return iModifiers; }
/* (non-Javadoc) * @see java.lang.Object#toString() */ public String toString() { StringBuffer sb = new StringBuffer(); for (Iterator iter = _modifiers.iterator(); iter.hasNext(); ) { Modifier mod = (Modifier) iter.next(); sb.append(mod.toString()); if (iter.hasNext()) sb.append(' '); } return sb.toString(); }
/** * @param name modifier name to parse * @param kinds if not empty, returns only a modifier that matches all of the kinds * @return Modifier that matches any of the kinds constraints */ public static Modifier parseModifier(String name, ModifierKind... kinds) { try { // Modifier modifier = Modifier.valueOf(name); Modifier modifier = mods.get(name); if (kinds.length == 0 || modifier == null) return modifier; for (ModifierKind kind : kinds) if (modifier.isA(kind)) return modifier; return kinds.length > 0 ? null : modifier; } catch (IllegalArgumentException ex) { return null; } }
public void onUnwield(Living who) { if (modifiers == null) return; Enumeration en = modifiers.elements(); while (en.hasMoreElements()) { Modifier m = (Modifier) en.nextElement(); m.deActivate(); } }
public static Modifier ref(Modifier... value) { Modifier first = PUBLIC; String seconds = ""; for (Modifier item : value) { if (item == PUBLIC || item == PACKAGE || item == PROTECTED || item == PRIVATE) { first = item; continue; } seconds += item.getValue(); } return new Modifier(first + seconds); }
/** * Given an abstract dispatch to an object of type c and a method m, gives a list of possible * receiver methods. */ public List resolveAbstractDispatch(SootClass c, SootMethod m) { c.checkLevel(SootClass.HIERARCHY); m.getDeclaringClass().checkLevel(SootClass.HIERARCHY); checkState(); Iterator<SootClass> classesIt = null; if (c.isInterface()) { classesIt = getImplementersOf(c).iterator(); HashSet<SootClass> classes = new HashSet<SootClass>(); while (classesIt.hasNext()) classes.addAll(getSubclassesOfIncluding(classesIt.next())); classesIt = classes.iterator(); } else classesIt = getSubclassesOfIncluding(c).iterator(); ArraySet s = new ArraySet(); while (classesIt.hasNext()) { SootClass cl = classesIt.next(); if (Modifier.isAbstract(cl.getModifiers())) continue; s.add(resolveConcreteDispatch(cl, m)); } List l = new ArrayList(); l.addAll(s); return Collections.unmodifiableList(l); }
private SimpleConfigList modify(Modifier modifier, ResolveStatus newResolveStatus) { // lazy-create for optimization List<AbstractConfigValue> changed = null; int i = 0; for (AbstractConfigValue v : value) { AbstractConfigValue modified = modifier.modifyChild(v); // lazy-create the new list if required if (changed == null && modified != v) { changed = new ArrayList<AbstractConfigValue>(); for (int j = 0; j < i; ++j) { changed.add(value.get(j)); } } // once the new list is created, all elements // have to go in it. if (changed != null) { changed.add(modified); } i += 1; } if (changed != null) { if (changed.size() != value.size()) throw new ConfigException.BugOrBroken("substituted list's size doesn't match"); return new SimpleConfigList(origin(), changed, newResolveStatus); } else { return this; } }
@Override public void act(float delta) { super.act(delta); if (modified) { modifier.getHandles().readActorTransformation(); modified = false; } }
@Customizer(link = "#getTranslationForDeleteMode") public DeleteFileOptions getDeleteMode() { // Modifier byPassDialog = getByPassDialogToggleModifier(); Modifier deletToggle = getDeleteFilesToggleModifier(); if (deleteMode == null) { deleteMode = DeleteFileOptions.REMOVE_LINKS_ONLY; } if (deletToggle != null && KeyObserver.getInstance().isModifierPressed(deletToggle.getModifier(), false)) { switch (deleteMode) { case REMOVE_LINKS_ONLY: return DeleteFileOptions.REMOVE_LINKS_AND_RECYCLE_FILES; case REMOVE_LINKS_AND_DELETE_FILES: case REMOVE_LINKS_AND_RECYCLE_FILES: return DeleteFileOptions.REMOVE_LINKS_ONLY; } } return deleteMode; }
/* 181: */ /* 182: */ public String toString() /* 183: */ { /* 184:142 */ StringBuffer buffer = new StringBuffer(getClass().getName()); /* 185:143 */ buffer.append("@"); /* 186:144 */ buffer.append(Integer.toHexString(hashCode())); /* 187:145 */ buffer.append("["); /* 188:146 */ buffer.append(Modifier.toString(getModifiers())); /* 189:147 */ extendToString(buffer); /* 190:148 */ buffer.append("]"); /* 191:149 */ return buffer.toString(); /* 192: */ }
public List<KeyStroke> getAdditionalShortcuts(KeyStroke keystroke) { if (keystroke == null) { return null; } ArrayList<KeyStroke> ret = new ArrayList<KeyStroke>(); Modifier mod1 = byPassDialog.getByPassDialogToggleModifier(); if (mod1 != null) { ret.add(KeyStroke.getKeyStroke(keystroke.getKeyCode(), keystroke.getModifiers() | mod1.getModifier())); } Modifier mod2 = getDeleteFilesToggleModifier(); if (mod2 != null) { ret.add(KeyStroke.getKeyStroke(keystroke.getKeyCode(), keystroke.getModifiers() | mod2.getModifier())); } if (mod2 != null && mod1 != null) { ret.add(KeyStroke.getKeyStroke(keystroke.getKeyCode(), keystroke.getModifiers() | mod2.getModifier() | mod1.getModifier())); } return ret; }
/* 200: */ /* 201: */ public boolean visibleFrom(CtClass clazz) /* 202: */ { /* 203:170 */ int mod = getModifiers(); /* 204:171 */ if (Modifier.isPublic(mod)) { /* 205:172 */ return true; /* 206: */ } /* 207:173 */ if (Modifier.isPrivate(mod)) { /* 208:174 */ return clazz == this.declaringClass; /* 209: */ } /* 210:176 */ String declName = this.declaringClass.getPackageName(); /* 211:177 */ String fromName = clazz.getPackageName(); /* 212: */ boolean visible; /* 213: */ boolean visible; /* 214:179 */ if (declName == null) { /* 215:180 */ visible = fromName == null; /* 216: */ } else { /* 217:182 */ visible = declName.equals(fromName); /* 218: */ } /* 219:184 */ if ((!visible) && (Modifier.isProtected(mod))) { /* 220:185 */ return clazz.subclassOf(this.declaringClass); /* 221: */ } /* 222:187 */ return visible; /* 223: */ }
public void appendSource(IndentingStringWriter writer) throws IOException { Annotation.appendAnnotationsSourceOf(annotations).to(writer); Modifier.appendModifiersSourceOf(modifiers).to(writer); appendReturnType(writer); writer.append(name); loopWrapped(parameters) .withPrefix("(") .andForEach(generateSource()) .commaSeperated() .withSuffix(")") .to(writer); loop(exceptions) .withPrefix(" throws ") .commaSeperated() .andForEach(generateSource()) .to(writer); body.appendSource(writer); }
public ASTMethodNode inline(SootMethod maybeInline) { // check if this method should be inlined if (sootClass != null) { // 1, method should belong to the same class as the clinit method if (sootClass.declaresMethod(maybeInline.getSubSignature())) { // System.out.println("The method invoked is from the same class"); // 2, method should be static if (Modifier.isStatic(maybeInline.getModifiers())) { // decided to inline // send the ASTMethod node of the TO BE INLINED METHOD // retireve the active body if (!maybeInline.hasActiveBody()) throw new RuntimeException("method " + maybeInline.getName() + " has no active body!"); Body bod = maybeInline.getActiveBody(); Chain units = ((DavaBody) bod).getUnits(); if (units.size() != 1) { throw new RuntimeException("DavaBody AST doesn't have single root."); } ASTNode ASTtemp = (ASTNode) units.getFirst(); if (!(ASTtemp instanceof ASTMethodNode)) throw new RuntimeException("Starting node of DavaBody AST is not an ASTMethodNode"); // restricting to methods which do not have any variables declared ASTMethodNode toReturn = (ASTMethodNode) ASTtemp; ASTStatementSequenceNode declarations = toReturn.getDeclarations(); if (declarations.getStatements().size() == 0) { // inline only if there are no declarations in the method inlined System.out.println("No declarations in the method. we can inline this method"); return toReturn; } } } } return null; // meaning dont inline }
/** * Read the fields table * * @param cls * @param fieldDatas * @param sharedStatics * @param isolatedStatics * @param slotSize * @param pragmaFlags */ private static void createFields( VmType<?> cls, FieldData[] fieldDatas, VmSharedStatics sharedStatics, VmIsolatedStatics isolatedStatics, int slotSize, int pragmaFlags) { final int fcount = fieldDatas.length; final VmField[] ftable = new VmField[fcount]; int objectSize = 0; for (int i = 0; i < fcount; i++) { final FieldData fd = fieldDatas[i]; final boolean wide; int modifiers = fd.modifiers; final String name = fd.name; final String signature = fd.signature; switch (signature.charAt(0)) { case 'J': case 'D': modifiers = modifiers | Modifier.ACC_WIDE; wide = true; break; default: wide = false; } final boolean isstatic = (modifiers & Modifier.ACC_STATIC) != 0; final int staticsIdx; final VmField fs; final VmStatics statics; if (isstatic) { // Determine if the static field should be shared. final boolean shared = cls.isSharedStatics(); if (shared) { statics = sharedStatics; } else { statics = isolatedStatics; } // If static allocate space for it. switch (signature.charAt(0)) { case 'B': staticsIdx = statics.allocIntField(); break; case 'C': staticsIdx = statics.allocIntField(); break; case 'D': staticsIdx = statics.allocLongField(); break; case 'F': staticsIdx = statics.allocIntField(); break; case 'I': staticsIdx = statics.allocIntField(); break; case 'J': staticsIdx = statics.allocLongField(); break; case 'S': staticsIdx = statics.allocIntField(); break; case 'Z': staticsIdx = statics.allocIntField(); break; default: { if (Modifier.isAddressType(signature)) { staticsIdx = statics.allocAddressField(); } else { staticsIdx = statics.allocObjectField(); // System.out.println(NumberUtils.hex(staticsIdx) // + "\t" + cls.getName() + "." + name); } break; } } fs = new VmStaticField(name, signature, modifiers, staticsIdx, cls, slotSize, shared); } else { staticsIdx = -1; statics = null; final int fieldOffset; // Set the offset (keep in mind that this will be fixed // by ClassResolver with respect to the objectsize of the // super-class. fieldOffset = objectSize; // Increment the objectSize if (wide) objectSize += 8; else if (Modifier.isPrimitive(signature)) { objectSize += 4; } else { objectSize += slotSize; } fs = new VmInstanceField(name, signature, modifiers, fieldOffset, cls, slotSize); } ftable[i] = fs; // Read field attributes if (isstatic && (fd.constantValue != null)) { switch (signature.charAt(0)) { case 'B': case 'C': case 'I': case 'S': case 'Z': statics.setInt(staticsIdx, ((VmConstInt) fd.constantValue).intValue()); break; case 'D': final long lval = Double.doubleToRawLongBits(((VmConstDouble) fd.constantValue).doubleValue()); statics.setLong(staticsIdx, lval); break; case 'F': final int ival = Float.floatToRawIntBits(((VmConstFloat) fd.constantValue).floatValue()); statics.setInt(staticsIdx, ival); break; case 'J': statics.setLong(staticsIdx, ((VmConstLong) fd.constantValue).longValue()); break; default: // throw new IllegalArgumentException("signature " // + signature); statics.setObject(staticsIdx, fd.constantValue); break; } } fs.setRuntimeAnnotations(fd.rVisAnn); fs.setRawAnnotations(fd.rawAnnotations); } // Align the instance fields for minimal object size. if ((pragmaFlags & TypePragmaFlags.NO_FIELD_ALIGNMENT) == 0) { objectSize = alignInstanceFields(ftable, slotSize); } cls.setFieldTable(ftable); if (objectSize > 0) { ((VmNormalClass<?>) cls).setObjectSize(objectSize); } }
/** * Decode a given class. * * @param data * @param rejectNatives * @param clc * @param protectionDomain * @return The decoded class * @throws ClassFormatError */ private static final VmType decodeClass( ByteBuffer data, boolean rejectNatives, VmClassLoader clc, ProtectionDomain protectionDomain) throws ClassFormatError { final VmSharedStatics sharedStatics = clc.getSharedStatics(); final VmIsolatedStatics isolatedStatics = clc.getIsolatedStatics(); final int slotSize = clc.getArchitecture().getReferenceSize(); final int magic = data.getInt(); if (magic != 0xCAFEBABE) { throw new ClassFormatError("invalid magic"); } final int min_version = data.getChar(); final int maj_version = data.getChar(); if (false) { BootLogInstance.get().debug("Class file version " + maj_version + ';' + min_version); } final int cpcount = data.getChar(); // allocate enough space for the CP final byte[] tags = new byte[cpcount]; final VmCP cp = new VmCP(cpcount); for (int i = 1; i < cpcount; i++) { final int tag = data.get() & 0xFF; tags[i] = (byte) tag; switch (tag) { case 1: // Utf8 cp.setUTF8(i, readUTF(data)); break; case 3: // int cp.setInt(i, data.getInt()); break; case 4: // float // cp.setInt(i, data.getInt()); final int ival = data.getInt(); final float fval = Float.intBitsToFloat(ival); cp.setFloat(i, fval); break; case 5: // long cp.setLong(i, data.getLong()); i++; break; case 6: // double // cp.setLong(i, data.getLong()); final long lval = data.getLong(); final double dval = Double.longBitsToDouble(lval); cp.setDouble(i, dval); i++; break; case 7: // class cp.setInt(i, data.getChar()); break; case 8: // String cp.setInt(i, data.getChar()); break; case 9: // Fieldref case 10: // Methodref case 11: // IMethodref { final int clsIdx = data.getChar(); final int ntIdx = data.getChar(); cp.setInt(i, clsIdx << 16 | ntIdx); break; } case 12: // Name and Type { final int nIdx = data.getChar(); final int dIdx = data.getChar(); cp.setInt(i, nIdx << 16 | dIdx); break; } default: throw new ClassFormatError("Invalid constantpool tag: " + tags[i]); } } // Now patch the required entries (level 1) for (int i = 1; i < cpcount; i++) { switch (tags[i]) { case 7: { // Class final int idx = cp.getInt(i); final VmConstClass constClass = new VmConstClass(cp.getUTF8(idx)); cp.setConstClass(i, constClass); break; } case 8: { // String final int idx = cp.getInt(i); final int staticsIdx = sharedStatics.allocConstantStringField(cp.getUTF8(idx)); final VmConstString constStr = new VmConstString(staticsIdx); cp.setString(i, constStr); break; } } } // Now patch the required entries (level 2) for (int i = 1; i < cpcount; i++) { final int tag = tags[i]; if ((tag >= 9) && (tag <= 11)) { final int v = cp.getInt(i); final VmConstClass constClass = cp.getConstClass(v >>> 16); final int nat = cp.getInt(v & 0xFFFF); final String name = cp.getUTF8(nat >>> 16); final String descriptor = cp.getUTF8(nat & 0xFFFF); switch (tag) { case 9: // FieldRef cp.setConstFieldRef(i, new VmConstFieldRef(constClass, name, descriptor)); break; case 10: // MethodRef cp.setConstMethodRef(i, new VmConstMethodRef(constClass, name, descriptor)); break; case 11: // IMethodRef cp.setConstIMethodRef(i, new VmConstIMethodRef(constClass, name, descriptor)); break; } } } // Cleanup the unwantend entries for (int i = 1; i < cpcount; i++) { switch (tags[i]) { case 12: // Name and Type cp.reset(i); break; } } final int classModifiers = data.getChar(); final VmConstClass this_class = cp.getConstClass(data.getChar()); final String clsName = this_class.getClassName(); final VmConstClass super_class = cp.getConstClass(data.getChar()); final String superClassName; if (super_class != null) { superClassName = super_class.getClassName(); } else { superClassName = null; } // Allocate the class object final VmType cls; if (Modifier.isInterface(classModifiers)) { cls = new VmInterfaceClass(clsName, superClassName, clc, classModifiers, protectionDomain); } else { cls = new VmNormalClass(clsName, superClassName, clc, classModifiers, protectionDomain); } cls.setCp(cp); // Determine if we can safely align the fields // int pragmaFlags = 0; if (isBootType(cls)) { cls.addPragmaFlags(TypePragmaFlags.NO_FIELD_ALIGNMENT); } cls.addPragmaFlags(getClassNamePragmaFlags(clsName)); // Interface table cls.addPragmaFlags(readInterfaces(data, cls, cp)); // Field table final FieldData[] fieldData = readFields(data, cp, slotSize, clc); // Method Table readMethods(data, rejectNatives, cls, cp, sharedStatics, clc); // Read class attributes final int acount = data.getChar(); VmAnnotation[] rVisAnn = null; VmAnnotation[] rInvisAnn = null; String sourceFile = null; String signature = null; for (int a = 0; a < acount; a++) { final String attrName = cp.getUTF8(data.getChar()); final int length = data.getInt(); if (VmArray.equals(RuntimeVisibleAnnotationsAttrName, attrName)) { byte[] buf = new byte[length]; data.slice().get(buf); cls.setRawAnnotations(buf); rVisAnn = readRuntimeAnnotations(data, cp, true, clc); } else if (VmArray.equals(RuntimeInvisibleAnnotationsAttrName, attrName)) { rInvisAnn = readRuntimeAnnotations(data, cp, false, clc); } else if (VmArray.equals(SourceFileAttrName, attrName)) { sourceFile = cp.getUTF8(data.getChar()); } else if (VmArray.equals(SignatureAttrName, attrName)) { signature = cp.getUTF8(data.getChar()); } else { skip(data, length); } } cls.setRuntimeAnnotations(rVisAnn); cls.setSourceFile(sourceFile); cls.setSignature(signature); if (rInvisAnn != null) { cls.addPragmaFlags(getClassPragmaFlags(rInvisAnn, clsName)); } if (rVisAnn != null) { cls.addPragmaFlags(getClassPragmaFlags(rVisAnn, clsName)); } // Create the fields if (fieldData != null) { createFields(cls, fieldData, sharedStatics, isolatedStatics, slotSize, cls.getPragmaFlags()); } return cls; }
public int countIn(Collection<Modifier> modifiers) { Modifier alias = resolveAlias(); int c = 0; for (Modifier modifier : modifiers) if (modifier.resolveAlias().equals(alias)) c++; return c; }
public static void init() { Thing t; t = Lib.extend("base poison", "temporary effect"); t.set("IsActive", 1); t.addHandler("OnAction", new PoisonAction()); t.set("IsPoison", 1); t.set("DamageType", "poison"); t.set("EffectName", "poisoned"); t.set("ResistStat", "TG"); t.set("ResistMessage", null); t.set("ResistDifficulty", 10); t.set("CureDifficulty", 5); Lib.add(t); t = Lib.extend("weakening poison", "base poison"); t.set("LifeTime", 50000); t.set("EffectName", "poisoned"); t.set("Strength", 100); t.set("Damage", 2); t.set("DamageType", "poison"); t.set("DamageMessage", "You feel sick..."); t.set("ResistMessage", "You manage to shake off a feeling of weakness"); t.set("AttributeAddMessage", "You feel weakened!"); t.add("CarriedModifiers", Modifier.linear("ST", 90, 0)); Lib.add(t); t = Lib.extend("poison", "base poison"); t.set("LifeTime", 20000); t.set("Strength", 200); t.set("Damage", 3); t.set("DamageType", "poison"); t.set("ResistMessage", "You feel queasy for a moment"); t.set("DamageMessage", "You feel the effects of poison..."); t.set("AttributeAddMessage", "You feel poisoned!"); Lib.add(t); t = Lib.extend("strong poison", "base poison"); t.set("LifeTime", 30000); t.set("Strength", 300); t.set("Damage", 6); t.set("DamageType", "poison"); t.set("ResistMessage", "You feel very queasy for a moment"); t.set("DamageMessage", "You feel the poison weakening you..."); t.set("AttributeAddMessage", "You feel badly poisoned!"); t.set("CureDifficulty", 15); Lib.add(t); t = Lib.extend("deadly poison", "base poison"); t.set("LifeTime", 40000); t.set("Strength", 2000); t.set("Damage", 10); t.set("DamageType", "poison"); t.set("ResistMessage", "You feel very queasy for a moment"); t.set("DamageMessage", "You feel the poison weakening you..."); t.set("AttributeAddMessage", "You feel badly poisoned!"); t.set("CureDifficulty", 40); Lib.add(t); t = Lib.extend("extreme poison", "base poison"); t.set("LifeTime", 50000); t.set("Strength", 6000); t.set("Damage", 15); t.set("DamageType", "poison"); t.set("ResistMessage", "You feel very queasy for a moment"); t.set("DamageMessage", "You feel the poison weakening you..."); t.set("AttributeAddMessage", "You feel badly poisoned!"); t.set("CureDifficulty", 100); Lib.add(t); t = Lib.extend("ultimate poison", "base poison"); t.set("LifeTime", 100000); t.set("Strength", 12000); t.set("Damage", 30); t.set("DamageType", "poison"); t.set("ResistMessage", "You feel very queasy for a moment"); t.set("DamageMessage", "You feel the poison weakening you..."); t.set("AttributeAddMessage", "You feel badly poisoned!"); t.set("CureDifficulty", 300); Lib.add(t); t = Lib.extend("sickness", "base poison"); t.set("LifeTime", 50000); t.set("Strength", 100); t.set("Damage", 2); t.set("DamageType", "poison"); t.set("DamageMessage", "You feel sick..."); t.set("ResistMessage", "You manage to shake off a feeling of illness"); t.set("AttributeAddMessage", "You feel sick!"); t.add("CarriedModifiers", Modifier.bonus("ST", -2)); t.add("CarriedModifiers", Modifier.bonus("SK", -2)); t.set("CureDifficulty", 15); Lib.add(t); t = Lib.extend("pestilence", "poison"); t.set("LifeTime", 120000); t.set("Strength", 200); t.set("Damage", 4); t.set("EffectName", "pestilent"); t.set("DamageType", "poison"); t.set("DamageMessage", "You feel grotty..."); t.set("AttributeAddMessage", "You feel the touch of pestilence!"); t.set("ResistDifficulty", 20); t.addHandler("OnAction", Scripts.generator("fly swarm", 100)); t.set("CureDifficulty", 25); Lib.add(t); t = Lib.extend("plague", "poison"); t.set("LifeTime", 100000); t.set("Strength", 200); t.set("Damage", 8); t.set("EffectName", "plague"); t.set("DamageType", "poison"); t.set("DamageMessage", "You feel sick..."); t.set("AttributeAddMessage", "You feel the touch of the plague!"); t.set("ResistDifficulty", 20); t.add("CarriedModifiers", Modifier.linear("CH", 100, -10)); t.addHandler("OnAction", Scripts.generator("plague cloud", 30)); t.set("CureDifficulty", 100); Lib.add(t); }
@Override public byte[] transform(String name, String transformedName, byte[] bytes) { if (bytes == null) { return null; } boolean makeAllPublic = FMLDeobfuscatingRemapper.INSTANCE.isRemappedClass(name); if (DEBUG) { FMLRelaunchLog.fine( "Considering all methods and fields on %s (%s): %b\n", name, transformedName, makeAllPublic); } if (!makeAllPublic && !modifiers.containsKey(name)) { return bytes; } ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(bytes); classReader.accept(classNode, 0); if (makeAllPublic) { // class Modifier m = new Modifier(); m.targetAccess = ACC_PUBLIC; m.modifyClassVisibility = true; modifiers.put(name, m); // fields m = new Modifier(); m.targetAccess = ACC_PUBLIC; m.name = "*"; modifiers.put(name, m); // methods m = new Modifier(); m.targetAccess = ACC_PUBLIC; m.name = "*"; m.desc = "<dummy>"; modifiers.put(name, m); if (DEBUG) { System.out.printf("Injected all public modifiers for %s (%s)\n", name, transformedName); } } Collection<Modifier> mods = modifiers.get(name); for (Modifier m : mods) { if (m.modifyClassVisibility) { classNode.access = getFixedAccess(classNode.access, m); if (DEBUG) { System.out.println( String.format( "Class: %s %s -> %s", name, toBinary(m.oldAccess), toBinary(m.newAccess))); } continue; } if (m.desc.isEmpty()) { for (FieldNode n : classNode.fields) { if (n.name.equals(m.name) || m.name.equals("*")) { n.access = getFixedAccess(n.access, m); if (DEBUG) { System.out.println( String.format( "Field: %s.%s %s -> %s", name, n.name, toBinary(m.oldAccess), toBinary(m.newAccess))); } if (!m.name.equals("*")) { break; } } } } else { for (MethodNode n : classNode.methods) { if ((n.name.equals(m.name) && n.desc.equals(m.desc)) || m.name.equals("*")) { n.access = getFixedAccess(n.access, m); if (DEBUG) { System.out.println( String.format( "Method: %s.%s%s %s -> %s", name, n.name, n.desc, toBinary(m.oldAccess), toBinary(m.newAccess))); } if (!m.name.equals("*")) { break; } } } } } ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(writer); return writer.toByteArray(); }
public void ensurePublicAccessFor(String modClazzName) { Modifier m = new Modifier(); m.setTargetAccess("public"); m.modifyClassVisibility = true; modifiers.put(modClazzName, m); }
/** * Display a detailed help message to the specified {@link CommandSender} * * <p>If the sender is a player or console it will display 'all' details. If it's not it will only * display the usage string. * * @param sender The {@link CommandSender} to send the message to. */ public void showHelp(CommandSender sender, String label, String[] args) { if ((!(sender instanceof Player) && sender instanceof Entity) || sender instanceof BlockCommandSender) { Msg.fromString(getUsage(sender, label, args)).send(sender); return; } String none = Msg.getString("command.none"); String noDesc = Msg.getString("command.no-description"); List<String> blacklisted = new ArrayList<>(); for (SenderType type : getSenderBlacklist()) { blacklisted.add(Str.camelCase(type.toString())); } String perm = ""; if (perm().isEmpty() && getBaseCmd().perm().isEmpty()) { perm = none; } else { if (!perm().isEmpty()) { perm = perm(); } if (isSub() && !getBaseCmd().perm().isEmpty()) { if (!perm.isEmpty()) { perm += " "; } perm += Msg.getString("command.permission-inherit", Param.P("permission", getBaseCmd().perm())); } } List<String> flagFormats = new ArrayList<>(); for (Flag flag : getAllFlags().values()) { boolean inherit = !flags.containsKey(flag.name().toLowerCase()) || flag.name().equals("?") || flag.name().equals("l"); if (sender instanceof Player) { flagFormats.add( Msg.getString( inherit ? "command.flag-entry-inherit" : "command.flag-entry", Param.P("name", flag.name()), Param.P("description", flag.desc().isEmpty() ? noDesc : flag.desc()), Param.P("permission", flag.perm().isEmpty() ? none : flag.perm()))); } else { flagFormats.add((inherit ? "&a&l-" : "&7&l-") + flag.name()); } } List<String> modifierFormats = new ArrayList<>(); for (Modifier mod : getAllModifiers().values()) { boolean inherit = !modifiers.containsKey(mod.name().toLowerCase()) || mod.name().equals("page"); if (sender instanceof Player) { modifierFormats.add( Msg.getString( inherit ? "command.modifier-entry-inherit" : "command.modifier-entry", Param.P("name", mod.name()), Param.P("description", mod.desc().isEmpty() ? noDesc : mod.desc()), Param.P("permission", mod.perm().isEmpty() ? none : mod.perm()), Param.P("type", mod.option().getTypeName()))); } else { modifierFormats.add( inherit ? "&a" + mod.name() + ":&8[&a" + mod.option().getTypeName() + "&8]" : "&7" + mod.name() + ":&8[&7" + mod.option().getTypeName() + "&8]"); } } String argClr = Msg.getString("command.argument-name-color"); String msg = Msg.getString( "command.help", Param.P("label", label), Param.P("cmd", getBaseCmd().getName()), Param.P( "usage", sender instanceof ConsoleCommandSender ? new CmdUsageParser(this, sender, label, args, argClr).getString() : new CmdUsageParser(this, sender, label, args, argClr).getJSON()), Param.P("description", desc().isEmpty() ? noDesc : desc()), Param.P("permission", perm), Param.P( "aliases", isSub() ? (((SubCmd) this).getSubAliases().isEmpty() ? none : Str.implode(((SubCmd) this).getSubAliases())) : (getAliases().isEmpty() ? none : Str.implode(getAliases()))), Param.P("flags", flagFormats.isEmpty() ? none : Str.implode(flagFormats, " ")), Param.P("modifiers", modifierFormats.isEmpty() ? none : Str.implode(modifierFormats))); Msg.fromString(msg).send(sender); }
/** * Returns the modifiers for the reference type. ACC_PUBLIC, ACC_FINAL, etc. Undefined for arrays * and primitive type. * * @return the class modifiers in JVM Spec format. */ public int getModifiers() { return klass.getModifiers() & Modifier.getJVMClassModifiers(); }
private Method lookupMethod( CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List list = cf.getMethods(); int n = list.size(); for (int i = 0; i < n; ++i) { MethodInfo minfo = (MethodInfo) list.get(i); if (minfo.getName().equals(methodName)) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else onlyExact = maybe != null; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) { } if (isIntf || Modifier.isAbstract(mod)) try { CtClass[] ifs = clazz.getInterfaces(); int size = ifs.length; for (int i = 0; i < size; ++i) { Method r = lookupMethod(ifs[i], methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) { } return maybe; }
@Override public void apply(T item) { for (Modifier<? super T> modifier : modifiers) { modifier.apply(item); } }
public void printTo(SootClass cl, PrintWriter out) { // add jimple line number tags setJimpleLnNum(1); // Print class name + modifiers { StringTokenizer st = new StringTokenizer(Modifier.toString(cl.getModifiers())); while (st.hasMoreTokens()) { String tok = (String) st.nextToken(); if (cl.isInterface() && tok.equals("abstract")) continue; out.print(tok + " "); } String classPrefix = ""; if (!cl.isInterface()) { classPrefix = classPrefix + " class"; classPrefix = classPrefix.trim(); } out.print(classPrefix + " " + Scene.v().quotedNameOf(cl.getName()) + ""); } // Print extension { if (cl.hasSuperclass()) out.print(" extends " + Scene.v().quotedNameOf(cl.getSuperclass().getName()) + ""); } // Print interfaces { Iterator interfaceIt = cl.getInterfaces().iterator(); if (interfaceIt.hasNext()) { out.print(" implements "); out.print("" + Scene.v().quotedNameOf(((SootClass) interfaceIt.next()).getName()) + ""); while (interfaceIt.hasNext()) { out.print(","); out.print(" " + Scene.v().quotedNameOf(((SootClass) interfaceIt.next()).getName()) + ""); } } } out.println(); incJimpleLnNum(); /* if (!addJimpleLn()) { Iterator clTagsIt = cl.getTags().iterator(); while (clTagsIt.hasNext()) { final Tag t = (Tag)clTagsIt.next(); out.println(t); } }*/ out.println("{"); incJimpleLnNum(); if (Options.v().print_tags_in_output()) { Iterator cTagIterator = cl.getTags().iterator(); while (cTagIterator.hasNext()) { Tag t = (Tag) cTagIterator.next(); out.print("/*"); out.print(t.toString()); out.println("*/"); } } // Print fields { Iterator fieldIt = cl.getFields().iterator(); if (fieldIt.hasNext()) { while (fieldIt.hasNext()) { SootField f = (SootField) fieldIt.next(); if (f.isPhantom()) continue; if (Options.v().print_tags_in_output()) { Iterator fTagIterator = f.getTags().iterator(); while (fTagIterator.hasNext()) { Tag t = (Tag) fTagIterator.next(); out.print("/*"); out.print(t.toString()); out.println("*/"); } } out.println(" " + f.getDeclaration() + ";"); if (addJimpleLn()) { setJimpleLnNum(addJimpleLnTags(getJimpleLnNum(), f)); } // incJimpleLnNum(); } } } // Print methods { Iterator methodIt = cl.methodIterator(); if (methodIt.hasNext()) { if (cl.getMethodCount() != 0) { out.println(); incJimpleLnNum(); } while (methodIt.hasNext()) { SootMethod method = (SootMethod) methodIt.next(); if (method.isPhantom()) continue; if (!Modifier.isAbstract(method.getModifiers()) && !Modifier.isNative(method.getModifiers())) { if (!method.hasActiveBody()) throw new RuntimeException("method " + method.getName() + " has no active body!"); else if (Options.v().print_tags_in_output()) { Iterator mTagIterator = method.getTags().iterator(); while (mTagIterator.hasNext()) { Tag t = (Tag) mTagIterator.next(); out.print("/*"); out.print(t.toString()); out.println("*/"); } } printTo(method.getActiveBody(), out); if (methodIt.hasNext()) { out.println(); incJimpleLnNum(); } } else { if (Options.v().print_tags_in_output()) { Iterator mTagIterator = method.getTags().iterator(); while (mTagIterator.hasNext()) { Tag t = (Tag) mTagIterator.next(); out.print("/*"); out.print(t.toString()); out.println("*/"); } } out.print(" "); out.print(method.getDeclaration()); out.println(";"); incJimpleLnNum(); if (methodIt.hasNext()) { out.println(); incJimpleLnNum(); } } } } } out.println("}"); incJimpleLnNum(); }
public boolean has(Modifier other) { return this.getValue().contains(other.getValue()); }
public boolean equals(Modifier other) { return this.getValue().equalsIgnoreCase(other.getValue()); }
public boolean isContainedBy(Collection<Modifier> modifiers) { Modifier alias = resolveAlias(); for (Modifier modifier : modifiers) if (modifier.resolveAlias().equals(alias)) return true; return false; }