I have a small command line application named "debugger" which acts as a debugger for a process A. Now this application works fine with x86 and x64. Now I have to migrate this "debugger" to ARM64 architecture. What this debugger very briefly does is attach breakpoints aka writes instruction int3(0xcc) to the start of functions it finds in the map file of the Process A. Now whenever I try to run my application via this "debugger" app I am able to set breakpoints but the app continuously gets "access_violation". My hunch is that for ARM64 architecture the instruction "0xcc" which I am writing to the start of the functions is causing the access_violation. Now I have two questions:
- Is "0xcc" valid instruction for putting breakpoint in ARM64?
- Can writing "0xcc" in ARM64 cause access_violation?
Please provide links for your answers as well.
Edit 2: Used "BRK" instead of "0xcc"
int BP_INSTRUCTION_OPCODE_ARM = 0x000020D4;
void * baseAddress = "Some Value";
mProcessHandle = "ProcessHandle";
SIZE_T NumBytesWritten;
::WriteProcessMemory(mProcessHandle, baseAddress, (void*)&BP_INSTRUCTION_OPCODE_ARM, sizeof(int), &NumBytesWritten);
This did not work for me... Am I doing something wrong here?
After disassembling the DebugBreak()
function I got the below assembly code. From this I tried to write the instruction 0x150
as breakpoint but I am still getting EXCEPTION_ACCESS_VIOLATION
.
126: DebugBreak();
00007FF7141C1884 90000128 adrp x8,__imp_SetSecurityDescriptorDacl (07FF7141E5000h)
00007FF7141C1888 F940A908 ldr x8,[x8,#0x150]
00007FF7141C188C D63F0100 blr x8