This repository has been archived by the owner on Oct 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
321 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.24720.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cc_unpacker", "cc_unpacker.vcxproj", "{83235E97-41C3-407E-952C-7711D0B28264}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{83235E97-41C3-407E-952C-7711D0B28264}.Debug|x64.ActiveCfg = Debug|x64 | ||
{83235E97-41C3-407E-952C-7711D0B28264}.Debug|x64.Build.0 = Debug|x64 | ||
{83235E97-41C3-407E-952C-7711D0B28264}.Debug|x86.ActiveCfg = Debug|Win32 | ||
{83235E97-41C3-407E-952C-7711D0B28264}.Debug|x86.Build.0 = Debug|Win32 | ||
{83235E97-41C3-407E-952C-7711D0B28264}.Release|x64.ActiveCfg = Release|x64 | ||
{83235E97-41C3-407E-952C-7711D0B28264}.Release|x64.Build.0 = Release|x64 | ||
{83235E97-41C3-407E-952C-7711D0B28264}.Release|x86.ActiveCfg = Release|Win32 | ||
{83235E97-41C3-407E-952C-7711D0B28264}.Release|x86.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup Label="ProjectConfigurations"> | ||
<ProjectConfiguration Include="Debug|Win32"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|Win32"> | ||
<Configuration>Release</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Debug|x64"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|x64"> | ||
<Configuration>Release</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
</ItemGroup> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>{83235E97-41C3-407E-952C-7711D0B28264}</ProjectGuid> | ||
<RootNamespace>cc_unpacker</RootNamespace> | ||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v120</PlatformToolset> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v100</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v140</PlatformToolset> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v140</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
<ImportGroup Label="ExtensionSettings"> | ||
</ImportGroup> | ||
<ImportGroup Label="Shared"> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<PropertyGroup Label="UserMacros" /> | ||
<PropertyGroup /> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>Disabled</Optimization> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions> | ||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat> | ||
</ClCompile> | ||
<Link> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
<Link> | ||
<AssemblyDebug>true</AssemblyDebug> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>Disabled</Optimization> | ||
<SDLCheck>true</SDLCheck> | ||
</ClCompile> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions> | ||
</ClCompile> | ||
<Link> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
</ClCompile> | ||
<Link> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemGroup> | ||
<ClCompile Include="main.cpp" /> | ||
</ItemGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
</ImportGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
#include <windows.h> | ||
#include <stdio.h> | ||
#include <sys/stat.h> | ||
|
||
typedef unsigned long long QWORD; | ||
|
||
#pragma pack(push, 1) | ||
|
||
struct ArchiveHeader | ||
{ | ||
char Header[64]; | ||
QWORD FilesCount; | ||
}; | ||
|
||
struct ArchiveEntry | ||
{ | ||
char FileName[128]; | ||
QWORD StartOffset; | ||
QWORD Length; | ||
}; | ||
|
||
#pragma pack(pop) | ||
|
||
#define SIG_PACKONLY ("PackOnly") | ||
#define SIG_PACKPLUS ("PackPlus") | ||
|
||
#define TYPE_PACKONLY 0 | ||
#define TYPE_PACKPLUS 1 | ||
|
||
#define SAFE_EXIT(x); fclose(x); return 0; | ||
|
||
inline BOOL dexist(const char* dir) | ||
{ | ||
struct stat buf; | ||
return (stat(dir, &buf) == 0 && buf.st_mode & S_IFDIR); | ||
} | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
if (argc < 3) | ||
{ | ||
printf("Usage: %s <filename> <out_directory>\n", argv[0]); | ||
return 0; | ||
} | ||
|
||
FILE* file = fopen(argv[1], "rb"); | ||
|
||
if (file) | ||
{ | ||
ArchiveHeader header; | ||
|
||
if (fread(&header, 1, sizeof(ArchiveHeader), file) != sizeof(ArchiveHeader)) | ||
{ | ||
printf("Can't read file header!\n"); | ||
SAFE_EXIT(file); | ||
} | ||
|
||
BYTE archive_type = (strcmp(header.Header, SIG_PACKONLY) != 0); | ||
|
||
if (archive_type && strcmp(header.Header, SIG_PACKPLUS) != 0) | ||
{ | ||
printf("This file is not a CC archive!\n"); | ||
SAFE_EXIT(file); | ||
} | ||
|
||
if (header.FilesCount <= 0) | ||
{ | ||
printf("There's no files in this archive!\n"); | ||
SAFE_EXIT(file); | ||
} | ||
|
||
fseek(file, 0, SEEK_END); | ||
|
||
if (ftell(file) < (sizeof(ArchiveHeader) + sizeof(ArchiveEntry) * header.FilesCount)) | ||
{ | ||
printf("Bad header (invalid entry count)\n"); | ||
SAFE_EXIT(file); | ||
} | ||
|
||
fseek(file, sizeof(ArchiveHeader), SEEK_SET); | ||
|
||
ArchiveEntry* arch_files = new ArchiveEntry[(DWORD)header.FilesCount]; | ||
|
||
QWORD biggest_offset = 0; | ||
|
||
for (QWORD i = 0; i < header.FilesCount; i++) | ||
{ | ||
if (fread(&arch_files[i], 1, sizeof(ArchiveEntry), file) != sizeof(ArchiveEntry)) | ||
{ | ||
printf("Can't read file entry (%llu)!\n", i); | ||
SAFE_EXIT(file); | ||
} | ||
|
||
QWORD sum = arch_files[i].StartOffset + arch_files[i].Length; | ||
|
||
if (sum > biggest_offset) | ||
biggest_offset = sum; | ||
} | ||
|
||
fseek(file, 0, SEEK_END); | ||
|
||
if (ftell(file) < biggest_offset) | ||
{ | ||
printf("Bad header (invalid data block size)\n"); | ||
SAFE_EXIT(file); | ||
} | ||
|
||
if (!dexist(argv[2]) && !CreateDirectory(argv[2], NULL)) | ||
{ | ||
printf("Unable to create output directory!\n"); | ||
SAFE_EXIT(file); | ||
} | ||
|
||
BYTE brk = FALSE; | ||
|
||
char path[MAX_PATH + 1]; | ||
|
||
for (QWORD i = 0; i < header.FilesCount; i++) | ||
{ | ||
fseek(file, (long)arch_files[i].StartOffset, SEEK_SET); | ||
QWORD to_read = arch_files[i].Length; | ||
|
||
strcpy(path, argv[2]); | ||
strcat(path, "\\"); | ||
strcat(path, arch_files[i].FileName); | ||
|
||
FILE* file_out = fopen(path, "wb"); | ||
|
||
if (!file_out) | ||
{ | ||
printf("Unable to create output file (%s)!", arch_files[i].FileName); | ||
SAFE_EXIT(file); | ||
} | ||
|
||
while (to_read > 0) | ||
{ | ||
int c = fgetc(file); | ||
|
||
if (c == EOF) | ||
{ | ||
brk = TRUE; | ||
break; | ||
} | ||
|
||
fputc((archive_type == TYPE_PACKONLY) ? c : ~c, file_out); | ||
|
||
to_read--; | ||
} | ||
|
||
fclose(file_out); | ||
|
||
if (brk) break; | ||
} | ||
|
||
if (brk) | ||
{ | ||
printf("Unexpected end of file!\n"); | ||
SAFE_EXIT(file); | ||
} | ||
|
||
fclose(file); | ||
} | ||
else printf("Can't find specified file!\n"); | ||
|
||
return 0; | ||
} |