Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <sstream>
- #include <string>
- #include <iostream>
- #include <vector>
- template <typename T>
- T GetBigEndianBytes(char* pData)
- {
- T seg = 0;
- for (int i = 0; i < sizeof(T); i++) {
- seg = (seg << 8) + *reinterpret_cast<unsigned char*>(pData);
- pData++;
- }
- return seg;
- };
- template<typename T>
- void CuttingByteArray(std::ifstream& data, std::ofstream& output)
- {
- std::vector<std::pair<T, T>> blocks{};
- //std::vector<T> blocks{};
- int type_size = sizeof(T);
- int counter = 0;
- while (!data.eof())
- {
- char* le = new char[8];
- data.read(le , type_size);
- //data.seekg(counter, std::ios_base::beg);
- auto pair = std::make_pair(*reinterpret_cast<T*>(le), GetBigEndianBytes<T>(le));
- //blocks.push_back(*reinterpret_cast<T*>(le));
- blocks.push_back(pair);
- counter++;
- delete[] le;
- }
- std::string strBlocks = "";
- for (auto i : blocks)
- {
- strBlocks += "{" + std::to_string(i.first) + "," + std::to_string(i.second) + "}\n";
- // strBlocks += "{" + std::to_string(i) +"}";
- }
- output << strBlocks;
- //std::cout << strBlocks;
- };
- void CuttingByteArray(std::ifstream& data, std::ofstream& output)
- {
- std::vector<uint8_t> blocks{};
- while (!data.eof())
- {
- char* le = new char[1];
- data.read(le,1);
- blocks.push_back(*reinterpret_cast<char*>(le));
- delete[] le;
- }
- std::string strBlocks = "";
- for (auto i : blocks)
- {
- strBlocks += "{" + std::to_string(i) +"}";
- }
- output << strBlocks;
- };
- int main() {
- std::ifstream fileBuffer("C:\\Users\\trixter\\source\\repos\\BinPacketAnalyzer\\BinPacketAnalyzer\\1", std::ios::in | std::ios::binary);
- std::ofstream outputBuffer("Logi.txt", std::ios::out);
- if (!fileBuffer.is_open())
- {
- std::cerr << " Файл не открыт" << std::endl;
- }
- CuttingByteArray<uint8_t>(fileBuffer, outputBuffer);
- outputBuffer << "РАЗДЕЛЕНИЕ" << std::endl;
- CuttingByteArray<uint16_t>(fileBuffer, outputBuffer);
- outputBuffer.close();
- fileBuffer.close();
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement