def gen_test_ecrw(pldrw):
    debug_print('gen_test_ecrw: pldrw type =', type(pldrw))
    debug_print('len pldrw =', len(pldrw), ' = ', hex(len(pldrw)))
    cookie1_pos = pldrw.find(b'\x99\x88w\xce')
    cookie2_pos = pldrw.find(b'\xdd\xbb\xaa\xce', (cookie1_pos + 4))
    t = struct.unpack('<L', pldrw[(cookie1_pos + 36):(cookie1_pos + 40)])
    size = t[0]
    debug_print('EC_RW size =', size, ' = ', hex(size))
    debug_print('Found cookie1 at ', hex(cookie1_pos))
    debug_print('Found cookie2 at ', hex(cookie2_pos))
    if ((cookie1_pos > 0) and (cookie2_pos > cookie1_pos)):
        for i in range(0, cookie1_pos):
            pldrw[i] = 165
        for i in range((cookie2_pos + 4), len(pldrw)):
            pldrw[i] = 165
    with open('ec_RW_test.bin', 'wb') as fecrw:
        fecrw.write(pldrw[:size])
def gen_test_ecrw(pldrw):
    debug_print('gen_test_ecrw: pldrw type =', type(pldrw))
    debug_print('len pldrw =', len(pldrw), ' = ', hex(len(pldrw)))
    cookie1_pos = pldrw.find(b'\x99\x88w\xce')
    cookie2_pos = pldrw.find(b'\xdd\xbb\xaa\xce', (cookie1_pos + 4))
    t = struct.unpack('<L', pldrw[(cookie1_pos + 36):(cookie1_pos + 40)])
    size = t[0]
    debug_print('EC_RW size =', size, ' = ', hex(size))
    debug_print('Found cookie1 at ', hex(cookie1_pos))
    debug_print('Found cookie2 at ', hex(cookie2_pos))
    if ((cookie1_pos > 0) and (cookie2_pos > cookie1_pos)):
        for i in range(0, cookie1_pos):
            pldrw[i] = 165
        for i in range((cookie2_pos + 4), len(pldrw)):
            pldrw[i] = 165
    with open('ec_RW_test.bin', 'wb') as fecrw:
        fecrw.write(pldrw[:size])