k.java 源代码


package j4;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.UnmodifiableIterator;
import g5.x;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import l5.y;
import p5.e;
import v5.s;

public class k {

    public final j4.d f23322a;

    public final d5.g f23323b;

    public final d5.h f23324c;

    public final ImmutableList<f5.f> f23325d;

    public final List<f5.f> f23326e;

    public final ImmutableList<d5.i> f23327f;

    public p f23328g;

    private final d f23329h = new d();

    private final s f23330i;

    private final s f23331j;

    private final p5.e f23332k;

    public class a extends l {
        a(int i6) {
            super(i6);
        }

        @Override
        public double d() {
            return -1000.0d;
        }

        @Override
        public boolean e(v5.k kVar) throws IOException {
            kVar.write("#@");
            kVar.m(this.f23337q & 4294967295L);
            return true;
        }
    }

    public class b extends l {
        b(int i6) {
            super(i6);
        }

        @Override
        public double d() {
            return -1000.0d;
        }

        @Override
        public boolean e(v5.k kVar) throws IOException {
            kVar.write("#@");
            kVar.m(this.f23337q & 4294967295L);
            return true;
        }
    }

    public static class c extends v5.g {

        private final int f23335r;

        public c(int i6) {
            super("No switch payload at offset: %d", Integer.valueOf(i6));
            this.f23335r = i6;
        }
    }

    public static class d {

        protected HashMap<j, j> f23336a = new HashMap<>();

        public Collection<j> a() {
            return this.f23336a.values();
        }

        public j b(j jVar) {
            j jVar2 = this.f23336a.get(jVar);
            if (jVar2 != null) {
                return jVar2;
            }
            this.f23336a.put(jVar, jVar);
            return jVar;
        }
    }

    public k(j4.d dVar, d5.g gVar, d5.h hVar) {
        boolean z6;
        int i6;
        boolean z7;
        this.f23322a = dVar;
        this.f23323b = gVar;
        this.f23324c = hVar;
        try {
            ImmutableList<f5.f> r6 = ImmutableList.r(hVar.b());
            this.f23325d = r6;
            this.f23327f = ImmutableList.s(gVar.getParameters());
            this.f23326e = Lists.h(r6);
            this.f23330i = new s(0);
            this.f23331j = new s(0);
            p5.e eVar = new p5.e(r6);
            this.f23332k = eVar;
            int a7 = eVar.a(r6.size() - 1) + r6.get(r6.size() - 1).e();
            for (int i7 = 0; i7 < this.f23325d.size(); i7++) {
                f5.f fVar = this.f23325d.get(i7);
                o4.g m6 = fVar.m();
                if (m6 == o4.g.f24897p0) {
                    int a8 = this.f23332k.a(i7);
                    int q6 = ((f5.h) fVar).q() + a8;
                    try {
                        q6 = e(q6, o4.g.f24921t4);
                        z7 = true;
                    } catch (c unused) {
                        z7 = false;
                    }
                    if (z7) {
                        if (this.f23330i.c(q6, -1) != -1) {
                            f5.f f6 = f(q6, o4.g.f24921t4);
                            this.f23326e.set(i7, new y(m6, ((x) fVar).k(), a7 - a8));
                            this.f23326e.add(f6);
                            i6 = f6.e() + a7;
                        } else {
                            i6 = a7;
                            a7 = q6;
                        }
                        this.f23330i.a(a7, a8);
                        a7 = i6;
                    }
                } else {
                    if (m6 == o4.g.f24902q0) {
                        int a9 = this.f23332k.a(i7);
                        int q7 = ((f5.h) fVar).q() + a9;
                        try {
                            q7 = e(q7, o4.g.f24926u4);
                            z6 = true;
                        } catch (c unused2) {
                            z6 = false;
                        }
                        if (z6) {
                            if (this.f23331j.c(q7, -1) != -1) {
                                f5.f f7 = f(q7, o4.g.f24926u4);
                                this.f23326e.set(i7, new y(m6, ((x) fVar).k(), a7 - a9));
                                this.f23326e.add(f7);
                                i6 = f7.e() + a7;
                            } else {
                                i6 = a7;
                                a7 = q7;
                            }
                            this.f23331j.a(a7, a9);
                            a7 = i6;
                        }
                    }
                }
            }
        } catch (Exception e6) {
            try {
                throw v5.g.c(e6, "Error while processing method %s", p5.i.d(gVar));
            } catch (Exception unused3) {
                throw v5.g.c(e6, "Error while processing method", new Object[0]);
            }
        }
    }

