Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How i can get commands of a debugged process ?

Featured Replies

Posted

Hello,

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


var
Commande : string;if Readcommand($004C5C74, PAnsiChar(Commande)) > 0 then
// success
else
// 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 ?

Thanks,

Mathieu

Edited by mrousse83

Hi

I have no Experience about Delphi

Readcommand return the size of bytes

Masm:


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

or


BYTE szCmd[MAXCMDSIZE]; dwAddr = dwBase + dwOffset; nRetCode = Readcommand(dwAddr, (char *)szCmd);
PROCESS_ERROR(nRetCode);
  • Author

ragdog, and cmd contains the instruction ?

Thanks

Edited by mrousse83

ragdog, and cmd contains the instruction ?

Thanks

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);

Parameters:

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

  • Author

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 ?

Mathieu

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

  • Author

OK !

What functions i need to use for get assembler instruction ?

Thanks,

Mathieu

var
Commande : string;if Readcommand($004C5C74, PAnsiChar(Commande)) > 0 then
// success
else
// 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:


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

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)
/>http://forum.tuts4you.com/index.php?app=forums&module=forums&section=findpost&pid=121002

Edited by BoB

  • Author

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,

Mathieu

Yeah, use this:


Function Disasm(src: PChar; srcsize: ULONG; srcip: ULONG; srcdec: PChar; disasm: p_disasm; disasmmode: Integer; threadid: ULONG): ULONG; cdecl;
  • Author

OK !

Thanks BoB !

Mathieu

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.