Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline method refactoring changes variables names after applying the transformation #759

Open
jonhnanthan opened this issue Feb 26, 2024 · 0 comments
Labels
bug Unexpected or incorrect user-visible behavior inline-refactor

Comments

@jonhnanthan
Copy link

jonhnanthan commented Feb 26, 2024

Inline method refactoring changes field signatures and generates uninitialized variables

Steps to reproduce the behavior:

  1. Code before refactoring:
def _calculate_tk(source):
    def RL(a, b):
        for c in range(0, len(b) - 2, 3):
            xa = a & ((1 << 32) - 1)
            d = ord(b[c + 2]) - 87 if b[c + 2] >= 'a' else int(b[c + 2])
            d = xa >> d if b[c + 1] == '+' else xa << d
            a = a + d & 4294967295 if b[c] == '+' else a ^ d
        return (a & ((1 << (32 - 1)) - 1)) - (a & (1 << (32 - 1)))

    b = 406398
    d = source.encode('utf-8')
    a = b

    for di in d:
        a = RL(a + di, "+-a^+6")

    a = RL(a, "+-3^+b+-f")
    
    return '{0:d}.{1:d}'.format(a, a ^ b)
  1. Apply the Inline Method refactoring to '_calculate_tk.RL'

  2. Expected code after refactoring:

def _calculate_tk(source):
    b = 406398
    d = source.encode('utf-8')
    a = b

    for di in d:
        for c in range(0, len("+-a^+6") - 2, 3):
            xa = a + di & ((1 << 32) - 1)
            d = ord("+-a^+6"[c + 2]) - 87 if "+-a^+6"[c + 2] >= 'a' else int("+-a^+6"[c + 2])
            d = xa >> d if "+-a^+6"[c + 1] == '+' else xa << d
            a = a + di + d & 4294967295 if "+-a^+6"[c] == '+' else a + di ^ d
        a = (a + di & ((1 << (32 - 1)) - 1)) - (a + di & (1 << (32 - 1)))

    for c in range(0, len("+-3^+b+-f") - 2, 3):
        xa = a & ((1 << 32) - 1)
        d = ord("+-3^+b+-f"[c + 2]) - 87 if "+-3^+b+-f"[c + 2] >= 'a' else int("+-3^+b+-f"[c + 2])
        d = xa >> d if "+-3^+b+-f"[c + 1] == '+' else xa << d
        a = a + d & 4294967295 if "+-3^+b+-f"[c] == '+' else a ^ d
    a = (a & ((1 << (32 - 1)) - 1)) - (a & (1 << (32 - 1)))

    return '{0:d}.{1:d}'.format(a, a ^ b)
  1. The result of the program after applied transformation:
def _calculate_tk(source):
    b = 406398
    d = source.encode('utf-8')
    a = b

    for di in d:
        for __0__c in range(0, len("+-a^+6") - 2, 3):
            __0__xa = __0__a + di & ((1 << 32) - 1)
            __0__d = ord("+-a^+6"[__0__c + 2]) - 87 if "+-a^+6"[__0__c + 2] >= 'a' else int("+-a^+6"[__0__c + 2])
            __0__d = __0__xa >> __0__d if "+-a^+6"[__0__c + 1] == '+' else __0__xa << __0__d
            __0__a = __0__a + di + __0__d & 4294967295 if "+-a^+6"[__0__c] == '+' else __0__a + di ^ __0__d
        a = (__0__a + di & ((1 << (32 - 1)) - 1)) - (__0__a + di & (1 << (32 - 1)))

    for __1__c in range(0, len("+-3^+b+-f") - 2, 3):
        __1__xa = __1__a & ((1 << 32) - 1)
        __1__d = ord("+-3^+b+-f"[__1__c + 2]) - 87 if "+-3^+b+-f"[__1__c + 2] >= 'a' else int("+-3^+b+-f"[__1__c + 2])
        __1__d = __1__xa >> __1__d if "+-3^+b+-f"[__1__c + 1] == '+' else __1__xa << __1__d
        __1__a = __1__a + __1__d & 4294967295 if "+-3^+b+-f"[__1__c] == '+' else __1__a ^ __1__d
    a = (__1__a & ((1 << (32 - 1)) - 1)) - (__1__a & (1 << (32 - 1)))
    
    return '{0:d}.{1:d}'.format(a, a ^ b)
@jonhnanthan jonhnanthan added the bug Unexpected or incorrect user-visible behavior label Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected or incorrect user-visible behavior inline-refactor
Projects
None yet
Development

No branches or pull requests

2 participants