ミラー
This commit is contained in:
83
src/hexeditor.hh
Normal file
83
src/hexeditor.hh
Normal file
@@ -0,0 +1,83 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <pdcurses.h>
|
||||
#else
|
||||
#include <ncurses.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class HexEditor {
|
||||
private:
|
||||
enum StatusMode : uint8_t {
|
||||
Status_Normal,
|
||||
Status_Command,
|
||||
Status_Search,
|
||||
Status_Replace,
|
||||
Status_Error,
|
||||
};
|
||||
|
||||
enum SearchDirection : uint8_t {
|
||||
Direction_Forward,
|
||||
Direction_Reverse,
|
||||
};
|
||||
|
||||
struct Edit {
|
||||
size_t offset;
|
||||
uint8_t oldByte;
|
||||
uint8_t newByte;
|
||||
};
|
||||
|
||||
struct FileSignature {
|
||||
std::vector<uint8_t> signature;
|
||||
std::string type;
|
||||
};
|
||||
|
||||
size_t curPos;
|
||||
size_t dpOffset;
|
||||
size_t bpr;
|
||||
StatusMode statusMode;
|
||||
bool modified;
|
||||
bool running;
|
||||
std::string lastSearch;
|
||||
|
||||
WINDOW *hexPanel;
|
||||
WINDOW *asciiPanel;
|
||||
std::vector<uint8_t> buf;
|
||||
std::string fname;
|
||||
int rows, cols;
|
||||
std::string statusText;
|
||||
std::vector<uint8_t> lastHexSearch;
|
||||
SearchDirection lastSearchDir;
|
||||
std::vector<size_t> matchOff;
|
||||
std::vector<Edit> undoStack;
|
||||
std::vector<Edit> redoStack;
|
||||
|
||||
size_t headerLen;
|
||||
std::string headerType;
|
||||
static const std::vector<FileSignature> signatures;
|
||||
|
||||
void render();
|
||||
void input();
|
||||
void highlightcol(size_t i, size_t row, uint8_t byte);
|
||||
void topbar();
|
||||
void statusbar();
|
||||
void handleCommand();
|
||||
void handleSave();
|
||||
void handleQuit(bool force);
|
||||
void handleSearch();
|
||||
void handleReverseSearch();
|
||||
void findNextMatch();
|
||||
void findPrevMatch();
|
||||
void handleReplace();
|
||||
void undo();
|
||||
void redo();
|
||||
|
||||
public:
|
||||
HexEditor(const std::string &filename);
|
||||
~HexEditor();
|
||||
|
||||
void run();
|
||||
};
|
||||
Reference in New Issue
Block a user