Universal Hooker - API Reference

Below is the API available when writing hook handlers for the uhooker in python.
questions to hochoa[ a t corest.com].

Proxy Object

  • buffer readmemory(memaddr, len)
  • retcode writememory(memaddr, bufflen, data)
  • (retcode, memaddr) allocmemory(byte_count)
  • retcode freememory(memaddr)
  • ascii_string readasciiz(memaddr)
  • unicode_string readunicode(memaddr)
  • retcode changeregs(threadid, regs)
  • (retcode, newregs) stepin(threadid)
  • abyte readbyte(memaddr)
  • aword readword(memaddr)
  • adword readdword(memaddr)
  • buffer readmemory(memaddr, len)

    (int)memaddr = memory address to read data from
    (int)len = number of bytes to read

    Returns:

    (string)buffer = data read

    Example:

    myproxy = Proxy()
    buffer = myproxy.readmemory(0x401000, 50)
    print buffer
    

    retcode writememory(memaddr, bufflen, data)

    (int)memaddr = memory address to write data to
    (int)bufflen = number of bytes to write
    (string)data = bytes to write

    Returns:

    (int)retcode = 0 = error, 1 = success

    Example:

    myproxy = Proxy()
    data = "remember remember, the fifth of november"
    retcode = myproxy.writememory(0x401000, len(data), data)
    print retcode 
    

    (retcode, memaddr) allocmemory(byte_count)

    (int)byte_count = number of bytes to allocate

    Returns:

    (int)retcode = 0 = error, 1 = success
    (int)memaddr = address of the allocated block of memory

    Example:

    myproxy = Proxy()
    (retcode, memaddr) = myproxy.allocmemory(0x1000)
    print retcode
    print str(hex(memaddr))
    

    retcode freememory(memaddr)

    (int)memaddr = memory address to free

    Returns:

    (int)retcode = 0 = error, 1 = success

    Example:

    myproxy = Proxy()
    (retcode, memaddr) = myproxy.allocmemory(0x1000)
    print retcode
    print str(hex(memaddr))
    retcode = myproxy.freememory( memaddr )
    print retcode
    

    ascii_string readasciiz(memaddr)

    (int)memaddr = memory address to read the asciiz string (ascii + '\0') from

    Returns:

    (string)ascii_string = the asciiz string

    Example:

    myproxy = Proxy()
    mystring = myproxy.readasciiz(0x401000)
    print mystring
    

    unicode_string readunicode(memaddr)

    (int)memaddr = memory address to read the unicode (wide in fact, not unicode) string from

    Returns:

    (string)unicode_string = the asciiz string

    Example:

    myproxy = Proxy()
    mystring = myproxy.readunicode(0x401000)
    print mystring
    

    retcode changeregs(threadid, regs)

    Changes the cpu registers for the program (current thread) being debugged.

    (int)threadid = threadid of the thread to which you want to change the registers
    (dictionary)regs = dictionary containing the new value of registers

    Returns:

    (int)retcode = 0 = error, 1 = success

    Example:

    myproxy = Proxy()
    print "eax: " + str( hex( hookcall.regs['eax'] ) )
    hookcall.regs['eax'] = hookcall.regs['eax'] + 0x8a8a8a8a
    retcode = myproxy.changeregs( hookcall.threadid, hookcall.regs )
    print retcode
    

    (retcode, newregs) stepin(threadid)

    Executes the next instruction of the program being debugged.

    (int)threadid = threadid of the thread to execute the instruction on (must be current thread as obtained from hookcall.threadid)

    Returns:

    (int)retcode = 0 = error, 1 = success
    (dictionary)newregs = dictionary containing the new values of the cpu registers after the instruction was executed

    Example:

    myproxy = Proxy()
    print "eip: " + str( hex( hookcall.regs['eip'] ) )
    (retcode, nregs) = myproxy.stepin( hookcall.threadid )
    print retcode
    print nregs
    

    abyte readbyte(memaddr)

    (int)memaddr = memory address of byte to read

    Returns:

    (string)abyte = byte read

    Example:

    myproxy = Proxy()
    abyte = myproxy.readbyte(0x400000)
    print abyte
    

    aword readword(memaddr)

    (int)memaddr = memory address of word to read

    Returns:

    (string)aword = word read

    Example:

    myproxy = Proxy()
    aword = myproxy.readword(0x400000)
    print aword
    

    adword readdword(memaddr)

    (int)memaddr = memory address of dword to read

    Returns:

    (string)adword = dword read

    Example:

    myproxy = Proxy()
    adword = myproxy.readdword(0x400000)
    print adword