    private void a(List<l> list) {
        this.f23322a.f23311a.getClass();
        d5.g gVar = this.f23323b;
        i4.b bVar = this.f23322a.f23311a;
        p4.g gVar2 = new p4.g(null, gVar, bVar.f22915n, bVar.f22912k);
        p4.a V = gVar2.V();
        if (V != null) {
            list.add(new e(String.format("AnalysisException: %s", V.getMessage()), V.f25532r, -2.147483648E9d));
            V.printStackTrace(System.err);
        }
        List<p4.b> W = gVar2.W();
        int i6 = 0;
        for (int i7 = 0; i7 < W.size(); i7++) {
            p4.b bVar2 = W.get(i7);
            list.add(m4.f.a(this, i6, bVar2.f()));
            if (bVar2.f().m().f24959u == o4.d.UnresolvedOdexInstruction) {
                list.add(new f(m4.f.a(this, i6, bVar2.i())));
            }
            if (i7 != W.size() - 1) {
                list.add(new j4.b(i6));
            }
            if (this.f23322a.f23311a.f22907f) {
                list.add(new b(i6));
            }
            if (this.f23322a.f23311a.f22913l != 0 && !bVar2.f().m().f24959u.f24810r) {
                list.add(new n(this.f23322a.f23311a.f22913l, gVar2, this.f23328g, bVar2, i6));
                list.add(new m(this.f23328g, bVar2, i6));
            }
            i6 += bVar2.f().e();
        }
    }

    private void b(List<l> list) {
        Iterator<? extends e5.a> it = this.f23324c.c().iterator();
        while (it.hasNext()) {
            list.add(k4.b.f(this.f23328g, it.next()));
        }
    }

    private void c(List<l> list) {
        int i6 = 0;
        for (int i7 = 0; i7 < this.f23326e.size(); i7++) {
            f5.f fVar = this.f23326e.get(i7);
            list.add(m4.f.a(this, i6, fVar));
            if (i7 != this.f23326e.size() - 1) {
                list.add(new j4.b(i6));
            }
            if (this.f23322a.f23311a.f22907f) {
                list.add(new a(i6));
            }
            i4.b bVar = this.f23322a.f23311a;
            if (bVar.f22908g) {
                bVar.getClass();
            }
            i6 += fVar.e();
        }
    }

    private void d(List<l> list) {
        List<? extends d5.k<? extends d5.e>> d6 = this.f23324c.d();
        if (d6.size() == 0) {
            return;
        }
        int a7 = this.f23332k.a(this.f23325d.size() - 1);
        ImmutableList<f5.f> immutableList = this.f23325d;
        int e6 = a7 + immutableList.get(immutableList.size() - 1).e();
        for (d5.k<? extends d5.e> kVar : d6) {
            int a8 = kVar.a();
            int c6 = a8 + kVar.c();
            if (a8 < e6) {
                if (c6 <= e6) {
                    int a9 = this.f23332k.a(this.f23332k.c(c6 - 1, false));
                    Iterator<? extends Object> it = kVar.b().iterator();
                    while (it.hasNext()) {
                        d5.e eVar = (d5.e) it.next();
                        int o02 = eVar.o0();
                        if (o02 < e6) {
                            list.add(new j4.c(this.f23322a.f23311a, this.f23329h, a9, eVar.i0(), a8, c6, o02));
                        } else {
                            throw new v5.g("Exception handler offset %d is past the end of the code block.", Integer.valueOf(o02));
                        }
                    }
                } else {
                    throw new RuntimeException(String.format("Try end offset %d is past the end of the code block.", Integer.valueOf(c6)));
                }
            } else {
                throw new RuntimeException(String.format("Try start offset %d is past the end of the code block.", Integer.valueOf(a8)));
            }
        }
    }

    private List<l> h() {
        ArrayList arrayList = new ArrayList();
        i4.b bVar = this.f23322a.f23311a;
        if (bVar.f22913l == 0 && !bVar.f22912k && (!bVar.f22910i || !k())) {
            c(arrayList);
        } else {
            a(arrayList);
        }
        d(arrayList);
        if (this.f23322a.f23311a.f22906e) {
            b(arrayList);
        }
        if (this.f23322a.f23311a.f22905d) {
            l();
        }
        Iterator<j> it = this.f23329h.a().iterator();
        while (it.hasNext()) {
            arrayList.add(it.next());
        }
        Collections.sort(arrayList);
        return arrayList;
    }

    private boolean k() {
        Iterator<? extends f5.f> it = this.f23324c.b().iterator();
        while (it.hasNext()) {
            if (it.next().m().q()) {
                return true;
            }
        }
        return false;
    }

