void Setcpu(ulong threadid,ulong asmaddr,ulong dumpaddr,ulong selsize,ulong stackaddr,int mode);
Sets code and memory areas that will be displayed in the CPU window. If necessary, creates or restores CPU.
Parameters:
threadid
(in)
Identifier of the thread that should be selected in the CPU window. If threadid is 0 or
invalid, thread remains unchanged
asmaddr
(in)
Address of the first selected command to be displayed in the
Disassembler pane. If address is currently not visible, Disassembler is
scrolled according to the mode.
If asmaddr
is 0 and threadid
is 0, Disassembler selection remains unchanged. If asmaddr is 0 and threadid is valid,
selection is moved to the EIP of the specified thread. If flag
CPU_RUNTRACE
is set, asmaddr is interpreted as the step back in the run
trace
dumpaddr
(in)
Address of the first byte to be displayed in the CPU Dump pane. If dumpaddr is 0,
current selection remains unchanged
selsize
(in) If asmaddr is not 0,
determines size, in bytes, of the selection in the Disassembler
pane. If asmaddr
is not 0 and selsize
is 0, OllyDbg selects single command at address asmaddr. If dumpaddr is not 0,
specifies size of the selection in the Dump pane. If dumpaddr is not 0
and selsize
is 0, OllyDbg selects single dump item.
stackaddr
(in)
Address of the selected
Stack doubleword. If address
is currently not visible, Stack is scrolled according to the mode.
mode
(in) A
combination of the following flags:
CPU_ASMHIST | Add asmaddr to the Disassembler history. User can walk history back and forth using menu items "Go to | Previous location", "Go to | Next location", or corresponding shortcuts |
CPU_ASMCENTER | If possible, places asmaddr in the middle of the CPU pane. If CPU_ASMCENTER is not set, asmaddr appears in the first displayed line |
CPU_ASMFOCUS | Moves focus to the Disassembler pane of the CPU window. Not compatible with CPU_DUMPFOCUS and CPU_STACKFOCUS |
CPU_DUMPHIST | Add dumpaddr to the CPU Dump history. User can walk history back and forth using menu items "Go to | Previous location", "Go to | Next location", or corresponding shortcuts |
CPU_DUMPFOCUS | Moves focus to the Dump pane of the CPU window. Not compatible with CPU_ASMFOCUS and CPU_STACKFOCUS |
CPU_STACKFOCUS | Moves focus to the Stack pane of the CPU window. Not compatible with CPU_ASMFOCUS and CPU_DUMPFOCUS |
CPU_STACKCTR | If possible, places stackaddr in the middle of the Stack pane. Necessary, for example for stack walk. If CPU_STACKCTR is not set, stackaddr appears in the first displayed line |
CPU_REGAUTO | Asks to switch FPU register display to FPU, MMX or 3DNow! mode depending on the command pointed to by asmaddr. If pointed command does not access FPU registers, display mode remains unchanged |
CPU_NOCREATE | If CPU window is absent, it will not be created |
CPU_REDRAW | Asks to redraw all panes of CPU window immediately. If CPU_REDRAW is not specified, OllyDbg only invalidates all panes of the CPU window |
CPU_NOFOCUS | Asks to not restore CPU window if it's
minimized and to not move keyboard focus to the CPU |
CPU_RUNTRACE | Asks to switch to the run trace display. asmaddr is interpreted as the step back in the run trace |
CPU_NOTRACE | Asks to stop run trace display if currently active |
Return values:
None
Example:
This
is the adapted menu function of the Dump window that executes command "Go to expression":
int Mgotoexpression(t_table *pt,wchar *name,ulong index,int mode) {
int answer;
ulong addr;
t_dump menudump;
POINT coord;
if (process==NULL)
return MENU_ABSENT;
menudump=(t_dump *)pt->customdata;
if (menudump==NULL)
return MENU_ABSENT; // In fact, internal error
if (menudump->menutype & DMT_STRUCT)
return MENU_ABSENT; // Not allowed for the structure dumps
if (mode==MENU_VERIFY)
return MENU_NORMAL; // In all other cases, allowed operation
else if (mode==MENU_EXECUTE) {
if (Gettableselectionxy(&(menudump->table),2,&coord)<0)
coord.x=coord.y=-1; // Unknown selection coordinates, use defaults
if (menudump->filecopy!=NULL)
answer=Getdwordexpression(pt->hw,T(L"Enter expression to follow"),&addr,
0,NM_GOTOSAV,coord.x,coord.y,menudump->table.font,0);
else
answer=Getgotoexpression(pt->hw,T(L"Enter expression to follow"),&addr,
Getcputhreadid(),NM_GOTOSAV,coord.x,coord.y,menudump->table.font,0);
if (answer!=0)
return MENU_NOREDRAW;
// Now we have address to follow. The action strongly depends on the dump type.
if (menudump->filecopy!=NULL && addr>=menudump->size) {
Flash(T(L"Offset beyond the end of file")); return MENU_NOREDRAW; }
else if (menudump->filecopy==NULL && Findmemory(addr)==NULL) {
Flash(T(L"No memory at the specified address")); return MENU_NOREDRAW; }
else if (menudump->menutype & DMT_CPUDASM)
// This is the CPU Disassembler pane.
Setcpu(0,addr,0,0,0,CPU_ASMHIST|CPU_ASMCENTER);
else if (menudump->menutype & DMT_CPUDUMP)
// This is the CPU Dump pane.
Setcpu(0,0,addr,0,0,CPU_DUMPHIST);
else if (menudump->menutype & DMT_CPUSTACK)
// This is the CPU stack.
Setcpu(0,0,0,0,addr,0);
else
// This is the standalone dump window.
Newdumpselection(menudump,addr,0);
return MENU_REDRAW; };
return MENU_ABSENT;
};
int Mgotoexpression(t_table *pt,wchar *name,ulong index,int mode) {
int answer;
ulong addr;
t_dump menudump;
POINT coord;
if (process==NULL)
return MENU_ABSENT;
menudump=(t_dump *)pt->customdata;
if (menudump==NULL)
return MENU_ABSENT; // In fact, internal error
if (menudump->menutype & DMT_STRUCT)
return MENU_ABSENT; // Not allowed for the structure dumps
if (mode==MENU_VERIFY)
return MENU_NORMAL; // In all other cases, allowed operation
else if (mode==MENU_EXECUTE) {
if (Gettableselectionxy(&(menudump->table),2,&coord)<0)
coord.x=coord.y=-1; // Unknown selection coordinates, use defaults
if (menudump->filecopy!=NULL)
answer=Getdwordexpression(pt->hw,T(L"Enter expression to follow"),&addr,
0,NM_GOTOSAV,coord.x,coord.y,menudump->table.font,0);
else
answer=Getgotoexpression(pt->hw,T(L"Enter expression to follow"),&addr,
Getcputhreadid(),NM_GOTOSAV,coord.x,coord.y,menudump->table.font,0);
if (answer!=0)
return MENU_NOREDRAW;
// Now we have address to follow. The action strongly depends on the dump type.
if (menudump->filecopy!=NULL && addr>=menudump->size) {
Flash(T(L"Offset beyond the end of file")); return MENU_NOREDRAW; }
else if (menudump->filecopy==NULL && Findmemory(addr)==NULL) {
Flash(T(L"No memory at the specified address")); return MENU_NOREDRAW; }
else if (menudump->menutype & DMT_CPUDASM)
// This is the CPU Disassembler pane.
Setcpu(0,addr,0,0,0,CPU_ASMHIST|CPU_ASMCENTER);
else if (menudump->menutype & DMT_CPUDUMP)
// This is the CPU Dump pane.
Setcpu(0,0,addr,0,0,CPU_DUMPHIST);
else if (menudump->menutype & DMT_CPUSTACK)
// This is the CPU stack.
Setcpu(0,0,0,0,addr,0);
else
// This is the standalone dump window.
Newdumpselection(menudump,addr,0);
return MENU_REDRAW; };
return MENU_ABSENT;
};
See also: