|
|
@ -82,7 +82,7 @@ BOOL ObfEmitRipRelativeMovB(PNATIVE_CODE_BLOCK Block, INT32 RipDelta, PUCHAR Dat
|
|
|
|
return TRUE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PNATIVE_CODE_BLOCK ObfEmitPreMovForInst(PNATIVE_CODE_LINK Link)
|
|
|
|
PNATIVE_CODE_BLOCK ObfEmitPreMovForInst(PNATIVE_CODE_LINK Link, INT32 DeltaToInst)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ULONG FourByte = Link->RawDataSize / 4;
|
|
|
|
ULONG FourByte = Link->RawDataSize / 4;
|
|
|
|
ULONG TwoByte = (Link->RawDataSize - (FourByte * 4)) / 2;
|
|
|
|
ULONG TwoByte = (Link->RawDataSize - (FourByte * 4)) / 2;
|
|
|
@ -99,6 +99,7 @@ PNATIVE_CODE_BLOCK ObfEmitPreMovForInst(PNATIVE_CODE_LINK Link)
|
|
|
|
INT32 RipDelta = (((Count - 1) * DWORD_MOV_INST_LENGTH) + (TwoByte * WORD_MOV_INST_LENGTH) + (OneByte * BYTE_MOV_INST_LENGTH));
|
|
|
|
INT32 RipDelta = (((Count - 1) * DWORD_MOV_INST_LENGTH) + (TwoByte * WORD_MOV_INST_LENGTH) + (OneByte * BYTE_MOV_INST_LENGTH));
|
|
|
|
//Account for already MOVd instructions
|
|
|
|
//Account for already MOVd instructions
|
|
|
|
RipDelta += ((FourByte - Count) * 4);
|
|
|
|
RipDelta += ((FourByte - Count) * 4);
|
|
|
|
|
|
|
|
RipDelta += DeltaToInst;
|
|
|
|
//Add the actual instruction
|
|
|
|
//Add the actual instruction
|
|
|
|
if (!ObfEmitRipRelativeMovD(Block, RipDelta, DataOffset))
|
|
|
|
if (!ObfEmitRipRelativeMovD(Block, RipDelta, DataOffset))
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -114,6 +115,7 @@ PNATIVE_CODE_BLOCK ObfEmitPreMovForInst(PNATIVE_CODE_LINK Link)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
INT32 RipDelta = (OneByte * BYTE_MOV_INST_LENGTH);
|
|
|
|
INT32 RipDelta = (OneByte * BYTE_MOV_INST_LENGTH);
|
|
|
|
RipDelta += (FourByte * 4);
|
|
|
|
RipDelta += (FourByte * 4);
|
|
|
|
|
|
|
|
RipDelta += DeltaToInst;
|
|
|
|
if (!ObfEmitRipRelativeMovW(Block, RipDelta, DataOffset))
|
|
|
|
if (!ObfEmitRipRelativeMovW(Block, RipDelta, DataOffset))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NcDelete(Block);
|
|
|
|
NcDelete(Block);
|
|
|
@ -127,6 +129,7 @@ PNATIVE_CODE_BLOCK ObfEmitPreMovForInst(PNATIVE_CODE_LINK Link)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
INT32 RipDelta = 0;
|
|
|
|
INT32 RipDelta = 0;
|
|
|
|
RipDelta += (FourByte * 4) + (TwoByte * 2);
|
|
|
|
RipDelta += (FourByte * 4) + (TwoByte * 2);
|
|
|
|
|
|
|
|
RipDelta += DeltaToInst;
|
|
|
|
if (!ObfEmitRipRelativeMovB(Block, RipDelta, DataOffset))
|
|
|
|
if (!ObfEmitRipRelativeMovB(Block, RipDelta, DataOffset))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NcDelete(Block);
|
|
|
|
NcDelete(Block);
|
|
|
@ -144,7 +147,7 @@ PNATIVE_CODE_BLOCK ObfEmitPreMovForInst(PNATIVE_CODE_LINK Link)
|
|
|
|
return Block;
|
|
|
|
return Block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PNATIVE_CODE_BLOCK ObfEmitPostMovForInst(PNATIVE_CODE_LINK Link)
|
|
|
|
PNATIVE_CODE_BLOCK ObfEmitPostMovForInst(PNATIVE_CODE_LINK Link, INT32 DeltaToInst)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ULONG FourByte = Link->RawDataSize / 4;
|
|
|
|
ULONG FourByte = Link->RawDataSize / 4;
|
|
|
|
ULONG TwoByte = (Link->RawDataSize - (FourByte * 4)) / 2;
|
|
|
|
ULONG TwoByte = (Link->RawDataSize - (FourByte * 4)) / 2;
|
|
|
@ -160,6 +163,7 @@ PNATIVE_CODE_BLOCK ObfEmitPostMovForInst(PNATIVE_CODE_LINK Link)
|
|
|
|
INT32 RipDelta = Link->RawDataSize - ((FourByte - Count) * 4);
|
|
|
|
INT32 RipDelta = Link->RawDataSize - ((FourByte - Count) * 4);
|
|
|
|
RipDelta += (FourByte - (Count - 1)) * DWORD_MOV_INST_LENGTH;
|
|
|
|
RipDelta += (FourByte - (Count - 1)) * DWORD_MOV_INST_LENGTH;
|
|
|
|
RipDelta *= (-1);
|
|
|
|
RipDelta *= (-1);
|
|
|
|
|
|
|
|
RipDelta += DeltaToInst;
|
|
|
|
if (!ObfEmitRipRelativeMovD(Block, RipDelta, (PUCHAR)&ZeroValue))
|
|
|
|
if (!ObfEmitRipRelativeMovD(Block, RipDelta, (PUCHAR)&ZeroValue))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NcDelete(Block);
|
|
|
|
NcDelete(Block);
|
|
|
@ -175,7 +179,7 @@ PNATIVE_CODE_BLOCK ObfEmitPostMovForInst(PNATIVE_CODE_LINK Link)
|
|
|
|
RipDelta += (FourByte * DWORD_MOV_INST_LENGTH);
|
|
|
|
RipDelta += (FourByte * DWORD_MOV_INST_LENGTH);
|
|
|
|
RipDelta += WORD_MOV_INST_LENGTH;
|
|
|
|
RipDelta += WORD_MOV_INST_LENGTH;
|
|
|
|
RipDelta *= (-1);
|
|
|
|
RipDelta *= (-1);
|
|
|
|
|
|
|
|
RipDelta += DeltaToInst;
|
|
|
|
if (!ObfEmitRipRelativeMovW(Block, RipDelta, (PUCHAR)&ZeroValue))
|
|
|
|
if (!ObfEmitRipRelativeMovW(Block, RipDelta, (PUCHAR)&ZeroValue))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NcDelete(Block);
|
|
|
|
NcDelete(Block);
|
|
|
@ -191,6 +195,7 @@ PNATIVE_CODE_BLOCK ObfEmitPostMovForInst(PNATIVE_CODE_LINK Link)
|
|
|
|
RipDelta += WORD_MOV_INST_LENGTH;
|
|
|
|
RipDelta += WORD_MOV_INST_LENGTH;
|
|
|
|
RipDelta += BYTE_MOV_INST_LENGTH;
|
|
|
|
RipDelta += BYTE_MOV_INST_LENGTH;
|
|
|
|
RipDelta *= (-1);
|
|
|
|
RipDelta *= (-1);
|
|
|
|
|
|
|
|
RipDelta += DeltaToInst;
|
|
|
|
if (!ObfEmitRipRelativeMovB(Block, RipDelta, (PUCHAR)&ZeroValue))
|
|
|
|
if (!ObfEmitRipRelativeMovB(Block, RipDelta, (PUCHAR)&ZeroValue))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NcDelete(Block);
|
|
|
|
NcDelete(Block);
|
|
|
@ -207,3 +212,4 @@ PNATIVE_CODE_BLOCK ObfEmitPostMovForInst(PNATIVE_CODE_LINK Link)
|
|
|
|
|
|
|
|
|
|
|
|
return Block;
|
|
|
|
return Block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|