CrackMe.apk
Download file
package com.google.common.eventbus;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.UnmodifiableIterator;
import com.google.common.primitives.Primitives;
import com.google.common.reflect.TypeToken;
import com.google.common.util.concurrent.UncheckedExecutionException;
import java.lang.reflect.Method;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArraySet;
import javax.annotation.CheckForNull;
@ElementTypesAreNonnullByDefault
final class SubscriberRegistry {
private static final LoadingCache<Class<?>, ImmutableSet<Class<?>>> flattenHierarchyCache = CacheBuilder.newBuilder().weakKeys().build(new CacheLoader<Class<?>, ImmutableSet<Class<?>>>() {
public ImmutableSet<Class<?>> load(Class<?> cls) {
return ImmutableSet.copyOf(TypeToken.of(cls).getTypes().rawTypes());
}
});
private static final LoadingCache<Class<?>, ImmutableList<Method>> subscriberMethodsCache = CacheBuilder.newBuilder().weakKeys().build(new CacheLoader<Class<?>, ImmutableList<Method>>() {
public ImmutableList<Method> load(Class<?> cls) throws Exception {
return SubscriberRegistry.getAnnotatedMethodsNotCached(cls);
}
});
private final EventBus bus;
private final ConcurrentMap<Class<?>, CopyOnWriteArraySet<Subscriber>> subscribers = Maps.newConcurrentMap();
SubscriberRegistry(EventBus eventBus) {
this.bus = (EventBus) Preconditions.checkNotNull(eventBus);
}
/* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r1v4, resolved type: java.lang.Object} */
/* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r2v5, resolved type: java.util.concurrent.CopyOnWriteArraySet} */
/* access modifiers changed from: package-private */
/* JADX WARNING: Multi-variable type inference failed */
/* Code decompiled incorrectly, please refer to instructions dump. */
public void register(java.lang.Object r5) {
/*
r4 = this;
com.google.common.collect.Multimap r5 = r4.findAllSubscribers(r5)
java.util.Map r5 = r5.asMap()
java.util.Set r5 = r5.entrySet()
java.util.Iterator r5 = r5.iterator()
L_0x0010:
boolean r0 = r5.hasNext()
if (r0 == 0) goto L_0x004a
java.lang.Object r0 = r5.next()
java.util.Map$Entry r0 = (java.util.Map.Entry) r0
java.lang.Object r1 = r0.getKey()
java.lang.Class r1 = (java.lang.Class) r1
java.lang.Object r0 = r0.getValue()
java.util.Collection r0 = (java.util.Collection) r0
java.util.concurrent.ConcurrentMap<java.lang.Class<?>, java.util.concurrent.CopyOnWriteArraySet<com.google.common.eventbus.Subscriber>> r2 = r4.subscribers
java.lang.Object r2 = r2.get(r1)
java.util.concurrent.CopyOnWriteArraySet r2 = (java.util.concurrent.CopyOnWriteArraySet) r2
if (r2 != 0) goto L_0x0046
java.util.concurrent.CopyOnWriteArraySet r2 = new java.util.concurrent.CopyOnWriteArraySet
r2.<init>()
java.util.concurrent.ConcurrentMap<java.lang.Class<?>, java.util.concurrent.CopyOnWriteArraySet<com.google.common.eventbus.Subscriber>> r3 = r4.subscribers
java.lang.Object r1 = r3.putIfAbsent(r1, r2)
java.util.concurrent.CopyOnWriteArraySet r1 = (java.util.concurrent.CopyOnWriteArraySet) r1
java.lang.Object r1 = com.google.common.base.MoreObjects.firstNonNull(r1, r2)
r2 = r1
java.util.concurrent.CopyOnWriteArraySet r2 = (java.util.concurrent.CopyOnWriteArraySet) r2
L_0x0046:
r2.addAll(r0)
goto L_0x0010
L_0x004a:
return
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.common.eventbus.SubscriberRegistry.register(java.lang.Object):void");
}
/* access modifiers changed from: package-private */
/* JADX WARNING: Removed duplicated region for block: B:3:0x0016 */
/* Code decompiled incorrectly, please refer to instructions dump. */
public void unregister(java.lang.Object r5) {
/*
r4 = this;
com.google.common.collect.Multimap r0 = r4.findAllSubscribers(r5)
java.util.Map r0 = r0.asMap()
java.util.Set r0 = r0.entrySet()
java.util.Iterator r0 = r0.iterator()
L_0x0010:
boolean r1 = r0.hasNext()
if (r1 == 0) goto L_0x0063
java.lang.Object r1 = r0.next()
java.util.Map$Entry r1 = (java.util.Map.Entry) r1
java.lang.Object r2 = r1.getKey()
java.lang.Class r2 = (java.lang.Class) r2
java.lang.Object r1 = r1.getValue()
java.util.Collection r1 = (java.util.Collection) r1
java.util.concurrent.ConcurrentMap<java.lang.Class<?>, java.util.concurrent.CopyOnWriteArraySet<com.google.common.eventbus.Subscriber>> r3 = r4.subscribers
java.lang.Object r2 = r3.get(r2)
java.util.concurrent.CopyOnWriteArraySet r2 = (java.util.concurrent.CopyOnWriteArraySet) r2
if (r2 == 0) goto L_0x0039
boolean r1 = r2.removeAll(r1)
if (r1 == 0) goto L_0x0039
goto L_0x0010
L_0x0039:
java.lang.IllegalArgumentException r0 = new java.lang.IllegalArgumentException
java.lang.String r5 = java.lang.String.valueOf(r5)
java.lang.String r1 = java.lang.String.valueOf(r5)
int r1 = r1.length()
int r1 = r1 + 65
java.lang.StringBuilder r2 = new java.lang.StringBuilder
r2.<init>(r1)
java.lang.String r1 = "missing event subscriber for an annotated method. Is "
r2.append(r1)
r2.append(r5)
java.lang.String r5 = " registered?"
r2.append(r5)
java.lang.String r5 = r2.toString()
r0.<init>(r5)
throw r0
L_0x0063:
return
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.common.eventbus.SubscriberRegistry.unregister(java.lang.Object):void");
}
/* access modifiers changed from: package-private */
public Set<Subscriber> getSubscribersForTesting(Class<?> cls) {
return (Set) MoreObjects.firstNonNull((AbstractCollection) this.subscribers.get(cls), ImmutableSet.of());
}
/* access modifiers changed from: package-private */
public Iterator<Subscriber> getSubscribers(Object obj) {
ImmutableSet<Class<?>> flattenHierarchy = flattenHierarchy(obj.getClass());
ArrayList newArrayListWithCapacity = Lists.newArrayListWithCapacity(flattenHierarchy.size());
UnmodifiableIterator<Class<?>> it = flattenHierarchy.iterator();
while (it.hasNext()) {
CopyOnWriteArraySet copyOnWriteArraySet = (CopyOnWriteArraySet) this.subscribers.get(it.next());
if (copyOnWriteArraySet != null) {
newArrayListWithCapacity.add(copyOnWriteArraySet.iterator());
}
}
return Iterators.concat(newArrayListWithCapacity.iterator());
}
private Multimap<Class<?>, Subscriber> findAllSubscribers(Object obj) {
HashMultimap create = HashMultimap.create();
UnmodifiableIterator<Method> it = getAnnotatedMethods(obj.getClass()).iterator();
while (it.hasNext()) {
Method next = it.next();
create.put(next.getParameterTypes()[0], Subscriber.create(this.bus, obj, next));
}
return create;
}
private static ImmutableList<Method> getAnnotatedMethods(Class<?> cls) {
try {
return subscriberMethodsCache.getUnchecked(cls);
} catch (UncheckedExecutionException e) {
Throwables.throwIfUnchecked(e.getCause());
throw e;
}
}
/* access modifiers changed from: private */
public static ImmutableList<Method> getAnnotatedMethodsNotCached(Class<?> cls) {
Set<Class> rawTypes = TypeToken.of(cls).getTypes().rawTypes();
HashMap newHashMap = Maps.newHashMap();
for (Class declaredMethods : rawTypes) {
for (Method method : declaredMethods.getDeclaredMethods()) {
if (method.isAnnotationPresent(Subscribe.class) && !method.isSynthetic()) {
Class[] parameterTypes = method.getParameterTypes();
Preconditions.checkArgument(parameterTypes.length == 1, "Method %s has @Subscribe annotation but has %s parameters. Subscriber methods must have exactly 1 parameter.", (Object) method, parameterTypes.length);
Preconditions.checkArgument(!parameterTypes[0].isPrimitive(), "@Subscribe method %s's parameter is %s. Subscriber methods cannot accept primitives. Consider changing the parameter to %s.", method, parameterTypes[0].getName(), Primitives.wrap(parameterTypes[0]).getSimpleName());
MethodIdentifier methodIdentifier = new MethodIdentifier(method);
if (!newHashMap.containsKey(methodIdentifier)) {
newHashMap.put(methodIdentifier, method);
}
}
}
}
return ImmutableList.copyOf(newHashMap.values());
}
static ImmutableSet<Class<?>> flattenHierarchy(Class<?> cls) {
try {
return flattenHierarchyCache.getUnchecked(cls);
} catch (UncheckedExecutionException e) {
throw Throwables.propagate(e.getCause());
}
}
private static final class MethodIdentifier {
private final String name;
private final List<Class<?>> parameterTypes;
MethodIdentifier(Method method) {
this.name = method.getName();
this.parameterTypes = Arrays.asList(method.getParameterTypes());
}
public int hashCode() {
return Objects.hashCode(this.name, this.parameterTypes);
}
public boolean equals(@CheckForNull Object obj) {
if (!(obj instanceof MethodIdentifier)) {
return false;
}
MethodIdentifier methodIdentifier = (MethodIdentifier) obj;
if (!this.name.equals(methodIdentifier.name) || !this.parameterTypes.equals(methodIdentifier.parameterTypes)) {
return false;
}
return true;
}
}
}
Download file