This repository was archived by the owner on Sep 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathhexedit.h
More file actions
206 lines (179 loc) · 6.82 KB
/
Copy pathhexedit.h
File metadata and controls
206 lines (179 loc) · 6.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
* Copyright 2016 CodiLime
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#pragma once
#include <functional>
#include <QAbstractScrollArea>
#include <QItemSelectionModel>
#include <QMenu>
#include <QMouseEvent>
#include <QStringList>
#include "ui/createchunkdialog.h"
#include "ui/fileblobmodel.h"
#include "ui/gotoaddressdialog.h"
#include "util/edit.h"
#include "util/encoders/hex_encoder.h"
#include "util/encoders/text_encoder.h"
#include "util/settings/shortcuts.h"
namespace veles {
namespace ui {
class HexEdit : public QAbstractScrollArea {
Q_OBJECT
public:
HexEdit(FileBlobModel *dataModel,
QItemSelectionModel *selectionModel = nullptr, QWidget *parent = 0);
/** Mark bytes as selected and optionally scroll screen to make these bytes visible */
void setSelection(qint64 start, qint64 size, bool set_visible = false);
/** Sets how many bytes should be displayed in the single hex row or optionaly
* turn on automatic mode which will adjust bytes per row to window size */
void setBytesPerRow(int bytesCount, bool automatic = false);
/** Scroll screen to make byte visible */
void scrollToByte(qint64 bytePos, bool minimal_change = false);
void scrollRows(qint64 num_rows);
FileBlobModel *dataModel() { return dataModel_;};
void setParserIds(QStringList ids);
void processEditEvent(QKeyEvent *event);
uint64_t byteValue(qint64 pos, bool modified = true);
void setBytesValues(qint64 pos, const data::BinData& new_data);
public slots:
void newBinData();
void dataChanged();
void modelSelectionChanged();
void applyChanges();
void undo();
void discardChanges();
protected:
void paintEvent(QPaintEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseDoubleClickEvent(QMouseEvent *event) override;
void contextMenuEvent(QContextMenuEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
bool focusNextPrevChild(bool next) override;
signals:
void selectionChanged(qint64 start_addr, qint64 selection_size);
void editStateChanged(bool has_changes, bool has_undo);
void visibleRegionChanged(qint64 start_addr, qint64 region_size);
private:
FileBlobModel *dataModel_;
uint32_t bindata_width_;
QItemSelectionModel *chunkSelectionModel_;
/** Total number of bytes in the blob */
qint64 dataBytesCount_;
/** Number of bytes displayed in singled hex edit row */
qint64 bytesPerRow_;
/** Indicates if bytes per row should be automatically adjusted to window width */
bool autoBytesPerRow_;
/** Byte offset of whole blob */
qint64 startOffset_;
/** Total number of rows in hex edit (counting last address only row) */
qint64 rowsCount_;
/** Number of rows displayed on the screen )calculated from window and font height) */
qint64 rowsOnScreen_;
/** Number of hex chars used to display one byte */
qint64 byteCharsCount_;
/** maximum value of byte */
quint64 byte_max_value_;
/** Number of pixels between two bytes in hex view (calculated from char width) */
qint64 spaceAfterByte_;
/** Width of single character in pixels */
qint64 charWidht_;
/** Height of single character in pixels */
qint64 charHeight_;
/** Number of pixels between two bytes (vertically) in hex view (calculated from char height) */
qint64 verticalByteBorderMargin_;
/** Number of bytes (8 bit) used to represent offset addr */
qint64 addressBytes_;
/** Width in pixels of address area */
qint64 addressWidth_;
/** Width in pixles of hex area */
qint64 hexAreaWidth_;
/** Width in pixels of ascii area */
qint64 asciiWidth_;
/** Height in pixels of area separator */
qint64 lineWidth_;
/** Number of first row displayed on the screen */
qint64 startRow_;
/** Number of first pixel from left which should be displayed on the screen */
qint64 startPosX_;
enum class WindowArea {
ADDRESS,
HEX,
ASCII,
OUTSIDE,
};
/** Number of byte where selection starts (counting from beginning of blob) */
qint64 current_position_;
/** Number of bytes in selection */
qint64 selection_size_;
WindowArea current_area_;
qint64 cursor_pos_in_byte_;
bool cursor_visible_;
CreateChunkDialog *createChunkDialog_;
GoToAddressDialog *goToAddressDialog_;
QAction *createChunkAction_;
QAction *createChildChunkAction_;
QAction *removeChunkAction_;
QAction *goToAddressAction_;
QAction *saveSelectionAction_;
QStringList parsers_ids_;
QMenu menu_;
QMenu parsers_menu_;
QTimer cursor_timer_;
QScopedPointer<util::encoders::HexEncoder> hexEncoder_;
QScopedPointer<util::encoders::TextEncoder> textEncoder_;
util::EditEngine edit_engine_;
qint64 visible_region_start_;
qint64 visible_region_size_;
void recalculateValues();
void initParseMenu();
void adjustBytesPerRowToWindowSize();
QRect bytePosToRect(qint64 pos, bool ascii = false, qint64 char_pos = 0);
qint64 pointToRowNum(QPoint pos);
qint64 pointToColumnNum(QPoint pos);
qint64 pointToBytePos(QPoint pos);
void flipCursorVisibility();
WindowArea pointToWindowArea(QPoint pos);
QString addressAsText(qint64 pos);
QString hexRepresentationFromBytePos(qint64 pos);
QString asciiRepresentationFromBytePos(qint64 pos);
void setByteValue(qint64 pos, uint64_t byte_value);
QColor byteTextColorFromPos(qint64 pos);
QColor byteBackroundColorFromPos(qint64 pos);
qint64 selectionStart();
qint64 selectionEnd();
qint64 selectionSize();
QModelIndex selectedChunk();
void createAction(util::settings::shortcuts::ShortcutType type, const std::function<void()>& f);
void getRangeFromIndex(QModelIndex index, qint64 *begin, qint64 *size);
void drawBorder(qint64 start, qint64 size, bool asciiArea = false,
bool doted = false);
void setSelectedChunk(QModelIndex newSelectedChunk);
bool isRangeVisible(qint64 start, qint64 size);
bool isByteVisible(qint64 bytePos);
void setSelectionEnd(qint64 bytePos);
void saveSelectionToFile(QString path);
void scrollToCurrentChunk();
void parse(QAction *action);
void resetCursor();
void transferChanges(data::BinData& bin_data, qint64 offset_shift = 0, qint64 max_bytes = -1);
private slots:
void copyToClipboard(util::encoders::IEncoder *enc = nullptr);
void pasteFromClipboard(util::encoders::IDecoder* enc = nullptr);
};
} // namespace ui
} // namespace veles