Skip to content

Commit

Permalink
Update Windows patches to 0.4.29, rewrite a bunch of code
Browse files Browse the repository at this point in the history
Closes #13
PS: fuck msvc
  • Loading branch information
geniiii committed Jun 5, 2021
1 parent 0755b67 commit 44cdb05
Show file tree
Hide file tree
Showing 26 changed files with 350 additions and 330 deletions.
11 changes: 11 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,16 @@ TabWidth: 4
UseTab: Always
BinPackParameters: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortBlocksOnASingleLine: true
CommentPragmas: '.\/[\*(\/\/)]+(.+\n.+)+\*\/'
ColumnLimit: 0
StatementMacros: ["PATCH", "CHECK"]
AlignConsecutiveDeclarations: true
AlignConsecutiveAssignments: true
AlignConsecutiveMacros: true
AllowShortFunctionsOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AlignOperands: true
SpaceAfterCStyleCast: true
SortIncludes: false
10 changes: 1 addition & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
.vs/*
*.exe
patcher
*.filters
*.user
*.obj
patcher.vcxproj
patcher.log
patcher.sln
build/
9 changes: 4 additions & 5 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ Currently has patches that allow you to:
* See deleted messages
* Send messages in channels with a cooldown enabled

Adding completely new features is not in the scope of this project.
Adding features that require more than changing a few bytes is not in the scope of this project.

== Supported platforms
Windows is the only one I make sure always works, as it's the platform I usually use.
I will occasionally test the Linux patches, however I can't assure you that they'll always work.
macOS is "supported", as in I've tried to make it work. I don't own a Mac, nor do I have a Hackintosh VM to test on.
Windows and Linux, though the latter won't get updated as quickly.

== Supported versions
0.4.28 on Windows, 0.4.27 on all other platforms, although you can go back a few commits if you want to use older versions.
Windows: `0.4.29`
Linux: `0.4.27`
This doesn't use pattern matching, so I have to manually update every time a new Ripcord version is released. It's usually updated within 12 hours of a new release, but I can't guarantee anything.
35 changes: 5 additions & 30 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ jobs:
vmImage: ubuntu-latest

steps:
- script: gcc -std=c99 -pedantic -Wextra -O3 -o patcher src/main.c src/patches.c src/checks.c
- script: gcc -std=c99 -pedantic -Wextra -O3 -DBUILD_LINUX=1 -o $BUILD_ARTIFACTSTAGINGDIRECTORY/patcher-linux-x64 src/build.c
displayName: 'Build'

- bash: mv $SYSTEM_DEFAULTWORKINGDIRECTORY/patcher $BUILD_ARTIFACTSTAGINGDIRECTORY/patcher-linux-x64
displayName: Move binary to artifact directory

- task: PublishBuildArtifacts@1
displayName: Upload binary to artifacts
inputs:
Expand All @@ -32,31 +29,10 @@ jobs:
vmImage: windows-latest

steps:
- task: MSBuild@1
inputs:
solution: $(System.DefaultWorkingDirectory)/patcher.vcxproj
platform: x64
configuration: Release

- bash: mv $SYSTEM_DEFAULTWORKINGDIRECTORY/x64/Release/patcher.exe $BUILD_ARTIFACTSTAGINGDIRECTORY/patcher-windows-x64.exe
displayName: Move binary to artifact directory

- task: PublishBuildArtifacts@1
displayName: Upload binary to artifacts
inputs:
artifactName: patcher
pathToPublish: $(Build.ArtifactStagingDirectory)

- job: macOS
pool:
vmImage: macos-latest

steps:
- script: clang -std=c99 -pedantic -Wextra -O3 -o patcher src/main.c src/patches.c src/checks.c
displayName: 'Build'

- bash: mv $SYSTEM_DEFAULTWORKINGDIRECTORY/patcher $BUILD_ARTIFACTSTAGINGDIRECTORY/patcher-macOS
displayName: Move binary to artifact directory
- script: |
call build_release.bat
move %SYSTEM_DEFAULTWORKINGDIRECTORY%\\build\\patcher.exe %BUILD_ARTIFACTSTAGINGDIRECTORY%\\patcher-windows-x64.exe
displayName: Build
- task: PublishBuildArtifacts@1
displayName: Upload binary to artifacts
Expand All @@ -72,7 +48,6 @@ jobs:
dependsOn:
- Windows
- Linux
- macOS

steps:
- task: DownloadBuildArtifacts@0
Expand Down
19 changes: 19 additions & 0 deletions build_debug.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@echo off

setlocal

call "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64

set application_name=patcher
set compiler=cl.exe

set build_options= /DBUILD_WIN32=1 /D_DEBUG /D_CRT_SECURE_NO_WARNINGS
set compile_flags= -nologo /W4 /permissive- /std:c17 /FC /TC /FS /Zi /I ../source/
set link_flags= -opt:ref -incremental:no /Debug:full

if not exist build mkdir build
pushd build
%compiler% %build_options% %compile_flags% ../source/build.c /link %link_flags% /out:%application_name%.exe
popd

endlocal
19 changes: 19 additions & 0 deletions build_release.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@echo off

setlocal

call "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64

set application_name=patcher
set compiler=cl.exe

set build_options= /DBUILD_WIN32=1 /D_CRT_SECURE_NO_WARNINGS
set compile_flags= -nologo /W4 /permissive- /std:c17 /FC /TC /O2 /I ../source/
set link_flags= -opt:ref -incremental:no /Debug:none

if not exist build mkdir build
pushd build
%compiler% %build_options% %compile_flags% ../source/build.c /link %link_flags% /out:%application_name%.exe
popd

endlocal
72 changes: 0 additions & 72 deletions patcher.vcxproj

This file was deleted.

17 changes: 17 additions & 0 deletions source/build.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "options.h"
#include "language_layer.h"

#include "strings.h"
#include "pattern.h"
#include "patches.h"

#include "strings.c"
#include "patches.c"
#include "checks.c"

#include "main.c"
26 changes: 26 additions & 0 deletions source/checks.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
typedef Patch Check;

#if BUILD_WIN32
#define CHECKS_INCLUDE_PATH "win32/checks.inc"
#elif BUILD_LINUX
#define CHECKS_INCLUDE_PATH "linux/checks.inc"
#endif

#define CHECK(check_name, check_offset, ...) \
global const Check check_name = { \
.name = S8LitComp(#check_name), \
.offset = check_offset, \
.pattern = PatternFromStringLitComp(__VA_ARGS__), \
};
#include CHECKS_INCLUDE_PATH
#undef CHECK

#define CHECK(checkname, ...) &checkname,
global const Check* checks[] = {
#include CHECKS_INCLUDE_PATH
};
#undef CHECK

global const u32 checks_count = ArraySize(checks);

#undef CHECKS_INCLUDE_PATH
16 changes: 16 additions & 0 deletions source/language_layer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#define global static
#define internal static
#define local_persist static
#define ArraySize(a) (sizeof(a) / sizeof((a)[0]))

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;

typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;

typedef i32 b32;
1 change: 1 addition & 0 deletions source/linux/checks.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHECK(version_check, 0x4C92AD, "0.4.27")
3 changes: 3 additions & 0 deletions source/linux/patches.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PATCH(deleted_message_details, 0x163FA0, {0xB8, 0x01, 0x00, 0x00, 0x00, 0xC3})
PATCH(deleted_message_append, 0x209DE3, {0xE9, 0x83, 0x00, 0x00})
PATCH(cooldown, 0x169CD0, {0xB8, 0x01, 0x00, 0x00, 0x00, 0xC3})
104 changes: 104 additions & 0 deletions source/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
i32 main(i32 argc, char** argv) {
// TODO(geni): Rewrite this whole thing
// TODO(geni): Memory-mapped files

if (argc == 2) {
if (CStringCompareToS8(argv[1], S8Lit("-h"))) {
String8 base_name = S8PathToBaseName(S8FromCString(argv[0]));
printf("Usage: %.*s [-h] [-l] [original (" DEFAULT_FILENAME ") [patched (" DEFAULT_PATCH_FILENAME ") [disabled patches]]]", S8Expand(base_name));
} else if (CStringCompareToS8(argv[1], S8Lit("-l"))) {
puts("Available patches:");
for (u32 i = 0; i < patches_count; ++i) {
printf("Patch \"%.*s\"\n", S8Expand(patches[i]->name));
}
}

return 0;
}

// NOTE(geni): User wants to disable specific patches
if (argc > 3) {
for (i32 i = 3; i < argc; ++i) {
for (u32 p = 0; p < patches_count; ++p) {
if (!patches[p]) {
continue;
}

if (S8CompareToCString(patches[p]->name, argv[i])) {
patches[p] = NULL;
}
}
}
}

FILE* fp = NULL;
if (argc == 1) {
fputs("No arguments passed, attempting to use " DEFAULT_FILENAME " as original binary...\n", stderr);
fp = fopen(DEFAULT_FILENAME, "rb");
} else {
fp = fopen(argv[1], "rb");
}

if (!fp) {
fputs("Failed to open original binary!\n", stderr);
return 1;
}

fseek(fp, 0, SEEK_END);
const u64 size = ftell(fp);
rewind(fp);

u8* buf = malloc(size);
if (!buf) {
fprintf(stderr, "Failed to allocate buffer (size %zu), not enough memory?", size);
fclose(fp);
return 1;
}
fread(buf, size, sizeof(u8), fp);
fclose(fp);

b32 failed_checks = 0;
for (u32 i = 0; i < checks_count; ++i) {
const Check* c = checks[i];

if (memcmp(buf + c->offset, PatternExpand(c->pattern)) != 0) {
fprintf(stderr, "Check \"%.*s\" failed!\n", S8Expand(c->name));
failed_checks = 1;
}
}
if (failed_checks) {
return 1;
}

for (u32 i = 0; i < patches_count; ++i) {
const Patch* p = patches[i];

// NOTE(geni): Patch is (hopefully) disabled
if (!p) {
continue;
}

memcpy(buf + p->offset, PatternExpand(p->pattern));
printf("Patch \"%.*s\" done\n", S8Expand(p->name));
}

if (argc < 2) {
fputs("No patched filename passed, attempting to use " DEFAULT_PATCH_FILENAME " as patched binary...\n", stderr);
fp = fopen(DEFAULT_PATCH_FILENAME, "wb");
} else {
fp = fopen(argv[2], "wb");
}

if (!fp) {
fputs("Failed to create patched binary!\n", stderr);
return 1;
}
const u64 written = fwrite(buf, sizeof(buf[0]), size, fp);
if (written != size) {
fputs("Number of bytes written differs from original size\n", stderr);
return 1;
}

fclose(fp);
free(buf);
}
Loading

0 comments on commit 44cdb05

Please sign in to comment.