示例#1
0
 def __init__(self, pointer, start, end, menu, textptr, name, target):
     self.pointer = hex2int(pointer)
     self.start = hex2int(start)
     self.end = hex2int(end)
     self.menu = hex2int(menu)
     self.textptr = hex2int(textptr)
     self.name = name.lower()
     self.target = target.lower()
     self.id = None
示例#2
0
    def __init__(self, itemid, pointer, name):
        self.itemid = hex2int(itemid)
        self.pointer = hex2int(pointer)
        self.name = name
        self.degree = None
        self.banned = False
        self.itemtype = 0

        self.price = 0
        self._rank = None
        self.dataname = bytes()
        self.heavy = False
def preprocess(df: pd.DataFrame) -> pd.DataFrame:
    df.dropna(subset=[col for col in COLS if col != "species"], inplace=True)
    df = df[df["color"].map(utils.check_hexacolor)]
    df = df[df["size"].map(lambda l: l > 0.0)]
    df = df[df["weight"].map(lambda l: l > 0.0)]
    df["monkey"] = df[COLS].apply(Monkey.monkify, axis=1)
    df["fur_color_int"] = df.color.map(lambda l: utils.hex2int(l[1:]))
    df["bmi"] = df.monkey.map(lambda l: l.compute_bmi())
    return df
 def __init__(self, pointer, name, rank, location):
     self.pointer = hex2int(pointer)
     self.name = name
     self.rank = int(rank)
     self.spells = []
     self.learnrates = []
     self.bonus = None
     self.id = None
     self.location = location
示例#5
0
    def get_value(_buf, type_value=None, length=0):
        if not type_value:
            type_value = ord(_buf.read(1))
        if isinstance(type_value, IntegerType):
            type_value = type_value.value
        if type_value < 0xF0:
            return type_value - 1

        integer_type = IntegerType(type_value)
        if integer_type == IntegerType.Byte:
            return ord(_buf.read(1))
        elif integer_type == IntegerType.ByteTimes256:
            return ord(_buf.read(1)) * 256
        elif integer_type == IntegerType.Int16:
            return hex2int(_buf.read(2), big_endian=True)
        elif integer_type == IntegerType.Int24:
            return hex2int(bytearray(b'\x00') + _buf.read(3), big_endian=True)
        elif integer_type == IntegerType.Int32:
            return hex2int(_buf.read(4), big_endian=True)
def discover():
    print "Scanning for BLE devices..."
    scan = utils.run_command("hcitool -i " + hci + " lescan",
                             timeout=scan_timeout)
    # search for MAC addresses
    devices = set(re.findall("(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)", scan))
    print "Found " + str(len(devices)) + " device(s):"
    # for each device
    for device in devices:
        print "\t- Device " + device + ":"
        # for value handles read the characteristics
        characteristics = utils.run_command("gatttool -i " + hci + " -b " +
                                            device +
                                            " -t random --characteristics")
        # filter by char properties (02 and 12 is READ)
        value_handles = re.findall(
            "char properties = 0x(12|02), char value handle = (.+), uuid =",
            characteristics)
        for value_handle in value_handles:
            # for each handle
            handle = value_handle[1]
            # read the value
            value = get_value(device, handle)
            print "\t\t - Value handle " + handle + ", value: " + str(
                value) + ", int=" + str(
                    utils.hex2int(value)) + ", string=" + str(
                        utils.hex2string(value))
        # for notification handles, find all the handles with 2902 UUID
        notifications = utils.run_command("gatttool -i " + hci + " -b " +
                                          device +
                                          " -t random --char-read -u 2902")
        notification_handles = re.findall("handle: (\S+) ", notifications)
        for notification_handle in notification_handles:
            # for each handle
            handle = notification_handle
            # get the value by enabling notifications
            value = get_notification(device, handle)
            print "\t\t - Notification handle " + handle + ", value: " + str(
                value) + ", int=" + str(
                    utils.hex2int(value)) + ", string=" + str(
                        utils.hex2string(value))
示例#7
0
 def __init__(self, address, name):
     self.address = hex2int(address)
     self.name = name.lower().capitalize()
     self.newname = self.name.upper()
     self.battle_commands = [0x00, None, None, None]
     self.id = None
     self.beserk = False
     self.original_appearance = None
     self.new_appearance = None
     self.natural_magic = None
     self.palette = None
     self.wor_location = None
