Skip to content

Commit

Permalink
v 1.4.1
Browse files Browse the repository at this point in the history
Address #6
  • Loading branch information
hfiref0x committed Dec 13, 2023
1 parent a691cad commit 289bf9b
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 48 deletions.
Binary file modified Binary/sxsexp32.exe
Binary file not shown.
Binary file modified Binary/sxsexp64.exe
Binary file not shown.
28 changes: 0 additions & 28 deletions SXSEXP.sha256

This file was deleted.

42 changes: 29 additions & 13 deletions Source/sxsexp/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*
* TITLE: MAIN.C
*
* VERSION: 1.40
* VERSION: 1.41
*
* DATE: 19 Jul 2023
* DATE: 10 Dec 2023
*
* Program entry point.
*
Expand All @@ -25,6 +25,7 @@
HANDLE g_Heap = NULL;

SUP_DECOMPRESSOR gDecompressor;
SUP_DELTA_COMPRESSION gMsDeltaContext;
SUP_CONSOLE gConsole;

#define T_UNSUPFORMAT TEXT("This format is not supported by this tool")
Expand All @@ -33,7 +34,7 @@ SUP_CONSOLE gConsole;
//
// Help output.
//
#define T_TITLE TEXT("SXSEXP v1.4.0 from Jul 20 2023, (c) 2016 - 2023 hfiref0x\r\n\
#define T_TITLE TEXT("SXSEXP v1.4.1 from Dec 10 2023, (c) 2016 - 2023 hfiref0x\r\n\
Expand compressed files from WinSxS folder (DCD01, DCN01, DCM01, DCS01 formats).\r\n")

