//---------------------------------------------------------------------- int find_ar(ea_t *res) { ea_t ea = cmd.ea; for ( int i=0; i < lookback; i++ ) { ea = prevInstruction(ea); if ( !isCode(get_flags_novalue(ea)) ) break; ushort code = (ushort)get_full_byte(ea); if ( isC2() ) { switch ( code >> 11 ) { case 6: // LAR return 0; case 0x18: // LARK *res = toEA(dataSeg(),(code & 0xFF)); return 1; case 0x1A: // LRLK if ( (code & 0xF8FF) == 0xD000 ) { ushort b = (ushort)get_full_byte(ea+1); *res = toEA(dataSeg(), b); return 1; } } continue; } switch ( code >> 11 ) { case 0: // Load AR from addressed data return 0; // LAR found, unknown address case 0x16: // Load AR short immediate *res = toEA(dataSeg(), code & 0xFF); return 1; case 0x17: // Load AR long immediate if ( (code & ~7) == 0xBF08 ) { ushort b = (ushort)get_full_byte(ea+1); *res = toEA(dataSeg(),b); return 1; } } } return 0; }
//---------------------------------------------------------------------- static void TouchArg(op_t &x,int isAlt,int isload) { switch ( x.type ) { case o_reg: case o_phrase: case o_port: break; case o_imm: if ( !isload ) goto badTouch; doImmdValue(x.n); if ( isOff(uFlag, x.n) ) ua_add_off_drefs2(x, dr_O, OOF_SIGNED); break; case o_displ: doImmdValue(x.n); if ( isAlt ) break; if ( isOff(uFlag, x.n) ) { ua_add_off_drefs2(x, isload ? dr_R : dr_W, OOF_ADDR); ea_t ea = calc_target(cmd.ea+x.offb, cmd.ea, x.n, x.addr); ua_dodata2(x.offb, ea, x.dtyp); if ( !isload ) doVar(ea); } break; case o_near: { cref_t ftype = fl_JN; ea_t ea = toEA(cmd.cs, x.addr); if ( InstrIsSet(cmd.itype, CF_CALL) ) { if ( !func_does_return(ea) ) flow = false; ftype = fl_CN; } ua_add_cref(x.offb, ea, ftype); } break; case o_mem: { ea_t ea = toEA(dataSeg(), x.addr); ua_add_dref(x.offb, ea, isload ? dr_R : dr_W); } break; default: badTouch: if ( cmd.itype != AVR_lpm && cmd.itype != AVR_elpm ) warning("%a: %s,%d: bad optype %d", cmd.ea, cmd.get_canon_mnem(), x.n, x.type); break; } }
bool ReadFileGps::readFileGpsGpx(QString fileName, QDateTime &peridoInicial, QDateTime &peridoFinal, int &segmentosLog) { int totalSegmentosTrackLog, totalLinhasArquivo; bool posicaoOk = false, altitudeOk = false, timeOk = false; GpsPosition *gpsPosition; double latitude = 0, longitude = 0, altitude = 0; int dia = 0, mes = 0, ano = 0, hora = 0, minuto = 0, segundo = 0; bool ativaLeitura; QDateTime *dataInicial, *dataFinal; QDateTime *dataHora; dataFinal = NULL; dataInicial = NULL; int pos1, pos2, posInicio, posFim; QFile file(fileName); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { return false; } totalSegmentosTrackLog = 0; totalLinhasArquivo = 0; ativaLeitura = false; while (!file.atEnd()) { posInicio = posFim = -1; totalLinhasArquivo++; QByteArray line = file.readLine(); pos1 = pos2 = 0; while (pos2 != -1) { if (!ativaLeitura) { posInicio = line.indexOf(QString("<trk>"), pos1); if (posInicio != -1) { ativaLeitura = true; pos1 = posInicio; } } else { posFim = line.indexOf(QString("</trk>"), pos1); if ((posFim != -1) && (posFim < pos2)) { ativaLeitura = false; pos1 = posFim; } } if (ativaLeitura) { pos2 = line.indexOf(QString("<trkpt"), pos1); if (pos2 != -1) { posicaoOk = true; int pos3, pos4, pos5, pos6; pos3 = line.indexOf(QString("lat=\""), pos2 + 6); pos4 = line.indexOf('"', pos3 + 5); latitude = QString(line.mid(pos3 + 5, pos4 - pos3 - 5)).replace('.', ',').toDouble(); pos5 = line.indexOf(QString("lon=\""), pos4); pos6 = line.indexOf('"', pos5 + 5); longitude = QString(line.mid(pos5 + 5, pos6 - pos5 - 5)).replace('.', ',').toDouble(); pos1 = pos6; } pos2 = line.indexOf(QString("<ele>"), pos1); if (pos2 != -1) { int pos7; altitudeOk = true; pos7 = line.indexOf(QString("</ele>"), pos2 + 5); altitude = QString(line.mid(pos2 + 5, pos7 - pos2 - 5)).replace('.', ',').toDouble(); pos1 = pos7; } pos2 = line.indexOf(QString("<time>"), pos1); if (pos2 != -1) { int pos8; QString dataHoraS; timeOk = true; pos8 = line.indexOf(QString("</time>"), pos2 + 6); dataHoraS = QString(line.mid(pos2 + 6, pos8 - pos2 - 6)); ano = dataHoraS.mid(0, 4).toInt(); mes = dataHoraS.mid(5, 2).toInt(); dia = dataHoraS.mid(8, 2).toInt(); hora = dataHoraS.mid(11, 2).toInt(); minuto = dataHoraS.mid(14, 2).toInt(); segundo = dataHoraS.mid(17, 2).toInt(); pos1 = pos8; } } else { pos2 = -1; } if (posicaoOk && altitudeOk && timeOk) { QDate dataSeg(ano, mes, dia); QTime horaSeg(hora, minuto, segundo); dataHora = new QDateTime(dataSeg, horaSeg); gpsPosition = new GpsPosition(latitude, longitude, altitude, dataHora); controlaPeriodoTracklog->insereGpsPosition(gpsPosition); if (dataFinal == NULL && dataInicial == NULL && ano != 0) { dataFinal = dataHora; dataInicial = dataHora; } else { if (dataHora->operator<(*dataInicial)) { dataInicial = dataHora; } if (dataHora->operator>(*dataFinal)) { dataFinal = dataHora; } } totalSegmentosTrackLog++; posicaoOk = altitudeOk = timeOk = false; } } } if (dataInicial != NULL && dataFinal != NULL && totalSegmentosTrackLog != 0) { peridoInicial.setDate(dataInicial->date()); peridoInicial.setTime(dataInicial->time()); peridoFinal.setDate(dataFinal->date()); peridoFinal.setTime(dataFinal->time()); segmentosLog = totalSegmentosTrackLog; return true; } else { return false; } }
bool ReadFileGps::readFileGpsTxt(QString fileName, QDateTime &peridoInicial, QDateTime &peridoFinal, int &segmentosLog) { QString valorColuna; int pos1, pos2, posColuna; bool armazenarCoodenadas; int dia = 0, mes = 0, ano = 0, hora = 0, minuto = 0, segundo = 0; GpsPosition *gpsPosition; int totalSegmentosTrackLog, totalLinhasArquivo; QDateTime *dataInicial, *dataFinal; QDateTime *dataHora; dataFinal = NULL; dataInicial = NULL; bool arquivoD, arquivoDM, arquivoDMS; arquivoD = false; arquivoDM = false; arquivoDMS = false; QFile file(fileName); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { return false; } totalSegmentosTrackLog = 0; totalLinhasArquivo = 0; while (!file.atEnd()) { double latitude = 0, longitude = 0, altitude = 0; pos1 = 0; pos2 = 0; posColuna = 1; armazenarCoodenadas = false; totalLinhasArquivo++; QByteArray line = file.readLine(); while (pos2 != -1) { pos2 = line.indexOf(',', pos1); valorColuna = QString(line.mid(pos1, pos2 - pos1)); if (posColuna == 1 && valorColuna == "t") { armazenarCoodenadas = true; totalSegmentosTrackLog++; } else { if ((posColuna == 2 && valorColuna.operator ==("d")) || arquivoD) { arquivoD = true; if (posColuna == 3 && armazenarCoodenadas) { latitude = valorColuna.toDouble(); } else if (posColuna == 4 && armazenarCoodenadas) { longitude = valorColuna.toDouble(); } else if (posColuna == 5 && armazenarCoodenadas) { fileTxtConverteData(valorColuna, dia, mes, ano); } else if (posColuna == 6 && armazenarCoodenadas) { hora = atoi(valorColuna.toStdString().substr(0, 2).c_str()); minuto = atoi(valorColuna.toStdString().substr(3, 2).c_str()); segundo = atoi(valorColuna.toStdString().substr(6, 2).c_str()); } else if (posColuna == 7 && armazenarCoodenadas) { altitude = atof(valorColuna.toStdString().c_str()); } } if ((posColuna == 2 && valorColuna.operator ==("dm")) || arquivoDM) { arquivoDM = true; if (posColuna == 3 && armazenarCoodenadas) { latitude = fileTxtConverteCoordenadaGrausMinutosParaGraus(valorColuna); } else if (posColuna == 4 && armazenarCoodenadas) { longitude = fileTxtConverteCoordenadaGrausMinutosParaGraus(valorColuna); } else if (posColuna == 5 && armazenarCoodenadas) { fileTxtConverteData(valorColuna, dia, mes, ano); } else if (posColuna == 6 && armazenarCoodenadas) { hora = atoi(valorColuna.toStdString().substr(0, 2).c_str()); minuto = atoi(valorColuna.toStdString().substr(3, 2).c_str()); segundo = atoi(valorColuna.toStdString().substr(6, 2).c_str()); } else if (posColuna == 7 && armazenarCoodenadas) { altitude = atof(valorColuna.toStdString().c_str()); } } if ((posColuna == 2 && valorColuna.operator ==("dms")) || arquivoDMS) { arquivoDMS = true; if (posColuna == 3 && armazenarCoodenadas) { latitude = fileTxtConverteCoordenadasGrausMinutosSegundosParaGraus(valorColuna); } else if (posColuna == 4 && armazenarCoodenadas) { longitude = fileTxtConverteCoordenadasGrausMinutosSegundosParaGraus(valorColuna); } else if (posColuna == 5 && armazenarCoodenadas) { fileTxtConverteData(valorColuna, dia, mes, ano); } else if (posColuna == 6 && armazenarCoodenadas) { hora = atoi(valorColuna.toStdString().substr(0, 2).c_str()); minuto = atoi(valorColuna.toStdString().substr(3, 2).c_str()); segundo = atoi(valorColuna.toStdString().substr(6, 2).c_str()); } else if (posColuna == 7 && armazenarCoodenadas) { altitude = atof(valorColuna.toStdString().c_str()); } } } posColuna++; pos1 = pos2 + 1; } if (armazenarCoodenadas && ano != 0) { QDate dataSeg(ano, mes, dia); QTime horaSeg(hora, minuto, segundo); dataHora = new QDateTime(dataSeg, horaSeg); gpsPosition = new GpsPosition(latitude, longitude, altitude, dataHora); controlaPeriodoTracklog->insereGpsPosition(gpsPosition); if (dataFinal == NULL && dataInicial == NULL && ano != 0) { dataFinal = dataHora; dataInicial = dataHora; } else { if (dataHora->operator<(*dataInicial)) { dataInicial = dataHora; } if (dataHora->operator>(*dataFinal)) { dataFinal = dataHora; } } } } if (dataInicial != NULL && dataFinal != NULL && totalSegmentosTrackLog != 0) { peridoInicial.setDate(dataInicial->date()); peridoInicial.setTime(dataInicial->time()); peridoFinal.setDate(dataFinal->date()); peridoFinal.setTime(dataFinal->time()); segmentosLog = totalSegmentosTrackLog; return true; } else { return false; } }
//---------------------------------------------------------------------- bool outop(op_t &x) { switch ( x.type ) { case o_void: return 0; case o_reg: if ( ram != BADADDR ) { char buf[MAXSTR]; const char *name = get_name(cmd.ea, ram+x.reg, buf, sizeof(buf)); if ( name != NULL ) { out_register(name); break; } } out_register(ph.regNames[x.reg]); break; case o_imm: if ( cmd.itype == AVR_cbi || cmd.itype == AVR_sbic || cmd.itype == AVR_sbi || cmd.itype == AVR_sbis ) { const char *bit = find_bit(cmd.Op1.addr, (size_t)x.value); if ( bit != NULL ) { out_line(bit, COLOR_REG); break; } } if ( x.specflag1 && isOff1(uFlag) && !is_invsign(cmd.ea, uFlag, 1) ) { out_symbol('-'); } OutValue(x, OOFS_IFSIGN|OOF_SIGNED|OOFW_8); break; case o_near: { ea_t ea = toEA(cmd.cs, x.addr); if ( !out_name_expr(x, ea, x.addr) ) out_bad_address(x.addr); } break; case o_mem: { ea_t ea = toEA(dataSeg(), x.addr); if ( !out_name_expr(x, ea, x.addr) ) out_bad_address(x.addr); } break; case o_phrase: out_phrase(x.phrase); break; case o_displ: out_phrase(x.phrase); OutValue(x,OOF_ADDR|OOFS_NEEDSIGN|OOFW_IMM); break; case o_port: { const char *pname = find_port(x.addr); if ( pname == NULL ) out_bad_address(x.addr); else out_register(pname); } break; default: warning("out: %a: bad optype %d", cmd.ea, x.type); break; } return 1; }
LoadedModule* Loader::loadRPL(const std::string& name, const std::vector<uint8_t> data) { auto in = BigEndianView{ data.data(), data.size() }; std::map<std::string, void*> symbolsMap; // Read header auto header = elf::Header{}; if (!elf::readHeader(in, header)) { gLog->error("Failed elf::readHeader"); return nullptr; } // Check it is a CAFE abi rpl if (header.abi != elf::EABI_CAFE) { gLog->error("Unexpected elf abi found {:02x} expected {:02x}", header.abi, elf::EABI_CAFE); return nullptr; } // Read sections auto sections = std::vector<elf::XSection>{}; if (!elf::readSectionHeaders(in, header, sections)) { gLog->error("Failed elf::readSectionHeaders"); return nullptr; } // Read FileInfo data elf::FileInfo info; readFileInfo(in, sections, info); void *codeSegAddr = mCodeHeap->alloc(info.textSize, info.textAlign); assert(codeSegAddr); SequentialMemoryTracker codeSeg(codeSegAddr, info.textSize); void *dataSegAddr = nullptr; if (OSDynLoad_MemAlloc(info.dataSize, info.dataAlign, &dataSegAddr) != 0) { dataSegAddr = nullptr; } assert(dataSegAddr); SequentialMemoryTracker dataSeg(dataSegAddr, info.dataSize); void *loadSegAddr = mCodeHeap->alloc(info.loadSize, info.loadAlign); assert(loadSegAddr); SequentialMemoryTracker loadSeg(loadSegAddr, info.loadSize); // Allocate { std::vector<uint8_t> sectionData; for (auto& section : sections) { if (section.header.flags & elf::SHF_ALLOC) { if (section.header.type == elf::SHT_NOBITS) { sectionData.clear(); sectionData.resize(section.header.size, 0); } else { if (!elf::readSectionData(in, section.header, sectionData)) { gLog->error("Failed to decompressed allocatable section"); return nullptr; } } void *allocData = nullptr; if (section.header.type == elf::SHT_PROGBITS || section.header.type == elf::SHT_NOBITS) { if (section.header.flags & elf::SHF_EXECINSTR) { allocData = codeSeg.get(sectionData.size(), section.header.addralign); } else { allocData = dataSeg.get(sectionData.size(), section.header.addralign); } } else { allocData = loadSeg.get(sectionData.size(), section.header.addralign); } memcpy(allocData, sectionData.data(), sectionData.size()); section.virtAddress = allocData; section.virtSize = static_cast<uint32_t>(sectionData.size()); } } } // I am a bad person and I should feel bad std::map<void*, void*> trampolines; void * trampSegStart = codeSeg.getCurrentAddr(); auto getTramp = [&](void *target, const std::string& symbolName) { auto trampIter = trampolines.find(target); if (trampIter != trampolines.end()) { return trampIter->second; } uint32_t *trampAddr = static_cast<uint32_t*>(codeSeg.getCurrentAddr()); uint32_t *targetAddr = static_cast<uint32_t*>(target); intptr_t delta = reinterpret_cast<uint8_t*>(targetAddr) - reinterpret_cast<uint8_t*>(trampAddr); if (delta > -0x1fffffc && delta < 0x1fffffc) { trampAddr = static_cast<uint32_t*>(codeSeg.get(4)); // Short jump using b auto b = gInstructionTable.encode(InstructionID::b); b.li = delta >> 2; b.lk = 0; b.aa = 0; *trampAddr = byte_swap(b.value); } else if (gMemory.untranslate(targetAddr) < 0x03fffffc) {