Browse Source

advanced instructions (AVX, RDRAND)

master
aaaaaa aaaaaaa 7 years ago
parent
commit
d350a8ed80
5 changed files with 53 additions and 1 deletions
  1. +17
    -0
      hook_tests/advanced_instructions.asm
  2. +15
    -0
      hook_tests/advanced_instructions.h
  3. +3
    -0
      hook_tests/hook_tests.vcxproj
  4. +7
    -0
      hook_tests/hook_tests.vcxproj.filters
  5. +11
    -1
      hook_tests/main.cpp

+ 17
- 0
hook_tests/advanced_instructions.asm View File

format ms64 coff

section '.text' code readable executable

use64

public _AVX
_AVX:
vbroadcastsd ymm0, xmm0 ; load @num into all slots
vsqrtpd ymm0, ymm0
vmovdqu [rdx], ymm0 ; store result in @res
ret

public _RDRAND
_RDRAND:
rdrand eax
ret

+ 15
- 0
hook_tests/advanced_instructions.h View File

#pragma once
extern "C" {
/**
* Gets the square root of num four times and writes it to @res
*
* @param num: the number of which the square root shall be taken
* @param res: where the 4 results shall be written
*/
void _AVX(float num, void* res);

/**
* Just a wrapper around RDRAND
*/
uint32_t _RDRAND(void);
}

+ 3
- 0
hook_tests/hook_tests.vcxproj View File

</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="advanced_instructions.h" />
<ClInclude Include="catch.hpp" /> <ClInclude Include="catch.hpp" />
<ClInclude Include="simple_tests.h" /> <ClInclude Include="simple_tests.h" />
</ItemGroup> </ItemGroup>
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="advanced_instructions.asm" />
<None Include="README.md" /> <None Include="README.md" />
<None Include="simple_tests.asm" /> <None Include="simple_tests.asm" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Object Include="advanced_instructions.obj" />
<Object Include="simple_tests.obj" /> <Object Include="simple_tests.obj" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

+ 7
- 0
hook_tests/hook_tests.vcxproj.filters View File

<ClInclude Include="simple_tests.h"> <ClInclude Include="simple_tests.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="advanced_instructions.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="main.cpp"> <ClCompile Include="main.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</None> </None>
<None Include="README.md" /> <None Include="README.md" />
<None Include="advanced_instructions.asm">
<Filter>Source Files</Filter>
</None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Object Include="simple_tests.obj" /> <Object Include="simple_tests.obj" />
<Object Include="advanced_instructions.obj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

+ 11
- 1
hook_tests/main.cpp View File

#define CATCH_CONFIG_MAIN #define CATCH_CONFIG_MAIN
#include "catch.hpp" #include "catch.hpp"
#include "simple_tests.h" #include "simple_tests.h"
#include "advanced_instructions.h"


TEST_CASE("Functions work as expected, unhooked") {
TEST_CASE("Simple functions work as expected, unhooked") {
REQUIRE(_small() == 0); REQUIRE(_small() == 0);


REQUIRE(_branch(1) == 0); REQUIRE(_branch(1) == 0);
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
REQUIRE(_rip_relative() == rand()); REQUIRE(_rip_relative() == rand());
} }
}

TEST_CASE("Advanced instruction functions work as expected, unhokked") {
double result[4];
_AVX(9., static_cast<void*>(result));
REQUIRE((result[0] - result[1]) < DBL_EPSILON);
REQUIRE((result[1] - result[2]) < DBL_EPSILON);
REQUIRE((result[2] - result[3]) < DBL_EPSILON);
REQUIRE((result[0] - 3.) < DBL_EPSILON);
} }

Loading…
Cancel
Save