|
|
|
@ -150,7 +150,7 @@ VOID ObfXorInstBytes(PNATIVE_CODE_LINK Link, PXOR_INST_DATA XorData)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PNATIVE_CODE_BLOCK ObfEmitPreXorForInst(PNATIVE_CODE_LINK Link, PXOR_INST_DATA XorData, BOOL SaveFlags)
|
|
|
|
|
PNATIVE_CODE_BLOCK ObfEmitPreXorForInst(PNATIVE_CODE_LINK Link, PXOR_INST_DATA XorData, BOOL SaveFlags, INT32 DeltaToInst)
|
|
|
|
|
{
|
|
|
|
|
ULONG FourByte = Link->RawDataSize / 4;
|
|
|
|
|
ULONG TwoByte = (Link->RawDataSize - (FourByte * 4)) / 2;
|
|
|
|
@ -177,6 +177,7 @@ PNATIVE_CODE_BLOCK ObfEmitPreXorForInst(PNATIVE_CODE_LINK Link, PXOR_INST_DATA X
|
|
|
|
|
RipDelta += 1;
|
|
|
|
|
//Account for already XORd instructions
|
|
|
|
|
RipDelta += ((FourByte - Count) * 4);
|
|
|
|
|
RipDelta += DeltaToInst;
|
|
|
|
|
//Add the actual instruction
|
|
|
|
|
if (!ObfEmitRipRelativeXorD(Block, RipDelta, XorData->Data[FourByte-Count]))
|
|
|
|
|
{
|
|
|
|
@ -193,6 +194,7 @@ PNATIVE_CODE_BLOCK ObfEmitPreXorForInst(PNATIVE_CODE_LINK Link, PXOR_INST_DATA X
|
|
|
|
|
if (SaveFlags)
|
|
|
|
|
RipDelta += 1;
|
|
|
|
|
RipDelta += (FourByte * 4);
|
|
|
|
|
RipDelta += DeltaToInst;
|
|
|
|
|
if (!ObfEmitRipRelativeXorW(Block, RipDelta, XorData->Data[3]))
|
|
|
|
|
{
|
|
|
|
|
NcDelete(Block);
|
|
|
|
@ -207,6 +209,7 @@ PNATIVE_CODE_BLOCK ObfEmitPreXorForInst(PNATIVE_CODE_LINK Link, PXOR_INST_DATA X
|
|
|
|
|
if (SaveFlags)
|
|
|
|
|
RipDelta += 1;
|
|
|
|
|
RipDelta += (FourByte * 4) + (TwoByte * 2);
|
|
|
|
|
RipDelta += DeltaToInst;
|
|
|
|
|
if (!ObfEmitRipRelativeXorB(Block, RipDelta, XorData->Data[4]))
|
|
|
|
|
{
|
|
|
|
|
NcDelete(Block);
|
|
|
|
@ -231,7 +234,7 @@ PNATIVE_CODE_BLOCK ObfEmitPreXorForInst(PNATIVE_CODE_LINK Link, PXOR_INST_DATA X
|
|
|
|
|
return Block;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PNATIVE_CODE_BLOCK ObfEmitPostXorForInst(PNATIVE_CODE_LINK Link, PXOR_INST_DATA XorData, BOOL SaveFlags)
|
|
|
|
|
PNATIVE_CODE_BLOCK ObfEmitPostXorForInst(PNATIVE_CODE_LINK Link, PXOR_INST_DATA XorData, BOOL SaveFlags, INT32 DeltaToInst)
|
|
|
|
|
{
|
|
|
|
|
ULONG FourByte = Link->RawDataSize / 4;
|
|
|
|
|
ULONG TwoByte = (Link->RawDataSize - (FourByte * 4)) / 2;
|
|
|
|
@ -256,6 +259,7 @@ PNATIVE_CODE_BLOCK ObfEmitPostXorForInst(PNATIVE_CODE_LINK Link, PXOR_INST_DATA
|
|
|
|
|
RipDelta += 1;
|
|
|
|
|
RipDelta += (FourByte - (Count - 1)) * DWORD_XOR_INST_LENGTH;
|
|
|
|
|
RipDelta *= (-1);
|
|
|
|
|
RipDelta += DeltaToInst;
|
|
|
|
|
if (!ObfEmitRipRelativeXorD(Block, RipDelta, XorData->Data[FourByte - Count]))
|
|
|
|
|
{
|
|
|
|
|
NcDelete(Block);
|
|
|
|
@ -273,7 +277,7 @@ PNATIVE_CODE_BLOCK ObfEmitPostXorForInst(PNATIVE_CODE_LINK Link, PXOR_INST_DATA
|
|
|
|
|
RipDelta += (FourByte * DWORD_XOR_INST_LENGTH);
|
|
|
|
|
RipDelta += WORD_XOR_INST_LENGTH;
|
|
|
|
|
RipDelta *= (-1);
|
|
|
|
|
|
|
|
|
|
RipDelta += DeltaToInst;
|
|
|
|
|
if (!ObfEmitRipRelativeXorW(Block, RipDelta, XorData->Data[3]))
|
|
|
|
|
{
|
|
|
|
|
NcDelete(Block);
|
|
|
|
@ -291,6 +295,7 @@ PNATIVE_CODE_BLOCK ObfEmitPostXorForInst(PNATIVE_CODE_LINK Link, PXOR_INST_DATA
|
|
|
|
|
RipDelta += WORD_XOR_INST_LENGTH;
|
|
|
|
|
RipDelta += BYTE_XOR_INST_LENGTH;
|
|
|
|
|
RipDelta *= (-1);
|
|
|
|
|
RipDelta += DeltaToInst;
|
|
|
|
|
if (!ObfEmitRipRelativeXorB(Block, RipDelta, XorData->Data[4]))
|
|
|
|
|
{
|
|
|
|
|
NcDelete(Block);
|
|
|
|
|