├── CSO Decryption Encryption.sln ├── CSO Decryption Encryption.vcxproj ├── README.md └── main.cpp /CSO Decryption Encryption.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29025.244 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CSO Decryption Encryption", "CSO Decryption Encryption.vcxproj", "{B02BFB2A-A7E0-4203-A7D6-E0E2F512B9DC}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {B02BFB2A-A7E0-4203-A7D6-E0E2F512B9DC}.Debug|x64.ActiveCfg = Debug|x64 17 | {B02BFB2A-A7E0-4203-A7D6-E0E2F512B9DC}.Debug|x64.Build.0 = Debug|x64 18 | {B02BFB2A-A7E0-4203-A7D6-E0E2F512B9DC}.Debug|x86.ActiveCfg = Debug|Win32 19 | {B02BFB2A-A7E0-4203-A7D6-E0E2F512B9DC}.Debug|x86.Build.0 = Debug|Win32 20 | {B02BFB2A-A7E0-4203-A7D6-E0E2F512B9DC}.Release|x64.ActiveCfg = Release|x64 21 | {B02BFB2A-A7E0-4203-A7D6-E0E2F512B9DC}.Release|x64.Build.0 = Release|x64 22 | {B02BFB2A-A7E0-4203-A7D6-E0E2F512B9DC}.Release|x86.ActiveCfg = Release|Win32 23 | {B02BFB2A-A7E0-4203-A7D6-E0E2F512B9DC}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {ABEB63D7-F8CE-4310-9206-B51D9CA165C8} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /CSO Decryption Encryption.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | {B02BFB2A-A7E0-4203-A7D6-E0E2F512B9DC} 24 | Win32Proj 25 | CSOdecenc 26 | 10.0.17763.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v140 33 | MultiByte 34 | 35 | 36 | Application 37 | false 38 | v140 39 | true 40 | MultiByte 41 | 42 | 43 | Application 44 | true 45 | v142 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v142 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | true 78 | 79 | 80 | false 81 | 82 | 83 | false 84 | 85 | 86 | 87 | 88 | 89 | Level3 90 | Disabled 91 | true 92 | WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CONSOLE;%(PreprocessorDefinitions) 93 | true 94 | 95 | 96 | Console 97 | true 98 | Shlwapi.lib;%(AdditionalDependencies) 99 | RequireAdministrator 100 | 101 | 102 | 103 | 104 | 105 | 106 | Level3 107 | Disabled 108 | true 109 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 110 | true 111 | 112 | 113 | Console 114 | true 115 | 116 | 117 | 118 | 119 | 120 | 121 | Level3 122 | MaxSpeed 123 | true 124 | true 125 | true 126 | WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CONSOLE;%(PreprocessorDefinitions) 127 | true 128 | true 129 | 130 | 131 | Console 132 | true 133 | true 134 | true 135 | Shlwapi.lib;%(AdditionalDependencies) 136 | 137 | 138 | 139 | 140 | 141 | 142 | Level3 143 | MaxSpeed 144 | true 145 | true 146 | true 147 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 148 | true 149 | 150 | 151 | Console 152 | true 153 | true 154 | true 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CSO-Decryption-Encryption 2 | Simple tool for CSO/CSN:Z .cso files decryption/encryption. 3 | 4 | Usage: 5 | ----- 6 | 7 | Run executable with follow arguments: 8 | -file "filepath" 9 | -dec / -enc 10 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define CLOSE_TIME 5000 6 | 7 | int key[4] 8 | { 9 | 0x4C7ADF03, 10 | 0x5F30E75F, 11 | 0x1D149820, 12 | 0x3985ADF, 13 | }; 14 | 15 | void DecryptCSO(uint32_t* v, int sz) 16 | { 17 | uint32_t count = sz / 4; 18 | for (uint32_t i = 0; i < count; i += 2) 19 | { 20 | uint32_t v0 = v[i]; 21 | uint32_t v1 = v[i + 1]; 22 | uint32_t sum = 0x9e3779b9 * 32; 23 | uint32_t delta = 0x9e3779b9; 24 | 25 | for (int i = 0; i < 32; i++) 26 | { 27 | v1 -= ((v0 << 4) - key[2]) ^ (v0 + sum) ^ ((v0 >> 5) - key[3]); 28 | v0 -= ((v1 << 4) - key[0]) ^ (v1 + sum) ^ ((v1 >> 5) + key[1]); 29 | sum -= delta; 30 | } 31 | 32 | v[i] = v0; 33 | v[i + 1] = v1; 34 | 35 | sum = 0x9e3779b9 * 32; 36 | } 37 | } 38 | 39 | void EncryptCSO(uint32_t* v, int sz) 40 | { 41 | uint32_t count = sz / 4; 42 | for (uint32_t i = 0; i < count; i += 2) 43 | { 44 | uint32_t v0 = v[i]; 45 | uint32_t v1 = v[i + 1]; 46 | uint32_t sum = 0; 47 | uint32_t delta = 0x9e3779b9; 48 | 49 | for (int i = 0; i < 32; i++) 50 | { 51 | sum += delta; 52 | v0 += ((v1 << 4) - key[0]) ^ (v1 + sum) ^ ((v1 >> 5) + key[1]); 53 | v1 += ((v0 << 4) - key[2]) ^ (v0 + sum) ^ ((v0 >> 5) - key[3]); 54 | } 55 | 56 | v[i] = v0; 57 | v[i + 1] = v1; 58 | 59 | sum = 0; 60 | } 61 | } 62 | 63 | 64 | void PrintUsage(int argc, char* argv[]) 65 | { 66 | printf("Use -file <\"file\"> and -enc or -dec parameter. Command line:\n"); 67 | for (int i = 0; i < argc; i++) 68 | { 69 | printf("%s\n", argv[i]); 70 | } 71 | printf("Quiting...\n"); 72 | } 73 | 74 | int main(int argc, char *argv[]) 75 | { 76 | char inputFilePath[MAX_PATH]; 77 | char outputFilePath[MAX_PATH]; 78 | bool encrypt; 79 | 80 | HFILE hFile; 81 | HFILE newFile; 82 | OFSTRUCT tOfStr; 83 | BY_HANDLE_FILE_INFORMATION bhFileInformation; 84 | DWORD bytesRead; 85 | DWORD bytesWritten; 86 | BYTE *readBuf; 87 | 88 | if (argc < 4) 89 | { 90 | PrintUsage(argc, argv); 91 | 92 | Sleep(CLOSE_TIME); 93 | return 0; 94 | } 95 | 96 | if (!strcmp(argv[1], "-file")) 97 | { 98 | strncpy(inputFilePath, argv[2], sizeof(inputFilePath)); 99 | } 100 | else 101 | { 102 | PrintUsage(argc, argv); 103 | 104 | Sleep(CLOSE_TIME); 105 | return 0; 106 | } 107 | 108 | if (!strcmp(argv[3], "-enc")) 109 | { 110 | encrypt = true; 111 | } 112 | else if (!strcmp(argv[3], "-dec")) 113 | { 114 | encrypt = false; 115 | } 116 | else 117 | { 118 | PrintUsage(argc, argv); 119 | 120 | Sleep(CLOSE_TIME); 121 | return 0; 122 | } 123 | 124 | hFile = OpenFile(inputFilePath, &tOfStr, OF_READWRITE); 125 | if (hFile == HFILE_ERROR) 126 | { 127 | CloseHandle((HANDLE)hFile); 128 | 129 | printf("OpenFile() failed: %d. Make sure that you entered currect file path. Quiting...\n", GetLastError()); 130 | 131 | Sleep(CLOSE_TIME); 132 | return 0; 133 | } 134 | 135 | GetFileInformationByHandle((HANDLE)hFile, &bhFileInformation); 136 | 137 | int viSize = bhFileInformation.nFileSizeLow; 138 | readBuf = new BYTE[viSize]; 139 | if (_llseek(hFile, 0 * sizeof(int), 0) != (long)(0 * sizeof(int))) 140 | { 141 | CloseHandle((HANDLE)hFile); 142 | 143 | Sleep(CLOSE_TIME); 144 | return 0; 145 | } 146 | 147 | if (!ReadFile((HANDLE)hFile, readBuf, viSize, &bytesRead, NULL)) 148 | { 149 | CloseHandle((HANDLE)hFile); 150 | 151 | printf("ReadFile() failed: %d. Make sure that you entered currect file path. Quiting...\n", GetLastError()); 152 | 153 | Sleep(CLOSE_TIME); 154 | return 0; 155 | } 156 | 157 | if (encrypt) 158 | { 159 | EncryptCSO((uint32_t*)readBuf, viSize); 160 | } 161 | else 162 | { 163 | DecryptCSO((uint32_t*)readBuf, viSize); 164 | } 165 | 166 | // get file name from path 167 | char* fileName = PathFindFileName(inputFilePath); 168 | 169 | // remove extension 170 | PathRemoveExtension(fileName); 171 | 172 | // remove filename from filepath 173 | PathRemoveFileSpecA(inputFilePath); 174 | 175 | if (encrypt) 176 | { 177 | sprintf(outputFilePath, "%s\\%s_enc.cso", inputFilePath, fileName); 178 | } 179 | else 180 | { 181 | sprintf(outputFilePath, "%s\\%s_dec.cso", inputFilePath, fileName); 182 | } 183 | 184 | // now create decrypted file 185 | newFile = (HFILE)CreateFile(outputFilePath, 186 | GENERIC_WRITE, 187 | 0, 188 | NULL, 189 | CREATE_ALWAYS, 190 | FILE_ATTRIBUTE_NORMAL, 191 | NULL); 192 | 193 | if (newFile == HFILE_ERROR) 194 | { 195 | printf("Could not create file: %d. Quiting...\n", GetLastError()); 196 | 197 | Sleep(CLOSE_TIME); 198 | return 0; 199 | } 200 | 201 | // write decrypted data to file 202 | WriteFile((HANDLE)newFile, readBuf, bytesRead, &bytesWritten, NULL); 203 | 204 | // save decrypted file 205 | CloseHandle((HANDLE)newFile); 206 | CloseHandle((HANDLE)hFile); 207 | 208 | printf("Operation completed.\n"); 209 | 210 | Sleep(CLOSE_TIME); 211 | return 0; 212 | } 213 | 214 | --------------------------------------------------------------------------------