Skip to content

Commit a8bf5ac

Browse files
committed
LogiOptions+ 1.94 compatibility
1 parent dd59b2e commit a8bf5ac

10 files changed

Lines changed: 98 additions & 61 deletions

File tree

logiopt-version/logiopt-version.vcxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535
<ClCompile Include="src\wrapped_api.cpp" />
3636
</ItemGroup>
3737
<ItemGroup>
38-
<MASM Include="src\inject32.asm">
39-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
40-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
41-
</MASM>
4238
<MASM Include="src\inject64.asm">
4339
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
4440
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>

logiopt-version/src/dllmain.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
#define TARGET_MACHINE_CODE_V146 0x48, 0x8D, 0x4D, 0xFF, 0x49, 0x83, 0xFE, 0x10, 0x48, 0x0F, 0x43, 0xCE, 0x48, 0x83, 0xFB, 0x0B, 0x75, 0x17, 0x4C, 0x8B, 0xC3
2626
#define TARGET_MACHINE_CODE_V168 0x48, 0x8D, 0x4D, 0xDF, 0x49, 0x83, 0xFE, 0x10, 0x48, 0x0F, 0x43, 0xCF, 0x48, 0x83, 0xFB, 0x0B, 0x75, 0x17, 0x4C, 0x8B, 0xC3
2727
#define TARGET_MACHINE_CODE_V186 0x48, 0x8D, 0x4D, 0xC0, 0x49, 0x83, 0xFE, 0x10, 0x48, 0x0F, 0x43, 0xCF, 0x48, 0x83, 0xFB, 0x0B, 0x75, 0x17, 0x4C, 0x8B, 0xC3
28+
#define TARGET_MACHINE_CODE_V194 0x48, 0x8D, 0x4D, 0x00, 0x48, 0x83, 0xFE, 0x0F, 0x48, 0x0F, 0x47, 0xCF, 0x48, 0x83, 0xFB, 0x0B, 0x75, 0x17, 0x4C, 0x8B, 0xC3
2829
// HOOK_MACHINE_CODE is the byte sequence of code to be replaced by injected code that is close to and after the found target code
2930
// (5 bytes minimum)
3031
#define HOOK_MACHINE_CODE_V100 0x88, 0x45, 0x28, 0x48, 0x8B, 0x7D, 0x08
3132
#define HOOK_MACHINE_CODE_V146 0x41, 0x88, 0x44, 0x24, 0x28, 0x4D, 0x8B, 0x64, 0x24, 0x08
3233
#define HOOK_MACHINE_CODE_V168 0x41, 0x88, 0x44, 0x24, 0x28, 0x4D, 0x8B, 0x64, 0x24, 0x08
3334
#define HOOK_MACHINE_CODE_V186 0x41, 0x88, 0x44, 0x24, 0x28, 0x4D, 0x8B, 0x64, 0x24, 0x08
35+
#define HOOK_MACHINE_CODE_V194 0x41, 0x88, 0x47, 0x28, 0x49, 0x8B, 0x7F, 0x08
3436
#define MAX_PATCH_CODE_DISP 0x20
3537
#else
3638
#define TARGET_MACHINE_CODE 0x48, 0x8D, 0x4C, 0x24, 0x78, 0x48, 0x83, 0xFF, 0x10, 0x48, 0x0F, 0x43, 0xCB, 0x48, 0x83, 0xFE, 0x0B, 0x75, 0x17, 0x4C, 0x8B, 0xC6
@@ -43,10 +45,12 @@ constexpr byte logioptions_target_code_V100[] = { TARGET_MACHINE_CODE_V100 };
4345
constexpr byte logioptions_target_code_V146[] = { TARGET_MACHINE_CODE_V146 };
4446
constexpr byte logioptions_target_code_V168[] = { TARGET_MACHINE_CODE_V168 };
4547
constexpr byte logioptions_target_code_V186[] = { TARGET_MACHINE_CODE_V186 };
48+
constexpr byte logioptions_target_code_V194[] = { TARGET_MACHINE_CODE_V194 };
4649
constexpr byte logioptions_hook_code_V100[] = { HOOK_MACHINE_CODE_V100 };
4750
constexpr byte logioptions_hook_code_V146[] = { HOOK_MACHINE_CODE_V146 };
4851
constexpr byte logioptions_hook_code_V168[] = { HOOK_MACHINE_CODE_V168 };
4952
constexpr byte logioptions_hook_code_V186[] = { HOOK_MACHINE_CODE_V186 };
53+
constexpr byte logioptions_hook_code_V194[] = { HOOK_MACHINE_CODE_V194 };
5054
constexpr long code_memory_protection = PAGE_EXECUTE | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY;
5155

