コード例 #1
0
ファイル: typecheck.c プロジェクト: Saruta/a2c
bool check_algo(struct algo* al, struct symtable *syms)
{
  bool correct = true;
  struct function* f = malloc(sizeof(struct function));
  f->ret = find_type(syms->types, al->return_type);
  struct declarations* decl = al->declarations;

  if(decl != NULL)
  {
    struct param_decl* p_decl = decl->param_decl;
    vardecllist_t loc = p_decl->local_param;
    vardecllist_t glo = p_decl->global_param;
    vardecllist_t vars = decl->var_decl;
    typedecllist_t typelist = decl->type_decls;
    constdecllist_t consts = decl->const_decls;
    for(unsigned i =0; i < consts.size; ++i)
      correct = correct && check_const(list_nth(consts,i), syms, true);
    if(loc.size > 0)
      correct = add_variables(syms, loc, false, false, false) && correct;
    if(glo.size > 0)
      correct = add_variables(syms, glo, false, true, false) && correct;
    correct = add_types(syms, typelist) && correct;
    correct = add_variables(syms, vars, false, false, false) && correct;
  }
  for(unsigned i = 0; i < al->instructions.size; i++)
    if(!check_inst(list_nth(al->instructions, i), f->ret, syms))
      correct = false;

  remove_decls(syms, decl);
  free(f);
  return correct;
}
コード例 #2
0
ファイル: typecheck.c プロジェクト: Saruta/a2c
bool check_prog(struct prog* prog, struct symtable *syms)
{
  bool correct = true;
  fill_std_types(syms);
  fill_std_fun(syms);
  constdecllist_t consts = prog->entry_point->const_decls;

  for(unsigned i =0; i < consts.size; ++i)
    correct = correct && check_const(list_nth(consts,i), syms, true);
  correct = correct && add_types(syms, prog->entry_point->type_decls);
  correct = correct && add_variables(syms, prog->entry_point->var_decl, true, false, false);
  for(unsigned i = 0; i < prog->algos.size; ++i)
  {
    struct algo* al = list_nth(prog->algos, i);
    struct function* f = malloc(sizeof(struct function));
    f->ident = al->ident;
    f->ret = find_type(syms->types, al->return_type);
    f->arg = get_args(al->declarations->param_decl, syms);
    add_function(syms->functions, f);
  }
  for (unsigned i = 0; i < prog->entry_point->instructions.size; ++i)
    if (!check_inst(
          prog->entry_point->instructions.data[i],
          find_type(syms->types, TYPE_INT), syms))
      correct = false;
  for(unsigned i = 0; i < prog->algos.size; ++i)
  {
    struct algo* al = list_nth(prog->algos, i);
    if (!check_algo(al, syms))
      correct = false;
  }
  return correct;
}
コード例 #3
0
Frame* TemplateEngineFixtures::person_with_null_attributes()
{
	auto person = new Frame();
	person->add_types({ "person","object" })
		->add_frame("name", "Pau Gasol");
	return person;
}
コード例 #4
0
Frame* TemplateEngineFixtures::person()
{

	auto person = new Frame();
	person->add_types({"person","object" })
		->add_frame("name", "Pau Gasol")
		->add_frame("birthday", boost::gregorian::date(1980, boost::date_time::Jul, 6))
		->add_frame("country", "Spain");
	return person;
}
コード例 #5
0
ファイル: TypeFunctionTest.cpp プロジェクト: jer0Me/ItRules
TEST(TypeFunctionTest, should_check_types_in_frame)
{
	auto type_function = new TypeFunction();
	auto frame = new Frame();
	frame->add_types({ "X", "Y", "Z" });
	auto trigger = new Trigger(frame, new Mark("f"));

	ASSERT_TRUE(type_function->match(trigger, "Y"));
	ASSERT_FALSE(type_function->match(trigger, "T"));
	ASSERT_TRUE(type_function->match(trigger, "X&Y&Z"));
	ASSERT_TRUE(type_function->match(trigger, "X & Y & Z"));
	ASSERT_FALSE(type_function->match(trigger, "X & Y & T"));
	ASSERT_TRUE(type_function->match(trigger, "A|Y|T"));
	ASSERT_TRUE(type_function->match(trigger, "A | Y | T"));
	ASSERT_FALSE(type_function->match(trigger, "A|S|T"));
	ASSERT_FALSE(type_function->match(trigger, "A | S | T"));
}
コード例 #6
0
ファイル: teloader.cpp プロジェクト: Yukariin/TELoader
/*
 * this is where we finally load the file and create segments and other processing
 */
