diff --git a/RyujinConsole/RyujinConsole/Ryujin.cc b/RyujinConsole/RyujinConsole/Ryujin.cc new file mode 100644 index 0000000..9b68c71 --- /dev/null +++ b/RyujinConsole/RyujinConsole/Ryujin.cc @@ -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() { + +} diff --git a/RyujinConsole/RyujinConsole/Ryujin.hh b/RyujinConsole/RyujinConsole/Ryujin.hh new file mode 100644 index 0000000..73ad84d --- /dev/null +++ b/RyujinConsole/RyujinConsole/Ryujin.hh @@ -0,0 +1,19 @@ +#pragma once +#include +#include +#include "RyujinUtils.hh" + +class Ryujin { + +private: + std::shared_ptr 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(); + +}; + diff --git a/RyujinConsole/RyujinConsole/RyujinConsole.cpp b/RyujinConsole/RyujinConsole/RyujinConsole.cpp index 028a4ff..7b13c99 100644 --- a/RyujinConsole/RyujinConsole/RyujinConsole.cpp +++ b/RyujinConsole/RyujinConsole/RyujinConsole.cpp @@ -1,10 +1,13 @@ #include +#include "Ryujin.hh" auto main() -> int { std::cout << "Hello World!\n"; + std::unique_ptr ryujin = std::make_unique("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; } \ No newline at end of file diff --git a/RyujinConsole/RyujinConsole/RyujinConsole.vcxproj b/RyujinConsole/RyujinConsole/RyujinConsole.vcxproj index 9a8db44..840da56 100644 --- a/RyujinConsole/RyujinConsole/RyujinConsole.vcxproj +++ b/RyujinConsole/RyujinConsole/RyujinConsole.vcxproj @@ -127,7 +127,13 @@ + + + + + + diff --git a/RyujinConsole/RyujinConsole/RyujinConsole.vcxproj.filters b/RyujinConsole/RyujinConsole/RyujinConsole.vcxproj.filters index 096e0a4..cd2aaad 100644 --- a/RyujinConsole/RyujinConsole/RyujinConsole.vcxproj.filters +++ b/RyujinConsole/RyujinConsole/RyujinConsole.vcxproj.filters @@ -18,5 +18,19 @@ Source Files + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + \ No newline at end of file diff --git a/RyujinConsole/RyujinConsole/RyujinUtils.cc b/RyujinConsole/RyujinConsole/RyujinUtils.cc new file mode 100644 index 0000000..81d328d --- /dev/null +++ b/RyujinConsole/RyujinConsole/RyujinUtils.cc @@ -0,0 +1 @@ +#include "RyujinUtils.hh" diff --git a/RyujinConsole/RyujinConsole/RyujinUtils.hh b/RyujinConsole/RyujinConsole/RyujinUtils.hh new file mode 100644 index 0000000..6290b77 --- /dev/null +++ b/RyujinConsole/RyujinConsole/RyujinUtils.hh @@ -0,0 +1,125 @@ +#pragma once +#include +#include +#include + +namespace RyujinUtils { + + inline std::pair MapPortableExecutableFileIntoMemory(const std::string& m_strInputFilePath, std::shared_ptr& 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( + + reinterpret_cast( + + ::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); + } + +}; +