<commit_before>#!/usr/bin/python3

import sys, os

# we're in directory 'tools/' we have to update sys.path
sys.path.append(os.path.dirname(sys.path[0]))

from rom.ips import IPS_Patch
from rom.rom import RealROM

vanilla=sys.argv[1]
ipsToReverse = sys.argv[2:]

rom = RealROM(vanilla)

for ips in ipsToReverse:
    ipsPath = os.path.abspath(ips)
    destDir, destFile = os.path.split(ipsPath)
    destFile = "remove_" + destFile
    destPath = os.path.join(destDir, destFile)
    patch = IPS_Patch.load(ips)
    patchDict = patch.toDict()
    reversePatchDict = {}
    for addr, bytez in patchDict.items():
        sz = len(bytez)
        origBytes = []
        rom.seek(addr)
        for i in range(sz):
            origBytes.append(rom.readByte())
        assert len(origBytes) == sz
        reversePatchDict[addr] = origBytes
    reversePatch = IPS_Patch(reversePatchDict)<commit_msg>tools: added dict patches to reverse ips<commit_after>#!/usr/bin/python3

import sys, os

# we're in directory 'tools/' we have to update sys.path
sys.path.append(os.path.dirname(sys.path[0]))

from rom.ips import IPS_Patch
from rom.rom import RealROM
from patches.common import patches as common_patches

vanilla=sys.argv[1]
ipsToReverse = sys.argv[2:]

rom = RealROM(vanilla)

for ips in ipsToReverse:
    if ips not in common_patches.patches:
        ipsPath = os.path.abspath(ips)
        destDir, destFile = os.path.split(ipsPath)
        patch = IPS_Patch.load(ips)
        patchDict = patch.toDict()
    else:
        patchDict = common_patches.patches[ips]
        destDir = sys.path[0] + "/../patches/common/ips"
        destFile = ips + ".ips"
    destFile = "remove_" + destFile
    destPath = os.path.join(destDir, destFile)
    reversePatchDict = {}
    for addr, bytez in patchDict.items():
        sz = len(bytez)
        origBytes = []
        rom.seek(addr)
        for i in range(sz):
            origBytes.append(rom.readByte())
        assert len(origBytes) == sz
        reversePatchDict[addr] = origBytes
    reversePatch = IPS_Patch(reversePatchDict)
{'fraction_non_alphanumeric': 0.11596312469674915, 'fraction_numerical': 0.004366812227074236, 'mean_word_length': 2.988394584139265, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6137739', 'n_tokens_mistral': 707, 'n_tokens_neox': 686, 'n_words': 161}