Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the corrupted image of x64 file dump #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion ExtremeDumper/Dumping/PEImageDumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,20 @@ public static byte[] Dump(uint processId, void* address, ref ImageLayout imageLa
using var process = NativeProcess.Open(processId);
return Dump(process, address, ref imageLayout);
}

/// <summary>
/// 修改PE文件的SizeOfImage值
/// </summary>
/// <param name="peImage">PE文件数据</param>
/// <param name="newSizeOfImage">新的SizeOfImage值</param>
/// <param name="oldSizeOfImage">原始的SizeOfImage值</param>
public static void ChangeSizeOfImage(byte[] peImage, uint newSizeOfImage, out uint oldSizeOfImage) {
if (peImage == null) throw new ArgumentNullException("ChageSizeOfImage -> peImageBuff is null.");
if (peImage == null) throw new ArgumentNullException("ChageSizeOfImage -> the peImageBuff size must be greater than 0.");
fixed (byte* pSizeOfImage = &peImage[0xd0]) {
oldSizeOfImage = *(uint*)(pSizeOfImage);
*(uint*)(pSizeOfImage) = newSizeOfImage;
}
}
/// <summary>
/// 直接从内存中复制模块,不执行格式转换操作
/// </summary>
Expand Down Expand Up @@ -70,6 +83,8 @@ public static byte[] Dump(NativeProcess process, void* address, ref ImageLayout
default:
throw new NotSupportedException();
}
//修正SizeOfImage
ChangeSizeOfImage(peImage, imageSize, out uint _);
// 转储

return peImage;
Expand Down