Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core]decompilation error in class ProviderFactory of simplexml #1377

Closed
zxt5105515 opened this issue Feb 11, 2022 · 3 comments
Closed

[core]decompilation error in class ProviderFactory of simplexml #1377

zxt5105515 opened this issue Feb 11, 2022 · 3 comments
Labels
bug Core Issues in jadx-core module java-input try-catch
Milestone

Comments

@zxt5105515
Copy link

decompilation error in class ProviderFactory of simplexml (simple-xml-2.7.1.jar.zip)

decompilation java code

package org.simpleframework.xml.stream;

/* loaded from: simple-xml-2.7.1.jar:org/simpleframework/xml/stream/ProviderFactory.class */
final class ProviderFactory {
    ProviderFactory() {
    }

    public static Provider getInstance() {
        try {
            return new StreamProvider();
        } catch (Throwable th) {
            return new DocumentProvider();
        }
    }
}

decompilation smali code

###### Class org.simpleframework.xml.stream.ProviderFactory (org.simpleframework.xml.stream.ProviderFactory)
.version 50  # Java 6
.class final super org/simpleframework/xml/stream/ProviderFactory
.source "ProviderFactory.java"

.method <init>()V
    .max stack 1
    .max locals 1

    .local 0 "this" Lorg/simpleframework/xml/stream/ProviderFactory;
    .line 33
    aload 0
    invokespecial java/lang/Object <init> ()V
    return
.end method

.method public static getInstance()Lorg/simpleframework/xml/stream/Provider;
    .max stack 2
    .max locals 1

  :L0
    .line 48
    new org/simpleframework/xml/stream/StreamProvider
    dup
    invokespecial org/simpleframework/xml/stream/StreamProvider <init> ()V
  :L1
    .catch java/lang/Throwable :L0 .. :L1 goto :L2
    .catch java/lang/Throwable :L0 .. :L1 goto :L3
    areturn
  :L2
    .line 49
    .stack same1 java/lang/Throwable
    astore 0
    .local 0 "e" Ljava/lang/Throwable;
    .line 50
    new org/simpleframework/xml/stream/PullProvider
    dup
    invokespecial org/simpleframework/xml/stream/PullProvider <init> ()V
  :L4
    .catch java/lang/Throwable :L2 .. :L4 goto :L3
    areturn
  :L3
    .line 52
    .end local 0 # "e"
    .stack same1 java/lang/Throwable
    astore 0
    .local 0 "e" Ljava/lang/Throwable;
    .line 53
    new org/simpleframework/xml/stream/DocumentProvider
    dup
    invokespecial org/simpleframework/xml/stream/DocumentProvider <init> ()V
    areturn
.end method

as you can see :L2 is not in java code

my jadx :
jadx version: 1.3.2
Java VM: OpenJDK 64-Bit Server VM
Java version: 17.0.2

@zxt5105515 zxt5105515 added bug Core Issues in jadx-core module labels Feb 11, 2022
@zxt5105515 zxt5105515 changed the title [core] [core]decompilation error in class ProviderFactory of simplexml Feb 11, 2022
@skylot
Copy link
Owner

skylot commented Feb 11, 2022

@zxt5105515 thanks! Looks like this issue is similar to recent #1374

Original code for reference (link):

   public static Provider getInstance() {
      try {
         try {
            return new StreamProvider();
         } catch(Throwable e) {
            return new PullProvider();
         }
      } catch(Throwable e) {
         return new DocumentProvider();
      }
   }

P.S. You refer to not smali but raung code :)
Raung is my project similar to smali but for java bytecode.
And looks like this code also cause an issue in raung code, i.e:

    .catch java/lang/Throwable :L0 .. :L1 goto :L2
    .catch java/lang/Throwable :L0 .. :L1 goto :L3

Maybe I incorrectly parse and process catch blocks in both projects 😕

@skylot skylot added this to the TBD milestone Feb 11, 2022
@tang350476527
Copy link

tang350476527 commented Feb 11, 2022 via email

@skylot
Copy link
Owner

skylot commented Feb 16, 2022

Turns out issue was caused by a weird catch table, i.e. one instruction can have several exception handlers with same type. For more general case: one exception handler can shadow others by wider type. I added a check to fix such cases (by removing shadowed handlers), so this issue is fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Core Issues in jadx-core module java-input try-catch
Projects
None yet
Development

No branches or pull requests

3 participants