void idaapi
load_file(linput_t *li, ushort neflags, const char *fileformatname)
{
    /* reset file position to 0 - accept_file changed it? */
    qlseek(li, 0);
    /* add header structures */
    add_types();
    create_filename_cmt();
    /* process header and create its own segment */
    EFI_IMAGE_TE_HEADER teHeader = {0};
    if (qlread(li, &teHeader, sizeof(EFI_IMAGE_TE_HEADER)) != sizeof(EFI_IMAGE_TE_HEADER))
    {
        warning("Failed to read TE header\n");
        return;
    }
    /* read the data to the database */
    /* header starts at 0 */
    ea_t delta = teHeader.StrippedSize - sizeof(EFI_IMAGE_TE_HEADER);
    ea_t header_start = teHeader.ImageBase - delta;
    /* header total size is the TE header plus all sections that follow */
    ea_t header_end = teHeader.ImageBase - delta + sizeof(EFI_IMAGE_TE_HEADER) + teHeader.NumberOfSections * sizeof(EFI_IMAGE_SECTION_HEADER);
#if 1
    msg("Header start: 0x%llx\n", header_start);
    msg("Header end: 0x%llx\n", header_end);
    msg("Delta: 0x%llx\n", delta);
#endif
    file2base(li, 0, header_start, header_end, 1);
    /* create the HEADER segment */
    add_segm(0, header_start, header_end, "HEADER", "DATA");
    /* set header structures */
    doStruct(teHeader.ImageBase - delta, sizeof(EFI_IMAGE_TE_HEADER), efi_image_te_header_struct);
    for (uint8_t i = 0; i < teHeader.NumberOfSections; i++)
    {
        doStruct(teHeader.ImageBase - delta + sizeof(EFI_IMAGE_TE_HEADER) + i * sizeof(EFI_IMAGE_SECTION_HEADER), sizeof(EFI_IMAGE_SECTION_HEADER), efi_image_section_header_struct);
    }
    
    int headerPosition = sizeof(EFI_IMAGE_TE_HEADER);

    /* read sections */
    for (uint8_t i = 0; i < teHeader.NumberOfSections; i++)
    {
        qlseek(li, headerPosition);
        EFI_IMAGE_SECTION_HEADER sectionHeader = {0};
        qlread(li, &sectionHeader, sizeof(EFI_IMAGE_SECTION_HEADER));
        msg("Section name: %s\n", sectionHeader.Name);
        /* ok */
        uint32_t position = sectionHeader.PointerToRawData - delta;
        msg("Position %x\n", position);
        qlseek(li, position);
        ea_t section_start = sectionHeader.VirtualAddress + teHeader.ImageBase - delta;
        ea_t section_end = 0;
        if (sectionHeader.Misc.VirtualSize > sectionHeader.SizeOfRawData)
        {
            section_end = sectionHeader.VirtualAddress + teHeader.ImageBase - delta + sectionHeader.Misc.VirtualSize;
        }
        else
        {
            section_end = sectionHeader.VirtualAddress + teHeader.ImageBase - delta + sectionHeader.SizeOfRawData;
        }
        msg("Section start: 0x%llx\n", section_start);
        msg("Section end: 0x%llx\n", section_end);
        file2base(li, position, section_start, section_end, 1);
        int bitness = -1;
        switch (teHeader.Machine) {
            case IMAGE_FILE_MACHINE_I386:
                bitness = 1;
                break;
            case IMAGE_FILE_MACHINE_X64:
                bitness = 2;
                break;
            default:
                bitness = 0;
        }
        const char *classType;
        if (qstrcmp((const char*)sectionHeader.Name, ".text") == 0)
        {
            classType = "CODE";
        }
        else
        {
            classType = "DATA";
        }
        add_segm(0, section_start, section_end, (const char*)sectionHeader.Name, classType);
        set_segm_addressing(get_segm_by_name((const char *)sectionHeader.Name), bitness);

        /* try to find the GUIDs in data section */
        if (qstrcmp((const char *)sectionHeader.Name, ".data") == 0)
        {
            find_guids(section_start, section_end);
        }

        /* advance to next section */
        headerPosition += sizeof(EFI_IMAGE_SECTION_HEADER);
    }
    /* configure the entrypoint address */
    add_entry(teHeader.AddressOfEntryPoint + teHeader.ImageBase - delta, teHeader.AddressOfEntryPoint + teHeader.ImageBase - delta, "_start", 1);

    /* all done */
}