#define T_HELP TEXT("SXSEXP <Source File> <Destination File>\r\n\
Expand Down Expand Up @@ -75,7 +76,7 @@ VOID PrintDataHeader(
inputDelta.lpStart = header.pDCD->Data;
inputDelta.uSize = SourceFileSize - FIELD_OFFSET(DCD_HEADER, Data); //size without header specific fields
inputDelta.Editable = FALSE;
if (!GetDeltaInfoB(inputDelta, &dhi)) {
if (!gMsDeltaContext.GetDeltaInfoB(inputDelta, &dhi)) {
supConsoleWriteLine(&gConsole, T_ERRORDELTA);
break;
}
Expand All @@ -98,7 +99,7 @@ VOID PrintDataHeader(
inputDelta.lpStart = header.pDCN->Data;
inputDelta.uSize = SourceFileSize - FIELD_OFFSET(DCN_HEADER, Data); //size without header
inputDelta.Editable = FALSE;
if (!GetDeltaInfoB(inputDelta, &dhi)) {
if (!gMsDeltaContext.GetDeltaInfoB(inputDelta, &dhi)) {
supConsoleWriteLine(&gConsole, T_ERRORDELTA);
break;
}
Expand Down Expand Up @@ -181,12 +182,12 @@ BOOL ProcessFileDCN(
inputDelta.Editable = FALSE;
inputDelta.lpStart = ((PDCN_HEADER)SourceFile)->Data;
inputDelta.uSize = SourceFileSize - FIELD_OFFSET(DCN_HEADER, Data);
if (GetDeltaInfoB(inputDelta, &deltaHeaderInfo)) {
if (gMsDeltaContext.GetDeltaInfoB(inputDelta, &deltaHeaderInfo)) {

RtlSecureZeroMemory(&sourceDelta, sizeof(DELTA_INPUT));
RtlSecureZeroMemory(&targetOutput, sizeof(DELTA_OUTPUT));

bResult = ApplyDeltaB(DELTA_FLAG_NONE, sourceDelta, inputDelta, &targetOutput);
bResult = gMsDeltaContext.ApplyDeltaB(DELTA_FLAG_NONE, sourceDelta, inputDelta, &targetOutput);
if (bResult) {

pvData = HeapAlloc(g_Heap, HEAP_ZERO_MEMORY, targetOutput.uSize);
Expand All @@ -197,7 +198,7 @@ BOOL ProcessFileDCN(
else {
dwLastError = GetLastError();
}
DeltaFree(targetOutput.lpStart);
gMsDeltaContext.DeltaFree(targetOutput.lpStart);
}
else {
dwLastError = GetLastError();
Expand Down Expand Up @@ -298,7 +299,7 @@ BOOL ProcessFileDCD(

ioutput.lpStart = NULL;
ioutput.uSize = 0;
bResult = ApplyDeltaB(DELTA_FLAG_NONE, isrc, idelta, &ioutput);
bResult = gMsDeltaContext.ApplyDeltaB(DELTA_FLAG_NONE, isrc, idelta, &ioutput);
if (bResult) {

pvData = HeapAlloc(g_Heap, HEAP_ZERO_MEMORY, ioutput.uSize);
Expand All @@ -309,7 +310,7 @@ BOOL ProcessFileDCD(
else {
dwLastError = GetLastError();
}
DeltaFree(ioutput.lpStart);
gMsDeltaContext.DeltaFree(ioutput.lpStart);
}
else {
dwLastError = GetLastError();
Expand Down Expand Up @@ -495,7 +496,7 @@ BOOL ProcessFileDCM(
inputDelta.Editable = FALSE;
inputDelta.lpStart = ((PDCM_HEADER)SourceFile)->Data;
inputDelta.uSize = SourceFileSize - FIELD_OFFSET(DCM_HEADER, Data);
if (!GetDeltaInfoB(inputDelta, &dhi)) {
if (!gMsDeltaContext.GetDeltaInfoB(inputDelta, &dhi)) {
dwLastError = GetLastError();
supConsoleWriteLine(&gConsole, T_ERRORDELTA);
break;
Expand All @@ -508,7 +509,7 @@ BOOL ProcessFileDCM(

RtlSecureZeroMemory(&targetDelta, sizeof(DELTA_OUTPUT));

bResult = ApplyDeltaB(DELTA_FLAG_NONE, sourceDelta, inputDelta, &targetDelta);
bResult = gMsDeltaContext.ApplyDeltaB(DELTA_FLAG_NONE, sourceDelta, inputDelta, &targetDelta);
if (bResult) {

pvData = HeapAlloc(g_Heap, HEAP_ZERO_MEMORY, targetDelta.uSize);
Expand All @@ -520,7 +521,7 @@ BOOL ProcessFileDCM(
dwLastError = GetLastError();
}

DeltaFree(targetDelta.lpStart);
gMsDeltaContext.DeltaFree(targetDelta.lpStart);
}
else {
dwLastError = GetLastError();
Expand Down Expand Up @@ -942,6 +943,21 @@ void main()
break;
}

if (!supInitializeMsDeltaAPI(&gMsDeltaContext)) {
supConsoleDisplayWin32Error(&gConsole, TEXT("SXSEXP: Fatal error, failed to initialize MsDelta API"));
break;
}
else {
RtlSecureZeroMemory(szSourcePath, sizeof(szSourcePath));
if (GetModuleFileName(gMsDeltaContext.hModule,
(LPWSTR)&szSourcePath,
MAX_PATH))
{
supConsoleWriteLine(&gConsole, TEXT("SXSEXP: Loaded MsDelta.dll"));
supConsoleWriteLine(&gConsole, szSourcePath);
}
}

if (_strcmpi(szBuffer, L"/d") == 0) {
uResult = DCDMode(lpCmdLine);
break;
Expand Down
46 changes: 46 additions & 0 deletions Source/sxsexp/sup.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,52 @@ CFILE_TYPE supGetFileType(
return Result;
}

/*
* supInitializeMsDeltaAPI
*
* Purpose:
*
* Allocate pointers to MsDelta engine routines.
*
*/
BOOL supInitializeMsDeltaAPI(
_Inout_ PSUP_DELTA_COMPRESSION MsDeltaContext
)
{
FARPROC pfn;
HMODULE hModule;

MsDeltaContext->ApplyDeltaB = NULL;
MsDeltaContext->DeltaFree = NULL;
MsDeltaContext->GetDeltaInfoB = NULL;

hModule = LoadLibrary(TEXT("msdelta.dll"));
MsDeltaContext->hModule = hModule;

if (hModule == NULL)
return FALSE;

pfn = GetProcAddress(hModule, "ApplyDeltaB");
if (pfn)
MsDeltaContext->ApplyDeltaB = (pfnApplyDeltaB)pfn;
else
return FALSE;

pfn = GetProcAddress(hModule, "DeltaFree");
if (pfn)
MsDeltaContext->DeltaFree = (pfnDeltaFree)pfn;
else
return FALSE;

pfn = GetProcAddress(hModule, "GetDeltaInfoB");
if (pfn)
MsDeltaContext->GetDeltaInfoB = (pfnGetDeltaInfoB)pfn;
else
return FALSE;

return TRUE;
}

/*
* supInitCabinetDecompressionAPI
*
Expand Down
33 changes: 28 additions & 5 deletions Source/sxsexp/sup.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*
* TITLE: SUP.H
*
* VERSION: 1.40
* VERSION: 1.41
*
* DATE: 19 Jul 2023
* DATE: 10 Dec 2023
*
* Program support routines header file.
*
Expand Down Expand Up @@ -101,6 +101,27 @@ typedef struct _SUP_DECOMPRESSOR {
pfnDecompress Decompress;
} SUP_DECOMPRESSOR, * PSUP_DECOMPRESSOR;

typedef BOOL (WINAPI* pfnApplyDeltaB)(
_In_ DELTA_FLAG_TYPE ApplyFlags,
_In_ DELTA_INPUT Source,
_In_ DELTA_INPUT Delta,
_Out_ LPDELTA_OUTPUT lpTarget);

typedef BOOL (WINAPI* pfnDeltaFree)(
_In_ LPVOID lpMemory);

typedef BOOL (WINAPI* pfnGetDeltaInfoB)(
_In_ DELTA_INPUT Delta,
_Out_ LPDELTA_HEADER_INFO lpHeaderInfo);

typedef struct _SUP_DELTA_COMPRESSION {
HMODULE hModule;
pfnApplyDeltaB ApplyDeltaB;
pfnDeltaFree DeltaFree;
pfnGetDeltaInfoB GetDeltaInfoB;
} SUP_DELTA_COMPRESSION, * PSUP_DELTA_COMPRESSION;


//
// CONSOLE START
//
Expand Down Expand Up @@ -137,6 +158,11 @@ VOID supConsoleDisplayWin32Error(
//
// CONSOLE END
//
BOOL supInitializeMsDeltaAPI(
_Inout_ PSUP_DELTA_COMPRESSION MsDeltaContext);

BOOL supInitCabinetDecompressionAPI(
_Inout_ PSUP_DECOMPRESSOR Decompressor);

CFILE_TYPE supGetFileType(
_In_ PVOID FileBuffer);
Expand All @@ -155,9 +181,6 @@ VOID supPrintDeltaHeaderInfo(
_In_ PSUP_CONSOLE Console,
_In_ LPDELTA_HEADER_INFO DeltaHeaderInfo);

BOOL supInitCabinetDecompressionAPI(
_Inout_ PSUP_DECOMPRESSOR Decompressor);

BOOL supMapInputFile(
_In_ LPCWSTR FileName,
_Out_ PULONG FileSize,
Expand Down
3 changes: 1 addition & 2 deletions Source/sxsexp/sxsexp.vcxproj.user
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerCommandArguments>
</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>c:\install\file.bin c:\install\file.unpacked</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
Expand Down
Binary file modified Source/sxsexp/sxsexpres.rc
Binary file not shown.

0 comments on commit 289bf9b

Please sign in to comment.