Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix relocation of branch instructions with RIP-relative memory operand #6

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions include/Zyrex/Internal/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ ZYAN_INLINE ZyanStatus ZyrexCalcAbsoluteAddress(const ZydisDecodedInstruction* i
}

// Relative branch instruction
if (instruction->raw.imm[0].is_signed &&
instruction->raw.imm[0].is_relative)
if (instruction->raw.imm[0].is_signed && instruction->raw.imm[0].is_relative)
{
*result_address = (ZyanU64)((ZyanI64)runtime_address + instruction->length +
instruction->raw.imm[0].value.s);
Expand Down
2 changes: 1 addition & 1 deletion include/Zyrex/Status.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern "C" {
/* ---------------------------------------------------------------------------------------------- */

/**
* @brief The zydis module id.
* @brief The Zyrex module id.
*/
#define ZYAN_MODULE_ZYREX 0x200

Expand Down
13 changes: 9 additions & 4 deletions src/Relocation.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ typedef struct ZyrexAnalyzedInstruction_
* @brief Contains the ids of all instructions inside the analyzed code chunk that are
* targeting this instruction using a relative offset.
*/
ZyanVector/*<ZyanU8>*/ incomming;
ZyanVector/*<ZyanU8>*/ incoming;
/**
* @brief The id of an instruction inside the analyzed code chunk which is targeted by
* this instruction using a relative offset, or `-1` if not applicable.
Expand Down Expand Up @@ -164,7 +164,7 @@ static void ZyrexAnalyzedInstructionDestroy(ZyrexAnalyzedInstruction* item)

if (item->is_internal_target)
{
ZyanVectorDestroy(&item->incomming);
ZyanVectorDestroy(&item->incoming);
}
}

Expand Down Expand Up @@ -267,11 +267,11 @@ static ZyanStatus ZyrexAnalyzeCode(const void* buffer, ZyanUSize length,
if (!current->is_internal_target)
{
current->is_internal_target = ZYAN_TRUE;
ZYAN_CHECK(ZyanVectorInit(&current->incomming, sizeof(ZyanU8), 2,
ZYAN_CHECK(ZyanVectorInit(&current->incoming, sizeof(ZyanU8), 2,
ZYAN_NULL));
}
const ZyanU8 value = (ZyanU8)j;
ZYAN_CHECK(ZyanVectorPushBack(&current->incomming, &value));
ZYAN_CHECK(ZyanVectorPushBack(&current->incoming, &value));
}
}
}
Expand All @@ -292,6 +292,11 @@ static ZyanBool ZyrexIsRelativeBranchInstruction(const ZydisDecodedInstruction*
{
ZYAN_ASSERT(instruction);

if (!instruction->raw.imm[0].is_relative)
{
return ZYAN_FALSE;
}

switch (instruction->mnemonic)
{
case ZYDIS_MNEMONIC_JMP:
Expand Down
Loading