Skip to content

Commit

Permalink
gust_enc: fix regression with adler checksum
Browse files Browse the repository at this point in the history
This caused non Fairy Tail files to be improperly scrambled and fail decoding
Closes #21
  • Loading branch information
VitaSmith committed Aug 14, 2020
1 parent c266042 commit 391eb3b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .vs/gust_enc.vcxproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>$(SolutionDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>-FT contents.xml.e</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>-A21 feedingevent.xml</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerWorkingDirectory>$(SolutionDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>-FT contents.xml.e</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>-A21 feedingevent.xml</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>-FT contents.xml.e</LocalDebuggerCommandArguments>
Expand Down
7 changes: 4 additions & 3 deletions gust_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ static bool scramble(uint8_t* payload, uint32_t payload_size, char* path, seed_d
uint32_t working_size, uint32_t version)
{
bool r = false;
uint32_t checksum[3] = { 0, 0, 0 };
uint32_t adler_sum, checksum[3] = { 0, 0, 0 };

// Align the size (plus an extra byte for the end marker) to 16-bytes
uint32_t main_payload_size = (payload_size + 1 + 0xf) & ~0xf;
Expand All @@ -536,10 +536,11 @@ static bool scramble(uint8_t* payload, uint32_t payload_size, char* path, seed_d
return false;
uint8_t* main_payload = &buf[E_HEADER_SIZE];
memcpy(main_payload, payload, payload_size);
adler_sum = adler32(payload, payload_size);

// Optionally scramble the beginning of the file
if (version == 2) {
init_random(checksum[2], seeds->main[2]);
init_random(adler_sum, seeds->main[2]);
if (!bit_scrambler(main_payload, min(payload_size, 0x800), 0x80, false))
goto out;
}
Expand All @@ -550,7 +551,7 @@ static bool scramble(uint8_t* payload, uint32_t payload_size, char* path, seed_d
switch (version) {
case 2:
#if !defined(VALIDATE_CHECKSUM)
checksum[2] = adler32(payload, payload_size);
checksum[2] = adler_sum;
#else
checksum[2] = VALIDATE_CHECKSUM;
#endif
Expand Down

0 comments on commit 391eb3b

Please sign in to comment.