Skip to content

Commit f009af4

Browse files
committed
[TEST:INSTRUCTION] Improve assembly code
1 parent a87b544 commit f009af4

4 files changed

Lines changed: 16 additions & 37 deletions

File tree

Source/Demo/Instruction.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ FN_INSTRUCTION(VOID);
1515

1616
#if defined(_M_X64)
1717

18-
EXTERN_C FN_INSTRUCTION* SimpleInstructionFunc1X64Ptr;
18+
EXTERN_C FN_INSTRUCTION SimpleInstructionFunc1X64;
1919

2020
#elif defined(_M_IX86)
2121

22-
EXTERN_C FN_INSTRUCTION* SimpleInstructionFunc1X86Ptr;
22+
EXTERN_C FN_INSTRUCTION SimpleInstructionFunc1X86;
2323

2424
#endif
2525

@@ -32,11 +32,11 @@ Hooked_InstructionFunc(VOID)
3232
return (ULONG_PTR)PRESET_RETURN_VALUE * 2;
3333
}
3434

35-
static FN_INSTRUCTION** g_apfnInstructionFunctions[] = {
35+
static FN_INSTRUCTION* g_apfnInstructionFunctions[] = {
3636
#if defined(_M_X64)
37-
&SimpleInstructionFunc1X64Ptr,
37+
&SimpleInstructionFunc1X64,
3838
#elif defined(_M_IX86)
39-
&SimpleInstructionFunc1X86Ptr,
39+
&SimpleInstructionFunc1X86,
4040
#endif
4141
NULL
4242
};
@@ -48,7 +48,7 @@ TEST_FUNC(Instruction)
4848

4949
for (ULONG i = 0; i < ARRAYSIZE(g_apfnInstructionFunctions) && g_apfnInstructionFunctions[i] != NULL; i++)
5050
{
51-
pfn2 = pfn1 = *g_apfnInstructionFunctions[i];
51+
pfn2 = pfn1 = g_apfnInstructionFunctions[i];
5252
if (pfn1() != (ULONG_PTR)PRESET_RETURN_VALUE)
5353
{
5454
TEST_SKIP("Instruction Function #%lu did not return the preset value\n", i);

Source/Demo/Instruction.inc

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
1-
IFDEF _M_IX86
1+
INCLUDE KNSoft\NDK\Assembly\Header.inc
2+
INCLUDE KNSoft\NDK\Assembly\NDK.inc
23

3-
SIZE_T equ <DWORD>
4-
PRESET_RETURN_VALUE equ 012345678h
5-
6-
ELSE
7-
8-
SIZE_T equ <QWORD>
4+
IFDEF _WIN64
95
PRESET_RETURN_VALUE equ 01234567890ABCDEFh
10-
6+
ELSE
7+
PRESET_RETURN_VALUE equ 012345678h
118
ENDIF
12-
13-
$PublicFuncAddr MACRO Func
14-
align 4
15-
@CatStr(Func, <Ptr SIZE_T offset >, Func)
16-
PUBLIC @CatStr(Func, <Ptr>)
17-
ENDM

Source/Demo/Instruction.x64.asm

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
include Instruction.inc
1+
INCLUDE Instruction.inc
22

3-
.code
3+
.CODE
44

55
SimpleInstructionFunc1X64 PROC
66

@@ -10,8 +10,4 @@ SimpleInstructionFunc1X64 PROC
1010

1111
SimpleInstructionFunc1X64 ENDP
1212

13-
.const
14-
15-
$PublicFuncAddr SimpleInstructionFunc1X64
16-
1713
END

Source/Demo/Instruction.x86.asm

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
.686P
2-
.XMM
3-
.model flat, stdcall
1+
INCLUDE Instruction.inc
42

5-
include Instruction.inc
3+
.CODE
64

7-
.code
8-
9-
SimpleInstructionFunc1X86 PROC
5+
SimpleInstructionFunc1X86 PROC C
106

117
xor eax, eax
128
mov eax, PRESET_RETURN_VALUE
139
ret
1410

1511
SimpleInstructionFunc1X86 ENDP
1612

17-
.const
18-
19-
$PublicFuncAddr SimpleInstructionFunc1X86
20-
2113
END

0 commit comments

Comments
 (0)