def parse(sensor, data):
    if data is "": return None
    # get what data format this sensor would expect
    formatter = conf["constants"]["formats"][sensor["format"]]["formatter"]
    # format the hex data into the expected format
    if formatter == "int" or formatter == "float_1" or formatter == "float_2":
        data = utils.hex2int(data)
    elif formatter == "string":
        data = utils.hex2string(data)
    else:
        log.error("Invalid formatter: " + str(formatter))
    # apply any transformation if needed
    if "transform" in sensor["plugin"]:
        if sensor["plugin"]["transform"] == "/10": data = float(data) / 10
        if sensor["plugin"]["transform"] == "/100": data = float(data) / 100
    return data
def generate_stealth_address(publicViewKey, privateTxKey,  publicSpendKey, index):
    ## multiply r*A
    derivation = utils.generate_key_derivation(publicViewKey, privateTxKey)
    
    ## concatenate index to derivation then hash and reduce
    ## Hs(rA|i)
    scalar = utils.derivation_to_scalar(derivation, index)
    
    ## multiply by base point
    ## Hs(rA|i)G
    sG = ed25519.scalarmultbase(utils.hex2int(scalar))
    
    ## interpret the public spend key as a point on the curve
    pubPoint  = ed25519.decodepoint(unhexlify(publicSpendKey))
    
    ## add the public spend key to the previously calculated point
    ## Hs(rA|i)G + B
    output = ed25519.edwards(pubPoint, sG)

    ## convert the point to a hex encoded public key
    return hexlify(ed25519.encodepoint(output))
示例#10
0
 def __init__(self, name, pointer, itemptr, controlptr, sketchptr, rageptr,
              aiptr):
     self.name = name.strip('_')
     if not self.name:
         self.name = "?????"
     self.graphicname = self.name
     self.pointer = hex2int(pointer)
     self.itemptr = hex2int(itemptr)
     self.controlptr = hex2int(controlptr)
     self.sketchptr = hex2int(sketchptr)
     self.rageptr = hex2int(rageptr)
     self.aiptr = hex2int(aiptr)
     self.stats = {}
     self.moulds = set([])
     self.width, self.height = None, None
     self.miny, self.maxy = None, None
示例#11
0
 def __init__(self, name, pointer, itemptr, controlptr,
              sketchptr, rageptr, aiptr):
     self.name = name.strip('_')
     if not self.name:
         self.name = "?????"
     self.graphicname = self.name
     self.pointer = hex2int(pointer)
     self.itemptr = hex2int(itemptr)
     self.controlptr = hex2int(controlptr)
     self.sketchptr = hex2int(sketchptr)
     self.rageptr = hex2int(rageptr)
     self.aiptr = hex2int(aiptr)
     self.stats = {}
     self.moulds = set([])
     self.width, self.height = None, None
     self.miny, self.maxy = None, None
示例#12
0
from utils import (hex2int, int2bytes, Substitution, SPELL_TABLE,
                   SPELLBANS_TABLE, name_to_bytes, utilrandom as random)

spelldict = {}
spellnames = {}
f = open(SPELL_TABLE)
for line in f:
    line = line.strip()
    while '  ' in line:
        line = line.replace('  ', ' ')
    value, strength, name = tuple(line.split(','))
    spellnames[hex2int(value)] = name
f.close()

spellbans = {}
f = open(SPELLBANS_TABLE)
for line in f:
    line = line.strip()
    if line[0] == '#':
        continue
    spellid, modifier, name, ban = tuple(line.split(','))
    if ban == "ban":
        modifier = int(modifier) * -1
    spellbans[hex2int(spellid)] = int(modifier)
f.close()


class SpellBlock:
    def __init__(self, spellid, filename):
        self.spellid = spellid
        if self.spellid in spellbans and spellbans[self.spellid] < 0:
