feat: Ryujin Core Logic

- Ryujin core logic, class organization.
- Ryujin Utils.
This commit is contained in:
keowu
2025-05-23 17:52:19 -03:00
parent 0a15f20bc1
commit 4aa9381177
7 changed files with 182 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
#include "Ryujin.hh"
Ryujin::Ryujin(const std::string& strInputFilePath, const std::string& strPdbFilePath, const std::string& strOutputFilePath) :
m_strInputFilePath(strInputFilePath), m_strOutputFilePath(strOutputFilePath), m_strPdbFilePath(strPdbFilePath) {
RyujinUtils::MapPortableExecutableFileIntoMemory(m_strInputFilePath, m_mappedPE);
std::printf("Goingggg :D\n0");
}
Ryujin::~Ryujin() {
}

View File

@@ -0,0 +1,19 @@
#pragma once
#include <iostream>
#include <memory>
#include "RyujinUtils.hh"
class Ryujin {
private:
std::shared_ptr<unsigned char> m_mappedPE;
const std::string& m_strInputFilePath;
const std::string& m_strPdbFilePath;
const std::string& m_strOutputFilePath;
public:
Ryujin(const std::string& strInputFilePath, const std::string& strPdbFilePath, const std::string& strOutputFilePath);
~Ryujin();
};

View File

@@ -1,10 +1,13 @@
#include <iostream>
#include "Ryujin.hh"
auto main() -> int {
std::cout << "Hello World!\n";
std::unique_ptr<Ryujin> ryujin = std::make_unique<Ryujin>("C:\\Users\\Keowu\\Documents\\GitHub\\MoFei\\x64\\Debug\\DemoObfuscation.exe", "C:\\Users\\Keowu\\Documents\\GitHub\\MoFei\\x64\\Debug\\DemoObfuscation.pdb", "C:\\Users\\Keowu\\Documents\\GitHub\\MoFei\\x64\\Debug\\DemoObfuscation2.exe");
ryujin.reset();
return 0;
}

View File

@@ -127,7 +127,13 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Ryujin.cc" />
<ClCompile Include="RyujinConsole.cpp" />
<ClCompile Include="RyujinUtils.cc" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Ryujin.hh" />
<ClInclude Include="RyujinUtils.hh" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@@ -18,5 +18,19 @@
<ClCompile Include="RyujinConsole.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Ryujin.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RyujinUtils.cc">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Ryujin.hh">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RyujinUtils.hh">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@@ -0,0 +1 @@
#include "RyujinUtils.hh"

View File

@@ -0,0 +1,125 @@
#pragma once
#include <iostream>
#include <memory>
#include <Windows.h>
namespace RyujinUtils {
inline std::pair<BOOL, uintptr_t> MapPortableExecutableFileIntoMemory(const std::string& m_strInputFilePath, std::shared_ptr<unsigned char>& mappedPE) {
auto hFile = ::CreateFileA(
_In_ m_strInputFilePath.c_str(),
_In_ GENERIC_READ,
_In_ FILE_SHARE_READ | FILE_SHARE_DELETE,
_In_opt_ nullptr,
_In_ OPEN_EXISTING,
_In_ FILE_ATTRIBUTE_NORMAL,
_In_opt_ nullptr
);
if (hFile == INVALID_HANDLE_VALUE) {
OutputDebugStringA(
_In_opt_ "RyujinUtils::MapExecutableFileIntoMemory: failed because cannot open a handle for input PE FILE\n"
);
return std::make_pair(FALSE, 0);
}
LARGE_INTEGER szFile;
if (!::GetFileSizeEx(
_In_ hFile,
_Out_ &szFile
)) {
::OutputDebugStringA(
_In_opt_ "RyujinUtils::MapExecutableFileIntoMemory: was not possible to get filesizeru for the PE FILE\n"
);
::CloseHandle(
_In_ hFile
);
return std::make_pair(FALSE, 0);
}
auto hMap = ::CreateFileMappingA(
_In_ hFile,
_In_opt_ nullptr,
_In_ PAGE_READONLY | SEC_IMAGE,
_In_ NULL,
_In_ NULL,
_In_opt_ nullptr
);
if (!hMap) {
::OutputDebugStringA(
_In_opt_ "RyujinUtils::MapExecutableFileIntoMemory: was not possible to create a mapping to the PE FILE.\n"
);
::CloseHandle(
_In_ hMap
);
return std::make_pair(FALSE, 0);
}
mappedPE = std::shared_ptr<unsigned char>(
reinterpret_cast<unsigned char*>(
::MapViewOfFile(
_In_ hMap,
_In_ FILE_MAP_READ,
_In_ NULL,
_In_ NULL,
_In_ NULL
)
),
[](unsigned char* p) {
if (p) ::UnmapViewOfFile(
_In_ p
);
}
);
::CloseHandle(
_In_ hMap
);
::CloseHandle(
_In_ hFile
);
return std::make_pair(TRUE, szFile.QuadPart);
}
};