maj du crypter

en attente d'une update de zydis sur vcpkg
This commit is contained in:
2023-02-05 07:12:26 +01:00
parent afb3db1078
commit 2b4e2bc775
3 changed files with 59 additions and 10 deletions

View File

@@ -78,9 +78,20 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<IncludePath>$(IncludePath)</IncludePath>
<AllProjectIncludesArePublic>false</AllProjectIncludesArePublic>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
<IncludePath>$(IncludePath)</IncludePath>
<AllProjectIncludesArePublic>false</AllProjectIncludesArePublic>
<LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);</LibraryPath>
</PropertyGroup>
<PropertyGroup Label="Vcpkg">
<VcpkgEnabled>true</VcpkgEnabled>
<VcpkgManifestInstall>true</VcpkgManifestInstall>
<VcpkgAutoLink>true</VcpkgAutoLink>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
@@ -121,6 +132,7 @@
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">

View File

@@ -14,9 +14,6 @@
<Filter Include="Config"> <Filter Include="Config">
<UniqueIdentifier>{47733102-deb7-437d-ada8-bca851a43356}</UniqueIdentifier> <UniqueIdentifier>{47733102-deb7-437d-ada8-bca851a43356}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Imports">
<UniqueIdentifier>{ecae1be1-6edb-45a9-bf23-273b5e5bf6f3}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="main.cpp"> <ClCompile Include="main.cpp">

View File

@@ -8,14 +8,13 @@
#include <inttypes.h> #include <inttypes.h>
#include <Zydis/Zydis.h> #include <Zydis/Zydis.h>
#include <Zydis/SharedTypes.h> #include <Zycore/LibC.h>
#include <Zydis/Decoder.h> #include <Zycore/API/Memory.h>
#include "random.hpp" #include "random.hpp"
#include "utils.hpp" #include "utils.hpp"
#include "config.hpp" #include "config.hpp"
extern g_random random; extern g_random random;
unsigned __int64 origSeed; unsigned __int64 origSeed;
@@ -165,10 +164,11 @@ int main(int argc, char* argv[]) {
} }
printf("\n"); printf("\n");
printf(" Enumerating .text instructions and finding the stuff to change...\n");
// Initialize decoder context // Initialize decoder context
ZydisDecoder decoder; ZydisDecoder decoder;
ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LEGACY_32, ZYDIS_ADDRESS_WIDTH_32); ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LEGACY_32, ZYDIS_STACK_WIDTH_32);
// Initialize formatter. Only required when you actually plan to do instruction // Initialize formatter. Only required when you actually plan to do instruction
// formatting ("disassembling"), like we do here // formatting ("disassembling"), like we do here
@@ -182,18 +182,58 @@ int main(int argc, char* argv[]) {
ZyanUSize offset = text_addr; ZyanUSize offset = text_addr;
const ZyanUSize length = sizeof((char*)mapped_file); const ZyanUSize length = sizeof((char*)mapped_file);
ZydisDecodedInstruction instruction; ZydisDecodedInstruction instruction;
ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT];
while (ZYAN_SUCCESS(ZydisDecoderDecodeBuffer(&decoder, (char*)mapped_file + offset, length - offset, while (ZYAN_SUCCESS(ZydisDecoderDecodeFull(&decoder, (char*)mapped_file + offset, length - offset,
&instruction)) && offset < text_size + text_addr) &instruction, operands)) && offset < text_size + text_addr)
{ {
// Print current instruction pointer. // Print current instruction pointer.
printf(" %016" PRIX64 " ", runtime_address); printf(" %016" PRIX64 " ", runtime_address);
// Format & print the binary instruction structure to human-readable format // Format & print the binary instruction structure to human-readable format
char buffer[256]; char buffer[256];
ZydisFormatterFormatInstruction(&formatter, &instruction, buffer, sizeof(buffer), runtime_address); ZydisFormatterFormatInstruction(&formatter, &instruction, operands, instruction.operand_count_visible, buffer, sizeof(buffer), runtime_address, ZYAN_NULL);
puts(buffer); puts(buffer);
// Create an encoder request from the previously decoded instruction.
ZydisEncoderRequest enc_req;
ZydisEncoderDecodedInstructionToEncoderRequest(&instruction, operands,
instruction.operand_count_visible, &enc_req);
// Now, change some things about the instruction!
// Change `jz` -> `jnz` and `add` -> `sub`.
bool changed = true;
switch (enc_req.mnemonic)
{
case ZYDIS_MNEMONIC_ADD:
enc_req.mnemonic = ZYDIS_MNEMONIC_SUB;
break;
case ZYDIS_MNEMONIC_JZ:
enc_req.mnemonic = ZYDIS_MNEMONIC_JNZ;
break;
default:
// Don't change other instructions.
changed = false;
break;
}
if (changed) {
printf(" Instruction %s changed\n", buffer);
}
// Encode the instruction back to raw bytes.
uint8_t new_bytes[ZYDIS_MAX_INSTRUCTION_LENGTH];
ZyanUSize new_instr_length = sizeof(new_bytes);
ZydisEncoderEncodeInstruction(&enc_req, new_bytes, &new_instr_length);
// Decode and print the new instruction. We re-use the old buffers.
ZydisDecoderDecodeFull(&decoder, new_bytes, new_instr_length, &instruction,
operands);
ZydisFormatterFormatInstruction(&formatter, &instruction, operands,
instruction.operand_count_visible, buffer, sizeof(buffer), 0, NULL);
printf(" New instruction: %s\n", buffer);
offset += instruction.length; offset += instruction.length;
runtime_address += instruction.length; runtime_address += instruction.length;
} }