示例#13
0
def manage_palettes(fout, change_to, char_ids):
    sabin_mode = options_.is_code_active('suplexwrecks')
    tina_mode = options_.is_code_active('bravenudeworld')
    christmas_mode = options_.is_code_active('christmas')
    new_palette_mode = not options_.is_code_active('sometimeszombies')

    characters = get_characters()
    npcs = get_npcs()
    charpal_options = {}
    for line in open(CHARACTER_PALETTE_TABLE):
        if line[0] == '#':
            continue
        charid, palettes = tuple(line.strip().split(':'))
        palettes = list(map(hex2int, palettes.split(',')))
        charid = hex2int(charid)
        charpal_options[charid] = palettes

    if new_palette_mode:
        twinpal = random.randint(0, 5)
        char_palette_pool = list(range(0, 6)) + list(range(0, 6))
        char_palette_pool.remove(twinpal)
        char_palette_pool.append(
            random.choice(list(range(0, twinpal)) + list(range(twinpal, 6))))
        while True:
            random.shuffle(char_palette_pool)
            #make sure terra, locke, and edgar are all different
            if twinpal in char_palette_pool[0:2]:
                continue
            if char_palette_pool[0] == char_palette_pool[1]:
                continue
            break
        char_palette_pool = char_palette_pool[:4] + [twinpal, twinpal
                                                     ] + char_palette_pool[4:]

    palette_change_to = {}
    additional_celeses = []
    for npc in npcs:
        if npc.graphics == 0x41:
            additional_celeses.append(npc)
        if npc.graphics not in charpal_options:
            continue
        # Don't recolor shadowy Sabin on Mt. Kolts
        if npc.locid in [0x60, 0x61]:
            continue
        if npc.graphics in change_to:
            new_graphics = change_to[npc.graphics]
            if (npc.graphics, npc.palette) in palette_change_to:
                new_palette = palette_change_to[(npc.graphics, npc.palette)]
            elif new_palette_mode and npc.graphics < 14:
                new_palette = char_palette_pool[npc.graphics]
                palette_change_to[(npc.graphics, npc.palette)] = new_palette
                npc.palette = new_palette
            else:
                while True:
                    new_palette = random.choice(charpal_options[new_graphics])
                    if sabin_mode or tina_mode:
                        new_palette = random.randint(0, 5)

                    if (new_palette == 5 and new_graphics
                            not in [3, 0xA, 0xC, 0xD, 0xE, 0xF, 0x12, 0x14]
                            and random.randint(1, 10) != 10):
                        continue
                    break
                palette_change_to[(npc.graphics, npc.palette)] = new_palette
                npc.palette = new_palette
            npc.palette = new_palette
    for npc in additional_celeses:
        if (6, 0) in palette_change_to:
            npc.palette = palette_change_to[(6, 0)]

    main_palette_changes = {}
    for character in characters:
        c = character.id
        if c not in change_to:
            continue
        fout.seek(0x2CE2B + c)
        before = ord(fout.read(1))
        new_graphics = change_to[c]
        new_palette = palette_change_to[(c, before)]
        main_palette_changes[c] = (before, new_palette)
        fout.seek(0x2CE2B + c)
        fout.write(bytes([new_palette]))
        pointers = [0, 4, 9, 13]
        pointers = [ptr + 0x18EA60 + (18 * c) for ptr in pointers]
        if c < 14:
            for ptr in pointers:
                fout.seek(ptr)
                byte = ord(fout.read(1))
                byte = byte & 0xF1
                byte |= ((new_palette + 2) << 1)
                fout.seek(ptr)
                fout.write(bytes([byte]))
        character.palette = new_palette

    if options_.is_code_active('repairpalette'):
        make_palette_repair(fout, main_palette_changes)

    if new_palette_mode:
        char_hues = [
            0, 10, 20, 30, 45, 60, 75, 90, 120, 150, 180, 200, 220, 240, 270,
            300, 330
        ]
        char_hues.append(random.choice([0, 0, 345, random.randint(105, 135)]))
        char_hues = shuffle_char_hues(char_hues)
        skintones = [((31, 24, 17), (25, 13, 7)), ((31, 23, 15), (25, 15, 8)),
                     ((31, 24, 17), (25, 13, 7)), ((31, 25, 15), (25, 19, 10)),
                     ((31, 25, 16), (24, 15, 12)),
                     ((27, 17, 10), (20, 12, 10)), ((25, 20, 14), (19, 12, 4)),
                     ((27, 22, 18), (20, 15, 12)), ((28, 22, 16), (22, 13, 6)),
                     ((28, 23, 15), (22, 16, 7)), ((27, 23, 15), (20, 14, 9))]
        snowmanvampire = ((29, 29, 30), (25, 25, 27))
        if christmas_mode or random.randint(1, 100) > 66:
            skintones.append(snowmanvampire)
        random.shuffle(skintones)
        # no vampire townsfolk
        if snowmanvampire in skintones[:6] and not christmas_mode:
            skintones.remove(snowmanvampire)
            skintones = skintones[:5] + [snowmanvampire]

    for i in range(6):
        pointer = 0x268000 + (i * 0x20)
        if new_palette_mode:
            palette = recolor_character_palette(fout,
                                                pointer,
                                                palette=None,
                                                flesh=(i == 5),
                                                santa=(christmas_mode
                                                       and i == 3),
                                                skintones=skintones,
                                                char_hues=char_hues)
        else:
            palette = recolor_character_palette(fout,
                                                pointer,
                                                palette=None,
                                                flesh=(i == 5),
                                                santa=(christmas_mode
                                                       and i == 3))
        pointer = 0x2D6300 + (i * 0x20)
        recolor_character_palette(fout, pointer, palette=palette)

    # esper terra
    pointer = 0x268000 + (8 * 0x20)
    if new_palette_mode:
        palette = recolor_character_palette(fout,
                                            pointer,
                                            palette=None,
                                            trance=True)
    else:
        palette = recolor_character_palette(fout,
                                            pointer,
                                            palette=None,
                                            flesh=True,
                                            middle=False)
    pointer = 0x2D6300 + (6 * 0x20)
    palette = recolor_character_palette(fout, pointer, palette=palette)

    # recolor magitek and chocobos
    transformer = get_palette_transformer(middle=True)

    def recolor_palette(pointer, size):
        fout.seek(pointer)
        palette = [read_multi(fout, length=2) for _ in range(size)]
        palette = transformer(palette)
        fout.seek(pointer)
        for c in palette:
            write_multi(fout, c, length=2)

    recolor_palette(0x2cfd4, 23)
    recolor_palette(0x268000 + (7 * 0x20), 16)
    recolor_palette(0x12ee20, 16)
    recolor_palette(0x12ef20, 16)

    for line in open(EVENT_PALETTE_TABLE):
        if line[0] == '#':
            continue
        line = line.split(' ')
        if len(line) > 1:
            if line[1] == 'c' and options_.is_code_active(
                    'thescenarionottaken'):
                return
            if line[1] == 'd' and not options_.is_code_active(
                    'thescenarionottaken'):
                return
        pointer = hex2int(line[0].strip())
        fout.seek(pointer)
        data = bytearray(fout.read(5))
        char_id, palette = data[1], data[4]
        if char_id not in char_ids:
            continue
        try:
            data[4] = palette_change_to[(char_id, palette)]
        except KeyError:
            continue

        fout.seek(pointer)
        fout.write(data)
