Exemplo n.º 1
0
def c_send_frame(channel_handle, frames_list):
    global _zlg_dll

    devtype, devidx, channel_number, _, _, _, _, _ = handle.get(channel_handle)
    count = 0
    for frame in frames_list:
        o = _VCI_CAN_OBJ()
        o.ID = frame.id
        o.SendType = 0
        o.RemoteFlag = 0
        o.ExternFlag = 0
        o.DataLen = len(frame.data)

        if len(frame.data) < 8:
            frame.data.extend([0] * (8-len(frame.data)))
        elif len(frame.data) > 8:
            frame.data = frame.data[:8]
        else:
            pass
        o.Data = tuple(frame.data)
        status = _zlg_dll.VCI_Transmit(devtype, devidx, channel_number, pointer(o), 1)
        if status == 1:
            count += 1

    return count
Exemplo n.º 2
0
def qualified_bug(id):  # 获取满足关键字条件的漏洞标号
    url = "http://www.wooyun.org/bugs/" + id
    page = get(url)
    print(url)
    re_key = re.compile(deal_keyword())
    flag = re.search(re_key, page)
    return flag, page
Exemplo n.º 3
0
def is_device_online(device_handle):
    global _zlg_dll

    devtype, devidx = handle.get(device_handle)
    info = _VCI_BOARD_INFO()
    status = _zlg_dll.VCI_ReadBoardInfo(devtype, devidx, pointer(info))

    return True if status == 1 else False
Exemplo n.º 4
0
def get_supported_bps_list_by_handle(device_handle):
    """
    根据设备句柄获取支持的波特率列表
    :param device_handle: 设备句柄,通过c_open_device返回
    :return: string list
    """
    devtype, devidx = handle.get(device_handle)
    driver = get_usbcan_driver_by_type(devtype)
    return driver.bps_map.keys()
Exemplo n.º 5
0
def get_bps_config_data_by_handle(device_handle, bps):
    """
    根据设备句柄获取指定波特率的配置字
    :param device_handle: 设备句柄,通过c_open_device返回
    :param bps: 波特率值字符串
    :return: config value.
    """
    devtype, devidx = handle.get(device_handle)
    driver = get_usbcan_driver_by_type(devtype)
    return driver.bps_map[bps]
Exemplo n.º 6
0
def c_get_frame(channel_handle, count, wait_ms):
    global _zlg_dll

    devtype, devidx, channel_number, _, _, _, _, _ = handle.get(channel_handle)

    CAN_OBJ_ARRY_TYPE = _VCI_CAN_OBJ * count
    buffer_list = CAN_OBJ_ARRY_TYPE()

    read_count = _zlg_dll.VCI_Receive(devtype, devidx, channel_number, pointer(buffer_list), count, wait_ms)
    if read_count in (0xffffffff, -1, 0):
        return list()

    return [can.CANFrame(id=obj.ID, tsp=obj.TimeStamp, data=obj.Data, size=obj.DataLen) for obj in buffer_list]
Exemplo n.º 7
0
def main():
    print("loudonghezi")
    m_keyword = matching_keywords()
    for n in get_url():
        n_page = get(n)
        soup = bs(n_page, "html.parser")
        text = soup.find_all(text=re.compile(m_keyword), limit=1)
        if text:
            keyword_back = re.search(m_keyword, text[0])
            title = soup.h3.string
            time = soup.find('span', class_='time').string[0:10]
            vul_name = title  # 漏洞名称
            vul_id = n[28:46]  # 漏洞编号
            vul_time = time  # 漏洞发布时间
            vul_keyword = keyword_back.group(0)  # 关键字
            loudonghezi_insert(vul_name, vul_id, vul_time, vul_keyword)
Exemplo n.º 8
0
def get_qid(last_data):  # 抓取每页的ID并与上次任务对比
    li = []
    for n in range(1, 10):
        url = 'https://www.vulbox.com/board/internet/page/%d' % n
        n_page = get(url)
        soup = bs(n_page, "html.parser")
        items = soup.find_all(href=re.compile('^/bugs/'),
                              class_='btn btn-default btn-check')
        for item in items:
            t = str(item)[49:67]
            li.append(t)
            loudonghezi_last_update(li[0])
            if t == last_data:
                if last_data == str(items[0].find('a', class_=''))[23:39]:
                    sys.exit()
                return li
    return li
