-
Notifications
You must be signed in to change notification settings - Fork 47
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
1 parent
b8d6027
commit 1d74f8b
Showing
6 changed files
with
122 additions
and
9 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 |
---|---|---|
|
@@ -360,3 +360,6 @@ MigrationBackup/ | |
|
||
# Fody - auto-generated XML schema | ||
FodyWeavers.xsd | ||
|
||
# Linux builds | ||
build |
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,10 @@ | ||
cmake_minimum_required(VERSION 3.8) | ||
|
||
project(LinuxUsermode) | ||
|
||
file(GLOB_RECURSE sourcefiles | ||
"src/*.h" | ||
"src/*.c" | ||
) | ||
|
||
add_executable(LinuxUsermode ${sourcefiles}) |
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,6 @@ | ||
rm -rf ./build | ||
mkdir build | ||
cd build | ||
cmake .. | ||
make | ||
./LinuxUsermode |
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,47 @@ | ||
#include "../../../Source/LightHook.h" | ||
#include <stdio.h> | ||
|
||
static HookInformation testHook; | ||
typedef int(*TestFunction_t)(int param1, int param2); | ||
|
||
int __attribute__ ((noinline))TestFunction(int param1, int param2) | ||
{ | ||
param2 -= param1; | ||
param1 += param2; | ||
for (int i = 0; i < 10; i++) | ||
param1 += param2 * param2; | ||
|
||
param2 *= param1; | ||
param1 *= param2; | ||
for (int i = 0; i < 5; i++) | ||
param1 += param2 * param2; | ||
|
||
printf("in func: %i\n", param1); | ||
return param1; | ||
} | ||
|
||
int __attribute__ ((noinline)) HookedTestFunction() | ||
{ | ||
printf("hook called\n"); | ||
|
||
TestFunction_t original = (TestFunction_t)testHook.Trampoline; | ||
return original(0, 2); | ||
//return 0; | ||
} | ||
|
||
int main() | ||
{ | ||
int output = TestFunction(0, 1); | ||
printf("before hook: %u\n", output); | ||
|
||
testHook = CreateHook((void*)&TestFunction, (void*)&HookedTestFunction); | ||
printf("size: %u\n", testHook.BytesToCopy); | ||
|
||
int status = EnableHook(&testHook); | ||
printf("status: %u\n", status); | ||
printf("trampoline: 0x%p\n", testHook.Trampoline); | ||
|
||
output = TestFunction(0, 1); | ||
printf("after hook: %u\n", output); | ||
return 0; | ||
} |
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,19 @@ | ||
Copyright (c) 2022 Samuel Tulach | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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