Skip to content

[core] content of try-catch block is not placed inside but after it #2627

@jpstotz

Description

@jpstotz

Issue details

Jadx decompiled code:

public static int getBatteryLevel(android.content.Context context) {
    try {
       // ERROR: try block is empty!
    } catch (java.lang.Exception e) {
        com.instabug.library.util.InstabugSDKLogger.m7327e("IBG-Core", "Got error while get battery level", e);
    }
    if (context.registerReceiver(null, new android.content.IntentFilter("android.intent.action.BATTERY_CHANGED")) != null) {
        return (int) ((r4.getIntExtra("level", -1) / r4.getIntExtra("scale", -1)) * 100.0f);
    }
    com.instabug.library.util.InstabugSDKLogger.m7325d("IBG-Core", "Could't obtain battery level");
    return -1;
}

If I had interpreted the Smali code correct, the method should have most of the code inside the try-catch block, not after it:

Expected decompiled code:

public static int getBatteryLevel(android.content.Context context) {
    try {
        if (context.registerReceiver(null, new android.content.IntentFilter("android.intent.action.BATTERY_CHANGED")) != null) {
            return (int) ((r4.getIntExtra("level", -1) / r4.getIntExtra("scale", -1)) * 100.0f);
        }
        com.instabug.library.util.InstabugSDKLogger.m7325d("IBG-Core", "Could't obtain battery level");
    } catch (java.lang.Exception e) {
        com.instabug.library.util.InstabugSDKLogger.m7327e("IBG-Core", "Got error while get battery level", e);
    }
    return -1;
}

Stripped APK:

cvm_issue.apk.zip

Smali code:

.method public static getBatteryLevel(Landroid/content/Context;)I
    .registers 5

    const-string v0, "IBG-Core"

    const/4 v1, -0x1

    .line 1
    :try_start_3
    new-instance v2, Landroid/content/IntentFilter;

    const-string v3, "android.intent.action.BATTERY_CHANGED"

    invoke-direct {v2, v3}, Landroid/content/IntentFilter;-><init>(Ljava/lang/String;)V

    const/4 v3, 0x0

    .line 2
    invoke-virtual {p0, v3, v2}, Landroid/content/Context;->registerReceiver(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;

    move-result-object p0

    if-eqz p0, :cond_25

    .line 4
    const-string v2, "level"

    invoke-virtual {p0, v2, v1}, Landroid/content/Intent;->getIntExtra(Ljava/lang/String;I)I

    move-result v2

    .line 5
    const-string v3, "scale"

    invoke-virtual {p0, v3, v1}, Landroid/content/Intent;->getIntExtra(Ljava/lang/String;I)I

    move-result p0

    int-to-float v0, v2

    int-to-float p0, p0

    div-float/2addr v0, p0

    const/high16 p0, 0x42c80000    # 100.0f

    mul-float/2addr v0, p0

    float-to-int p0, v0

    return p0

    .line 9
    :cond_25
    const-string p0, "Could\'t obtain battery level"

    invoke-static {v0, p0}, Lcom/instabug/library/util/InstabugSDKLogger;->d(Ljava/lang/String;Ljava/lang/String;)V
    :try_end_2a
    .catch Ljava/lang/Exception; {:try_start_3 .. :try_end_2a} :catch_2b

    goto :goto_31

    :catch_2b
    move-exception p0

    .line 12
    const-string v2, "Got error while get battery level"

    invoke-static {v0, v2, p0}, Lcom/instabug/library/util/InstabugSDKLogger;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V

    :goto_31
    return v1
.end method

Jadx version

latest from git 4335864

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions