Skip to content

Commit

Permalink
Fix improper patch offset when pairs of different sizes are supplied
Browse files Browse the repository at this point in the history
* Closes #8
* Also produce SHA of executable during AppVeyor build
  • Loading branch information
pbatard committed Aug 14, 2020
1 parent 8213ba7 commit 93e3c2e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .vs/winpatch.vcxproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerCommandArguments>-o C:\tmp\USBXHCI.SYS EA000037E8630091 EA000036E8630091 0A010037E8430091 0A010036E8430091</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>-o C:\tmp\USBXHCI.SYS 0037e8430091e1 0036e8430091e1 ea000037e8630091 ea000036e8630091</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerCommandArguments>-o C:\tmp\USBXHCI.SYS EA000037E8630091 EA000036E8630091 0A010037E8430091 0A010036E8430091</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>-o C:\tmp\USBXHCI.SYS 0037e8430091e1 0036e8430091e1 ea000037e8630091 ea000036e8630091</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ after_build:
ps: |-
# Make sure you use quotes around variables below!
7z a "$env:APPVEYOR_PROJECT_NAME.zip" ".\x86\Release\*.exe" LICENSE.txt
Get-FileHash ".\x86\Release\*.exe" | Format-List
Get-FileHash "$env:APPVEYOR_PROJECT_NAME.zip" -Algorithm SHA256 | Format-List
artifacts:
Expand Down
8 changes: 5 additions & 3 deletions src/winpatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ static int main_utf8(int argc, char** argv)
return -1;
}

spout("%s %s © 2020 Pete Batard <pete@akeo.ie>\n\n", appname(argv[0]), APP_VERSION_STR);
spout("\n%s %s © 2020 Pete Batard <pete@akeo.ie>\n\n", appname(argv[0]), APP_VERSION_STR);
if ((!ignore_patch && (hex_value_size < 2)) || help) {
pout("DESCRIPTION\n Take ownership, patch, update checksum and update digital\n");
pout(" signature (self-sign) of a PE executable.\n\n");
Expand Down Expand Up @@ -731,10 +731,10 @@ static int main_utf8(int argc, char** argv)
if ((chunk_list[i].patched++ == 1) && warn_on_multiple) {
perr("WARNING: More than one section with data %s is being patched!\n", hex_value[2 * i]);
}
static_sprintf(format, "%08llX - %%s\n", pos);
static_sprintf(format, "%08llX - %%s\n", pos - val_size + chunk_list[i].size);
SplitHexString(format, " - %s\n", hex_value[2 * i]);
memcpy(val, chunk_list[i].new, chunk_list[i].size);
fseek(file, (long)pos, SEEK_SET);
fseek(file, (long)(pos - val_size + chunk_list[i].size), SEEK_SET);
if (fwrite(&val, 1, chunk_list[i].size, file) != chunk_list[i].size) {
SplitHexString(" = %s [FAILED!]\n", " = %s\n", hex_value[2 * i]);
} else {
Expand Down Expand Up @@ -804,6 +804,8 @@ static int main_utf8(int argc, char** argv)

int wmain(int argc, wchar_t** argv16)
{
fflush(stdin);
fflush(stdout);
SetConsoleOutputCP(CP_UTF8);
char** argv = calloc(argc, sizeof(char*));
if (argv == NULL)
Expand Down

0 comments on commit 93e3c2e

Please sign in to comment.