biosandbox/biosandbox/BinFile.cpp
2025-12-28 13:56:24 -05:00

44 lines
782 B
C++

#include "BinFile.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
bio::BinFile::BinFile()
{
}
bio::BinFile::BinFile(std::string path)
{
LoadFile(path);
}
void bio::BinFile::LoadFile(std::string path)
{
std::ifstream fileHandle(path, std::ios::binary);
std::stringstream fileContentHandle;
fileContentHandle << fileHandle.rdbuf();
std::string file = fileContentHandle.str();
app.bufferLength = file.size();
app.buffer = (unsigned char*) malloc(app.bufferLength);
for (int i = 0; i < app.bufferLength; i++) {
app.buffer[i] = 0;
}
memcpy(app.buffer, file.data(), app.bufferLength);
bio::emu::symbol sym;
sym.offset = 0;
app.symbols.push_back(sym);
}
bio::BinFile::~BinFile()
{
free((void*)app.buffer);
app.symbols.clear();
}