Exemplo n.º 1
0
def native_check():
    """Check if this is natvie os"""
    cmd = "cpuid -r -l 0x01"
    res = parser_lib.cmd_excute(cmd)
    while True:
        line = parser_lib.decode_stdout(res)

        if line:

            if len(line.split()) <= 2:
                continue

            reg_value = line.split()[4].split('=')[1]
            break

    return int(reg_value, 16) & 0x80000000 == 0
Exemplo n.º 2
0
def dump_cpuid_reg(cmd, reg):
    """execute the cmd of cpuid, and return the register value by reg
    :param cmd: command what can be executed in shell
    :param reg: register name
    """
    res = parser_lib.cmd_execute(cmd)
    if reg == "eax":
        idx = 2
    if reg == "ebx":
        idx = 3
    if reg == "edx":
        idx = 5

    while True:
        line = parser_lib.decode_stdout(res)

        if not line:
            break

        if len(line.split()) <= 2:
            continue

        reg_value = line.split()[idx].split('=')[1]

        if reg == "eax":
            res_info = int(reg_value, 16) + 1
            break
        elif reg == "ebx":
            res_info = []
            if int(reg_value, 16) & RDT_TYPE['L2'] != 0:
                res_info.append("L2")
            if int(reg_value, 16) & RDT_TYPE['L3'] != 0:
                res_info.append("L3")
            if int(reg_value, 16) & RDT_TYPE['MBA'] != 0:
                res_info.append("MBA")
            break
        elif reg == "edx":
            res_info = int(reg_value, 16) + 1
            break

    return res_info
Exemplo n.º 3
0
def dump_cpuid_reg(cmd, reg):
    """execute the cmd of cpuid, and return the register value by reg
    :param cmd: command what can be executed in shell
    :param reg: register name
    """
    cache_t = ''

    res = parser_lib.cmd_execute(cmd)
    if reg == "ebx":
        idx = 3

    if reg == "edx":
        idx = 5

    while True:
        line = parser_lib.decode_stdout(res)

        if not line:
            break

        if len(line.split()) <= 2:
            continue

        reg_value = line.split()[idx].split('=')[1]

        if reg == "ebx":
            if int(reg_value, 16) & CACHE_TYPE['L2'] != 0:
                cache_t = "L2"
                break
            elif int(reg_value, 16) & CACHE_TYPE['L3'] != 0:
                cache_t = "L3"
                break
            else:
                cache_t = False
                break
        elif reg == "edx":
            cache_t = int(reg_value, 16) + 1
            break

    return cache_t
Exemplo n.º 4
0
def execute(cmd, reg):
    """Execute the cmd"""
    cache_t = ''

    res = parser_lib.cmd_excute(cmd)
    if reg == "ebx":
        idx = 3

    if reg == "edx":
        idx = 5

    while True:
        line = parser_lib.decode_stdout(res)

        if not line:
            break

        if len(line.split()) <= 2:
            continue

        reg_value = line.split()[idx].split('=')[1]

        if reg == "ebx":
            if int(reg_value, 16) & CACHE_TYPE['L2'] != 0:
                cache_t = "L2"
                break
            elif int(reg_value, 16) & CACHE_TYPE['L3'] != 0:
                cache_t = "L3"
                break
            else:
                cache_t = False
                break
        elif reg == "edx":
            cache_t = int(reg_value, 16) + 1
            break

    return cache_t