예제 #1
0
def extract_file_format():
    format_name = ida_loader.get_file_type_name()

    if "PE" in format_name:
        yield Format(FORMAT_PE), 0x0
    elif "ELF64" in format_name:
        yield Format(FORMAT_ELF), 0x0
    elif "ELF32" in format_name:
        yield Format(FORMAT_ELF), 0x0
    else:
        raise NotImplementedError("file format: %s", format_name)
예제 #2
0
def extract_file_format():
    file_info = idaapi.get_inf_structure()

    if file_info.filetype == idaapi.f_PE:
        yield Format(FORMAT_PE), 0x0
    elif file_info.filetype == idaapi.f_ELF:
        yield Format(FORMAT_ELF), 0x0
    elif file_info.filetype == idaapi.f_BIN:
        # no file type to return when processing a binary file, but we want to continue processing
        return
    else:
        raise NotImplementedError("file format: %d" % file_info.filetype)
예제 #3
0
def extract_format(buf):
    if buf.startswith(b"MZ"):
        yield Format(FORMAT_PE), 0x0
    elif buf.startswith(b"\x7fELF"):
        yield Format(FORMAT_ELF), 0x0
    else:
        # we likely end up here:
        #  1. handling a file format (e.g. macho)
        #
        # for (1), this logic will need to be updated as the format is implemented.
        logger.debug("unsupported file format: %s", binascii.hexlify(buf[:4]).decode("ascii"))
        return
예제 #4
0
def test_format_features():
    rule = textwrap.dedent(
        """
        rule:
            meta:
                name: test rule
                scope: file
            features:
                - and:
                    - format: pe
        """
    )
    r = capa.rules.Rule.from_yaml(rule)
    children = list(r.statement.get_children())
    assert (Format(FORMAT_PE) in children) == True
    assert (Format(FORMAT_ELF) not in children) == True
예제 #5
0
 # before this we used ambiguous (0x4556E5, False), which has a data reference / indirect recursive call, see #386
 ("mimikatz", "function=0x456BB9",
  capa.features.common.Characteristic("calls to"), False),
 # file/function-name
 ("pma16-01", "file", capa.features.file.FunctionName("__aulldiv"), True
  ),
 # os & format & arch
 ("pma16-01", "file", OS(OS_WINDOWS), True),
 ("pma16-01", "file", OS(OS_LINUX), False),
 ("pma16-01", "function=0x404356", OS(OS_WINDOWS), True),
 ("pma16-01", "function=0x404356,bb=0x4043B9", OS(OS_WINDOWS), True),
 ("pma16-01", "file", Arch(ARCH_I386), True),
 ("pma16-01", "file", Arch(ARCH_AMD64), False),
 ("pma16-01", "function=0x404356", Arch(ARCH_I386), True),
 ("pma16-01", "function=0x404356,bb=0x4043B9", Arch(ARCH_I386), True),
 ("pma16-01", "file", Format(FORMAT_PE), True),
 ("pma16-01", "file", Format(FORMAT_ELF), False),
 # elf support
 ("7351f.elf", "file", OS(OS_LINUX), True),
 ("7351f.elf", "file", OS(OS_WINDOWS), False),
 ("7351f.elf", "file", Format(FORMAT_ELF), True),
 ("7351f.elf", "file", Format(FORMAT_PE), False),
 ("7351f.elf", "file", Arch(ARCH_I386), False),
 ("7351f.elf", "file", Arch(ARCH_AMD64), True),
 ("7351f.elf", "function=0x408753",
  capa.features.common.String("/dev/null"), True),
 ("7351f.elf", "function=0x408753,bb=0x408781",
  capa.features.insn.API("open"), True),
 ("79abd...", "function=0x10002385,bb=0x10002385",
  capa.features.common.Characteristic("call $+5"), True),
 ("946a9...", "function=0x10001510,bb=0x100015c0",
예제 #6
0
def extract_file_format(**kwargs) -> Iterator[Tuple[Format, int]]:
    yield Format(FORMAT_DOTNET), 0x0
예제 #7
0
def extract_file_format(**kwargs):
    yield Format(FORMAT_ELF), 0x0