Exemplo n.º 9
0
def c_open_channel(device_handle, channel_number, bps, work_mode, acc_code, acc_mask):
    global _zlg_dll
    global _bps_table

    devtype, devidx = handle.get(device_handle)
    # 避免重复打开设备
    token = ChannelToken(devtype, devidx, channel_number, bps, work_mode, device_handle, acc_code, acc_mask)
    exsits_handle = handle.find(token)
    if exsits_handle is not None:
        return exsits_handle

    ic = _VCI_INIT_CONFIG()

    ic.Mode = work_mode
    #ic.AccCode, ic.AccMask = acc_code, acc_mask
    #ic.Filter = 0
    #ic.Timing0, ic.Timing1 = _bps_table[bps]

    bps_config_data = get_bps_config_data_by_handle(device_handle, bps)
    # VCI_SetReference 必须在VCI_InitCAN之前调用
    status = _zlg_dll.VCI_SetReference(devtype, devidx, channel_number, 0, pointer(bps_config_data))
    if status != 1:
        print("set bps to", bps, "failed!")
        return 0
    else:
        print("set bps to", bps, "successed!")

    status = _zlg_dll.VCI_InitCAN(devtype, devidx, channel_number, pointer(ic))
    if status != 1:
        print("configure failed, dev, dev-idx, channel-idx", devtype, devidx, acc_mask)
        return 0

    status = _zlg_dll.VCI_StartCAN(devtype, devidx, channel_number)
    if status != 1:
        print("start channel", channel_number, "failed!")
        return 0
    else:
        print("start channel", channel_number, "successed!")

    # 打开通道后先清空缓冲区
    _zlg_dll.VCI_ClearBuffer(devtype, devidx, channel_number)

    return handle.new(token)
Exemplo n.º 10
0
def get_bug_ids():      # 获取所有漏洞标号
    base_url = "http://www.wooyun.org/bugs/page/"
    bug_id_list = []
    last_id = wooyun_last()
    for i in range(1, 11):
        url = base_url + str(i)
        bug_id_page = get(url)
        bug_ids = re.findall(
            r'<a href="/bugs/(wooyun-\d{4}-\d{7})">', bug_id_page)
        if bug_id_list == bug_ids[0]:
            return None
        for id in bug_ids:
            bug_id_list.append(id)
            if id == last_id:
                return bug_id_list
    if bug_id_list:
        return bug_id_list
    else:
        return None
Exemplo n.º 11
0
def c_close_device(device_handle):
    global _zlg_dll

    # 关闭设备之前必须将关联的通道一并关闭, 做到资源主动回收
    channel_close_list = list()
    for ch, token in handle.all():
        if token.name != _token_name_can_channel:
            continue

        _, _, _, _, _, h, _, _ = token.payload()[0]
        if device_handle != h:
            continue

        channel_close_list.append(int(ch))

    for channel_handle in channel_close_list:
        handle.delete(channel_handle)

    devtype, devidx = handle.get(device_handle)
    handle.delete(device_handle)

    return True if 0 == _zlg_dll.VCI_CloseDevice(devtype, devidx) else False
Exemplo n.º 12
0
def c_reset_channel(channel_handle):
    global _zlg_dll

    # 关闭原有句柄,重新打开新的句柄
    devtype, devidx, channel_number, bps, work_mode, device_handle, acc_code, acc_mask = handle.get(channel_handle)
    handle.delete(channel_handle)

    return c_open_channel(device_handle, channel_number, bps, work_mode, acc_code, acc_mask)
Exemplo n.º 13
0
def c_get_cache_counter(channel_handle):
    global _zlg_dll

    devtype, devidx, channel_number, _, _, _, _, _ = handle.get(channel_handle)

    return _zlg_dll.VCI_GetReceiveNum(devtype, devidx, channel_number)
Exemplo n.º 14
0
def c_clear_cache(channel_handle):
    global _zlg_dll

    devtype, devidx, channel_number, _, _, _, _, _ = handle.get(channel_handle)
    return True if 0 == _zlg_dll.VCI_ClearBuffer(devtype, devidx, channel_number) else False