Skip to content

Commit

Permalink
Merge branch 'auto_add_imp' (Issue #16)
Browse files Browse the repository at this point in the history
  • Loading branch information
hasherezade committed Feb 5, 2023
2 parents 2e5624a + 3a0dce7 commit 34c70c4
Show file tree
Hide file tree
Showing 14 changed files with 738 additions and 74 deletions.
41 changes: 41 additions & 0 deletions build_codelite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
echo "Trying to build PE-bear..."

#QT check

QT_VER=`qmake -v`
str=$QT_VER
substr="Qt version 5"

echo $QT_VER
if [[ $str == *"$substr"* ]]; then
echo "[+] Qt5 found!"
else
str2=`whereis qt5`
substr2="/qt5"
if [[ $str2 == *"$substr2"* ]]; then
echo "[+] Qt5 found!"
else
echo "Install Qt5 SDK first"
exit -1
fi
fi


CMAKE_VER=`cmake --version`
CMAKEV="cmake version"
if echo "$CMAKE_VER" | grep -q "$CMAKEV"; then
echo "[+] CMake found!"
else
echo "[-] CMake NOT found!"
echo "Install cmake first"
exit -1
fi
echo $CMAKE_VER
mkdir build_qt5
echo "[+] build directory created"
cd build_qt5
cmake -G"CodeLite - Unix Makefiles" -DCMAKE_INSTALL_PREFIX:PATH=$(pwd) ..
cmake --build . --target install
make
cd ..

3 changes: 3 additions & 0 deletions pe-bear/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ set (pebear_base_hdrs
base/PeHandlerFactory.h
base/PeHandlersManager.h
base/RegKeyManager.h
base/ImportsAutoadderSettings.h
)

set (pebear_gui_base_srcs
Expand Down Expand Up @@ -188,6 +189,7 @@ set (pebear_windows_srcs
gui/windows/OffsetsBrowseWindow.cpp
gui/windows/SignaturesBrowseWindow.cpp
gui/windows/SectionAddWindow.cpp
gui/windows/ImportsAddWindow.cpp
gui/windows/UserConfigWindow.cpp
gui/windows/DiffWindow.cpp
gui/windows/MainWindow.cpp
Expand All @@ -197,6 +199,7 @@ set (pebear_windows_hdrs
gui/windows/OffsetsBrowseWindow.h
gui/windows/SignaturesBrowseWindow.h
gui/windows/SectionAddWindow.h
gui/windows/ImportsAddWindow.h
gui/windows/UserConfigWindow.h
gui/windows/DiffWindow.h
gui/windows/MainWindow.h
Expand Down
2 changes: 1 addition & 1 deletion pe-bear/REbear.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define TITLE "PE-bear"
#define V_MAJOR 0
#define V_MINOR 6
#define V_PATCH 1
#define V_PATCH 2
#define V_PATCH_SUB 0
#define V_DESC ""

Expand Down
1 change: 1 addition & 0 deletions pe-bear/application.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@
<file>icons/reload.ico</file>
<file>icons/dump.ico</file>
<file>icons/information.ico</file>
<file>icons/magic_wand.ico</file>
</qresource>
</RCC>
70 changes: 70 additions & 0 deletions pe-bear/base/ImportsAutoadderSettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#pragma once

#include <QtCore>
//---

struct ImportsAutoadderSettings
{
ImportsAutoadderSettings() : addNewSec(false) {}

bool addImport(const QString &dll, const QString &func)
{
if (dll.length() == 0 || func.length() == 0) return false;
if (dllFunctions.contains(dll)) {
if (dllFunctions[dll].contains(func)) return false; // already exists
}
dllFunctions[dll].append(func);
return true;
}

bool removeImport(const QString &dll, const QString &func)
{
if (!dllFunctions.contains(dll)) {
return false;
}
if (!dllFunctions[dll].contains(func)) {
return false;
}
dllFunctions[dll].removeAll(func);
if (dllFunctions[dll].size() == 0) {
dllFunctions.remove(dll);
}
return true;
}

size_t calcDllNamesSpace() const
{
size_t areaSize = 0;
for (auto itr = dllFunctions.begin(); itr != dllFunctions.end(); ++itr) {
const QString dllName = itr.key();
areaSize += dllName.length() + 1;
}
return areaSize;
}

size_t calcFuncNamesSpace() const
{
size_t areaSize = 0;
for (auto dItr = dllFunctions.begin(); dItr != dllFunctions.end(); ++dItr) {
const QStringList funcs = dItr.value();
for (auto fItr = funcs.begin(); fItr != funcs.end(); ++fItr) {
const QString func = *fItr;
areaSize += func.length() + 1;
}
}
return areaSize;
}

size_t calcThunksCount() const
{
size_t thunksNeeded = 0;
for (auto dItr = dllFunctions.begin(); dItr != dllFunctions.end(); ++dItr) {
const QStringList funcs = dItr.value();
thunksNeeded = funcs.size() + 1; // records for all the functions, plus the terminator
}
return thunksNeeded;
}

bool addNewSec;
QMap<QString, QStringList> dllFunctions;
};
6 changes: 3 additions & 3 deletions pe-bear/base/Modification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool ModifBackup::apply(AbstractByteBuffer* file)
BYTE *modPtr = file->getContentAt(this->offset, this->size);

if (!modPtr) {
std::cerr << "Cannot apply backup at: " << std::hex << this->offset << " on the given file! Area size mismatch!" << std::endl;
std::cerr << "Cannot apply backup at offset: " << std::hex << this->offset << " on the given file! Area size mismatch!" << std::endl;
return false;
}

Expand Down Expand Up @@ -198,8 +198,8 @@ bool ModificationHandler::undoLastOperation()
if (!op) return false;

size_t undone = 0;
for (std::vector<ModifBackup*>::iterator itr = op->modifs.begin();
itr != op->modifs.end();
for (std::vector<ModifBackup*>::reverse_iterator itr = op->modifs.rbegin();
itr != op->modifs.rend();
++itr)
{
ModifBackup* patch = *itr;
Expand Down
Loading

0 comments on commit 34c70c4

Please sign in to comment.