    private void l() {
        HashMap hashMap = new HashMap();
        ArrayList arrayList = new ArrayList(this.f23329h.a());
        Collections.sort(arrayList);
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            j jVar = (j) it.next();
            Integer num = (Integer) hashMap.get(jVar.g());
            if (num == null) {
                num = 0;
            }
            jVar.h(num.intValue());
            hashMap.put(jVar.g(), Integer.valueOf(num.intValue() + 1));
        }
    }

    private static void m(v5.k kVar, int i6, Set<o4.e> set) throws IOException {
        for (o4.a aVar : o4.a.e(i6)) {
            kVar.write(aVar.toString());
            kVar.write(32);
        }
        Iterator<o4.e> it = set.iterator();
        while (it.hasNext()) {
            kVar.write(it.next().toString());
            kVar.write(32);
        }
    }

    public static void n(v5.k kVar, d5.g gVar, i4.b bVar) throws IOException {
        String str;
        kVar.write(".method ");
        m(kVar, gVar.a0(), gVar.d0());
        kVar.write(gVar.getName());
        kVar.write("(");
        ImmutableList s6 = ImmutableList.s(gVar.getParameters());
        UnmodifiableIterator it = s6.iterator();
        while (it.hasNext()) {
            kVar.write(((d5.i) it.next()).getType());
        }
        kVar.write(")");
        kVar.write(gVar.getReturnType());
        kVar.write(10);
        kVar.e(4);
        o(kVar, gVar, s6, bVar);
        if (bVar.f22911j) {
            str = gVar.Z();
        } else {
            str = null;
        }
        j4.a.b(kVar, gVar.getAnnotations(), str);
        kVar.d(4);
        kVar.write(".end method\n");
    }

    private static void o(v5.k kVar, d5.g gVar, List<? extends d5.i> list, i4.b bVar) throws IOException {
        String str;
        int i6 = !o4.a.STATIC.f(gVar.a0()) ? 1 : 0;
        for (d5.i iVar : list) {
            String type = iVar.getType();
            String name = iVar.getName();
            Set<? extends d5.a> annotations = iVar.getAnnotations();
            if ((bVar.f22906e && name != null) || annotations.size() != 0) {
                kVar.write(".param p");
                kVar.f(i6);
                if (name != null && bVar.f22906e) {
                    kVar.write(", ");
                    o.c(kVar, name);
                }
                kVar.write("    # ");
                kVar.write(type);
                kVar.write("\n");
                if (annotations.size() > 0) {
                    kVar.e(4);
                    if (bVar.f22911j) {
                        str = gVar.Z();
                    } else {
                        str = null;
                    }
                    j4.a.b(kVar, annotations, str);
                    kVar.d(4);
                    kVar.write(".end param\n");
                }
            }
            i6++;
            if (p5.j.c(type)) {
                i6++;
            }
        }
    }

    public int e(int i6, o4.g gVar) {
        int i7;
        try {
            int b6 = this.f23332k.b(i6);
            f5.f fVar = this.f23325d.get(b6);
            if (fVar.m() != gVar) {
                if (fVar.m() == o4.g.f24937x && (i7 = b6 + 1) < this.f23325d.size() && this.f23325d.get(i7).m() == gVar) {
                    return this.f23332k.a(i7);
                }
                throw new c(i6);
            }
            return i6;
        } catch (e.b unused) {
            throw new c(i6);
        }
    }

    public f5.f f(int i6, o4.g gVar) {
        int i7;
        try {
            int b6 = this.f23332k.b(i6);
            f5.f fVar = this.f23325d.get(b6);
            if (fVar.m() != gVar) {
                if (fVar.m() == o4.g.f24937x && (i7 = b6 + 1) < this.f23325d.size()) {
                    f5.f fVar2 = this.f23325d.get(i7);
                    if (fVar2.m() == gVar) {
                        return fVar2;
                    }
                }
                throw new c(i6);
            }
            return fVar;
        } catch (e.b unused) {
            throw new c(i6);
        }
    }

    public d g() {
        return this.f23329h;
    }

    public int i(int i6) {
        return this.f23330i.c(i6, -1);
    }

    public int j(int i6) {
        return this.f23331j.c(i6, -1);
    }

    public void p(v5.k kVar) throws IOException {
        String str;
        int i6 = !o4.a.STATIC.f(this.f23323b.a0()) ? 1 : 0;
        kVar.write(".method ");
        m(kVar, this.f23323b.a0(), this.f23323b.d0());
        kVar.write(this.f23323b.getName());
        kVar.write("(");
        UnmodifiableIterator<d5.i> it = this.f23327f.iterator();
        while (it.hasNext()) {
            String type = it.next().getType();
            kVar.write(type);
            i6++;
            if (p5.j.c(type)) {
                i6++;
            }
        }
        kVar.write(")");
        kVar.write(this.f23323b.getReturnType());
        kVar.write(10);
        kVar.e(4);
        if (this.f23322a.f23311a.f22904c) {
            kVar.write(".locals ");
            kVar.f(this.f23324c.a() - i6);
        } else {
            kVar.write(".registers ");
            kVar.f(this.f23324c.a());
        }
        kVar.write(10);
        o(kVar, this.f23323b, this.f23327f, this.f23322a.f23311a);
        if (this.f23328g == null) {
            this.f23328g = new p(this.f23322a.f23311a, this.f23324c.a(), i6);
        }
        if (this.f23322a.f23311a.f22911j) {
            str = this.f23323b.Z();
        } else {
            str = null;
        }
        j4.a.b(kVar, this.f23323b.getAnnotations(), str);
        kVar.write(10);
        Iterator<l> it2 = h().iterator();
        while (it2.hasNext()) {
            if (it2.next().e(kVar)) {
                kVar.write(10);
            }
        }
        kVar.d(4);
        kVar.write(".end method\n");
    }
}