Jump to content
Tuts 4 You

How i can get commands of a debugged process ?


Recommended Posts


I search how i can get each commands of a debugged process in OllyDbg.

I think i need to use this function : ulong Readcommand(ulong ip,char *cmd);

My program entry point :

004C5C74 > $ 55 PUSH EBP

Commande : string;if Readcommand($004C5C74, PAnsiChar(Commande)) > 0 then
// success
// error

But when u try it, it's not working :(

Readcommand return all time 0 !

I need to have : Commande := 'PUSH EBP'

Can you help me ?



Edited by mrousse83
Link to comment


I have no Experience about Delphi

Readcommand return the size of bytes


local cmd [256]:DWORD invoke Readcommand,0040100Ch, addr cmd
.if eax!=0


BYTE szCmd[MAXCMDSIZE]; dwAddr = dwBase + dwOffset; nRetCode = Readcommand(dwAddr, (char *)szCmd);
Link to comment

ragdog, and cmd contains the instruction ?


Yes correct

Reads command from the memory of debugged process and restored breakpoints. Returns length of the read code (at most MAXCMDSIZE bytes) or 0 if memory can't be read.

Note: Any access to the memory in different process is extremely time-expensive. As in many cases different parts of OllyDbg access same command several times, Readcommand maintains small 1-command cache significantly improves the wholesave productivity of OllyDbg. If you need to access several compactly placed commands, Readmemory is usually much faster.

ulong Readcommand(ulong ip,char *cmd);


ip - address of the command in the memory space of debugged process. If ip is 0, function invalidates cache and returns 0;

cmd - buffer of length at least MAXCMDSIZE bytes that receives command.

You can all Read about Api Interface in Plugins.hlp of the Pdk package from Olly

Link to comment

Thanks for your precisions ragdog.

Do you know why memory can't be read, because Readcommand return all time 0 ?

I need to change memory rights access ?


Link to comment

Readcommand does not return the assembler instruction. It does return the opcode of the command.

Maybe you have to use a char array instead of string for this function, not sure.

Edited by GoJonnyGo
Link to comment
Commande : string;if Readcommand($004C5C74, PAnsiChar(Commande)) > 0 then
// success
// error

Ok, firstly you haven't initialized the Commande string in this code. If you are using a string as a buffer you must first give it a size, and it might help to initialize the chars to nulls too.

Secondly, it's a string not a buffer, meaning that it's data starts at 1 not 0. So to reference the data at index 1 it's best to use @Commande[1]

But anyway, code should look more like this:

Cmd : Array [0 .. MAXCMDSIZE-1] Of Char;
Len : DWord;
FillChar(Cmd, MAXCMDSIZE, 0);
Len := Readcommand($004C5C74, Cmd);
If (Len > 0) Then Begin
// Do further processing ..
End Else Begin
// Fail ..

In Delphi an array of chars is treated as a PAnsiChar, so usage is exactly the same.

Also, you might want to check out my Delphi PDK, which will make your plugin compatible with OllyDbg and Immunity Debugger (including patched OllyDbg editions)

Edited by BoB
Link to comment

Thanks for your help and example BoB, work's fine !

Readcommand return opcode, but i want to get assembler instruction, do you know what functions i need to use for get assembler instruction of a given address ?

Thanks a lot,


Link to comment

Yeah, use this:

Function Disasm(src: PChar; srcsize: ULONG; srcip: ULONG; srcdec: PChar; disasm: p_disasm; disasmmode: Integer; threadid: ULONG): ULONG; cdecl;
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...