Giter Club home page Giter Club logo

Comments (5)

melcz avatar melcz commented on September 15, 2024

Hi, could you share the changes on rewriting that happen between the first and second disassembly attempts? Preferably in a minimal code snippet to try to reproduce the error on our end.

from smali.

weary-adventurer avatar weary-adventurer commented on September 15, 2024

There are no changes between loading the file and rewriting it. Simply rewriting a file without changes using DexRewriter and then writing the rewritten file produces the broken dex. The code snippet that does it is listed as the first thing in the issue.

Here are all the files needed to reproduce it locally: smali_repro.zip.

Steps:

  1. Download and extract smali_repro.zip
Libraries used
  1. Compile repro program:
    javac -cp ".;lib\*" Main.java (Windows)
    javac -cp ".:lib/*" Main.java (Linux)

  2. Run repro program (it reads classes_original.dex and writes broken classes_rewritten.dex)
    java -cp ".;lib\*" Main (Windows)
    java -cp ".:lib/*" Main (Linux)

  3. Disassemble original file classes_original.dex (no error):
    java -cp ".;lib\*" com.android.tools.smali.baksmali.Main dis -o out_original classes_original.dex (Windows)
    java -cp ".:lib/*" com.android.tools.smali.baksmali.Main dis -o out_original classes_original.dex (Linux)

  4. Disassemble broken file classes_rewritten.dex (error as the file is broken):
    java -cp ".;lib\*" com.android.tools.smali.baksmali.Main dis -o out_rewritten classes_rewritten.dex (Windows)
    java -cp ".:lib/*" com.android.tools.smali.baksmali.Main dis -o out_rewritten classes_rewritten.dex (Linux)

The classes_rewritten.dex file is generated by using DexRewriter and then writing the file with DexFileFactory.writeDexFile.

from smali.

weary-adventurer avatar weary-adventurer commented on September 15, 2024

Actually it looks like DexFileFactory.writeDexFile is broken.

Repro:

import com.android.tools.smali.dexlib2.DexFileFactory;
import com.android.tools.smali.dexlib2.dexbacked.DexBackedDexFile;

public class Main {
    public static void main(String[] args) throws Exception {
        DexBackedDexFile dexFile = DexFileFactory.loadDexFile("classes_original.dex", null);
        DexFileFactory.writeDexFile("classes_writedexfile.dex", dexFile);
    }
}

Compile and run:

$ javac -cp ".;lib\*" Main.java

$ java -cp ".;lib\*" Main

$ md5sum classes_original.dex
73d6b886ad21105a077ba4ff8dc70a83 *classes_original.dex

$ md5sum classes_writedexfile.dex
9b638d2cf2e768c87b44a4f7dd3f3e50 *classes_writedexfile.dex

$ stat -c "%s %n" -- *.dex
2938412 classes_original.dex
3172524 classes_writedexfile.dex

$ java -cp ".;lib\*" com.android.tools.smali.baksmali.Main dis -o out classes_writedexfile.dex
Error occurred while disassembling class LFC0; - skipping class
com.android.tools.smali.util.ExceptionWithContext: Invalid uleb128 integer encountered at offset 0x110642

from smali.

melcz avatar melcz commented on September 15, 2024

Could you test with the changes in the rewriter branch?
https://github.com/google/smali/tree/rewriter

from smali.

weary-adventurer avatar weary-adventurer commented on September 15, 2024

It does not compile from command line. I've used both gradlew assemble and gradlew smali:fatJar and both fail.
If you can build the jars like the ones I can download from maven then I'll be able to test it.

> Task :smali:generateGrammarSource FAILED
error(10):  internal error:  : java.lang.Error: Error parsing smaliTreeWalker.g: 'third_party' not expected 'grammar'
org.antlr.tool.GrammarSpelunker.match(GrammarSpelunker.java:70)
org.antlr.tool.GrammarSpelunker.grammarHeader(GrammarSpelunker.java:108)
org.antlr.tool.GrammarSpelunker.parse(GrammarSpelunker.java:80)
org.antlr.Tool.sortGrammarFiles(Tool.java:585)
org.antlr.Tool.process(Tool.java:439)
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
> Task :smali:generateGrammarSource FAILED

> Task :dexlib2:compileJava
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':smali:generateGrammarSource'.
> There were 19 errors during grammar generation

from smali.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.