Skip to content

ESP handling for external calls #879

@XVilka

Description

@XVilka

For example we want to run CGC example with Primus:

bap ./CGC_Image_Parser --run --run-entry-points=main \
--rooter=ida --symbolizer=ida --x86-abi=cdecl \
--primus-lisp-load=posix,memcheck-malloc

This is how BIL looks like for the function cgc_putc():

image

This is the actual diassembly (cgc_transmit is an imported function):

image

┌ (fcn) sym.imp.cgc_transmit 6                                                                                                                                                                                                               
│   sym.imp.cgc_transmit ();                                                                                                                                                                                                                 
│ ⁝⁝⁝⁝⁝⁝⁝   ; CALL XREF from sym.cgc_puts (0x804a76f)                                                                                                                                                                                        
│ ⁝⁝⁝⁝⁝⁝⁝   ; CALL XREF from sym.cgc_putc (0x804a7b2)                                                                                                                                                                                        
└ ⁝⁝⁝⁝⁝⁝⁝   0x08049650      ff2598230508   jmp dword [reloc.cgc_transmit]       ; 0x8052398 ; "V\x96\x04\bf\x96\x04\bv\x96\x04\b\x86\x96\x04\b\x96\x96\x04\b\xa6\x96\x04\b\xb6\x96\x04\b"                                                    
  ⁝⁝⁝⁝⁝⁝⁝   0x08049656      6818000000     push 0x18                   ; 24                                                                                                                                                                  
  └───────< 0x0804965b      e9b0ffffff     jmp 0x8049610               ;[1]   

So the function do not call return in the end, just a simple jump. Thus the ESP value is not corrected back, which messes the execution.

Example: CGC_Image_Parser.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions