bitdefender / bddisasm

bddisasm is a fast, lightweight, x86/x64 instruction decoder. The project also features a fast, basic, x86/x64 instruction emulator, designed specifically to detect shellcode-like behavior.
Apache License 2.0
888 stars 115 forks source link

Emulating: 0x000000014009a531 LOCK OR dword ptr [rbx+0x14], 0x00000282 This instruction emulation will cause a crash #59

Closed icyfox168168 closed 2 years ago

icyfox168168 commented 2 years ago

Unable to intercept information with access to external memory

000000014009A531 | F0:814B 14 82020000 | lock or dword ptr ds:[rbx+14],282 | _sftbuf.cpp:91

            case ND_INS_OR:
    case ND_INS_XOR:
    case ND_INS_AND:
    case ND_INS_TEST:
        /*
        if (Context->Instruction.HasLock)
        {
            break;
        }
        */
        printf("lock %d\n", Context->Instruction.HasLock);

        GET_OP(Context, 0, &dst);
        GET_OP(Context, 1, &src);

        res.Size = dst.Size;

        if (ND_INS_OR == Context->Instruction.Instruction)
        {
            printf("%p\n", dst.Value.Qwords[0]);

            res.Value.Qwords[0] = dst.Value.Qwords[0] | src.Value.Qwords[0];
        }

    RAX = 0x0000000000002002 RCX = 0x0000000140165760 RDX = 0x00000001401c7250 RBX = 0x00000001401657b8
    RSP = 0x00000000004989c0 RBP = 0x0000000000498af0 RSI = 0x000000014014761c RDI = 0x00000001401c7698
    R8  = 0x0000000000498f60 R9  = 0x0000000000498f50 R10 = 0x00007ff9d07f13a0 R11 = 0x0000000000000000
    R12 = 0x0000000000000000 R13 = 0x0000000000000000 R14 = 0x0000000000498f10 R15 = 0x00000001401657b8
    RIP = 0x000000014009a531 RFLAGS = 0x0000000000000246   CF:0 PF:1 AF:0 ZF:1 SF:0 TF:0 IF:1 DF:0 OF:0

Emulating: 0x000000014009a531 LOCK OR dword ptr [rbx+0x14], 0x00000282 Instruction id 407 lock 1

vlutas commented 2 years ago

Hello,

Where does the crash take place? Do you have a stack trace, and a test file which reproduces it? Are you using the external memory access callback, to handle accesses outside the emulated code/stack?

icyfox168168 commented 2 years ago

I simulate the printf function because I am simulating in the same exe environment, ShemuEmulate also has a printf function, there may be conflicts, I can use another way to directly simulate the printf in msvcrt.dll, which is perfect

ok DEFINE_FUNC_PTR3(LoadLibraryA("msvcrt.dll"), printf);

printf("123\n");

ko

printf("123\n");