use of jadx.core.dex.info.FieldInfo in project jadx by skylot.
the class FieldNode method build.
public static FieldNode build(ClassNode cls, IFieldData fieldData) {
FieldInfo fieldInfo = FieldInfo.fromRef(cls.root(), fieldData);
FieldNode fieldNode = new FieldNode(cls, fieldInfo, fieldData.getAccessFlags());
fieldNode.addAttrs(fieldData.getAttributes());
return fieldNode;
}
use of jadx.core.dex.info.FieldInfo in project jadx by skylot.
the class Deobfuscator method getFieldAlias.
@Nullable
private String getFieldAlias(FieldNode field) {
FieldInfo fieldInfo = field.getFieldInfo();
String alias = fldMap.get(fieldInfo);
if (alias != null) {
return alias;
}
alias = deobfPresets.getForFld(fieldInfo);
if (alias != null) {
fldMap.put(fieldInfo, alias);
return alias;
}
if (shouldRename(field.getName())) {
return makeFieldAlias(field);
}
return null;
}
use of jadx.core.dex.info.FieldInfo in project jadx by skylot.
the class Deobfuscator method renameField.
private void renameField(FieldNode field) {
FieldInfo fieldInfo = field.getFieldInfo();
String alias = getFieldAlias(field);
if (alias != null) {
fieldInfo.setAlias(alias);
}
}
use of jadx.core.dex.info.FieldInfo in project jadx by skylot.
the class AndroidResourcesUtils method addResourceFields.
private static void addResourceFields(ClassNode resCls, ResourceStorage resStorage, boolean rClsExists) {
Map<Integer, FieldNode> resFieldsMap = fillResFieldsMap(resCls);
Map<String, ResClsInfo> innerClsMap = new TreeMap<>();
if (rClsExists) {
for (ClassNode innerClass : resCls.getInnerClasses()) {
ResClsInfo innerResCls = new ResClsInfo(innerClass);
innerClass.getFields().forEach(field -> innerResCls.getFieldsMap().put(field.getName(), field));
innerClsMap.put(innerClass.getShortName(), innerResCls);
}
}
for (ResourceEntry resource : resStorage.getResources()) {
String resTypeName = resource.getTypeName();
String resName = resTypeName.equals("style") ? resource.getKeyName().replace('.', '_') : resource.getKeyName();
ResClsInfo typeClsInfo = innerClsMap.computeIfAbsent(resTypeName, name -> getClassForResType(resCls, rClsExists, name));
typeClsInfo.getFieldsMap().computeIfAbsent(resName, name -> {
ClassNode typeCls = typeClsInfo.getTypeCls();
FieldInfo rFieldInfo = FieldInfo.from(typeCls.root(), typeCls.getClassInfo(), resName, ArgType.INT);
FieldNode newResField = new FieldNode(typeCls, rFieldInfo, AccessFlags.PUBLIC | AccessFlags.STATIC | AccessFlags.FINAL);
newResField.addAttr(new EncodedValue(EncodedType.ENCODED_INT, resource.getId()));
typeCls.getFields().add(newResField);
if (rClsExists) {
newResField.addInfoComment("Added by JADX");
}
return newResField;
});
FieldNode fieldNode = resFieldsMap.get(resource.getId());
if (fieldNode != null && !fieldNode.getName().equals(resName) && NameMapper.isValidAndPrintable(resName) && resCls.root().getArgs().isRenameValid()) {
fieldNode.add(AFlag.DONT_RENAME);
fieldNode.getFieldInfo().setAlias(resName);
}
}
}
use of jadx.core.dex.info.FieldInfo in project jadx by skylot.
the class InsnUtils method getConstValueByInsn.
/**
* Return constant value from insn or null if not constant.
*
* @return LiteralArg, String, ArgType or null
*/
@Nullable
public static Object getConstValueByInsn(RootNode root, InsnNode insn) {
switch(insn.getType()) {
case CONST:
return insn.getArg(0);
case CONST_STR:
return ((ConstStringNode) insn).getString();
case CONST_CLASS:
return ((ConstClassNode) insn).getClsType();
case SGET:
FieldInfo f = (FieldInfo) ((IndexInsnNode) insn).getIndex();
FieldNode fieldNode = root.resolveField(f);
if (fieldNode == null) {
LOG.warn("Field {} not found", f);
return null;
}
EncodedValue constVal = fieldNode.get(JadxAttrType.CONSTANT_VALUE);
if (constVal != null) {
return EncodedValueUtils.convertToConstValue(constVal);
}
return null;
default:
return null;
}
}
Aggregations