Skip to content

Commit

Permalink
remove hidden access flags
Browse files Browse the repository at this point in the history
cherry-pick f6dc51e
  • Loading branch information
pxb1988 committed Sep 1, 2023
1 parent d90f4ef commit b6957fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public interface DexConstants {
int ACC_CONSTRUCTOR = 0x10000;// constructor method (class or instance initializer)
int ACC_DECLARED_SYNCHRONIZED = 0x20000;

int ACC_VISIBILITY_FLAGS = ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED;
int ACC_DEX_HIDDEN_BIT = 0x00000020; // field, method (not native)
int ACC_DEX_HIDDEN_BIT_NATIVE = 0x00000200; // method (native)

String ANNOTATION_DEFAULT_TYPE = "Ldalvik/annotation/AnnotationDefault;";
String ANNOTATION_SIGNATURE_TYPE = "Ldalvik/annotation/Signature;";
String ANNOTATION_THROWS_TYPE = "Ldalvik/annotation/Throws;";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -981,10 +981,24 @@ private String getType(int id) {
return getString(typeIdIn.getInt(id * 4));
}

private static boolean isPowerOfTwo(int i) {
return (i & (i - 1)) == 0;
}

private static int removeHiddenAccess(int accessFlags) {
// Refer to art/libdexfile/dex/hidden_api_access_flags.h
if (!isPowerOfTwo(accessFlags & DexConstants.ACC_VISIBILITY_FLAGS)) {
accessFlags ^= DexConstants.ACC_VISIBILITY_FLAGS;
}
accessFlags &= ~((accessFlags & DexConstants.ACC_NATIVE) != 0 ?
DexConstants.ACC_DEX_HIDDEN_BIT_NATIVE : DexConstants.ACC_DEX_HIDDEN_BIT);
return accessFlags;
}

private int acceptField(ByteBuffer in, int lastIndex, DexClassVisitor dcv,
Map<Integer, Integer> fieldAnnotationPositions, Object value, int config) {
int diff = readULeb128i(in);
int field_access_flags = readULeb128i(in);
int field_access_flags = removeHiddenAccess(readULeb128i(in));
int field_id = lastIndex + diff;
Field field = getField(field_id);
// //////////////////////////////////////////////////////////////
Expand All @@ -1010,7 +1024,7 @@ private int acceptMethod(ByteBuffer in, int lastIndex, DexClassVisitor cv, Map<I
Map<Integer, Integer> parameterAnnos, int config, boolean firstMethod) {
int offset = in.position();
int diff = readULeb128i(in);
int method_access_flags = readULeb128i(in);
int method_access_flags = removeHiddenAccess(readULeb128i(in));
int code_off = readULeb128i(in);
int method_id = lastIndex + diff;
Method method = getMethod(method_id);
Expand Down

0 comments on commit b6957fa

Please sign in to comment.