feat: Ryujin Core Logic
- Ryujin core logic, class organization. - Ryujin Utils.
This commit is contained in:
14
RyujinConsole/RyujinConsole/Ryujin.cc
Normal file
14
RyujinConsole/RyujinConsole/Ryujin.cc
Normal 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() {
|
||||
|
||||
}
|
||||
19
RyujinConsole/RyujinConsole/Ryujin.hh
Normal file
19
RyujinConsole/RyujinConsole/Ryujin.hh
Normal 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();
|
||||
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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">
|
||||
|
||||
@@ -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>
|
||||
1
RyujinConsole/RyujinConsole/RyujinUtils.cc
Normal file
1
RyujinConsole/RyujinConsole/RyujinUtils.cc
Normal file
@@ -0,0 +1 @@
|
||||
#include "RyujinUtils.hh"
|
||||
125
RyujinConsole/RyujinConsole/RyujinUtils.hh
Normal file
125
RyujinConsole/RyujinConsole/RyujinUtils.hh
Normal 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);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user