first commit

Version 3.x.x
This commit is contained in:
VNGhostMans
2023-05-14 20:21:09 +07:00
parent a3037a8db3
commit 5ec92ee05e
1166 changed files with 1036539 additions and 0 deletions

53
minidumpfixer/main.cpp Normal file
View File

@@ -0,0 +1,53 @@
#include "minidumpfixer.h"
int _tmain(int argc, _TCHAR* argv[])
{
wprintf(L"MiniDump Fixer v 2.0 Copyright 2003-2019 VMProtect Software\n\n");
if (argc < 3) {
wprintf(L"Usage: %s dmp_file exe_file\n", PathFindFileNameW(argv[0]));
return 1;
}
const wchar_t *dmp_file_name = argv[1];
if (wcslen(dmp_file_name) == 0) {
wprintf(L"Crash dump file does not specified.");
return 1;
}
const wchar_t *exe_file_name = argv[2];
if (wcslen(dmp_file_name) == 0) {
wprintf(L"Executable file does not specified.");
return 1;
}
FileInfo file_info;
switch (GetFileInfo(exe_file_name, file_info)) {
case ERROR_OPEN:
wprintf(L"Can not open \"%s\".", exe_file_name);
return 1;
break;
case ERROR_INVALID_FORMAT:
wprintf(L"File \"%s\" has an incorrect format.", exe_file_name);
return 1;
break;
}
switch (FixDump(dmp_file_name, file_info)) {
case ERROR_OPEN:
wprintf(L"Can not open \"%s\".", dmp_file_name);
return 1;
break;
case ERROR_INVALID_FORMAT:
wprintf(L"File \"%s\" has an incorrect format.", dmp_file_name);
return 1;
break;
case ERROR_MODULE_NOT_FOUND:
wprintf(L"Module \"%s\" not found in the DMP file.", PathFindFileNameW(exe_file_name));
return 1;
break;
}
wprintf(L"DMP file sucessfully updated.");
return 0;
}

View File

@@ -0,0 +1,85 @@
#include "minidumpfixer.h"
int GetFileInfo(const wchar_t *file_name, FileInfo &file_info)
{
int res = ERROR_OPEN;
HANDLE file = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (file != INVALID_HANDLE_VALUE) {
HANDLE map = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL);
if (map) {
IMAGE_DOS_HEADER *dos_header = reinterpret_cast<IMAGE_DOS_HEADER *>(MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0));
if (dos_header) {
res = ERROR_INVALID_FORMAT;
try {
if (dos_header->e_magic == IMAGE_DOS_SIGNATURE) {
IMAGE_NT_HEADERS32 *nt_header32 = reinterpret_cast<IMAGE_NT_HEADERS32 *>(reinterpret_cast<byte *>(dos_header) + dos_header->e_lfanew);
if (nt_header32->Signature == IMAGE_NT_SIGNATURE) {
if (nt_header32->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
file_info.TimeDateStamp = nt_header32->FileHeader.TimeDateStamp;
file_info.SizeOfImage = nt_header32->OptionalHeader.SizeOfImage;
file_info.CheckSum = nt_header32->OptionalHeader.CheckSum;
res = ERROR_SUCCESS;
} else if (nt_header32->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
IMAGE_NT_HEADERS64 *nt_header64 = reinterpret_cast<IMAGE_NT_HEADERS64 *>(nt_header32);
file_info.TimeDateStamp = nt_header64->FileHeader.TimeDateStamp;
file_info.SizeOfImage = nt_header64->OptionalHeader.SizeOfImage;
file_info.CheckSum = nt_header64->OptionalHeader.CheckSum;
res = ERROR_SUCCESS;
}
}
}
} catch(...) {
res = ERROR_INVALID_FORMAT;
}
UnmapViewOfFile(dos_header);
}
CloseHandle(map);
}
CloseHandle(file);
}
return res;
}
int FixDump(const wchar_t *file_name, const FileInfo &file_info)
{
int res = ERROR_OPEN;
HANDLE file = CreateFileW(file_name, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (file != INVALID_HANDLE_VALUE) {
HANDLE map = CreateFileMapping(file, NULL, PAGE_READWRITE, 0, 0, NULL);
if (map) {
MINIDUMP_HEADER *header = reinterpret_cast<MINIDUMP_HEADER *>(MapViewOfFile(map, SECTION_MAP_WRITE, 0, 0, 0));
if (header) {
res = ERROR_INVALID_FORMAT;
try {
if (header->Signature == MINIDUMP_SIGNATURE) {
res = ERROR_MODULE_NOT_FOUND;
MINIDUMP_DIRECTORY *directory = reinterpret_cast<MINIDUMP_DIRECTORY *>(reinterpret_cast<byte *>(header) + header->StreamDirectoryRva);
for (ULONG32 i = 0; i < header->NumberOfStreams; i++, directory++) {
if (directory->StreamType == ModuleListStream) {
MINIDUMP_MODULE_LIST *module_list = reinterpret_cast<MINIDUMP_MODULE_LIST *>(reinterpret_cast<byte *>(header) + directory->Location.Rva);
for (ULONG32 j = 0; j < module_list->NumberOfModules; j++) {
MINIDUMP_MODULE *module = &module_list->Modules[j];
if (module->TimeDateStamp == file_info.TimeDateStamp) {
module->SizeOfImage = file_info.SizeOfImage;
module->CheckSum = file_info.CheckSum;
res = ERROR_SUCCESS;
}
}
}
}
if (res == ERROR_SUCCESS)
FlushViewOfFile(header, 0);
}
} catch(...) {
res = ERROR_INVALID_FORMAT;
}
UnmapViewOfFile(header);
}
CloseHandle(map);
}
CloseHandle(file);
}
return res;
}

View File

@@ -0,0 +1,14 @@
struct FileInfo {
DWORD TimeDateStamp;
DWORD SizeOfImage;
DWORD CheckSum;
};
enum {
ERROR_OPEN = 1,
ERROR_INVALID_FORMAT,
ERROR_MODULE_NOT_FOUND
};
int GetFileInfo(const wchar_t *file_name, FileInfo &file_info);
int FixDump(const wchar_t *file_name, const FileInfo &file_info);

View File

@@ -0,0 +1 @@
#include "precompiled.h"

View File

@@ -0,0 +1,13 @@
#pragma once
#ifndef MDF_PCH
#define MDF_PCH
#include <stdio.h>
#include <tchar.h>
#include <Windows.h>
#pragma warning( disable : 4091 )
#include <DbgHelp.h>
#include <Shlwapi.h>
#pragma warning( default: 4091 )
#endif //MDF_PCH