threadtear icon indicating copy to clipboard operation
threadtear copied to clipboard

Boolean value is inverted when casting

Open foaw opened this issue 2 years ago • 0 comments

In Casts#castWithPrimitives(...) there seems to be a typo. When converting Number values with boolean.class as the type, it returns true when the given value is 0, and false when the value is 1.

https://github.com/GraxCode/threadtear/blob/f0a13d5d515f769db33cd408cb65944b027d9ef0/core/src/main/java/me/nov/threadtear/util/reflection/Casts.java#L17-L25

As of Java 16, Java Virtual Machine Specification says:

The Java Virtual Machine encodes boolean array components using 1 to represent true and 0 to represent false. Where Java programming language boolean values are mapped by compilers to values of Java Virtual Machine type int, the compilers must use the same encoding.

Below I am attaching a list of all calls to this method:

  • when converting values on stack in BasicReferenceHandler; https://github.com/GraxCode/threadtear/blob/f0a13d5d515f769db33cd408cb65944b027d9ef0/core/src/main/java/me/nov/threadtear/analysis/stack/BasicReferenceHandler.java#L65

  • when building ConstantValue; https://github.com/GraxCode/threadtear/blob/f0a13d5d515f769db33cd408cb65944b027d9ef0/core/src/main/java/me/nov/threadtear/analysis/stack/ConstantValue.java#L18

  • when updating proxy field values in StringObfuscationStringer https://github.com/GraxCode/threadtear/blob/f0a13d5d515f769db33cd408cb65944b027d9ef0/core/src/main/java/me/nov/threadtear/execution/stringer/StringObfuscationStringer.java#L162

Not much to fix, but I could send a PR if you want.

foaw avatar Sep 10 '21 09:09 foaw