static void add_reloc(Elf *elf) { char name[100]; for (int i = 0; i < LIST_LEN(elf->sections); i++) { Section *sect = LIST_REF(elf->sections, i); if (LIST_LEN(sect->rels) == 0) continue; String *b = make_string(); for (int j = 0; j < LIST_LEN(sect->rels); j++) { Reloc *rel = LIST_REF(sect->rels, j); o8(b, rel->off); if (rel->sym) { o8(b, ELF64_R_INFO(find_symbol(elf, rel->sym)->index, rel->type)); } else { o8(b, ELF64_R_INFO(rel->section->symindex, rel->type)); } o8(b, rel->addend); } strcpy(name, ".rela"); strcpy(name + 5, sect->name); Section *relsec = make_section(name, SHT_RELA); relsec->link = elf->symtabnum; relsec->info = i + 1; relsec->body = b; relsec->entsize = 24; relsec->align = 4; add_section(elf, relsec); } }
static void add_symtab(Elf *elf) { String *symtabb = make_string(); String *strtabb = make_string(); o1(strtabb, 0); // Null symbol for (int i = 0; i < 24; i++) o1(symtabb, 0); // File symbol o4(symtabb, STRING_LEN(strtabb)); // st_name ostr(strtabb, "noname"); o1(symtabb, ELF64_ST_INFO(STB_LOCAL, STT_FILE)); // st_info o1(symtabb, 0); // other o2(symtabb, SHN_ABS); // st_shndx o8(symtabb, 0); // st_value o8(symtabb, 0); // st_size int index = 2; write_sym_to_buf(elf, &index, symtabb, strtabb, true); int localidx = index; write_section_sym(elf, &index, symtabb, strtabb); write_sym_to_buf(elf, &index, symtabb, strtabb, false); elf->symtabnum = LIST_LEN(elf->sections) + 1; Section *symtab = make_section(".symtab", SHT_SYMTAB); symtab->body = symtabb; symtab->link = LIST_LEN(elf->sections) + 2; symtab->info = localidx + 2; symtab->entsize = 24; symtab->align = 4; add_section(elf, symtab); Section *strtab = make_section(".strtab", SHT_STRTAB); strtab->body = strtabb; add_section(elf, strtab); }
static void write_one_symbol(Symbol *sym, int *index, String *symtab, String *strtab) { if (sym->name) { o4(symtab, STRING_LEN(strtab)); // st_name ostr(strtab, STRING_BODY(sym->name)); } else { o4(symtab, 0); // st_name } o1(symtab, ELF64_ST_INFO(sym->bind, sym->type)); // st_info; o1(symtab, 0); // st_other; if (sym->defined) { o2(symtab, sym->section->shndx); // st_shndx } else { o2(symtab, 0); // st_shndx } o8(symtab, sym->value); // st_value o8(symtab, 0); // st_size sym->index = (*index)++; }
void write_elf(FILE *outfile, Elf *elf) { add_symtab(elf); add_reloc(elf); add_shstrtab(elf); // Section header String *sh = make_string(); for (int i = 0; i < 64; i++) o1(sh, 0); // NULL section header // Body String *content = make_string(); for (int i = 0; i < LIST_LEN(elf->sections); i++) { write_section(sh, content, LIST_REF(elf->sections, i), 64); } align(content, 16); // ELF header String *eh = make_string(); int numsect = LIST_LEN(elf->sections) + 1; out(eh, elf_ident, sizeof(elf_ident)); o2(eh, 1); // e_type = ET_REL o2(eh, 62); // e_machine = EM_X86_64 o4(eh, 1); // e_version = EV_CURRENT o8(eh, 0); // e_entry o8(eh, 0); // e_phoff o8(eh, STRING_LEN(content) + 64); // e_shoff; o4(eh, 0); // e_flags o2(eh, 64); // e_ehsize o2(eh, 0); // e_phentsize o2(eh, 0); // e_phnum o2(eh, 64); // e_shentsize o2(eh, numsect); // e_shnum o2(eh, elf->shnum); // e_shstrndx fwrite(STRING_BODY(eh), STRING_LEN(eh), 1, outfile); fwrite(STRING_BODY(content), STRING_LEN(content), 1, outfile); fwrite(STRING_BODY(sh), STRING_LEN(sh), 1, outfile); fclose(outfile); }
TEST(Obis, Obis_strparsing) { Obis o1(0x1, 0x1, 97, 97, 0xff, 0xff); // 97 = SC_F Obis o2("1-1:F.F"); ASSERT_EQ(o1, o2); Obis o3(0x1, 0x1, 96, 98, 0xff, 0xff); // 96 = SC_C, 98 = SC_L Obis o4("1-1:C.L"); ASSERT_EQ(o3, o4); Obis o5(0x1, 0x1, 96, 99, 0xff, 0xff); // 96 = SC_C, 99 = SC_P Obis o6("1-1:C.P"); ASSERT_EQ(o5, o6); ASSERT_THROW(Obis o7("1-1:x:y"), vz::VZException); Obis o8("power-l1"); ASSERT_EQ(Obis("1-0:21.7"), o8); }
static void write_section(String *header, String *content, Section *sect, int offset) { o4(header, sect->shstrtab_off); // sh_name o4(header, sect->type); // sh_type o8(header, sect->flags); // sh_flags o8(header, 0); // sh_addr o8(header, STRING_LEN(content) + offset); // sh_offset o8(header, STRING_LEN(sect->body)); // sh_size o4(header, sect->link); // sh_link = SHN_UNDEF o4(header, sect->info); // sh_info o8(header, sect->align); // sh_addralign o8(header, sect->entsize); // sh_entsize out(content, STRING_BODY(sect->body), STRING_LEN(sect->body)); align(content, 16); }
TEST(Obis, Obis_extStrParsing) { Obis o1(0xff, 0xff, 0x0, 0x0, 0x0, 0xff); Obis o2("0.0.0"); ASSERT_EQ(o1, o2) << o1.toString( )<< o2.toString(); ASSERT_EQ(o1.toString(), o2.toString()); Obis o3(0xff, 0xff, 0x1, 0x2, 0x3, 0xff); Obis o4("1.2.3"); ASSERT_EQ(o3, o4); ASSERT_EQ(o3.toString(), o4.toString()); Obis o5(0xff, 0xff, 0x61, 0x61, 0xff, 0xff); Obis o6("F.F"); ASSERT_EQ(o5, o6); Obis o7(0xff, 0xff, 0x0, 0x0, 0x2, 0xff); Obis o8("0.0.2"); ASSERT_EQ(o7, o8); // this should throw an exception as hex codes are not valid inside obis codes. ASSERT_THROW(Obis o10("1.8.0*FF"), vz::VZException); ASSERT_THROW(Obis o10("1.8.0*F1"), vz::VZException); }
bool SparseRec2View::save() { if(!_onlymatch) { //save reconstructed points string path1(dir+imgname1+string("-")+imgname2+string(".X")); std::ofstream o1(path1.c_str()); o1 << "VERTEX " << (int)results.size() << endl; for(int i=0; i<(int)results.size(); ++i) { o1<<results[i].x<<" "<<results[i].y<<" "<<results[i].z<<endl; } o1.close(); TagI("save reconstructed points to\n %s\n",path1.c_str()); //save cam par string path7(imgpath1+string(".par")); std::ofstream o7(path7.c_str()); o7.setf(std::ios::scientific); o7 << "K(alphaX alphaY u0 v0)=" <<endl; o7 << K[0] << " " << K[4] << " " << K[2] << " " << K[5] << endl; o7 << "R=" << endl; o7 << "1 0 0\n0 1 0\n0 0 1" <<endl; o7 << "T=" << endl; o7 << "0 0 0" << endl; o7.close(); TagI("save camera 1's parameters to\n %s\n",path7.c_str()); string path8(imgpath2+string(".par")); std::ofstream o8(path8.c_str()); o8.setf(std::ios::scientific); o8 << "K(alphaX alphaY u0 v0)=" <<endl; o8 << K[0] <<" "<< K[4] <<" "<< K[2] <<" "<< K[5] << endl; o8 << "R=" << endl; for(int i=0; i<3; ++i) { for(int j=0; j<3; ++j) { o8 << R[i*3+j] << " "; } o8 << endl; } o8 << "T=" << endl; o8 << t[0] <<" "<< t[1] <<" "<< t[2] << endl; o8.close(); TagI("save camera 2's parameters to\n %s\n",path8.c_str()); } double fontScale=0.5; CvPoint text_origin; //save matched point pairs string path2(dir+imgname1+string("-")+imgname2+string(".p1p2")); std::ofstream o2(path2.c_str()); //out.setf(std::ios::scientific); int cnt = 0; for(int i=0; i<(int)p1.size(); ++i) { if(!inliers[i]) continue; o2 << p1[i].x <<" "<< p1[i].y <<" "<< p2[i].x <<" "<< p2[i].y <<endl; char tmp[256]; sprintf(tmp, "%d", cnt++); text_origin.x = (int)p1[i].x+5; text_origin.y = (int)p1[i].y-5; putText(img1, tmp, text_origin, CV_FONT_HERSHEY_PLAIN, fontScale, CV_BLACK); text_origin.x = (int)p2[i].x+5; text_origin.y = (int)p2[i].y-5; putText(img2, tmp, text_origin, CV_FONT_HERSHEY_PLAIN, fontScale, CV_BLACK); } o2.close(); TagI("save matched point pairs to\n %s\n",path2.c_str()); //save images string path3(imgpath1+string("-detect.jpg")); string path4(imgpath2+string("-detect.jpg")); string path5(dir+imgname1+string("-")+imgname2+string(".jpg")); if(!img1.empty()) cv::imwrite(path3, img1); else { TagE("no valid image to save!\n"); return false; } if(!img2.empty()) cv::imwrite(path4, img2); if(!combined.empty()) cv::imwrite(path5, combined); TagI("save surfed image 1 to\n %s\n",path3.c_str()); TagI("save surfed image 2 to\n %s\n",path4.c_str()); TagI("save combined image to\n %s\n",path5.c_str()); //save F string path6(dir+imgname1+string("-")+imgname2+string(".fmatrix")); std::ofstream o6(path6.c_str()); o6 << helper::PrintMat<>(3,3,F); o6.close(); TagI("save fundamental matrix to\n %s\n",path6.c_str()); return true; }
/* * START THE VM */ void startVM(Vm* vm) { vm->PC = 0; while (charArrayToInt(0,2,vm->IR) != 99) { nextInstruction(vm); switch (charArrayToInt(0,2,vm->IR)) { case 0: o0(vm); break; case 1: o1(vm); break; case 2: o2(vm); break; case 3: o3(vm); break; case 4: o4(vm); break; case 5: o5(vm); break; case 6: o6(vm); break; case 7: o7(vm); break; case 8: o8(vm); break; case 9: o9(vm); break; case 10: o10(vm); break; case 11: o11(vm); break; case 12: o12(vm); break; case 13: o13(vm); break; case 14: o14(vm); break; case 15: o15(vm); break; case 16: o16(vm); break; case 17: o17(vm); break; case 18: o18(vm); break; case 19: o19(vm); break; case 20: o20(vm); break; case 21: o21(vm); break; case 22: o22(vm); break; case 23: o23(vm); break; case 24: o24(vm); break; case 25: o25(vm); break; case 26: o26(vm); break; case 27: o27(vm); break; case 28: o28(vm); break; case 29: o29(vm); break; case 30: o30(vm); break; case 31: o31(vm); break; case 32: o32(vm); break; case 33: o33(vm); break; case 34: o34(vm); break; case 35: o35(vm); break; case 99: o99(vm); break; default: // Code break; } displayVmFinal(vm); } }