Skip to content

Instantly share code, notes, and snippets.

@hfiref0x
Created Jul 24, 2018
Embed
What would you like to do?
DCDv1 unpack
#include <Windows.h>
#include <msdelta.h>
#pragma comment(lib, "msdelta.lib")
BOOL load_file(LPCTSTR FileName, LPDWORD BytesRead, LPVOID *AllocatedBuffer)
{
HANDLE f;
LARGE_INTEGER fsz;
LPVOID buffer = NULL;
BOOL result = FALSE;
f = CreateFile(FileName, GENERIC_READ | SYNCHRONIZE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
while (f != INVALID_HANDLE_VALUE) {
fsz.QuadPart = 0;
if (!GetFileSizeEx(f, &fsz))
break;
if (fsz.QuadPart > 2147483648ll)
break;
buffer = VirtualAlloc(NULL, fsz.LowPart,
MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (buffer == NULL)
break;
if (!ReadFile(f, buffer, fsz.LowPart, BytesRead, NULL))
{
VirtualFree(buffer, 0, MEM_RELEASE);
buffer = NULL;
break;
}
result = TRUE;
break;
}
if (f != INVALID_HANDLE_VALUE)
CloseHandle(f);
*AllocatedBuffer = buffer;
return result;
}
BOOL save_file(LPCTSTR FileName, DWORD FileSize, LPVOID Buffer)
{
HANDLE f;
DWORD bytesIO;
BOOL result = FALSE;
f = CreateFile(FileName, GENERIC_WRITE | SYNCHRONIZE,
FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (f != INVALID_HANDLE_VALUE)
{
result = WriteFile(f, Buffer, FileSize, &bytesIO, NULL);
CloseHandle(f);
}
return result;
}
void main()
{
DELTA_HEADER_INFO dhi;
unsigned char *bsrc = NULL, *bdelta = NULL;
DWORD filesize_src = 0, filesize_delta = 0;
DELTA_INPUT isrc, idelta, ioutput;
BOOL result;
load_file(
TEXT("C:\\TEMP\\PA30\\format.com.src"),
&filesize_src,
&bsrc);
load_file(
TEXT("C:\\TEMP\\PA30\\format.com.delta"),
&filesize_delta,
&bdelta);
isrc.Editable = TRUE;
isrc.lpStart = bsrc;
isrc.uSize = filesize_src;
idelta.Editable = FALSE;
idelta.lpStart = bdelta+0x0c;
idelta.uSize = filesize_delta-0x0c;
result = GetDeltaInfoB(idelta, &dhi);
result = ApplyDeltaB(DELTA_DEFAULT_FLAGS_RAW, isrc, idelta, &ioutput);
save_file(TEXT("C:\\TEMP\\PA30\\format.com.target"), ioutput.uSize, ioutput.lpcStart);
ExitProcess(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment