Skip to content

Commit

Permalink
implemented core functionality required to work on issue #484
Browse files Browse the repository at this point in the history
  • Loading branch information
eteran committed May 24, 2017
1 parent 2f1388e commit b211a8d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/IProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class IProcess {
virtual QList<std::shared_ptr<IThread>> threads() const = 0;
virtual std::shared_ptr<IThread> current_thread() const = 0;
virtual std::size_t write_bytes(edb::address_t address, const void *buf, size_t len) = 0;
virtual std::size_t patch_bytes(edb::address_t address, const void *buf, size_t len) = 0;
virtual std::size_t read_bytes(edb::address_t address, void *buf, size_t len) const = 0;
virtual std::size_t read_pages(edb::address_t address, void *buf, size_t count) const = 0;
virtual void pause() = 0;
Expand Down
27 changes: 27 additions & 0 deletions plugins/DebuggerCore/unix/linux/PlatformProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,33 @@ std::size_t PlatformProcess::read_bytes(edb::address_t address, void* buf, std::
return read;
}

//------------------------------------------------------------------------------
// Name: patch_bytes
// Desc: same as write_bytes, except that it also records the original data
// that was found at the address being written to.
// Note: unlike the read_bytes, write_bytes functions, this will not apply the
// write if we could not properly backup <len> bytes as requested.
// Note: on the off chance that we can READ <len> bytes, but can't WRITE <len>
// bytes, we will return the number of bytes written, but record <len>
// bytes of patch data.
//------------------------------------------------------------------------------
std::size_t PlatformProcess::patch_bytes(edb::address_t address, const void *buf, size_t len) {
Q_ASSERT(buf);
Q_ASSERT(core_->process_ == this);

QByteArray orig_bytes;
orig_bytes.resize(len);

size_t read_ret = read_bytes(address, orig_bytes.data(), len);
if(read_ret != len) {
return 0;
}

patches_.insert(address, orig_bytes);

return write_bytes(address, buf, len);
}

//------------------------------------------------------------------------------
// Name: write_bytes
// Desc: writes <len> bytes from <buf> starting at <address>
Expand Down
10 changes: 6 additions & 4 deletions plugins/DebuggerCore/unix/linux/PlatformProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class PlatformProcess : public IProcess {

public:
virtual std::size_t write_bytes(edb::address_t address, const void *buf, size_t len) override;
virtual std::size_t patch_bytes(edb::address_t address, const void *buf, size_t len) override;
virtual std::size_t read_bytes(edb::address_t address, void *buf, size_t len) const override;
virtual std::size_t read_pages(edb::address_t address, void *buf, size_t count) const override;

Expand All @@ -73,10 +74,11 @@ class PlatformProcess : public IProcess {
void write_byte_via_ptrace(edb::address_t address, quint8 value, bool *ok);

private:
DebuggerCore* core_;
edb::pid_t pid_;
QFile* ro_mem_file_;
QFile* rw_mem_file_;
DebuggerCore* core_;
edb::pid_t pid_;
QFile* ro_mem_file_;
QFile* rw_mem_file_;
QMap<edb::address_t, QByteArray> patches_;
};

}
Expand Down

0 comments on commit b211a8d

Please sign in to comment.