Skip to content

Commit 0a5fe29

Browse files
committed
vbfeditor [add] replace section function
[fix] GetSectionRaw
1 parent 00f6fd5 commit 0a5fe29

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

VbfEditor/VbfFile.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ int VbfFile::SaveToFile(std::string file_path) {
310310
return 0;
311311
}
312312

313-
int VbfFile::GetSectionRaw(uint8_t section_idx, std::vector<uint8_t> section_data) {
313+
int VbfFile::GetSectionRaw(uint8_t section_idx, std::vector<uint8_t>& section_data) {
314314

315315
if(section_idx >= m_bin_sections.size()) {
316316
return -1;
@@ -322,3 +322,18 @@ int VbfFile::GetSectionRaw(uint8_t section_idx, std::vector<uint8_t> section_dat
322322

323323
return 0;
324324
}
325+
326+
int VbfFile::ReplaceSectionRaw(uint8_t section_idx, const vector<uint8_t> &section_data) {
327+
328+
if(section_idx >= m_bin_sections.size()) {
329+
return -1;
330+
}
331+
332+
auto sections_it = m_bin_sections.begin();
333+
std::advance(sections_it, section_idx);
334+
(*sections_it)->data = section_data;
335+
(*sections_it)->length = section_data.size();
336+
(*sections_it)->crc16 = CRC::Calculate(section_data.data(), section_data.size(), CRC::CRC_16_CCITTFALSE());
337+
338+
return 0;
339+
}

VbfEditor/VbfFile.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class VbfFile {
3434
int Export(const std::string& out_dir);
3535
int Import(const std::string& conf_file_path);
3636

37-
int GetSectionRaw(uint8_t section_idx, std::vector<uint8_t> section_data);
37+
int GetSectionRaw(uint8_t section_idx, std::vector<uint8_t>& section_data);
38+
int ReplaceSectionRaw(uint8_t section_idx,const std::vector<uint8_t>& section_data);
3839
};
3940

4041

0 commit comments

Comments
 (0)