示例#14
0
 def __init__(self, itemid, pointer, name):
     self.itemid = hex2int(itemid)
     self.pointer = hex2int(pointer)
     self.name = name
     self.degree = None
     self.banned = False
示例#15
0
 def __init__(self, pointer, name, rank):
     self.pointer = hex2int(pointer)
     self.name = name
     self.rank = int(rank)
示例#16
0
 def __init__(self, itemid, pointer, name):
     self.itemid = hex2int(itemid)
     self.pointer = hex2int(pointer)
     self.name = name
     self.degree = None
     self.banned = False
示例#17
0
def deploy(path_to_vk):
    miximus_interface , verifier_interface  = compile()
    with open(path_to_vk) as json_data:
        vk = json.load(json_data)
    vk  = [
        hex2int(vk["a"][0]),
        hex2int(vk["a"][1]),
        hex2int(vk["b"]),
        hex2int(vk["c"][0]),
        hex2int(vk["c"][1]),
        hex2int(vk["g"][0]),
        hex2int(vk["g"][1]),
        hex2int(vk["gb1"]),
        hex2int(vk["gb2"][0]),
        hex2int(vk["gb2"][1]),
        hex2int(vk["z"][0]),
        hex2int(vk["z"][1]),
        hex2int(sum(vk["IC"], []))
    ]

    # Instantiate and deploy contract
    miximus = w3.eth.contract(abi=miximus_interface['abi'], bytecode=miximus_interface['bin'])
    verifier = w3.eth.contract(abi=verifier_interface['abi'], bytecode=verifier_interface['bin'])

    # Get transaction hash from deployed Verifier contract
    tx_hash = verifier.deploy(transaction={'from': w3.eth.accounts[0], 'gas': 4000000}, args=vk)

    # Get tx receipt to get Verifier contract address
    tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash, 10000)
    verifier_address = tx_receipt['contractAddress']
    print("[INFO] Verifier address: ", verifier_address)

    # Deploy the Miximus contract once the Verifier is successfully deployed
    tx_hash = miximus.deploy(transaction={'from': w3.eth.accounts[0], 'gas': 4000000}, args=[verifier_address])

    # Get tx receipt to get Miximus contract address
    tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash, 10000)
    miximus_address = tx_receipt['contractAddress']
    print("[INFO] Miximus address: ", miximus_address)

    # Contract instance in concise mode
    abi = miximus_interface['abi']
    miximus = w3.eth.contract(address=miximus_address, abi=abi, ContractFactoryClass=ConciseContract)

    return(miximus)
示例#18
0
 def __init__(self, pointer, name, rank):
     self.pointer = hex2int(pointer)
     self.name = name
     self.rank = int(rank)