ULONGOriDisasm(PUCHAR str,ULONG Eip)
{
UDISud_obj;
ULONGlen;
ud_init(&ud_obj); //初始化结构体
ud_set_mode(&ud_obj,32); //设置为32位元CPU模式
ud_set_syntax(&ud_obj,UD_SYN_INTEL); //结果使用Intel语法
ud_set_pc(&ud_obj,(int)Eip); //设置反汇编起点
ud_set_input_buffer(&ud_obj,(uint8_t*)Eip,32); //设置输入缓冲区
len=ud_disassemble(&ud_obj); //开始反汇编
strcpy(str,ud_insn_asm(&ud_obj)); //复制结果
returnlen;
}
004017F0 75 64 jnz short 00401856
004017F2 8B45 10 mov eax, dword ptr [ebp+10]
004017F5 C1E8 10 shr eax, 10
004017F8 83F8 07 cmp eax, 7
004017F6 E8 1083F807 call 08389B0B
004017F8 83F8 07 cmp eax, 7
004017F7 1083 F807754B adc byte ptr [ebx+4B7507F8], al
004017F6 E8 1083F807 call 08389B0B
004017F5 C1E8 10 shr eax, 10
004017F8 83F8 07 cmp eax, 7
004017F4 10C1 adc cl, al
004017F6 E8 1083F807 call 08389B0B
004017F3 45 inc ebp
004017F4 10C1 adc cl, al
004017F6 E8 1083F807 call 08389B0B
004017F2 8B45 10 mov eax, dword ptr [ebp+10]
004017F5 C1E8 10 shr eax, 10
004017F8 83F8 07 cmp eax, 7
4017F5 40次
XXXXXX 1次
typedefstruct {
ULONGpInstrAddr; //上一条指令的位址
ULONGHitCount; //命中次数
}PREV_INSTR_HITTEST,*PPREV_INSTR_HITTEST;
ULONGGetPrevIp(ULONG Eip)
{
PREV_INSTR_HITTESTHitTest[16];
ULONGCurrentAddr = Eip - 1;
ULONGPrevAddr;
ULONGDisasmLimit = 0x100;
ULONGlen;
ULONGi;
ULONGPrevAddr_MaxHit = 0;
ULONGMaxHit = 0;
if(!Eip)
returnFALSE;
memset(&HitTest,0,sizeof(HitTest));
while(DisasmLimit)
{
PrevAddr= CurrentAddr;
if(!IsAddressExist(PrevAddr)) //保证地址空间可读
break;
while(1)
{
len= FastDisasm(PrevAddr);
if(len!= -1 && len){
if(len+ PrevAddr >= Eip)
{
AddHit(&HitTest[0],16,PrevAddr);
break;
}
elseif(len + PrevAddr > Eip)
{
break;
}
}
else
{
break;
}
PrevAddr+= len;
}
DisasmLimit--;
CurrentAddr--;
}
for(i= 0; i < 16; i++)
{
if(HitTest.HitCount> MaxHit)
{
MaxHit= HitTest.HitCount;
PrevAddr_MaxHit= HitTest.pInstrAddr;
}
}
returnPrevAddr_MaxHit;
}
typedefstruct{
CHAR*Cmd; //命令前缀
CHAR*Desc; //命令描述
CHAR*Usage; //命令用法描述
CHAR*Example; //命令用例
PCMD_HANDLERpHandler; //命令分发处理函数
}CMD_HELP,*PCMD_HELP;
CMD_HELPCmdHelp[] = {
{"BC","Clearbreakpoint","BC [*|id]",NULL,CmdClearBreakpoint},
{"BL","Listcurrent breakpoints","No param forBL",NULL,CmdListBreakpoint},
{"BPX","Breakpointon execute","BPX [addr] if [condition] do [cmd]","bpxntsetvaluekey if \"[[esp+8]+4]==\"imagepath\"\"do \"? byte [esp+4]\"\n",CmdSetSwBreakpoint},
{"CPU","Displaycpu registers information","No param forCPU",NULL,CmdDisplayCpuReg},
{"!DB","Displayphysical memory(byte)","!DB [address]","!db39000\n",CmdDisplayPhysicalMemoryByte},
{"!DW","Displayphysical memory(word)","!DW [address]","!dw39000\n",CmdDisplayPhysicalMemoryWord},
{"!DD","Displayphysical memory(dword)","!DD [address]","!dd39000\n",CmdDisplayPhysicalMemoryDword},
{"DB","Displaymemory(byte)","DB [address|symbolname]","db[esp+4]\n",CmdDisplayMemoryByte},
{"DW","Displaymemory(word)","DW [address|symbolname]","dw[esp+4]\n",CmdDisplayMemoryWord},
{"DD","Displaymemory(dword)","DD [address|symbolname]","dd[esp+4]\n",CmdDisplayMemoryDword},
};
dd[esi+eax*4+14]
表4-1:LL-1分析法计算步骤
符号栈 | 值栈 | 串 |
[ | 1 | |
[ | 1 | +4]>=45&&(([1+8]<9)||([1+c]&10)) |
[ + | 1 | 4]>=45&&(([1+8]<9)||([1+c]&10)) |
[ + | 1 4 | ]>=45&&(([1+8]<9)||([1+c]&10)) |
[5] | >=45&&(([1+8]<9)||([1+c]&10)) | |
>= | [5] | 45&&(([1+8]<9)||([1+c]&10)) |
>= | [5] 45 | &&(([1+8]<9)||([1+c]&10)) |
&& | 1 | (([1+8]<9)||([1+c]&10)) |
&& ( | 1 | ([1+8]<9)||([1+c]&10)) |
&& ( ( | 1 | [1+8]<9)||([1+c]&10)) |
&& ( ( [ | 1 | 1+8]<9)||([1+c]&10)) |
&& ( ( [ | 1 1 | +8]<9)||([1+c]&10)) |
&& ( ( [ + | 1 1 | 8]<9)||([1+c]&10)) |
&& ( ( [ + | 1 1 8 | ]<9)||([1+c]&10)) |
&& ( ( | 1 [9] | <9)||([1+c]&10)) |
&& ( ( < | 1 [9] | 9)||([1+c]&10)) |
&& ( ( < | 1 [9] 9 | )||([1+c]&10)) |
&& ( | 1 0 | ||([1+c]&10)) |
&& ( || | 1 0 | ([1+c]&10)) |
&& ( || ( | 1 0 | [1+c]&10)) |
&& ( || ( [ | 1 0 | 1+c]&10)) |
&& ( || ( [ | 1 0 1 | +c]&10)) |
&& ( || ( [ + | 1 0 1 | c]&10)) |
&& ( || ( [ + | 1 0 1 c | ]&10)) |
&& ( || ( | 1 0 1c | &10)) |
&& ( || ( & | 1 0 1c | 10)) |
&& ( || ( & | 1 0 1c 10 | )) |
&& ( || | 1 0 1 | ) |
&& | 1 1 | |
1 |
typedefstruct{
ULONGProcessCR3; //进程页目录
USHORTCodeSeg; //代码段
ULONGAddress; //断点地址
CHAROldOpcode; //断点位址处原指令备份
CHARIfCondition[128]; //条件表达式
CHARDoCmd[128]; //满足条件后运行的语句
}SW_BP,*PSW_BP;
#defineINT3_OPCODE 0xCC
4.2.3.3回应断点push ebp
mov esp,ebp
…
while(EBP)
{
返回地址=*(EBP+4);
打印信息;
EBP= *EBP;
}
4.3.4查看CPU信息欢迎光临 中科因仑“3+1”工程特种兵精英论坛 (http://bbs.enlern.com/) | Powered by Discuz! X3.4 |