/*this function loads the information from summary file and conclude it to a rule which stores in the min_rds and max_rds*/ void loadRuleFromFile(struct RECORD_S *min_rds, struct RECORD_S *max_rds, char *fileName) { struct FILE_INFO fileinfo; struct RECORD_S mean, overmean; int i; readFileInfo(fileName, &fileinfo); fread(&mean, sizeof(struct RECORD_S), 1, fileinfo.fp); fread(min_rds, sizeof(struct RECORD_S), 1, fileinfo.fp); fread(max_rds, sizeof(struct RECORD_S), 1, fileinfo.fp); fread(&overmean, sizeof(struct RECORD_S), 1, fileinfo.fp); for (i=0; i<FIELDS; i++) { if (overmean.elem[i] < fileinfo.rds_num*THRESHOLD) { min_rds->elem[i] = 0; max_rds->elem[i] = 1; } else { min_rds->elem[i] = mean.elem[i]*MINSHIFT; } } fclose(fileinfo.fp); }
ZipReader::ZipReader(const QString& filename) { m_archive = zip_open(QFile::encodeName(filename), 0, 0); if (m_archive) { readFileInfo(); } }
/************************************************************ * 功能 : 读取xx.xml中的信息 显示在界面 * 输入 : 无 * 返回值 : void *************************************************************/ void CreatModel::showAllInfo() { m_fileInfo = QStringList(); if (m_root.isElement()) { QString sName = m_root.attributeNode("name").value(); QString sId = m_root.attributeNode("id").value(); QString sVersion = m_root.attributeNode("version").value(); QString sSubject = m_root.attributeNode("subject").value(); QString sType = m_root.attributeNode("type").value(); QString sProperty = m_root.attributeNode("property").value(); QString sGroup = m_root.attributeNode("group").value(); QString sDescription = m_root.attributeNode("description").value(); QString sAuthor = m_root.attributeNode("author").value(); QString sLog = m_root.attributeNode("log").value(); QString sUpdate = m_root.attributeNode("update_date").value(); ledit_modelName->setText(sName); ledit_modelId->setText(sId); lb_modelId->setEnabled(true); ledit_modelId->setEnabled(true); ledit_modelId->setReadOnly(true); ledit_version->setText(sVersion); lb_version->setEnabled(true); ledit_version->setEnabled(true); ledit_version->setReadOnly(true); ledit_subject->setText(sSubject); int typeIndex = combox_type->findText(sType); combox_type->setCurrentIndex(typeIndex); int proIndex = combox_property->findText(sProperty); combox_property->setCurrentIndex(proIndex); int groupIndex = combox_group->findText(sGroup); combox_group->setCurrentIndex(groupIndex); ledit_descript->setText(sDescription); ledit_author->setText(sAuthor); tedit_log->setText(sLog); date_update->setDate(QDate::fromString(sUpdate, "yyyy-M-d")); } QDomNode n = m_root.firstChild(); QString sAllInfo = ""; while (!n.isNull()) { if (n.isElement()) { QString fileName = n.toElement().attributeNode("name").value(); QString filePath = n.toElement().attributeNode("path").value(); QString fileDescript = n.toElement().attributeNode("description").value(); sAllInfo = fileName + ";" + fileDescript + ";" + filePath; } n = n.nextSibling(); m_fileInfo.append(sAllInfo); } readFileInfo(m_fileInfo); }
/*this function pick every rule from specified dir, and apply this rule to a target file.*/ void applyRulesToDir(char *dirName, char *targetFileName) { DIR *dp; struct dirent *ep; char tmpdirname[DIRNAME_LEN], tmpstr[DIRNAME_LEN]; struct FILE_INFO fileinfo; FILE *match_fp; struct RULE ruleset[RULES_PER_SET]; int rules_num; dp = opendir (dirName); if (dp == NULL) { printf("ERR: Couldn't open the directory\n"); return; } else { memset(tmpdirname, 0, DIRNAME_LEN); strcpy(tmpdirname, dirName); tmpdirname[strlen(dirName)] = '/'; while (ep = readdir(dp)) { printf("%s \n", ep->d_name); if (strstr(ep->d_name, "Optimized")) { memset(tmpstr, 0, DIRNAME_LEN); strcpy(tmpstr, tmpdirname); strcat(tmpstr, ep->d_name); /*read this file's info*/ if (rules_num < RULES_PER_SET) { loadRuleFromFile(&ruleset[rules_num].min, &ruleset[rules_num].max, tmpstr); } strcat(tmpstr, MATCH_SUFFIX); ruleset[rules_num].fp = fopen(tmpstr, "w+"); if (ruleset[rules_num].fp == NULL) { printf("ERR: cannot create file [%s]\n", tmpstr); return; } rules_num++; } } closedir (dp); readFileInfo(targetFileName, &fileinfo); applyRulesToFile(&fileinfo, ruleset); fclose(fileinfo.fp); } }
int main(int argc, char* argv[]) { char newFileName[DIRNAME_LEN], string[16]; struct FILE_INFO fileinfo; int suffix = 0, rds_num = 0, tmp; struct RECORD_S memblock[4000]; FILE *fp; /*parse argument*/ if (argc != 2) { return 1; } readFileInfo(argv[1], &fileinfo); while (rds_num < fileinfo.rds_num) { memset(newFileName, 0, DIRNAME_LEN); strcpy(newFileName, argv[1]); itoa(suffix, string); strcat(newFileName, string); suffix++; fp = fopen(newFileName, "w+"); if (fp == NULL) { printf("ERR: cannot create file [%s]\n", newFileName); } if (rds_num + 4000 < fileinfo.rds_num) { tmp = 4000; fread(&memblock, sizeof(struct RECORD_S), tmp, fileinfo.fp); fwrite(&memblock, sizeof(struct RECORD_S), tmp, fp); fwrite(&tmp, sizeof(int), 1, fp); rds_num += tmp; } else { tmp = fileinfo.rds_num - rds_num; fread(&memblock, sizeof(struct RECORD_S), tmp, fileinfo.fp); fwrite(&memblock, sizeof(struct RECORD_S), tmp, fp); rds_num = fileinfo.rds_num; } fclose(fp); } fclose(fileinfo.fp); //printMathRds(argv[1]); printf("rds_num=[%d]\n", fileinfo.rds_num); return 0; }
ZipReader::ZipReader(QIODevice* device) : m_archive(0) { QFile* file = qobject_cast<QFile*>(device); if (file) { m_archive = zip_fdopen(file->handle(), 0, 0); if (m_archive) { readFileInfo(); } } }
foreach(file_path, unknown_file_paths){ file_was_renamed = false; FileInfo unknown_fi = readFileInfo(file_path); foreach(QString missing_file_path, missing_file_paths){ QCoreApplication::processEvents(); FileInfo missing_fi = state->fileInfoByFilePath(missing_file_path); if (missing_fi.isIdenticalTo(unknown_fi)){ // this unknown file is actually a missing file renamed file_was_renamed = true; missing_file_paths.removeAll(missing_file_path); unknown_file_paths.removeAll(file_path); diff.renameFile(missing_file_path, file_path); } }
int main (int argc, char *argv[]) { int ret = 0; CString info; #ifdef FOR_ADSP_RELEASE doReadSvnLog(); #endif ret = readFileInfo(info); if (0 != ret) { TRACE(_T("readFileInfo exit -1\n")); return -1; } praseVersionInfo(info); CCreateHeaderFile::createFile(gpVersionInfo); deleteTempFile(); return 0; }
/*Calculate the mean, min max value and count overmean number from attack records. We only check the attack file with more than 20 records.*/ void recordsDir(char *dirName) { DIR *dp; struct dirent *ep; char tmpdirname[DIRNAME_LEN], tmpstr[DIRNAME_LEN]; struct FILE_INFO fileinfo; struct RECORD_S min_rds, max_rds, mean_rds, overmean, temp; int i,j; FILE *sum_fp; dp = opendir (dirName); if (dp == NULL) { printf("ERR: Couldn't open the directory\n"); return; } else { memset(tmpdirname, 0, DIRNAME_LEN); strcpy(tmpdirname, dirName); tmpdirname[strlen(dirName)] = '/'; //printMemRds(&overmean); //printMemRds(&mean_rds); //printMemRds(&min_rds); //printMemRds(&max_rds); while (ep = readdir(dp)) { printf("%s \n", ep->d_name); if (strstr(ep->d_name, "Optimized")) { memset(tmpstr, 0, DIRNAME_LEN); strcpy(tmpstr, tmpdirname); strcat(tmpstr, ep->d_name); /*read this file's info*/ readFileInfo(tmpstr, &fileinfo); memset(&overmean, 0, sizeof(struct RECORD_S)); memset(&mean_rds, 0, sizeof(struct RECORD_S)); memsetFlt((float *)&min_rds, 2, FIELDS); memsetFlt((float *)&max_rds, -1, FIELDS); /*iterate file to get min, max and mean*/ for (i=0; i<fileinfo.rds_num; i++) { fread(&temp, sizeof(struct RECORD_S), 1, fileinfo.fp); for (j=0; j<FIELDS; j++) { if (temp.elem[j] < min_rds.elem[j]) { min_rds.elem[j] = temp.elem[j]; } if (temp.elem[j] > max_rds.elem[j]) { max_rds.elem[j] = temp.elem[j]; } mean_rds.elem[j] += temp.elem[j]; } } for (i=0; i<FIELDS; i++) { mean_rds.elem[i] = mean_rds.elem[i]/fileinfo.rds_num; } /*get overmean*/ rewind(fileinfo.fp); for (i=0; i<fileinfo.rds_num; i++) { fread(&temp, sizeof(struct RECORD_S), 1, fileinfo.fp); for (j=0; j<FIELDS; j++) { if (temp.elem[j] > mean_rds.elem[j]) { overmean.elem[j]++; } } } /*write min, max, mean and overmean*/ strcat(tmpstr, SUMMARY_SUFFIX); sum_fp = fopen(tmpstr, "w+"); if (sum_fp == NULL) { printf("ERR: cannot create file [%s]\n", tmpstr); return; } fwrite(&mean_rds, sizeof(struct RECORD_S), 1, sum_fp); fwrite(&min_rds, sizeof(struct RECORD_S), 1, sum_fp); fwrite(&max_rds, sizeof(struct RECORD_S), 1, sum_fp); fwrite(&overmean, sizeof(struct RECORD_S), 1, sum_fp); fwrite(&fileinfo.rds_num, sizeof(int), 1, sum_fp); } } closedir (dp); } }
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) {