Java Code Examples for com.android.dx.rop.code.AccessFlags#ACC_PUBLIC

The following examples show how to use com.android.dx.rop.code.AccessFlags#ACC_PUBLIC . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FixAccessModifiers.java    From Box with Apache License 2.0 6 votes vote down vote up
private static int fixVisibility(MethodNode mth) {
	if (mth.isVirtual()) {
		// make virtual methods public
		return AccessFlags.ACC_PUBLIC;
	} else {
		AccessInfo accessFlags = mth.getAccessFlags();
		if (accessFlags.isAbstract()) {
			// make abstract methods public
			return AccessFlags.ACC_PUBLIC;
		}
		// enum constructor can't be public
		if (accessFlags.isConstructor()
				&& accessFlags.isPublic()
				&& mth.getParentClass().isEnum()) {
			return 0;
		}
		if (accessFlags.isConstructor() || accessFlags.isStatic()) {
			// TODO: make public if used outside
			return -1;
		}
		// make other direct methods private
		return AccessFlags.ACC_PRIVATE;
	}
}
 
Example 2
Source File: FixAccessModifiers.java    From Box with Apache License 2.0 6 votes vote down vote up
private static int fixVisibility(MethodNode mth) {
	if (mth.isVirtual()) {
		// make virtual methods public
		return AccessFlags.ACC_PUBLIC;
	} else {
		AccessInfo accessFlags = mth.getAccessFlags();
		if (accessFlags.isAbstract()) {
			// make abstract methods public
			return AccessFlags.ACC_PUBLIC;
		}
		// enum constructor can't be public
		if (accessFlags.isConstructor()
				&& accessFlags.isPublic()
				&& mth.getParentClass().isEnum()) {
			return 0;
		}
		if (accessFlags.isConstructor() || accessFlags.isStatic()) {
			// TODO: make public if used outside
			return -1;
		}
		// make other direct methods private
		return AccessFlags.ACC_PRIVATE;
	}
}
 
Example 3
Source File: MethodInlineVisitor.java    From Box with Apache License 2.0 5 votes vote down vote up
private static boolean fixVisibilityOfInlineCode(MethodNode mth, InsnNode insn) {
	int newVisFlag = AccessFlags.ACC_PUBLIC; // TODO: calculate more precisely
	InsnType insnType = insn.getType();
	if (insnType == InsnType.INVOKE) {
		InvokeNode invoke = (InvokeNode) insn;
		MethodNode callMthNode = mth.root().deepResolveMethod(invoke.getCallMth());
		if (callMthNode != null) {
			FixAccessModifiers.changeVisibility(callMthNode, newVisFlag);
		}
		return true;
	}
	if (insnType == InsnType.ONE_ARG) {
		InsnArg arg = insn.getArg(0);
		if (!arg.isInsnWrap()) {
			return false;
		}
		return fixVisibilityOfInlineCode(mth, ((InsnWrapArg) arg).getWrapInsn());
	}
	if (insn instanceof IndexInsnNode) {
		Object indexObj = ((IndexInsnNode) insn).getIndex();
		if (indexObj instanceof FieldInfo) {
			FieldNode fieldNode = mth.root().deepResolveField(((FieldInfo) indexObj));
			if (fieldNode != null) {
				FixAccessModifiers.changeVisibility(fieldNode, newVisFlag);
			}
			return true;
		}
	}
	if (Consts.DEBUG) {
		mth.addAttr(AType.COMMENTS, "JADX DEBUG: can't inline method, not implemented redirect type: " + insn);
	}
	return false;
}
 
Example 4
Source File: AndroidResourcesUtils.java    From Box with Apache License 2.0 5 votes vote down vote up
@Nullable
private static ClassNode makeClass(RootNode root, String clsName, ResourceStorage resStorage) {
	List<DexNode> dexNodes = root.getDexNodes();
	if (dexNodes.isEmpty()) {
		return null;
	}
	ClassNode rCls = new ClassNode(dexNodes.get(0), clsName, AccessFlags.ACC_PUBLIC | AccessFlags.ACC_FINAL);
	rCls.addAttr(AType.COMMENTS, "This class is generated by JADX");
	rCls.setState(ProcessState.PROCESS_COMPLETE);
	return rCls;
}
 