5256
std::vector<std::string> enabled_names;
@@ -60,6 +64,7 @@ extern "C"
6064
extern void injected_handler_V146();
6165
extern void injected_handler_V168();
6266
extern void injected_handler_V186();
67+
extern void injected_handler_V194();
6368

6469
bool patched_switch_foreground_process_handler(const char* name, size_t length, bool previous_check)
6570
{
@@ -266,7 +271,13 @@ namespace
266271
size_t target_code_size, hook_code_size;
267272
void (*injected_handler)();
268273
byte* found_addr;
269-
if (find_data(memory, bytes_count, logioptions_target_code_V186, target_code_size = sizeof logioptions_target_code_V186, found_addr))
274+
if (find_data(memory, bytes_count, logioptions_target_code_V194, target_code_size = sizeof logioptions_target_code_V194, found_addr))
275+
{
276+
injected_handler = injected_handler_V194;
277+
hook_code = logioptions_hook_code_V194;
278+
hook_code_size = sizeof logioptions_hook_code_V194;
279+
}
280+
else if (find_data(memory, bytes_count, logioptions_target_code_V186, target_code_size = sizeof logioptions_target_code_V186, found_addr))
270281
{
271282
injected_handler = injected_handler_V186;
272283
hook_code = logioptions_hook_code_V186;

logiopt-version/src/inject32.asm

Lines changed: 0 additions & 22 deletions
This file was deleted.

logiopt-version/src/inject64.asm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,18 @@ injected_handler_V186 proc
8282
jmp [original_jump_address]
8383
injected_handler_V186 endp
8484

85+
injected_handler_V194 proc
86+
; Not saving registers in stack, due to not required by the patched code
87+
; Shadow space of the target function may be used in the callee
88+
lea rcx, [rbp+70h-70h]
89+
cmp rsi, 0Fh
90+
cmova rcx, rdi ; name
91+
mov rdx, rbx ; length
92+
movzx r8, al ; previous check
93+
call patched_switch_foreground_process_handler
94+
mov [r15+28h], al
95+
mov rdi, [r15+8h]
96+
jmp [original_jump_address]
97+
injected_handler_V194 endp
98+
8599
end

logiopt_agent-patch/inject32.asm

Lines changed: 0 additions & 22 deletions
This file was deleted.

logiopt_agent-patch/inject64.asm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,18 @@ injected_handler_V186 proc
8282
jmp [original_jump_address]
8383
injected_handler_V186 endp
8484

85+
injected_handler_V194 proc
86+
; Not saving registers in stack, due to not required by the patched code
87+
; Shadow space of the target function may be used in the callee
88+
lea rcx, [rbp+70h-70h]
89+
cmp rsi, 0Fh
90+
cmova rcx, rdi ; name
91+
mov rdx, rbx ; length
92+
movzx r8, al ; previous check
93+
call patched_switch_foreground_process_handler
94+
mov [r15+28h], al
95+
mov rdi, [r15+8h]
96+
jmp [original_jump_address]
97+
injected_handler_V194 endp
98+
8599
end

logiopt_agent-patch/logiopt_agent-patch.vcxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
<ClCompile Include="utilities.cpp" />
2525
</ItemGroup>
2626
<ItemGroup>
27-
<MASM Include="inject32.asm">
28-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
29-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
30-
</MASM>
3127
<MASM Include="inject64.asm">
3228
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
3329
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>

logiopt_agent-patch/logiopt_agent-patch.vcxproj.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
<MASM Include="inject64.asm">
3030
<Filter>Source Files</Filter>
3131
</MASM>
32-
<MASM Include="inject32.asm">
33-
<Filter>Source Files</Filter>
34-
</MASM>
3532
<MASM Include="target64.asm">
3633
<Filter>Source Files</Filter>
3734
</MASM>

logiopt_agent-patch/main.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define TARGET_MACHINE_CODE_V146 0x48, 0x8D, 0x4D, 0xFF, 0x49, 0x83, 0xFE, 0x10, 0x48, 0x0F, 0x43, 0xCE, 0x48, 0x83, 0xFB, 0x0B, 0x75, 0x17, 0x4C, 0x8B, 0xC3
2424
#define TARGET_MACHINE_CODE_V168 0x48, 0x8D, 0x4D, 0xDF, 0x49, 0x83, 0xFE, 0x10, 0x48, 0x0F, 0x43, 0xCF, 0x48, 0x83, 0xFB, 0x0B, 0x75, 0x17, 0x4C, 0x8B, 0xC3
2525
#define TARGET_MACHINE_CODE_V186 0x48, 0x8D, 0x4D, 0xC0, 0x49, 0x83, 0xFE, 0x10, 0x48, 0x0F, 0x43, 0xCF, 0x48, 0x83, 0xFB, 0x0B, 0x75, 0x17, 0x4C, 0x8B, 0xC3
26+
#define TARGET_MACHINE_CODE_V194 0x48, 0x8D, 0x4D, 0x00, 0x48, 0x83, 0xFE, 0x0F, 0x48, 0x0F, 0x47, 0xCF, 0x48, 0x83, 0xFB, 0x0B, 0x75, 0x17, 0x4C, 0x8B, 0xC3
2627
#define PATCH_MACHINE_CODE 0x32, 0xC0
2728
#define REPLACEMENT_MACHINE_CODE 0xB0, 0x01
2829
// HOOK_MACHINE_CODE is the byte sequence of code to be replaced by injected code that is close to and after the found target code
@@ -31,6 +32,7 @@
3132
#define HOOK_MACHINE_CODE_V146 0x41, 0x88, 0x44, 0x24, 0x28, 0x4D, 0x8B, 0x64, 0x24, 0x08
3233
#define HOOK_MACHINE_CODE_V168 0x41, 0x88, 0x44, 0x24, 0x28, 0x4D, 0x8B, 0x64, 0x24, 0x08
3334
#define HOOK_MACHINE_CODE_V186 0x41, 0x88, 0x44, 0x24, 0x28, 0x4D, 0x8B, 0x64, 0x24, 0x08
35+
#define HOOK_MACHINE_CODE_V194 0x41, 0x88, 0x47, 0x28, 0x49, 0x8B, 0x7F, 0x08
3436
//#define CAVE_MACHINE_CODE_V100 0x5D, 0xC3, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC // 13 bytes minimum (after displacement)
3537
//#define CAVE_MACHINE_CODE_DISP_V100 2
3638
#define MAX_PATCH_CODE_DISP 0x20
@@ -49,12 +51,14 @@ constexpr byte logioptions_target_code_V100[] = { TARGET_MACHINE_CODE_V100 };
4951
constexpr byte logioptions_target_code_V146[] = { TARGET_MACHINE_CODE_V146 };
5052
constexpr byte logioptions_target_code_V168[] = { TARGET_MACHINE_CODE_V168 };
5153
constexpr byte logioptions_target_code_V186[] = { TARGET_MACHINE_CODE_V186 };
54+
constexpr byte logioptions_target_code_V194[] = { TARGET_MACHINE_CODE_V194 };
5255
constexpr byte logioptions_hook_code_V100[] = { HOOK_MACHINE_CODE_V100 };
5356
constexpr byte logioptions_hook_code_V146[] = { HOOK_MACHINE_CODE_V146 };
5457
constexpr byte logioptions_hook_code_V168[] = { HOOK_MACHINE_CODE_V168 };
5558
constexpr byte logioptions_hook_code_V186[] = { HOOK_MACHINE_CODE_V186 };
56-
const byte *logioptions_target_code = logioptions_target_code_V186;
57-
const byte *logioptions_hook_code = logioptions_hook_code_V186;
59+
constexpr byte logioptions_hook_code_V194[] = { HOOK_MACHINE_CODE_V194 };
60+
const byte *logioptions_target_code = logioptions_target_code_V194;
61+
const byte *logioptions_hook_code = logioptions_hook_code_V194;
5862
#ifdef CODE_CAVE
5963
//constexpr byte logioptions_cave_code_V100[] = { CAVE_MACHINE_CODE_V100 };
6064
//constexpr size_t logioptions_cave_code_disp_V100 = CAVE_MACHINE_CODE_DISP_V100;
@@ -72,11 +76,13 @@ extern "C"
7276
extern bool target_handler_V146(const char* name, size_t length);
7377
extern bool target_handler_V168(const char* name, size_t length);
7478
extern bool target_handler_V186(const char* name, size_t length);
79+
extern bool target_handler_V194(const char* name, size_t length);
7580

7681
extern void injected_handler_V100();
7782
extern void injected_handler_V146();
7883
extern void injected_handler_V168();
7984
extern void injected_handler_V186();
85+
extern void injected_handler_V194();
8086

8187
bool patched_switch_foreground_process_handler(const char* name, size_t length, bool previous_check)
8288
{
@@ -373,7 +379,13 @@ void hook_current_process()
373379
size_t target_code_size, hook_code_size;
374380
void (*injected_handler)();
375381
byte* found_addr;
376-
if (find_data(memory, bytes_count, logioptions_target_code_V186, target_code_size = sizeof logioptions_target_code_V186, found_addr))
382+
if (find_data(memory, bytes_count, logioptions_target_code_V194, target_code_size = sizeof logioptions_target_code_V194, found_addr))
383+
{
384+
injected_handler = injected_handler_V194;
385+
hook_code = logioptions_hook_code_V194;
386+
hook_code_size = sizeof logioptions_hook_code_V194;
387+
}
388+
else if (find_data(memory, bytes_count, logioptions_target_code_V186, target_code_size = sizeof logioptions_target_code_V186, found_addr))
377389
{
378390
injected_handler = injected_handler_V186;
379391
hook_code = logioptions_hook_code_V186;
@@ -465,7 +477,7 @@ int main()
465477
//patch_another_process();
466478
read_config();
467479
hook_current_process();
468-
const bool result = target_handler_V186(PROGRAM_NAME_CHARS, sizeof PROGRAM_NAME_CHARS);
480+
const bool result = target_handler_V194(PROGRAM_NAME_CHARS, sizeof PROGRAM_NAME_CHARS);
469481
std::cout << "Handler result = " << static_cast<int>(result) << '\n';
470482
return 0;
471483
}

logiopt_agent-patch/target64.asm

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ notfound:
161161
return:
162162
mov [r12+28h], al
163163
mov r12, [r12+8h]
164-
add rsp, 0B0h
164+
add rsp, 110h
165165
pop r14
166166
pop r12
167167
pop rdi
@@ -172,4 +172,45 @@ return:
172172
db 12 dup(0cch)
173173
target_handler_V186 endp
174174

175+
target_handler_V194 proc
176+
push rbp
177+
push rbx
178+
push rsi
179+
push rdi
180+
push r15
181+
lea rbp, [rsp-50h]
182+
sub rsp, 150h
183+
mov r15, rsp
184+
mov rdi, rcx ; name
185+
mov rbx, rdx ; length
186+
mov [rbp+70h-70h], rcx
187+
mov rsi, 10h
188+
lea rcx, [rbp+70h-70h]
189+
cmp rsi, 0Fh
190+
cmova rcx, rdi
191+
cmp rbx, sizeof firefox_exe - 1
192+
jnz notfound
193+
mov r8, rbx
194+
lea rdx, [firefox_exe]
195+
call memcmp
196+
test eax, eax
197+
jz notfound
198+
found:
199+
mov al, 1
200+
jmp return
201+
notfound:
202+
xor al, al
203+
return:
204+
mov [r15+28h], al
205+
mov rdi, [r15+8h]
206+
add rsp, 150h
207+
pop r15
208+
pop rdi
209+
pop rsi
210+
pop rbx
211+
pop rbp
212+
ret
213+
db 12 dup(0cch)
214+
target_handler_V194 endp
215+
175216
end

0 commit comments

Comments
 (0)