char *RawDataEncoder::encode(int seq, int &sz) { char *p = m_buf; { int n; char *h = getHeader(seq, n); memcpy(p, h, n); p += n; } if (seq == 0) { int n; char *pp = getDataHeader(n); memcpy(p, pp, n); p += n; } else { // Image data int N = packetNum(); int datalen = 0; if (seq + 1 < N) { datalen = UNIT_DATA_SIZE; } else { // last packet int datasize = getDataLen(); int left = datasize % UNIT_DATA_SIZE; datalen = left != 0? left: UNIT_DATA_SIZE; } BINARY_SET_DATA_S_INCR(p, unsigned short, datalen); char *data = getData(); char *pp = data + UNIT_DATA_SIZE*(seq-1); memcpy(p, pp, datalen); p += datalen; } { int n; char *f = getFooter(n); memcpy(p, f, n); p += n; } sz = p - m_buf; setPacketSize(m_buf, sz); return m_buf; }
char *NoDataEncoder::encode(int seq, int &sz) { int n; char *p = m_buf; char *h = getHeader(seq, n); memcpy(p, h, n); p += n; char *f = getFooter(n); memcpy(p, f, n); p += n; sz = p - m_buf; setPacketSize(m_buf, sz); return m_buf; }
QString MidiTable::patchRequest(int bank, int patch) { bool ok; QString addr1, addr2; if((bank != 0 && patch != 0) && bank <= bankTotalUser) { int patchOffset = (((bank - 1 ) * patchPerBank) + patch) - 1; if(bank > bankTotalUser) patchOffset += 87; int addrMaxSize = 128; int n = (int)(patchOffset / addrMaxSize); addr1 = QString::number(32 + n, 16).toUpper(); addr2 = QString::number(patchOffset - (addrMaxSize * n), 16).toUpper(); } else { addr1 = tempDataWrite; addr2 = "00"; }; if (addr1.length() < 2) addr1.prepend("0"); if (addr2.length() < 2) addr2.prepend("0"); QString hex1 = "00"; QString hex2 = "00"; QString sysxMsg; sysxMsg.append(getHeader(true)); sysxMsg.append(addr1); sysxMsg.append(addr2); sysxMsg.append(hex1); sysxMsg.append(hex2); sysxMsg.append(patchRequestDataSize); //(getSize()); int dataSize = 0; for(int i=checksumOffset;i<sysxMsg.size()-1;++i) { dataSize += sysxMsg.mid(i*2, 2).toInt(&ok, 16); }; sysxMsg.append(getCheckSum(dataSize)); sysxMsg.append(getFooter()); return sysxMsg; }
char *DisplayText::encode(int seq, int &sz) { int n; char *p = m_buf; { char *h = getHeader(seq, n); memcpy(p, h, n); p += n; } { BINARY_SET_DATA_S_INCR(p, short, m_fs); BINARY_SET_DATA_S_INCR(p, short, m_color); BINARY_SET_STRING_INCR(p, m_msg.c_str()); } { char *f = getFooter(n); memcpy(p, f, n); p += n; } sz = p - m_buf; setPacketSize(m_buf, sz); return m_buf; }
/* checkheap: Returns 0 if no errors were found, * otherwise returns the error */ int mm_checkheap(int verbose) { char *firstList = heap_listp + DSIZE; char *lastList = firstList + (LISTNUM-1) * DSIZE; char *curBlock = heap_listp + DSIZE; size_t size = getSize(getHeader(curBlock)); int freeCountHeap = 0; int freeCountList = 0; char *nextFreePtr; char *list; char *ptr; int s,a; size_t prevAlloc; verbose = verbose; /* check alignment padding*/ if (get(mem_heap_lo()) != 0) { printf("Alignment padding error!\n"); } /* check prologue */ if (!getAlloc(getHeader(heap_listp+DSIZE))) { printf("Prologue error!\n"); } /* Check the heap */ while (size != 0){ // Check whether the block is in heap if (!inHeap(curBlock)){ dbg_printf("Block %p is not in the heap\n", curBlock); } // Check each blk's address alignment if (!aligned(curBlock)) { dbg_printf("Block %p is not aligned.\n", curBlock); exit(0); } if (!getAlloc(getHeader(curBlock))){ freeCountHeap ++; // Check each blk's header and footer s = (getSize(getHeader(curBlock)) == getSize(getFooter(curBlock))); a = (getAlloc(getHeader(curBlock)) == getAlloc(getFooter(curBlock))); if (!s || !a) { dbg_printf("Header&Footer does not match in %p\n", curBlock); } // Check coalescing prevAlloc = getPrevAlloc(getHeader(curBlock)); if (!prevAlloc){ dbg_printf("Coalescing error! \n"); } } curBlock = nextBlock(curBlock); size = getSize(getHeader(curBlock)); } /* Check the free list */ for (list = firstList; list != (char *)lastList + DSIZE; list = (char *)list + DSIZE){ for (ptr = nextFree(list); ptr != list; ptr = nextFree(ptr)){ // Check the free list node is in heap if (!inHeap(ptr)){ dbg_printf("list node %p is not in the heap\n", ptr); } freeCountList ++; nextFreePtr = nextFree(ptr); // Check all next/prev pointers are consistent if (prevFree(nextFreePtr) != (ptr)){ dbg_printf("next/prev pointers is not consistent!\n"); } } } // Check free blocks by iterating thru every blk and traversing // free list by pointers and see if they match. if (freeCountHeap != freeCountList){ dbg_printf("Free block count does not match!\n"); } return 0; }
bool RecordFrame::isValid() { return mightBeHeader() && mightBeHeaderOf(getFooter()); }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); IO::IODevicePtr src_device = nullptr; if (argc == param_count) { uint64_t start_offset = 0; std::string offset_txt(argv[offset_param]); if (offset_txt.compare(offset_str) == 0) { start_offset = boost::lexical_cast<uint64_t>(argv[offset_value]); qInfo() << "offset : " << start_offset <<"(sectors)"; } std::string disk_file_string(argv[disk_file_param]); if (disk_file_string.compare(d_str) == 0) { auto drive_number = boost::lexical_cast<uint32_t>(argv[source_value]); auto drive_list = IO::ReadPhysicalDrives(); auto physical_drive = drive_list.find_by_number(drive_number); start_offset *= physical_drive->getBytesPerSector(); if (physical_drive) { qInfo() << "You selected"; qInfo() << "Number : " << drive_number; qInfo() << "Name :" << physical_drive->getDriveName().c_str(); qInfo() << "Serial number : " << physical_drive->getSerialNumber().c_str(); qInfo() << "Size : " << physical_drive->getSize() << "(bytes)"; } src_device = std::make_shared<IO::DiskDevice>(physical_drive); } else if (disk_file_string.compare(f_str) == 0) { std::string src_path = argv[source_value]; src_device = IO::makeFilePtr(IO::path_string(src_path.begin(), src_path.end())); start_offset *= default_sector_size; } if (!src_device->Open(IO::OpenMode::OpenRead)) { qInfo() << "Error open source device."; return -1; } std::string targer_path = argv[target_value]; IO::path_string target_folder(targer_path.begin(), targer_path.end()); if (!src_device) return -1; ////////////////////////////////////////////////////////////////////////// QList<JsonFileStruct> listFileStruct; QFile file("video.json"); if (!file.open(QIODevice::ReadOnly)) { qInfo() << "Error to open file. \"" << file.fileName() << "\""; return -1; } auto json_str = file.readAll(); ReadJsonFIle(json_str, listFileStruct); if ( listFileStruct.empty()) { qInfo() << "Error to read" << file.fileName() << "file. Wrong syntax."; return -1; } IO::HeaderBase::Ptr headerBase = std::make_shared<IO::HeaderBase>(); for (auto theFileStruct : listFileStruct) headerBase->addFileFormat(toFileStruct(theFileStruct)); IO::RawFactoryManager factory_manager; initFactoryMananger(factory_manager); IO::SignatureFinder signatureFinder(src_device, headerBase); //uint64_t start_offset = 0x0; uint64_t header_offset = 0; uint32_t counter = 0; while (start_offset < src_device->Size()) { auto file_struct = signatureFinder.findHeader(start_offset, header_offset); if (!file_struct) { qInfo() << endl << endl << endl << "No more signatures found. Press any key to exit."; break; } qInfo() << "Found signature for [" << file_struct->getName().c_str() << "] file."; qInfo() << "Offset : " << header_offset << "(bytes)"; start_offset = header_offset; auto raw_factory = factory_manager.Lookup(file_struct->getName()); IO::RawAlgorithm * raw_algorithm = nullptr; if (!raw_factory) { IO::StandartRaw * standard_raw = new IO::StandartRaw(src_device); standard_raw->setMaxFileSize(file_struct->getMaxFileSize()); standard_raw->setFooter(file_struct->getFooter(), file_struct->getFooterTailEndSize()); standard_raw->setFooterOffsetSearchBlock(4, 4096); raw_algorithm = standard_raw; } else { raw_algorithm = raw_factory->createRawAlgorithm(src_device); } if (raw_algorithm->Specify(header_offset)) { auto target_file = IO::offsetToPath(target_folder, header_offset, file_struct->getExtension(), 512); auto dst_file = IO::makeFilePtr(target_file); if (dst_file->Open(IO::OpenMode::Create)) { auto target_size = raw_algorithm->SaveRawFile(*dst_file, header_offset); if ( target_size == 0) { qInfo() << "Error to save file. Exit." ; //break; } auto dst_size = dst_file->Size(); dst_file->Close(); qInfo() << "Successfully saved " << target_size << "(bytes)" << endl << endl; uint64_t jump_size = default_sector_size; if ( raw_algorithm->Verify(target_file) ) { target_size /= default_sector_size; target_size *= default_sector_size; ////////////////////////////////////////////////////////////////////////// jump_size = target_size; } else { // remove file IO::path_string new_fileName = target_file + L".bad_file"; boost::filesystem::rename(target_file, new_fileName); //{ // qInfo() << "File" << target_file.c_str() << "was removed." << endl; //} //else // qInfo() << "File" << target_file.c_str() << "Error to delete." << endl; } //if (jump_size == 0) jump_size = default_sector_size; start_offset = header_offset + jump_size; } else { qInfo() << "Error to create target file." << QString::fromStdWString(target_file); qInfo() << "Exit."; break; } } else { qInfo() << "Not specified for " << QString::fromStdString(file_struct->getName()) << "continue search for other signatures."<<endl; start_offset += default_sector_size; } if ( raw_algorithm) delete raw_algorithm; } } else qInfo() << "Wrong params"; return a.exec(); }