Skip to content

Commit

Permalink
Add type variable to DecompiledObject. Connect DecompiledObject type …
Browse files Browse the repository at this point in the history
…to ObjectMapper type.

Fix shared_ptr in ObjectMapper.
Add example menu on list of decompiled objects.
  • Loading branch information
Thomas Epperson committed Apr 11, 2020
1 parent cfb15d2 commit 9115ad7
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 14 deletions.
12 changes: 12 additions & 0 deletions gui/Decompiler32/decompiledobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
DecompiledObject::DecompiledObject(QString file, QObject *parent) : QObject(parent)
{
name = file;
type = "Invalid";
emit name_changed();
emit type_changed();
}

void DecompiledObject::qml_register()
Expand All @@ -23,4 +25,14 @@ void DecompiledObject::give_stream(std::shared_ptr<QDataStream> ds)
{
stream = ds;
mapper = ObjectMapper::examine_object(ds);
connect(mapper.get(), &ObjectMapper::type_changed, this, &DecompiledObject::type_changed);
}

QString DecompiledObject::get_type()
{
if (mapper.get() != nullptr)
{
return mapper->get_type();
}
return "fdsasdf";
}
7 changes: 6 additions & 1 deletion gui/Decompiler32/decompiledobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class DecompiledObject : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ get_name NOTIFY name_changed) ///< The name of the object.
Q_PROPERTY(QString type READ get_type NOTIFY type_changed) ///< String describing the type of the object
public:
/*! Create a decompiled object with the given file.
* The file is the filename once it is copied to the project directory.
Expand All @@ -28,19 +29,23 @@ class DecompiledObject : public QObject

/*! Return the name of the object. */
QString get_name() { return name; }
/*! Return the type of the object. */
QString get_type();

/*! Give a datastream to the object that corresponds to a stream for the decompiled object.
* @param ds The datastream to use for reading the bytes of the object to decompile. */
void give_stream(std::shared_ptr<QDataStream> ds);
signals:
void name_changed(); ///< Triggered when the name changes.
void type_changed(); ///< The type of the object changed

protected:
QString name; ///< The name of the generated object
QString extension; ///< The extension of the generated object (if applicable)
QString type; ///< A string representing the type of the object. This is simply for convenience to the user.

std::shared_ptr<QDataStream> stream; ///< The data stream used to read data from the object.
std::shared_ptr<ObjectMapper *> mapper; ///< The mapper that allows us to get data from the object file
std::shared_ptr<ObjectMapper> mapper; ///< The mapper that allows us to get data from the object file
};

#endif // DECOMPILEDOBJECT_H
6 changes: 3 additions & 3 deletions gui/Decompiler32/dummyobjectmapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ DummyObjectMapper::DummyObjectMapper()

}

std::shared_ptr<ObjectMapper*> DummyObjectMapper::examine_object(std::shared_ptr<QDataStream> str)
std::shared_ptr<ObjectMapper> DummyObjectMapper::examine_object(std::shared_ptr<QDataStream> str)
{
std::shared_ptr<ObjectMapper*> ret = std::shared_ptr<ObjectMapper*>(nullptr);

std::shared_ptr<ObjectMapper> ret = std::shared_ptr<ObjectMapper>(static_cast<ObjectMapper*>(new DummyObjectMapper()));
ret->set_type("Dummy");
return ret;
}
4 changes: 2 additions & 2 deletions gui/Decompiler32/dummyobjectmapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#include <QObject>

/// A object mapper for demo purposes.
class DummyObjectMapper : ObjectMapper
class DummyObjectMapper : public ObjectMapper
{
Q_OBJECT
public:
DummyObjectMapper();
static std::shared_ptr<ObjectMapper*> examine_object(std::shared_ptr<QDataStream> str);
static std::shared_ptr<ObjectMapper> examine_object(std::shared_ptr<QDataStream> str);
};

#endif // DUMMYOBJECTMAPPER_H
16 changes: 15 additions & 1 deletion gui/Decompiler32/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ Window {
}
}

Menu {
id: contextMenu
Text { text: "Name: " + list.model[list.currentIndex].name }
Text { text: "Type: " + list.model[list.currentIndex].type }
MenuItem { text: "Cut " + list.currentIndex }
MenuItem { text: "Copy " + list.model[list.currentIndex].name }
MenuItem { text: "Paste" }
}

Column {
Text {
text: "Decompilation Objects (" + DecompileProject.Objects.length + ")"
Expand All @@ -45,7 +54,12 @@ Window {
}
MouseArea {
anchors.fill: parent
onClicked: list.currentIndex = index
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
list.currentIndex = index
if (mouse.button == Qt.RightButton)
contextMenu.popup()
}
}
}
highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
Expand Down
9 changes: 5 additions & 4 deletions gui/Decompiler32/objectmapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

#include <QQmlEngine>

std::vector<std::function<std::shared_ptr<ObjectMapper*>(std::shared_ptr<QDataStream>)>> ObjectMapper::examiners;
std::vector<std::function<std::shared_ptr<ObjectMapper>(std::shared_ptr<QDataStream>)>> ObjectMapper::examiners;

ObjectMapper::ObjectMapper(QObject *parent) : QObject(parent)
{

type = "Invalid";
emit type_changed();
}

void ObjectMapper::setup_examiners(void)
Expand All @@ -21,9 +22,9 @@ void ObjectMapper::qml_register()
qmlRegisterType<ObjectMapper>("uglyoldbob", 1, 0, "ObjectMapper");
}

std::shared_ptr<ObjectMapper*> ObjectMapper::examine_object(std::shared_ptr<QDataStream> str)
std::shared_ptr<ObjectMapper> ObjectMapper::examine_object(std::shared_ptr<QDataStream> str)
{
std::shared_ptr<ObjectMapper*> ret = std::shared_ptr<ObjectMapper*>(nullptr);
std::shared_ptr<ObjectMapper> ret = std::shared_ptr<ObjectMapper>(nullptr);
for (unsigned int i = 0; i < ObjectMapper::examiners.size(); i++)
{
ret = examiners[i](str);
Expand Down
13 changes: 10 additions & 3 deletions gui/Decompiler32/objectmapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,27 @@
class ObjectMapper : public QObject
{
Q_OBJECT
Q_PROPERTY(QString type READ get_type NOTIFY type_changed) ///< String describing the type of the object
public:
explicit ObjectMapper(QObject *parent = nullptr);
static void qml_register(); ///< This registers this class with QML
/*! \brief Examines an object using the specified QDataStream to try to determine what type of object it is.
* \param str The data stream for reading the contents of the object file.
* \return An instance of an ObjectMapper class if able to automatically determine the type
*/
static std::shared_ptr<ObjectMapper*> examine_object(std::shared_ptr<QDataStream> str);
static std::shared_ptr<ObjectMapper> examine_object(std::shared_ptr<QDataStream> str);
static void setup_examiners(void); ///< Setup all the examiners
/*! Return the type of the object. */
QString get_type() { return type; }

signals:
void set_type(QString t) { type = t; emit type_changed(); }

signals:
void type_changed(); ///< The type of the object changed
protected:
QString type; ///< A string representing the type of the object. This is simply for convenience to the user.
private:
static std::vector<std::function<std::shared_ptr<ObjectMapper*>(std::shared_ptr<QDataStream>)>> examiners; ///< The list of functions to examine an object.
static std::vector<std::function<std::shared_ptr<ObjectMapper>(std::shared_ptr<QDataStream>)>> examiners; ///< The list of functions to examine an object.
};

#endif // OBJECTMAPPER_H

0 comments on commit 9115ad7

Please sign in to comment.