facebook / redex

A bytecode optimizer for Android apps
https://fbredex.com/
MIT License
6.02k stars 655 forks source link

Type checker Error after ResolveRefsPass #504

Open fengruisd opened 4 years ago

fengruisd commented 4 years ago

Hi I am using redex and get an error

the TRACE is

Inconsistency found in Dex code for Lcom/xxx/xxx;.a:(Ljava/lang/String;)J

 Type error in method Lcom/xxx/xxx;.a:(Ljava/lang/String;)J class name Lcom/xxx/xxx; at instruction 'INVOKE_VIRTUAL v1, v0, Lcom/yyy/yyy;.e:(Ljava/lang/String;)Ljava/io/File;' @ 0x7fd2c2dae200 for 

illegal access to package-private Lcom/yyy/yyy;.e:(Ljava/lang/String;)Ljava/io/File;

I test it for several times and found that maybe "ResolveRefsPass" cause the problem

RefStats ResolveRefsPass::refine_virtual_callsites(DexMethod* method,
                                                   bool desuperify) {
  // ...
  auto callee = resolve_method(mref, opcode_to_search(insn), method);
  // ...
  TRACE(RESO, 1, "AccessFlag: callee %s , def_meth %s", SHOW(callee->get_access()), SHOW(def_meth->get_access()));
  insn->set_method(def_meth);
    if (is_invoke_interface(opcode) && !is_interface(def_cls)) {
      insn->set_opcode(OPCODE_INVOKE_VIRTUAL);
      stats.num_invoke_interface_replaced++;
    } else {
      stats.num_invoke_virtual_refined++;
    }
  // ...
}

I add the log "TRACE(RESO, 1, "AccessFlag: callee %s , def_meth %s", SHOW(callee->get_access()), SHOW(def_meth->get_access()));" in the code, and it print like this

AccessFlag: callee 1025 , def_meth 16

it means the access flag of callee is "PUBLIC ABSTRACT" and def_meth's access flag is "FINAL", maybe it's why the problem happened.

I am not sure if I am right.

Kindly if you could help me to check it.

Thanks

Feng23 commented 4 years ago

Can you share your configuration? Do you also have ReBindRefsPass, we need the two passes work together. cc @thezhangwei

thezhangwei commented 3 years ago

Sorry for the late comment. I'm wondering if it could be a glitch in the input. The overriding method cannot have more restricted access than the base one?

fengruisd commented 3 years ago

I didn't have ReBindRefsPass in my configuration, I'll try it

thezhangwei commented 3 years ago

I didn't have ReBindRefsPass in my configuration, I'll try it

Hi, I don't think you absolutely need ReBindRefsPass here. It would be great to find out why ResolveRefsPass causes the problem. You mentioned that the def_meth has a more restricted access flag than callee above. Can you share the relevant input so we can look into the root cause? It's odd that the type inferred def_meth has a more restricted access. Thx,