mov 명령이 표시되지 않는 이유는 무엇입니까? 디버깅 모드에있는 경우
, 당신은 그게 해결하기 위해, 당신이 잘못된 주소에서 바이트를 읽는 또 다른 몇 가지 실수가 말은, 당신은 GetCurrentDate (PVOID)에 주소를 잘못 전달하는 것을 알 필요가 이 문제는 이러한 단계를 수행
첫째, 코드에서 생성 된 바이트 :
mov eax, x // code bytes: 8B 45 08
mov result, eax // code bytes: 89 45 FC
코드 0x8B 및 0x89를 당신이 당신의 추가 내부 (INT, INT) 기능을 찾아야한다 값됩니다. 셋째
#define ASM_CALL 0x000000E8
#define ASM_JMP 0x000000E9
#define ASM_CALL_SIZE 0x00000001
#define ASM_CALL_FULL_SIZE 0x00000005
DWORD GetFuncAddress(DWORD funcAddress)
{
BYTE calledAddress = *(BYTE*)funcAddress;
while (calledAddress == ASM_CALL || calledAddress == ASM_JMP) {
funcAddress = funcAddress + *(DWORD*)(funcAddress + ASM_CALL_SIZE) + ASM_CALL_FULL_SIZE;
calledAddress = *(BYTE*)funcAddress;
}
return funcAddress; // The address of the first byte of the function.
}
, 당신의 GetFunctionSize (DOWRD) 내부 최적화를 제안한다
둘째, 추가 기능의 첫 번째 바이트의 주소 (INT, INT) 함수는 내가이 기능을 사용하는 것이 좋습니다를 얻을 수
return result; // code bytes: C3
가 왜 그냥 루프, 추가 기능의 바이트를 던져 당신이 0xC3에 바이트 equivalente을 찾을 때, 당신이 정확한 크기로 끝날 것입니다 : 당신은 당신의 추가 기능이 하나의 복귀로 끝나는 것을 알고 (바이트 단위로)이 코드는 일을 명확하게합니다 :
#define ASM_RET 0xC3
SIZE_T GetFunctionSize(DWORD functionAddress)
{
SIZE_T funcSize = 0;
// Loop thru func's bytes, and breaks when return byte found.
while (*((PBYTE)functionAddress++) != RET)
funcSize++;
return funcSize;
}
넷째는 GetCurrentByte은 (PVOID)의 기능을 일부 유지 보수가 필요, 그래서 내가 제안 :
#define ASM_MOV1 0x8B
#define ASM_MOV2 0x89
VOID GetCurrentByte(DWORD functionAddress, UINT &index)
{
BYTE tempByte = *((PBYTE)functionAddress + index);
// search for bytes which contains a mov instruction:
if (tempByte == ASM_MOV1 || tempByte == ASM_MOV2)
cout << "MOV instr found at : " << hex << ((DWORD)functionAddress + index) << endl;
}
마지막으로, 전체 코드는 다음과 같이 될 것입니다 :
#include <iostream>
#include <Windows.h>
#define ASM_RET 0xC3
#define ASM_MOV1 0x8B
#define ASM_MOV2 0x89
#define ASM_CALL 0xE8
#define ASM_JMP 0xE9
#define ASM_CALL_SIZE 0x01
#define ASM_CALL_FULL_SIZE 0x05
using namespace std;
INT add(INT x, INT y)
{
int result;
__asm
{
mov eax, x
add eax, y
mov result, eax
xor eax, eax
}
return result;
}
DWORD GetFuncAddress(DWORD funcAddress)
{
BYTE calledAddress = *(BYTE*)funcAddress;
while (calledAddress == ASM_CALL || calledAddress == ASM_JMP) {
funcAddress = funcAddress + *(DWORD*)(funcAddress + ASM_CALL_SIZE) + ASM_CALL_FULL_SIZE;
calledAddress = *(BYTE*)funcAddress;
}
return funcAddress;
}
SIZE_T GetFunctionSize(DWORD functionAddress)
{
SIZE_T funcSize = 0;
while (*((PBYTE)functionAddress++) != ASM_RET)
{
funcSize++;
}
return funcSize;
}
VOID GetCurrentByte(DWORD functionAddress, UINT &index)
{
BYTE tempByte = *((PBYTE)functionAddress + index);
if (tempByte == ASM_MOV1 || tempByte == ASM_MOV2)
cout << "MOV instr found at : " << hex << ((DWORD)functionAddress + index) << endl;
}
INT main()
{
DWORD funcAddress = GetFuncAddress((DWORD)add); // Get func address.
SIZE_T size = GetFunctionSize(funcAddress); // Get func size (bytes).
for (UINT i = 0; i < size; i++) // loop thru the function memory block.
{
GetCurrentByte(funcAddress, i);
}
system("pause");
return 0;
}
하지 마십시오 컴파일러가 함수를 만들었 기 때문에 함수에서 많은 MOV 명령어를 발견하면 놀라실 것입니다.
Amrane Abdelkader.
나는 아직도 당신이 달성하고자하는 것을 이해하지 못합니다. 필자가 알고있는 점은 함수의 opcode가 런타임 중에 변경되지 않는다는 것입니다. 따라서 모니터링이 필요한 이유는 무엇입니까? * 벤치마킹 * 또는 * 프로파일 링 * 일부 코드입니까? –
나중에 mov의 돌연변이를 추가 할 계획입니다. http://pastebin.com/G8WnSCDY – SamLaren