JesusFreke / smali

smali/baksmali
6.3k stars 1.07k forks source link

Fixing missing reference type handling for rewriting purposes #852

Closed andvgal closed 1 year ago

andvgal commented 2 years ago

During some DEX rewriting using the latest features, exceptions get thrown because of missing handling of some reference types.

Fixed that, and also went through the code to fix all other missing stuff. In some cases, maybe no real opcode would be coded such way that some code path would be triggered, but this way is more safe.

Also, likely fixed a bug of interning METHOD_HANDLE type.

andvgal commented 2 years ago

@JesusFreke perhaps, with this one, it would be good to release v2.5.3 as a number of important fixes have piled up.

salvogiangri commented 1 year ago

@andvgal the following error happens to me when trying to build with the applied 8d139eb7630e61a6177bd02765e653210265073c patch:

> Task :dexlib2:compileJava FAILED
/home/mesa/Scrivania/Android/Sorgenti/m/smali/dexlib2/src/main/java/org/jf/dexlib2/rewriter/InstructionRewriter.java:47: error: cannot find symbol
public class InstructionRewriter implements Rewriter<Instruction> {
                                            ^
  symbol: class Rewriter
/home/mesa/Scrivania/Android/Sorgenti/m/smali/dexlib2/src/main/java/org/jf/dexlib2/rewriter/InstructionRewriter.java:48: error: cannot find symbol
    @Nonnull protected final Rewriters rewriters;
                             ^
  symbol:   class Rewriters
  location: class InstructionRewriter
/home/mesa/Scrivania/Android/Sorgenti/m/smali/dexlib2/src/main/java/org/jf/dexlib2/rewriter/InstructionRewriter.java:50: error: cannot find symbol
    public InstructionRewriter(@Nonnull Rewriters rewriters) {
                                        ^
  symbol:   class Rewriters
  location: class InstructionRewriter
/home/mesa/Scrivania/Android/Sorgenti/m/smali/dexlib2/src/main/java/org/jf/dexlib2/rewriter/InstructionRewriter.java:318: error: class InstructionRewriter.RewrittenInstruction4rcc is already defined in class InstructionRewriter
    protected class RewrittenInstruction4rcc extends BaseRewrittenDualReferenceInstruction<Instruction4rcc>
              ^
/home/mesa/Scrivania/Android/Sorgenti/m/smali/dexlib2/src/main/java/org/jf/dexlib2/rewriter/InstructionRewriter.java:54: error: method does not override or implement a method from a supertype
    @Nonnull @Override public Instruction rewrite(@Nonnull Instruction instruction) {
             ^
/home/mesa/Scrivania/Android/Sorgenti/m/smali/dexlib2/src/main/java/org/jf/dexlib2/rewriter/InstructionRewriter.java:95: error: cannot find symbol
                        (MethodProtoReference)reference);
                         ^
  symbol:   class MethodProtoReference
  location: class InstructionRewriter
/home/mesa/Scrivania/Android/Sorgenti/m/smali/dexlib2/src/main/java/org/jf/dexlib2/rewriter/InstructionRewriter.java:98: error: cannot find symbol
                        rewriters, (MethodHandleReference)reference);
                                    ^
  symbol:   class MethodHandleReference
  location: class InstructionRewriter
/home/mesa/Scrivania/Android/Sorgenti/m/smali/dexlib2/src/main/java/org/jf/dexlib2/rewriter/InstructionRewriter.java:100: error: cannot find symbol
                return rewriters.getCallSiteReferenceRewriter().rewrite((CallSiteReference)reference);
                                                                         ^
  symbol:   class CallSiteReference
  location: class InstructionRewriter
/home/mesa/Scrivania/Android/Sorgenti/m/smali/dexlib2/src/main/java/org/jf/dexlib2/rewriter/InstructionRewriter.java:102: error: cannot find symbol
                throw new ExceptionWithContext("Invalid reference type: %d",
                          ^
  symbol:   class ExceptionWithContext
  location: class InstructionRewriter
/home/mesa/Scrivania/Android/Sorgenti/m/smali/dexlib2/src/main/java/org/jf/dexlib2/rewriter/RewriterModule.java:70: error: incompatible types: InstructionRewriter cannot be converted to Rewriter<Instruction>
        return new InstructionRewriter(rewriters);
               ^
Note: /home/mesa/Scrivania/Android/Sorgenti/m/smali/dexlib2/src/main/java/org/jf/dexlib2/analysis/CustomInlineMethodResolver.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
10 errors

Any idea on what could be the cause?

andvgal commented 1 year ago

@BlackMesa123 pardon, I missed GH notification, if there was any.

Note: this PR had incomplete code changes unfortunately (not pushed).

A new PR has been submitted against Google's upstream https://github.com/google/smali/pull/11 So, closing,