GithubHelp home page GithubHelp logo

Seg fault for memory read about pylibemu HOT 8 CLOSED

buffer avatar buffer commented on June 8, 2024
Seg fault for memory read

from pylibemu.

Comments (8)

buffer avatar buffer commented on June 8, 2024

Could you please provide a test code which reproduces the issue?

Thanks,
Angelo

from pylibemu.

cperdana avatar cperdana commented on June 8, 2024

emu = pylibemu.Emulator()

emu.prepare('\x90\x90\xc3\x90\x90\x90', 0)
emu.test(2)
eip = emu.cpu_eip_get()
print "eip:", eip, hex(eip)
print emu.memory_read_byte(eip)
----------output-----------
eip: 4288514 0x417002L
Segmentation fault (core dumped)

platform:
ubuntu 12.04 64bit
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3] on linux2
Cython version 0.15.1

from pylibemu.

buffer avatar buffer commented on June 8, 2024

I'm not able to reproduce it here...

buffer@alnitak ~ $ python
Python 2.7.3 (default, May 15 2012, 11:39:38)
[GCC 4.5.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import pylibemu
emu = pylibemu.Emulator()
emu.prepare('\x90\x90\xc3\x90\x90\x90', 0)
emu.test(2)
0
eip = emu.cpu_eip_get()
print "eip:", eip, hex(eip)
eip: 4288514 0x417002L
print emu.memory_read_byte(eip)
195

Cython is really not needed by your side because setup.py compiles the generated C file so the only difference between our environments is gcc (here 4.5.3).

Could you please try creating a .py file and run it in gdb? You should just do something like

$ gdb python

run test.py

After the segfault please something like backtrace' andinfo frame N' would be really useful to understand what's going on by your side.

from pylibemu.

cperdana avatar cperdana commented on June 8, 2024

(gdb) run rkaji.py
Starting program: /usr/bin/python rkaji.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
eip: 4288513 0x417001L

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff55662e5 in emu_memory_read_byte (m=0xc2c780, addr=4288513, byte=0x0) at emu_memory.c:272
272 *byte = *((uint8_t *)address);

from pylibemu.

cperdana avatar cperdana commented on June 8, 2024

I think the problem is uninitialize pointer in memory_read_byte in pylibemu.pyc.
You declare byte:
cdef uint8_t *byte # line 993
then without initialize it, you send it as parameter in
if emu_memory_read_byte(_mem, addr, byte) # line 999

I change the function as below and it works.
#--------------code-begin---------------------------
def memory_read_byte(self, uint32_t addr):
cdef c_emu_memory *_mem
cdef uint8_t byte # I change this line

    if self._emu is NULL:
        raise RuntimeError('Emulator not initialized')

    _mem = emu_memory_get(self._emu)
    if emu_memory_read_byte(_mem, addr, &byte):   #  I change this line
        raise RuntimeError("Error while reading a byte at address 0x%x" % (addr, ))

    return byte#  I change this line

#-------------code-end---------------------------

from pylibemu.

buffer avatar buffer commented on June 8, 2024

Committed a patch for your issue. I still had not the possibility to test memory_read_string method but the other memory_read methods should work for you too now. Please run tests/cpu_mem_test.py and tell if everything is ok.

from pylibemu.

buffer avatar buffer commented on June 8, 2024

Added a test for memory_read_string method too.

from pylibemu.

cperdana avatar cperdana commented on June 8, 2024

Great, its working now. Thank you.

from pylibemu.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.