RunPE 项目使用教程
RunPEC# Reflective loader for unmanaged binaries.项目地址:https://gitcode.com/gh_mirrors/run/RunPE
1. 项目的目录结构及介绍
RunPE 项目的目录结构如下:
RunPE/
├── README.md
├── RunPE.sln
├── RunPE/
│ ├── App.config
│ ├── Program.cs
│ ├── RunPE.csproj
│ └── bin/
│ └── Debug/
│ └── RunPE.exe
└── obj/
目录结构介绍
- README.md: 项目说明文件,包含项目的基本信息和使用方法。
- RunPE.sln: 项目的解决方案文件,用于在 Visual Studio 中打开和管理项目。
- RunPE/: 项目的主要代码目录。
- App.config: 项目的配置文件。
- Program.cs: 项目的启动文件,包含程序的入口点。
- RunPE.csproj: 项目的项目文件,包含项目的配置信息。
- bin/: 编译生成的二进制文件目录。
- Debug/: 调试版本的二进制文件目录。
- RunPE.exe: 编译生成的可执行文件。
- Debug/: 调试版本的二进制文件目录。
- obj/: 编译过程中生成的中间文件目录。
2. 项目的启动文件介绍
项目的启动文件是 Program.cs
,它包含了程序的入口点。以下是 Program.cs
的主要内容:
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
namespace RunPE
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("Usage: RunPE.exe <path_to_pe_file>");
return;
}
string peFilePath = args[0];
if (!File.Exists(peFilePath))
{
Console.WriteLine("File not found: " + peFilePath);
return;
}
byte[] peFileBytes = File.ReadAllBytes(peFilePath);
Process process = new Process();
process.StartInfo.FileName = "dummy.exe";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.Start();
IntPtr hProcess = process.Handle;
IntPtr pModuleBase = VirtualAllocEx(hProcess, IntPtr.Zero, (uint)peFileBytes.Length, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (pModuleBase == IntPtr.Zero)
{
Console.WriteLine("VirtualAllocEx failed");
return;
}
if (!WriteProcessMemory(hProcess, pModuleBase, peFileBytes, (uint)peFileBytes.Length, out IntPtr bytesWritten))
{
Console.WriteLine("WriteProcessMemory failed");
return;
}
IntPtr pEntryPoint = GetEntryPoint(pModuleBase, peFileBytes);
if (pEntryPoint == IntPtr.Zero)
{
Console.WriteLine("GetEntryPoint failed");
return;
}
IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, pEntryPoint, IntPtr.Zero, 0, out IntPtr threadId);
if (hThread == IntPtr.Zero)
{
Console.WriteLine("CreateRemoteThread failed");
return;
}
Console.WriteLine("PE file executed successfully");
}
// 其他辅助函数和常量定义...
}
}
启动文件介绍
- Main 方法: 程序的入口点,负责解析命令行参数,读取 PE 文件,并执行 RunPE 过程。
- 辅助函数和常量定义: 包含了一些用于内存分配、写入和线程创建的 Windows API 调用。
3. 项目的配置文件介绍
项目的配置文件是 App.config
,它包含了程序的配置信息。以下是 App.config
的主要内容:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
RunPEC# Reflective loader for unmanaged binaries.项目地址:https://gitcode.com/gh_mirrors/run/RunPE