def categorize_block(d, address, size, addr_space='arm'):
    # Look at everything we can get in one round trip.
    # Returns scaled red and green values, but raw blue values;
    # they can't be calculated until the whole image is known.

    t1 = time.time()
    try:
        head = read_block(d, address, size, max_round_trips=1, addr_space=addr_space)
    except IOError, e:
        print e
        head = None
    t2 = time.time()

    if head is None:
        # Error marker
        return [0xFF, 0x00, t2-t1]

    # Red/green channels: Statistics. Red is mean,
    # green is mod-256 sum of squared differences between
    # consecutive bytes. Blue encodes the access time.
    # The amount of time it takes to read is a good
    # indicator of the bus type or cache settings!

    red = 0
    green = 0
    prev = '\x00'

    for b in head:
        signed_diff = struct.unpack('b', struct.pack('B', 0xFF & (ord(b) - ord(prev))))[0]
        red += ord(b)
        green += signed_diff * signed_diff
        prev = b

    return [
        min(0xFF, max(0, int(red / len(head)))),   # Divide by total to finish calculating the mean
        green & 0xFF,                              # Modulo diff from above
        t2 - t1                                    # Blue is in floating point seconds. We post-process below.
    ]
dataset/ETHPy150Open scanlime/coastermelt/backdoor/memsquare.py/categorize_block/original