Example 5
Source File: AndroidResourcesUtils.java    From Box with Apache License 2.0 5 votes vote down vote up
private static void addResourceFields(ClassNode resCls, ResourceStorage resStorage, boolean rClsExists) {
	Map<Integer, FieldNode> resFieldsMap = fillResFieldsMap(resCls);
	Map<String, ClassNode> innerClsMap = new TreeMap<>();
	if (rClsExists) {
		for (ClassNode innerClass : resCls.getInnerClasses()) {
			innerClsMap.put(innerClass.getShortName(), innerClass);
		}
	}
	for (ResourceEntry resource : resStorage.getResources()) {
		final String resTypeName = resource.getTypeName();
		ClassNode typeCls = innerClsMap.computeIfAbsent(
				resTypeName,
				name -> addClassForResType(resCls, rClsExists, name));
		final String resName;
		if ("style".equals(resTypeName)) {
			resName = resource.getKeyName().replace('.', '_');
		} else {
			resName = resource.getKeyName();
		}
		FieldNode rField = typeCls.searchFieldByName(resName);
		if (rField == null) {
			FieldInfo rFieldInfo = FieldInfo.from(typeCls.dex(), typeCls.getClassInfo(), resName, ArgType.INT);
			rField = new FieldNode(typeCls, rFieldInfo, AccessFlags.ACC_PUBLIC | AccessFlags.ACC_STATIC | AccessFlags.ACC_FINAL);
			rField.addAttr(FieldInitAttr.constValue(resource.getId()));
			typeCls.getFields().add(rField);
			if (rClsExists) {
				rField.addAttr(AType.COMMENTS, "added by JADX");
			}
		}
		FieldNode fieldNode = resFieldsMap.get(resource.getId());
		if (fieldNode != null
				&& !fieldNode.getName().equals(resName)
				&& NameMapper.isValidAndPrintable(resName)
				&& resCls.root().getArgs().isRenameValid()) {
			fieldNode.add(AFlag.DONT_RENAME);
			fieldNode.getFieldInfo().setAlias(resName);
		}
	}
}
 
Example 6
Source File: AndroidResourcesUtils.java    From Box with Apache License 2.0 5 votes vote down vote up
@NotNull
private static ClassNode addClassForResType(ClassNode resCls, boolean rClsExists, String typeName) {
	ClassNode newTypeCls = new ClassNode(resCls.dex(), resCls.getFullName() + '$' + typeName,
			AccessFlags.ACC_PUBLIC | AccessFlags.ACC_STATIC | AccessFlags.ACC_FINAL);
	resCls.addInnerClass(newTypeCls);
	if (rClsExists) {
		newTypeCls.addAttr(AType.COMMENTS, "added by JADX");
	}
	return newTypeCls;
}
 
Example 7
Source File: MethodInlineVisitor.java    From Box with Apache License 2.0 5 votes vote down vote up
private static boolean fixVisibilityOfInlineCode(MethodNode mth, InsnNode insn) {
	int newVisFlag = AccessFlags.ACC_PUBLIC; // TODO: calculate more precisely
	InsnType insnType = insn.getType();
	if (insnType == InsnType.INVOKE) {
		InvokeNode invoke = (InvokeNode) insn;
		MethodNode callMthNode = mth.root().deepResolveMethod(invoke.getCallMth());
		if (callMthNode != null) {
			FixAccessModifiers.changeVisibility(callMthNode, newVisFlag);
		}
		return true;
	}
	if (insnType == InsnType.ONE_ARG) {
		InsnArg arg = insn.getArg(0);
		if (!arg.isInsnWrap()) {
			return false;
		}
		return fixVisibilityOfInlineCode(mth, ((InsnWrapArg) arg).getWrapInsn());
	}
	if (insn instanceof IndexInsnNode) {
		Object indexObj = ((IndexInsnNode) insn).getIndex();
		if (indexObj instanceof FieldInfo) {
			FieldNode fieldNode = mth.root().deepResolveField(((FieldInfo) indexObj));
			if (fieldNode != null) {
				FixAccessModifiers.changeVisibility(fieldNode, newVisFlag);
			}
			return true;
		}
	}
	if (Consts.DEBUG) {
		mth.addAttr(AType.COMMENTS, "JADX DEBUG: can't inline method, not implemented redirect type: " + insn);
	}
	return false;
}
 
