mirror of
https://github.com/isledecomp/isle.git
synced 2026-01-23 16:21:15 +00:00
Match uninit variables with all nulls
This commit is contained in:
parent
6e39e87613
commit
7f37098305
@ -188,24 +188,33 @@ def do_the_comparison(args: argparse.Namespace) -> Iterable[ComparisonItem]:
|
|||||||
orig_raw = origfile.read(var.orig_addr, data_size)
|
orig_raw = origfile.read(var.orig_addr, data_size)
|
||||||
recomp_raw = recompfile.read(var.recomp_addr, data_size)
|
recomp_raw = recompfile.read(var.recomp_addr, data_size)
|
||||||
|
|
||||||
# If either read exceeded the raw data size for the section,
|
# The IMAGE_SECTION_HEADER defines the SizeOfRawData and VirtualSize for the section.
|
||||||
# assume the entire variable is uninitialized.
|
# If VirtualSize > SizeOfRawData, the section is comprised of the initialized data
|
||||||
# TODO: This is not correct, strictly speaking. However,
|
# corresponding to bytes in the file, and the rest is padded with zeroes when
|
||||||
# it is probably impossible for a variable to exceed
|
# Windows loads the image.
|
||||||
# the virtual size of the section, so all that is left is
|
# The linker might place variables initialized to zero on the threshold between
|
||||||
# the uninitialized data.
|
# physical data and the virtual (uninitialized) data.
|
||||||
# If the variable falls at the end of the section like this,
|
# If this happens (i.e. we get an incomplete read) we just do the same padding
|
||||||
# it is highly likely to be uninitialized.
|
# to prepare for the comparison.
|
||||||
if orig_raw is not None and len(orig_raw) < data_size:
|
if orig_raw is not None and len(orig_raw) < data_size:
|
||||||
orig_raw = None
|
orig_raw = orig_raw.ljust(data_size, b"\x00")
|
||||||
|
|
||||||
if recomp_raw is not None and len(recomp_raw) < data_size:
|
if recomp_raw is not None and len(recomp_raw) < data_size:
|
||||||
recomp_raw = None
|
recomp_raw = recomp_raw.ljust(data_size, b"\x00")
|
||||||
|
|
||||||
# If both variables are uninitialized, we consider them equal.
|
# If one or both variables are entirely uninitialized
|
||||||
# Otherwise, this is a diff but there is nothing to compare.
|
|
||||||
if orig_raw is None or recomp_raw is None:
|
if orig_raw is None or recomp_raw is None:
|
||||||
|
# If both variables are uninitialized, we consider them equal.
|
||||||
match = orig_raw is None and recomp_raw is None
|
match = orig_raw is None and recomp_raw is None
|
||||||
|
|
||||||
|
# We can match a variable initialized to all zeroes with
|
||||||
|
# an uninitialized variable, but this may or may not actually
|
||||||
|
# be correct, so we flag it for the user.
|
||||||
|
uninit_force_match = not match and (
|
||||||
|
(orig_raw is None and all(b == 0 for b in recomp_raw))
|
||||||
|
or (recomp_raw is None and all(b == 0 for b in orig_raw))
|
||||||
|
)
|
||||||
|
|
||||||
orig_value = "(uninitialized)" if orig_raw is None else "(initialized)"
|
orig_value = "(uninitialized)" if orig_raw is None else "(initialized)"
|
||||||
recomp_value = (
|
recomp_value = (
|
||||||
"(uninitialized)" if recomp_raw is None else "(initialized)"
|
"(uninitialized)" if recomp_raw is None else "(initialized)"
|
||||||
@ -220,6 +229,7 @@ def do_the_comparison(args: argparse.Namespace) -> Iterable[ComparisonItem]:
|
|||||||
values=(orig_value, recomp_value),
|
values=(orig_value, recomp_value),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
raw_only=uninit_force_match,
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user