UnsafeAllocator.smali 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. .class public abstract Lcom/google/gson/internal/UnsafeAllocator;
  2. .super Ljava/lang/Object;
  3. .source ""
  4. # direct methods
  5. .method public constructor <init>()V
  6. .locals 0
  7. invoke-direct {p0}, Ljava/lang/Object;-><init>()V
  8. return-void
  9. .end method
  10. .method static assertInstantiable(Ljava/lang/Class;)V
  11. .locals 3
  12. .annotation system Ldalvik/annotation/Signature;
  13. value = {
  14. "(",
  15. "Ljava/lang/Class<",
  16. "*>;)V"
  17. }
  18. .end annotation
  19. invoke-virtual {p0}, Ljava/lang/Class;->getModifiers()I
  20. move-result v0
  21. invoke-static {v0}, Ljava/lang/reflect/Modifier;->isInterface(I)Z
  22. move-result v1
  23. if-nez v1, :cond_1
  24. invoke-static {v0}, Ljava/lang/reflect/Modifier;->isAbstract(I)Z
  25. move-result v0
  26. if-nez v0, :cond_0
  27. return-void
  28. :cond_0
  29. new-instance v0, Ljava/lang/UnsupportedOperationException;
  30. new-instance v1, Ljava/lang/StringBuilder;
  31. invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V
  32. const-string v2, "Abstract class can\'t be instantiated! Class name: "
  33. invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  34. invoke-virtual {p0}, Ljava/lang/Class;->getName()Ljava/lang/String;
  35. move-result-object p0
  36. invoke-virtual {v1, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  37. invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  38. move-result-object p0
  39. invoke-direct {v0, p0}, Ljava/lang/UnsupportedOperationException;-><init>(Ljava/lang/String;)V
  40. throw v0
  41. :cond_1
  42. new-instance v0, Ljava/lang/UnsupportedOperationException;
  43. new-instance v1, Ljava/lang/StringBuilder;
  44. invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V
  45. const-string v2, "Interface can\'t be instantiated! Interface name: "
  46. invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  47. invoke-virtual {p0}, Ljava/lang/Class;->getName()Ljava/lang/String;
  48. move-result-object p0
  49. invoke-virtual {v1, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  50. invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  51. move-result-object p0
  52. invoke-direct {v0, p0}, Ljava/lang/UnsupportedOperationException;-><init>(Ljava/lang/String;)V
  53. throw v0
  54. .end method
  55. .method public static create()Lcom/google/gson/internal/UnsafeAllocator;
  56. .locals 9
  57. const-string v0, "newInstance"
  58. const-string v1, "sun.misc.Unsafe"
  59. const/4 v2, 0x0
  60. const/4 v3, 0x0
  61. const/4 v4, 0x1
  62. :try_start_0
  63. invoke-static {v1}, Ljava/lang/Class;->forName(Ljava/lang/String;)Ljava/lang/Class;
  64. move-result-object v1
  65. const-string v5, "theUnsafe"
  66. invoke-virtual {v1, v5}, Ljava/lang/Class;->getDeclaredField(Ljava/lang/String;)Ljava/lang/reflect/Field;
  67. move-result-object v5
  68. invoke-virtual {v5, v4}, Ljava/lang/reflect/Field;->setAccessible(Z)V
  69. invoke-virtual {v5, v2}, Ljava/lang/reflect/Field;->get(Ljava/lang/Object;)Ljava/lang/Object;
  70. move-result-object v5
  71. const-string v6, "allocateInstance"
  72. new-array v7, v4, [Ljava/lang/Class;
  73. const-class v8, Ljava/lang/Class;
  74. aput-object v8, v7, v3
  75. invoke-virtual {v1, v6, v7}, Ljava/lang/Class;->getMethod(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;
  76. move-result-object v1
  77. new-instance v6, Lcom/google/gson/internal/UnsafeAllocator$1;
  78. invoke-direct {v6, v1, v5}, Lcom/google/gson/internal/UnsafeAllocator$1;-><init>(Ljava/lang/reflect/Method;Ljava/lang/Object;)V
  79. :try_end_0
  80. .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0
  81. return-object v6
  82. :catch_0
  83. const/4 v1, 0x2
  84. :try_start_1
  85. const-class v5, Ljava/io/ObjectStreamClass;
  86. const-string v6, "getConstructorId"
  87. new-array v7, v4, [Ljava/lang/Class;
  88. const-class v8, Ljava/lang/Class;
  89. aput-object v8, v7, v3
  90. invoke-virtual {v5, v6, v7}, Ljava/lang/Class;->getDeclaredMethod(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;
  91. move-result-object v5
  92. invoke-virtual {v5, v4}, Ljava/lang/reflect/Method;->setAccessible(Z)V
  93. new-array v6, v4, [Ljava/lang/Object;
  94. const-class v7, Ljava/lang/Object;
  95. aput-object v7, v6, v3
  96. invoke-virtual {v5, v2, v6}, Ljava/lang/reflect/Method;->invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
  97. move-result-object v2
  98. check-cast v2, Ljava/lang/Integer;
  99. invoke-virtual {v2}, Ljava/lang/Integer;->intValue()I
  100. move-result v2
  101. const-class v5, Ljava/io/ObjectStreamClass;
  102. new-array v6, v1, [Ljava/lang/Class;
  103. const-class v7, Ljava/lang/Class;
  104. aput-object v7, v6, v3
  105. sget-object v7, Ljava/lang/Integer;->TYPE:Ljava/lang/Class;
  106. aput-object v7, v6, v4
  107. invoke-virtual {v5, v0, v6}, Ljava/lang/Class;->getDeclaredMethod(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;
  108. move-result-object v5
  109. invoke-virtual {v5, v4}, Ljava/lang/reflect/Method;->setAccessible(Z)V
  110. new-instance v6, Lcom/google/gson/internal/UnsafeAllocator$2;
  111. invoke-direct {v6, v5, v2}, Lcom/google/gson/internal/UnsafeAllocator$2;-><init>(Ljava/lang/reflect/Method;I)V
  112. :try_end_1
  113. .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_1
  114. return-object v6
  115. :catch_1
  116. :try_start_2
  117. const-class v2, Ljava/io/ObjectInputStream;
  118. new-array v1, v1, [Ljava/lang/Class;
  119. const-class v5, Ljava/lang/Class;
  120. aput-object v5, v1, v3
  121. const-class v3, Ljava/lang/Class;
  122. aput-object v3, v1, v4
  123. invoke-virtual {v2, v0, v1}, Ljava/lang/Class;->getDeclaredMethod(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;
  124. move-result-object v0
  125. invoke-virtual {v0, v4}, Ljava/lang/reflect/Method;->setAccessible(Z)V
  126. new-instance v1, Lcom/google/gson/internal/UnsafeAllocator$3;
  127. invoke-direct {v1, v0}, Lcom/google/gson/internal/UnsafeAllocator$3;-><init>(Ljava/lang/reflect/Method;)V
  128. :try_end_2
  129. .catch Ljava/lang/Exception; {:try_start_2 .. :try_end_2} :catch_2
  130. return-object v1
  131. :catch_2
  132. new-instance v0, Lcom/google/gson/internal/UnsafeAllocator$4;
  133. invoke-direct {v0}, Lcom/google/gson/internal/UnsafeAllocator$4;-><init>()V
  134. return-object v0
  135. .end method
  136. # virtual methods
  137. .method public abstract newInstance(Ljava/lang/Class;)Ljava/lang/Object;
  138. .annotation system Ldalvik/annotation/Signature;
  139. value = {
  140. "<T:",
  141. "Ljava/lang/Object;",
  142. ">(",
  143. "Ljava/lang/Class<",
  144. "TT;>;)TT;"
  145. }
  146. .end annotation
  147. .annotation system Ldalvik/annotation/Throws;
  148. value = {
  149. Ljava/lang/Exception;
  150. }
  151. .end annotation
  152. .end method