-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(smali-input): compile one smali file at a time to avoid 64k limit (…
- Loading branch information
Showing
8 changed files
with
204 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/IDexData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package jadx.plugins.input.dex.utils; | ||
|
||
public interface IDexData { | ||
|
||
String getFileName(); | ||
|
||
byte[] getContent(); | ||
} |
28 changes: 28 additions & 0 deletions
28
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/SimpleDexData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package jadx.plugins.input.dex.utils; | ||
|
||
import java.util.Objects; | ||
|
||
public class SimpleDexData implements IDexData { | ||
private final String fileName; | ||
private final byte[] content; | ||
|
||
public SimpleDexData(String fileName, byte[] content) { | ||
this.fileName = Objects.requireNonNull(fileName); | ||
this.content = Objects.requireNonNull(content); | ||
} | ||
|
||
@Override | ||
public String getFileName() { | ||
return fileName; | ||
} | ||
|
||
@Override | ||
public byte[] getContent() { | ||
return content; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DexData{" + fileName + ", size=" + content.length + '}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
jadx-plugins/jadx-smali-input/src/main/java/jadx/plugins/input/smali/SmaliInputOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package jadx.plugins.input.smali; | ||
|
||
import jadx.api.plugins.options.impl.BasePluginOptionsBuilder; | ||
|
||
public class SmaliInputOptions extends BasePluginOptionsBuilder { | ||
|
||
private int apiLevel; | ||
private int threads; // use jadx global threads count option | ||
|
||
@Override | ||
public void registerOptions() { | ||
intOption(SmaliInputPlugin.PLUGIN_ID + ".api-level") | ||
.description("Android API level") | ||
.defaultValue(27) | ||
.setter(v -> apiLevel = v); | ||
} | ||
|
||
public int getApiLevel() { | ||
return apiLevel; | ||
} | ||
|
||
public int getThreads() { | ||
return threads; | ||
} | ||
|
||
public void setThreads(int threads) { | ||
this.threads = threads; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
jadx-plugins/jadx-smali-input/src/main/java/jadx/plugins/input/smali/SmaliUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package jadx.plugins.input.smali; | ||
|
||
import java.io.IOException; | ||
import java.io.Reader; | ||
|
||
import org.antlr.runtime.CommonTokenStream; | ||
import org.antlr.runtime.RecognitionException; | ||
import org.antlr.runtime.TokenSource; | ||
import org.antlr.runtime.tree.CommonTreeNodeStream; | ||
|
||
import com.android.tools.smali.dexlib2.Opcodes; | ||
import com.android.tools.smali.dexlib2.writer.builder.DexBuilder; | ||
import com.android.tools.smali.dexlib2.writer.io.MemoryDataStore; | ||
import com.android.tools.smali.smali.LexerErrorInterface; | ||
import com.android.tools.smali.smali.SmaliOptions; | ||
import com.android.tools.smali.smali.smaliFlexLexer; | ||
import com.android.tools.smali.smali.smaliParser; | ||
import com.android.tools.smali.smali.smaliTreeWalker; | ||
|
||
/** | ||
* Utility methods to assemble smali to in-memory buffer. | ||
* This implementation uses smali library internal classes. | ||
*/ | ||
public class SmaliUtils { | ||
|
||
@SuppressWarnings("ExtractMethodRecommender") | ||
public static byte[] assemble(Reader reader, SmaliOptions options) throws IOException, RecognitionException { | ||
LexerErrorInterface lexer = new smaliFlexLexer(reader, options.apiLevel); | ||
CommonTokenStream tokens = new CommonTokenStream((TokenSource) lexer); | ||
smaliParser parser = new smaliParser(tokens); | ||
parser.setVerboseErrors(options.verboseErrors); | ||
parser.setAllowOdex(options.allowOdexOpcodes); | ||
parser.setApiLevel(options.apiLevel); | ||
smaliParser.smali_file_return parseResult = parser.smali_file(); | ||
if (parser.getNumberOfSyntaxErrors() > 0 || lexer.getNumberOfSyntaxErrors() > 0) { | ||
throw new RuntimeException("Parse error"); | ||
} | ||
CommonTreeNodeStream treeStream = new CommonTreeNodeStream(parseResult.getTree()); | ||
treeStream.setTokenStream(tokens); | ||
|
||
DexBuilder dexBuilder = new DexBuilder(Opcodes.forApi(options.apiLevel)); | ||
smaliTreeWalker dexGen = new smaliTreeWalker(treeStream); | ||
dexGen.setApiLevel(options.apiLevel); | ||
dexGen.setVerboseErrors(options.verboseErrors); | ||
dexGen.setDexBuilder(dexBuilder); | ||
dexGen.smali_file(); | ||
if (dexGen.getNumberOfSyntaxErrors() > 0) { | ||
throw new RuntimeException("Compile error"); | ||
} | ||
MemoryDataStore dataStore = new MemoryDataStore(); | ||
dexBuilder.writeTo(dataStore); | ||
return dataStore.getData(); | ||
} | ||
} |