fix of by one in static values generation

This commit is contained in:
Jean-Marie Mineau 2024-02-07 10:35:38 +01:00
parent fcfe2dc6e9
commit e0f348aecc
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
2 changed files with 19 additions and 7 deletions

View file

@ -1662,13 +1662,13 @@ impl DexWriter {
let mut static_fields: Vec<IdField> = class.static_fields.keys().cloned().collect(); let mut static_fields: Vec<IdField> = class.static_fields.keys().cloned().collect();
static_fields.sort(); static_fields.sort();
let mut array = vec![]; let mut array = vec![];
let mut last_defined_field_idx = 0; let mut last_defined_field_index = 0;
for (idx, f) in static_fields.iter().enumerate() { for (idx, f) in static_fields.iter().enumerate() {
if class.static_fields.get(f).unwrap().value.is_some() { if class.static_fields.get(f).unwrap().value.is_some() {
last_defined_field_idx = idx; last_defined_field_index = idx;
} }
} }
for f in &static_fields[..last_defined_field_idx] { for f in &static_fields[..=last_defined_field_index] {
let field = class.static_fields.get(f).unwrap(); let field = class.static_fields.get(f).unwrap();
if let Some(val) = field.value.as_ref() { if let Some(val) = field.value.as_ref() {
array.push(val.clone()); array.push(val.clone());

20
test.py
View file

@ -67,12 +67,13 @@ classes = list(
IdType("Lcom/example/testapplication/ui/home/HomeViewModel;"), IdType("Lcom/example/testapplication/ui/home/HomeViewModel;"),
IdType("Landroidx/navigation/NavDeepLink$Builder;"), IdType("Landroidx/navigation/NavDeepLink$Builder;"),
IdType("Landroidx/constraintlayout/core/widgets/ConstraintWidget$1;"), IdType("Landroidx/constraintlayout/core/widgets/ConstraintWidget$1;"),
IdType("Landroidx/appcompat/app/ActionBar;"),
], ],
apk.classes.keys(), apk.classes.keys(),
) )
) )
for cls in classes: # for cls in classes:
apk.remove_class(cls) # apk.remove_class(cls)
print("[+] Recompile") print("[+] Recompile")
@ -94,9 +95,13 @@ for dex in dex_raw:
# apksigner=Path.home() / "Android" / "Sdk" / "build-tools" / "34.0.0" / "apksigner", # apksigner=Path.home() / "Android" / "Sdk" / "build-tools" / "34.0.0" / "apksigner",
# ) # )
last_id = None
MAX_REQ = 1
def cmp(a, b, req=0): def cmp(a, b, req=0):
if req > 6: if req > MAX_REQ:
return return
if type(a) == dict: if type(a) == dict:
cmp_dict(a, b, req) cmp_dict(a, b, req)
@ -116,10 +121,15 @@ def nice_bool(b) -> str:
def cmp_other(a, b, req=0): def cmp_other(a, b, req=0):
ident = " " * req ident = " " * req
for f in dir(a): for f in dir(a):
if getattr(getattr(a, f), "__call__", None) is None: if getattr(getattr(a, f), "__call__", None) is None and (
len(f) < 2 or f[:2] != "__"
):
eq = getattr(a, f) == getattr(b, f) eq = getattr(a, f) == getattr(b, f)
print(f"{f'{ident}{f}: ':<150}{nice_bool(eq)}") print(f"{f'{ident}{f}: ':<150}{nice_bool(eq)}")
if not eq: if not eq:
if "descriptor" in dir(a):
global last_id
last_id = a.descriptor
cmp(getattr(a, f), getattr(b, f), req + 1) cmp(getattr(a, f), getattr(b, f), req + 1)
@ -133,6 +143,8 @@ def cmp_dict(a, b, req=0):
eq = a[key] == b[key] eq = a[key] == b[key]
print(f"{f'{ident}{str(key)}: ':<150}{nice_bool(eq)}") print(f"{f'{ident}{str(key)}: ':<150}{nice_bool(eq)}")
if not eq: if not eq:
global last_id
last_id = a.descriptor
cmp(a[key], b[key], req + 1) cmp(a[key], b[key], req + 1)