Example 8
Source File: AndroidResourcesUtils.java    From Box with Apache License 2.0 5 votes vote down vote up
@Nullable
private static ClassNode makeClass(RootNode root, String clsName, ResourceStorage resStorage) {
	List<DexNode> dexNodes = root.getDexNodes();
	if (dexNodes.isEmpty()) {
		return null;
	}
	ClassNode rCls = new ClassNode(dexNodes.get(0), clsName, AccessFlags.ACC_PUBLIC | AccessFlags.ACC_FINAL);
	rCls.addAttr(AType.COMMENTS, "This class is generated by JADX");
	rCls.setState(ProcessState.PROCESS_COMPLETE);
	return rCls;
}
 
Example 9
Source File: AndroidResourcesUtils.java    From Box with Apache License 2.0 5 votes vote down vote up
private static void addResourceFields(ClassNode resCls, ResourceStorage resStorage, boolean rClsExists) {
	Map<Integer, FieldNode> resFieldsMap = fillResFieldsMap(resCls);
	Map<String, ClassNode> innerClsMap = new TreeMap<>();
	if (rClsExists) {
		for (ClassNode innerClass : resCls.getInnerClasses()) {
			innerClsMap.put(innerClass.getShortName(), innerClass);
		}
	}
	for (ResourceEntry resource : resStorage.getResources()) {
		final String resTypeName = resource.getTypeName();
		ClassNode typeCls = innerClsMap.computeIfAbsent(
				resTypeName,
				name -> addClassForResType(resCls, rClsExists, name));
		final String resName;
		if ("style".equals(resTypeName)) {
			resName = resource.getKeyName().replace('.', '_');
		} else {
			resName = resource.getKeyName();
		}
		FieldNode rField = typeCls.searchFieldByName(resName);
		if (rField == null) {
			FieldInfo rFieldInfo = FieldInfo.from(typeCls.dex(), typeCls.getClassInfo(), resName, ArgType.INT);
			rField = new FieldNode(typeCls, rFieldInfo, AccessFlags.ACC_PUBLIC | AccessFlags.ACC_STATIC | AccessFlags.ACC_FINAL);
			rField.addAttr(FieldInitAttr.constValue(resource.getId()));
			typeCls.getFields().add(rField);
			if (rClsExists) {
				rField.addAttr(AType.COMMENTS, "added by JADX");
			}
		}
		FieldNode fieldNode = resFieldsMap.get(resource.getId());
		if (fieldNode != null
				&& !fieldNode.getName().equals(resName)
				&& NameMapper.isValidAndPrintable(resName)
				&& resCls.root().getArgs().isRenameValid()) {
			fieldNode.add(AFlag.DONT_RENAME);
			fieldNode.getFieldInfo().setAlias(resName);
		}
	}
}
 
Example 10
Source File: AndroidResourcesUtils.java    From Box with Apache License 2.0 5 votes vote down vote up
@NotNull
private static ClassNode addClassForResType(ClassNode resCls, boolean rClsExists, String typeName) {
	ClassNode newTypeCls = new ClassNode(resCls.dex(), resCls.getFullName() + '$' + typeName,
			AccessFlags.ACC_PUBLIC | AccessFlags.ACC_STATIC | AccessFlags.ACC_FINAL);
	resCls.addInnerClass(newTypeCls);
	if (rClsExists) {
		newTypeCls.addAttr(AType.COMMENTS, "added by JADX");
	}
	return newTypeCls;
}
 
Example 11
Source File: AccessInfo.java    From Box with Apache License 2.0 4 votes vote down vote up
public boolean isPublic() {
	return (accFlags & AccessFlags.ACC_PUBLIC) != 0;
}
 
Example 12
Source File: AccessInfoTest.java    From Box with Apache License 2.0 4 votes vote down vote up
@Test
public void changeVisibilityNoOp() {
	AccessInfo accessInfo = new AccessInfo(AccessFlags.ACC_PUBLIC, AFType.METHOD);
	AccessInfo result = accessInfo.changeVisibility(AccessFlags.ACC_PUBLIC);
	assertSame(accessInfo, result);
}
 
Example 13
Source File: AccessInfo.java    From Box with Apache License 2.0 4 votes vote down vote up
public boolean isPublic() {
	return (accFlags & AccessFlags.ACC_PUBLIC) != 0;
}
 
Example 14
Source File: AccessInfoTest.java    From Box with Apache License 2.0 4 votes vote down vote up
@Test
public void changeVisibilityNoOp() {
	AccessInfo accessInfo = new AccessInfo(AccessFlags.ACC_PUBLIC, AFType.METHOD);
	AccessInfo result = accessInfo.changeVisibility(AccessFlags.ACC_PUBLIC);
	assertSame(accessInfo, result);
}