/* 1.5 ~ToListExpr~ converts this MFaces-object to a RList-representation of a moving region over the given interval with the given restrictions. */ RList MFaces::ToListExpr(Interval iv, double start, double end) { RList ret; if (faces.empty()) return ret; if (start == 0 && end == 1) { // No restrictions, so we can start the real work // Build the ListExpr for the time-interval RList uregion, uregions; RList interval; interval.append(iv.startstr()); interval.append(iv.endstr()); interval.append(iv.lc); interval.append(iv.rc); uregion.append(interval); // Now convert the mface-objects one by one and put them into one list for (unsigned int i = 0; i < faces.size(); i++) { uregions.append(faces[i].ToListExpr()); } uregion.append(uregions); return uregion; } else { // We need to restrict the interval first MFaces f = divide(start, end); // and then recall this function with the new mfaces w/o restrictions. return f.ToListExpr(iv, 0, 1); } }
// Program entry point int main (int argc, char **argv) { const char *arg = "distance"; if (argc < 5) { cerr << "Usage: rip <sregfile> <dregfile> <srctime> <dsttime> [args]\n" << " timeformat: YYYY-MM-DD hh:mm:ss\n" << "Example: rip box1 box2 \"2014-01-01 00:00\" " << "\"2014-01-02 12:00\" Overlap:30\n\n"; exit(1); } if (argc == 6) arg = argv[5]; RList *sreg = parseFile(argv[1]); RList *dreg = parseFile(argv[2]); RList ret = regioninterpolate(*sreg, *dreg, argv[3], argv[4], arg); stringstream ss; #ifdef SECONDO_STYLE ss << "(OBJECT obj () mregion "; #endif ss << ret.ToString() << "\n"; #ifdef SECONDO_STYLE ss << ")\n"; #endif cout << ss.str(); exit(0); }
static RList* symbols(RBinFile *arch) { r_bin_xbe_obj_t *obj; RList *ret = r_list_new(); int i, found = R_FALSE; ut32 thunk_addr[XBE_MAX_THUNK]; ut32 kt_addr; xbe_section sect; if (!ret || !arch || !arch->o) return NULL; obj = arch->o->bin_obj; kt_addr = obj->header->kernel_thunk_addr ^ obj->kt_key; ret->free = free; //eprintf ("VA %llx %llx\n", sym->paddr, sym->vaddr); // PA -> VA translation for (i = 0; found == R_FALSE && i < obj->header->sections; i++) { r_buf_read_at (arch->buf, obj->header->sechdr_addr - \ obj->header->base + (sizeof (xbe_section) * i), \ (ut8 *)§, sizeof(sect)); if (kt_addr >= sect.vaddr && kt_addr < sect.vaddr + sect.vsize) found = R_TRUE; } if (found == R_FALSE) { free (ret); return NULL; } r_buf_read_at (arch->buf, sect.offset + (kt_addr - sect.vaddr), \ (ut8 *)&thunk_addr, sizeof (thunk_addr)); for (i = 0; thunk_addr[i]; i++) { RBinSymbol *sym = R_NEW0 (RBinSymbol); if (!sym) { ret->free(sym); return NULL; } const ut32 thunk_index = thunk_addr[i] ^ 0x80000000; // Basic sanity checks if (thunk_addr[i]&0x80000000 && thunk_index <= XBE_MAX_THUNK) { snprintf(sym->name, R_BIN_SIZEOF_STRINGS, "kt.%s\n", kt_name[thunk_index]); sym->vaddr = (obj->header->kernel_thunk_addr ^ obj->kt_key) + (4 * i); sym->paddr = sym->vaddr - obj->header->base; sym->size = 4; sym->ordinal = i; r_list_append (ret, sym); } else free (sym); } return ret; }
TEST_F(RpcConainersTest, testRList) { RList<Int32> expected; expected.push_back(1); expected.push_back(3); expected.push_back(5); expected.serialize(*ostream_); RList<Int32> actual; actual.serialize(*istream_); EXPECT_EQ(expected.size(), actual.size()); EXPECT_EQ(expected.back(), actual.back()); }
/* 1.7 ~fallback~ can used, when the construction of a valid moving region failed in the steps before. This can for example happen because of numerical instability and resulting errors in the intersection checks or because of bugs in the interpolation code. This function tries to create a moving region RList representation in such a simple manner, that no errors are to be expected in any case: * Divide the time-interval in two halves * The first half shows statically the source region * The second half shows statically the destination region If the source- and destination-faces are valid, this can only fail if the time interval is too short. One of the intervals must be half-open and so has to have a certain minimum duration. */ RList MFaces::fallback(vector<Face> *sfaces, vector<Face> *dfaces, Interval iv) { RList mreg; Interval startiv(iv.start, iv.start + (iv.end - iv.start) / 2, true, true); // Build the static MSegs of the source-faces MFaces start = Face::CreateMFaces(sfaces); mreg.append(start.ToListExpr(startiv, 0, 1)); // This interval is half-open on the left end, since the preceding interval // above is closed there Interval endiv(startiv.end, iv.end, false, true); // Build the static MSegs of the destination-faces MFaces end = Face::CreateMFaces(dfaces); mreg.append(end.ToListExpr(endiv, 0, 1)); return mreg; }
static RList* symbols(RBinFile *arch) { r_bin_xbe_obj_t *obj; RList *ret; int i, found = false; ut32 thunk_addr[XBE_MAX_THUNK]; ut32 kt_addr; xbe_section sect; if (!arch || !arch->o) return NULL; obj = arch->o->bin_obj; kt_addr = obj->header->kernel_thunk_addr ^ obj->kt_key; ret = r_list_new(); ret->free = free; //eprintf ("VA %llx %llx\n", sym->paddr, sym->vaddr); // PA -> VA translation eprintf ("sections %d\n", obj->header->sections); int limit = obj->header->sections; if (limit * (sizeof(xbe_section)) >= arch->buf->length - obj->header->sechdr_addr) limit = arch->buf->length; for (i = 0; found == false && i < limit; i++) { r_buf_read_at (arch->buf, obj->header->sechdr_addr - \ obj->header->base + (sizeof (xbe_section) * i), \ (ut8 *)§, sizeof(sect)); if (kt_addr >= sect.vaddr && kt_addr < sect.vaddr + sect.vsize) found = true; } if (found == false) { free (ret); return NULL; } i = r_buf_read_at (arch->buf, sect.offset + (kt_addr - sect.vaddr), \ (ut8 *)&thunk_addr, sizeof (thunk_addr)); if (i != sizeof (thunk_addr)) { free (ret); return NULL; } for (i = 0; thunk_addr[i]; i++) { RBinSymbol *sym = R_NEW0 (RBinSymbol); if (!sym) { ret->free (sym); free (ret); return NULL; } const ut32 thunk_index = thunk_addr[i] ^ 0x80000000; // Basic sanity checks if (thunk_addr[i]&0x80000000 && thunk_index < XBE_MAX_THUNK) { sym->name = r_str_newf ("kt.%s", kt_name[thunk_index]); sym->vaddr = (obj->header->kernel_thunk_addr ^ obj->kt_key) + (4 * i); sym->paddr = sym->vaddr - obj->header->base; sym->size = 4; sym->ordinal = i; r_list_append (ret, sym); } else free (sym); } return ret; }
static RList* symbols(RBinFile *bf) { RList *ret = NULL; RBinSymbol *ptr[13]; int i; if (!(ret = r_list_new())) return NULL; ret->free = free; for (i = 0; i < 8; i++) { if (!(ptr[i] = R_NEW0 (RBinSymbol))) { ret->free (ret); return NULL; } ptr[i]->name = r_str_newf ("rst_%i", i*8); ptr[i]->paddr = ptr[i]->vaddr = i*8; ptr[i]->size = 1; ptr[i]->ordinal = i; r_list_append (ret, ptr[i]); } if (!(ptr[8] = R_NEW0 (RBinSymbol))) return ret; ptr[8]->name = strdup ("Interrupt_Vblank"); ptr[8]->paddr = ptr[8]->vaddr = 64; ptr[8]->size = 1; ptr[8]->ordinal = 8; r_list_append (ret, ptr[8]); if (!(ptr[9] = R_NEW0 (RBinSymbol))) return ret; ptr[9]->name = strdup ("Interrupt_LCDC-Status"); ptr[9]->paddr = ptr[9]->vaddr = 72; ptr[9]->size = 1; ptr[9]->ordinal = 9; r_list_append (ret, ptr[9]); if (!(ptr[10] = R_NEW0 (RBinSymbol))) return ret; ptr[10]->name = strdup ("Interrupt_Timer-Overflow"); ptr[10]->paddr = ptr[10]->vaddr = 80; ptr[10]->size = 1; ptr[10]->ordinal = 10; r_list_append (ret, ptr[10]); if (!(ptr[11] = R_NEW0 (RBinSymbol))) return ret; ptr[11]->name = strdup ("Interrupt_Serial-Transfere"); ptr[11]->paddr = ptr[11]->vaddr = 88; ptr[11]->size = 1; ptr[11]->ordinal = 11; r_list_append (ret, ptr[11]); if (!(ptr[12] = R_NEW0 (RBinSymbol))) return ret; ptr[12]->name = strdup ("Interrupt_Joypad"); ptr[12]->paddr = ptr[12]->vaddr = 96; ptr[12]->size = 1; ptr[12]->ordinal = 12; r_list_append (ret, ptr[12]); return ret; }
/* 1.6 ~ToMListExpr~ converts this MFaces-object to the RList representation of an moving region suitable for import into a dbms. It takes care of creating the correct intervals (evaporation, main and/or condensation), and the borderregions. */ RList MFaces::ToMListExpr(Interval iv) { RList mreg; // Determine if we need a start- or endregion. This is exactly the case when // one of the contained MFace-objects of this MFaces-object needs it. bool needStartRegion = false, needEndRegion = false; for (unsigned int i = 0; i < faces.size(); i++) { needStartRegion = needStartRegion || faces[i].needStartRegion; needEndRegion = needEndRegion || faces[i].needEndRegion; } // one-third of the whole interval is used for the evaporisation and/or // condensation-phase double onethird = (iv.end - iv.start) / 3; // Calculate the intervals Interval evaporIv, condensIv; Interval startRegIv, endRegIv; Interval mainIv; mainIv = iv; mainIv.lc = mainIv.rc = true; if (needSEvap) { // Create the evaporation interval // the left side of the evaporation interval is always open, since we // need a borderregion there evaporIv.lc = false; evaporIv.start = mainIv.start; mainIv.start = mainIv.start + onethird; evaporIv.end = mainIv.start; evaporIv.rc = false; } if (needDEvap) { // Create the condensation interval // the right side of the condensation interval is always open, since we // need a borderregion there condensIv.rc = false; condensIv.end = mainIv.end; mainIv.end = mainIv.end - onethird; condensIv.start = mainIv.end; condensIv.lc = false; } if (needStartRegion) { // Create the start-region interval startRegIv.lc = true; startRegIv.start = mainIv.start; mainIv.start = mainIv.start + MOMENTMS; startRegIv.end = mainIv.start; startRegIv.rc = true; mainIv.lc = false; } if (needEndRegion) { // Create the end-region interval endRegIv.rc = true; endRegIv.end = mainIv.end; mainIv.end = mainIv.end - MOMENTMS; endRegIv.start = mainIv.end; endRegIv.lc = true; mainIv.rc = false; } if (needSEvap) { // We need to perform an evaporations-phase Interval siv(evaporIv.start, evaporIv.start, true, true); MFaces s = Face::CreateMFaces(sregs); mreg.append(s.ToListExpr(siv, 0, 1)); MFaces fs; // Reconstruct the borderfaces at the start of the main interpolation .. vector<Face> borderfaces = CreateBorderFaces(true); // and interpolate them with the original sourceregion with // the evaporation-mode-flag set. fs = interpolate(sregs, &borderfaces, 0, true, ""); mreg.append(fs.ToListExpr(evaporIv, 0, 1)); } if (needStartRegion) { // Create the borderregion at the begin of the main interpolation // interval here and add it to the list. mreg.append(CreateBorderMFaces(true).ToListExpr(startRegIv, 0, 1)); } // Add the main-interpolation mreg.append(ToListExpr(mainIv, 0, 1)); if (needEndRegion) { // Create the borderregion at the end of the main interpolation // interval here and add it to the list. mreg.append(CreateBorderMFaces(false).ToListExpr(endRegIv, 0, 1)); } if (needDEvap) { // A condensation-phase is needed MFaces fs; // Reconstruct the borderfaces at the end of the main interpolation .. vector<Face> borderdregs = CreateBorderFaces(false); // and interpolate them with the original destinationregion with // the evaporation-mode-flag set. fs = interpolate(&borderdregs, dregs, 0, true, ""); mreg.append(fs.ToListExpr(condensIv, 0, 1)); Interval eiv(condensIv.end, condensIv.end, true, true); MFaces s = Face::CreateMFaces(dregs); mreg.append(s.ToListExpr(eiv, 0, 1)); } return mreg; }
static RList* symbols(RBinFile *arch) { RList *ret = NULL; RBinSymbol *ptr[13]; int i; if (!(ret = r_list_new())) return NULL; ret->free = free; for (i = 0; i < 8; i++) { if (!(ptr[i] = R_NEW (RBinSymbol))) { ret->free (ret); return NULL; } snprintf (ptr[i]->name, R_BIN_SIZEOF_STRINGS, "rst_%i", i*8); ptr[i]->paddr = ptr[i]->vaddr = i*8; ptr[i]->size = 1; ptr[i]->ordinal = i; r_list_append (ret, ptr[i]); } if (!(ptr[8] = R_NEW (RBinSymbol))) return ret; strncpy (ptr[8]->name, "Interrupt_Vblank", R_BIN_SIZEOF_STRINGS); ptr[8]->paddr = ptr[8]->vaddr = 64; ptr[8]->size = 1; ptr[8]->ordinal = 8; r_list_append (ret, ptr[8]); if (!(ptr[9] = R_NEW (RBinSymbol))) return ret; strncpy (ptr[9]->name, "Interrupt_LCDC-Status", R_BIN_SIZEOF_STRINGS); ptr[9]->paddr = ptr[9]->vaddr = 72; ptr[9]->size = 1; ptr[9]->ordinal = 9; r_list_append (ret, ptr[9]); if (!(ptr[10] = R_NEW (RBinSymbol))) return ret; strncpy(ptr[10]->name, "Interrupt_Timer-Overflow", R_BIN_SIZEOF_STRINGS); ptr[10]->paddr = ptr[10]->vaddr = 80; ptr[10]->size = 1; ptr[10]->ordinal = 10; r_list_append (ret, ptr[10]); if (!(ptr[11] = R_NEW (RBinSymbol))) return ret; strncpy(ptr[11]->name, "Interrupt_Serial-Transfere", R_BIN_SIZEOF_STRINGS); ptr[11]->paddr = ptr[11]->vaddr = 88; ptr[11]->size = 1; ptr[11]->ordinal = 11; r_list_append (ret, ptr[11]); if (!(ptr[12] = R_NEW (RBinSymbol))) return ret; strncpy (ptr[12]->name, "Interrupt_Joypad", R_BIN_SIZEOF_STRINGS); ptr[12]->paddr = ptr[12]->vaddr = 96; ptr[12]->size = 1; ptr[12]->ordinal = 12; r_list_append (ret, ptr[12]); return ret; }