use of jadx.core.dex.attributes.nodes.SourceFileAttr in project jadx by skylot.
the class DebugInfoParser method process.
public void process() throws DecodeException {
int addr = 0;
int line = section.readUleb128();
int paramsCount = section.readUleb128();
List<RegisterArg> mthArgs = mth.getArguments(false);
for (int i = 0; i < paramsCount; i++) {
int id = section.readUleb128() - 1;
if (id != DexNode.NO_INDEX) {
String name = dex.getString(id);
if (i < mthArgs.size()) {
mthArgs.get(i).setName(name);
}
}
}
for (RegisterArg arg : mthArgs) {
int rn = arg.getRegNum();
locals[rn] = new LocalVar(arg);
activeRegisters[rn] = arg;
}
// process '0' instruction
addrChange(-1, 1, line);
setLine(addr, line);
int c = section.readByte() & 0xFF;
while (c != DBG_END_SEQUENCE) {
switch(c) {
case DBG_ADVANCE_PC:
{
int addrInc = section.readUleb128();
addr = addrChange(addr, addrInc, line);
setLine(addr, line);
break;
}
case DBG_ADVANCE_LINE:
{
line += section.readSleb128();
break;
}
case DBG_START_LOCAL:
{
int regNum = section.readUleb128();
int nameId = section.readUleb128() - 1;
int type = section.readUleb128() - 1;
LocalVar var = new LocalVar(dex, regNum, nameId, type, DexNode.NO_INDEX);
startVar(var, addr, line);
break;
}
case DBG_START_LOCAL_EXTENDED:
{
int regNum = section.readUleb128();
int nameId = section.readUleb128() - 1;
int type = section.readUleb128() - 1;
int sign = section.readUleb128() - 1;
LocalVar var = new LocalVar(dex, regNum, nameId, type, sign);
startVar(var, addr, line);
break;
}
case DBG_RESTART_LOCAL:
{
int regNum = section.readUleb128();
LocalVar var = locals[regNum];
if (var != null) {
if (var.end(addr, line)) {
setVar(var);
}
var.start(addr, line);
}
break;
}
case DBG_END_LOCAL:
{
int regNum = section.readUleb128();
LocalVar var = locals[regNum];
if (var != null) {
var.end(addr, line);
setVar(var);
}
break;
}
case DBG_SET_PROLOGUE_END:
case DBG_SET_EPILOGUE_BEGIN:
// do nothing
break;
case DBG_SET_FILE:
{
int idx = section.readUleb128() - 1;
if (idx != DexNode.NO_INDEX) {
String sourceFile = dex.getString(idx);
mth.addAttr(new SourceFileAttr(sourceFile));
}
break;
}
default:
{
if (c >= DBG_FIRST_SPECIAL) {
int adjustedOpcode = c - DBG_FIRST_SPECIAL;
int addrInc = adjustedOpcode / DBG_LINE_RANGE;
addr = addrChange(addr, addrInc, line);
line += DBG_LINE_BASE + adjustedOpcode % DBG_LINE_RANGE;
setLine(addr, line);
} else {
throw new DecodeException("Unknown debug insn code: " + c);
}
break;
}
}
c = section.readByte() & 0xFF;
}
for (LocalVar var : locals) {
if (var != null && !var.isEnd()) {
var.end(mth.getCodeSize() - 1, line);
setVar(var);
}
}
setSourceLines(addr, insnByOffset.length, line);
}
use of jadx.core.dex.attributes.nodes.SourceFileAttr in project jadx by skylot.
the class ClassNode method addSourceFilenameAttr.
private void addSourceFilenameAttr(String fileName) {
if (fileName == null) {
return;
}
if (fileName.endsWith(".java")) {
fileName = fileName.substring(0, fileName.length() - 5);
}
if (fileName.isEmpty() || fileName.equals("SourceFile") || fileName.equals("\"")) {
return;
}
if (clsInfo != null) {
String name = clsInfo.getShortName();
if (fileName.equals(name)) {
return;
}
if (fileName.contains("$") && fileName.endsWith("$" + name)) {
return;
}
ClassInfo parentClass = clsInfo.getTopParentClass();
if (parentClass != null && fileName.equals(parentClass.getShortName())) {
return;
}
}
this.addAttr(new SourceFileAttr(fileName));
LOG.debug("Class '{}' compiled from '{}'", this, fileName);
}
use of jadx.core.dex.attributes.nodes.SourceFileAttr in project jadx by skylot.
the class Deobfuscator method getAliasFromSourceFile.
@Nullable
private String getAliasFromSourceFile(ClassNode cls) {
SourceFileAttr sourceFileAttr = cls.get(AType.SOURCE_FILE);
if (sourceFileAttr == null) {
return null;
}
String name = sourceFileAttr.getFileName();
if (name.endsWith(".java")) {
name = name.substring(0, name.length() - ".java".length());
}
if (NameMapper.isValidIdentifier(name) && !NameMapper.isReserved(name)) {
// TODO: check if no class with this name exists or already renamed
cls.remove(AType.SOURCE_FILE);
return name;
}
return null;
}
Aggregations