[Linux][wine] Reading memory - ptrace menu

Shout-Out

User Tag List

Results 1 to 12 of 12
  1. #1
    klipeto's Avatar Private
    Reputation
    1
    Join Date
    Jul 2011
    Posts
    4
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Linux][wine] Reading memory - ptrace

    I was thinking about learning some WoW memory stuff and I would like to create a class for WoW memory reading and possibly tweaking which could be used later in other projects.
    There are some already but my approach is memory tweaking from out of the wine environment in Linux, ie. without injecting or dll replacing.

    I'll probably write more stuff here if I find something interesting. In the meantime this is my first chapter of my adventure in the land of WoW memory...

    For reading WoW memory running through wine I use ptrace system function which is able to read/write memory of a process if you are root. I've found nice ptrace library for python.
    If you are interested python-ptrace is just a ptrace wrapper or you can try to find your favourite language library or just use C/++
    Just man ptrace and search for PEEK and POKE. Actually scanmem uses ptrace as well.

    Base memory address seems to be always 0x00400000 as it is usually. I think that you can get the actual address by reading /proc/pid/maps where are all memory ranges of the process. ie. in shell you can get the base this way:
    Code:
    $ grep Wow.exe /proc/`pidof Wow.exe`/maps
    00400000-00401000 r-xp 00000000 08:01 1337759                            /path/to/Wow.exe
    Here is a small python script just to show you how you can read the memory:
    Code:
    #!/usr/bin/env python
    
    from ptrace.debugger.debugger import PtraceDebugger
    from ptrace.debugger.process import PtraceProcess
    from struct import unpack
    from os import popen
    
    # read Word, or ByteArray if size is provided
    def read(address, size=None):
        global tracer
    
        if not size:
            return tracer.readWord(address)
        return tracer.readBytes(address, size)
    
    # read unsigned int
    def readInt4(address):
        return unpack("I", read(address, 4))[0]
    
    # get pid and instantiate ptrace wrapper
    pid = int(popen("pidof Wow.exe", "r").read().strip())
    tracer = PtraceProcess(PtraceDebugger(), pid, False)
    
    # read 4 byte unsigned integer
    data = readInt4(yourFavouriteOffset) # instead of yourFavouriteOffset provide your favourite offset, ie. 0x12345
    If you need to read something else then Word, uInt or byteArray, check method unpack and the provided readInt4 function which you can copy, change number of bytes you need and change unpack's format character.
    Here are unpack's format characters: 7.3. struct ? Interpret strings as packed binary data — Python v2.7.2 documentation
    Also PtraceProcess has some others readSomething functions which might be worth to be checked: https://bitbucket.org/haypo/python-p...cess.py#cl-100

    PS: Don't forget that you need root access to ptrace a process. Just sudo or login as root.

    [Linux][wine] Reading memory - ptrace
  2. #2
    flo8464's Avatar Active Member
    Reputation
    30
    Join Date
    Apr 2009
    Posts
    434
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's better to attach via ptrace and use /proc/[pid]/mem tro read/write process memory.
    Hey, it compiles! Ship it!

  3. #3
    klipeto's Avatar Private
    Reputation
    1
    Join Date
    Jul 2011
    Posts
    4
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @flo8464 Ah, that works well. Thank you. I didn't know that /proc/pid/mem becames available when I attach it by ptrace.

  4. #4
    kouteiheika's Avatar Private
    Reputation
    14
    Join Date
    May 2011
    Posts
    7
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Generally there isn't really much of a point in doing this as it's usually easier to just use the LD_PRELOAD trick, though it can be a bit challenging to make an LD_PRELOAD hack in a scripting language; I've made one in Ruby and it required some creative stack pointer manipulation and jumping around to get it to work properly. The only other advantage I can think of that this method has is that you can restart your hack/bot/whatever while WoW is running, but that also can be easily achieved with LD_PRELOAD by using a 2-stage loading process.

  5. #5
    flo8464's Avatar Active Member
    Reputation
    30
    Join Date
    Apr 2009
    Posts
    434
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by kouteiheika View Post
    Generally there isn't really much of a point in doing this as it's usually easier to just use the LD_PRELOAD trick, though it can be a bit challenging to make an LD_PRELOAD hack in a scripting language; I've made one in Ruby and it required some creative stack pointer manipulation and jumping around to get it to work properly. The only other advantage I can think of that this method has is that you can restart your hack/bot/whatever while WoW is running, but that also can be easily achieved with LD_PRELOAD by using a 2-stage loading process.
    On Windows injection is also easier and people are still writing out-of-process bots. So I guess it's ok to work out-of-process on linux, especially as it is extremly safe. (Without massive hacking there's no chance to detect a passive Kinux bot)


    @klipeto: You might want to take a look at my library, it's written in C++ and does many things you like to do:
    http://www.mmowned.com/forums/world-...g-library.html
    Hey, it compiles! Ship it!

  6. #6
    kouteiheika's Avatar Private
    Reputation
    14
    Join Date
    May 2011
    Posts
    7
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by flo8464 View Post
    On Windows injection is also easier and people are still writing out-of-process bots. So I guess it's ok to work out-of-process on linux, especially as it is extremly safe. (Without massive hacking there's no chance to detect a passive Kinux bot)
    Well, on Windows people write out-of-process bots as it's supposedly safer, right? On Linux on other hand an LD_PRELOAD hack is just as safe as such out-of-process hack.

  7. #7
    namreeb's Avatar Legendary

    Reputation
    668
    Join Date
    Sep 2008
    Posts
    1,029
    Thanks G/R
    8/222
    Trade Feedback
    0 (0%)
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    People write out-of-process bots because they have fallen for the fallacy that it is supposedly safer. It is not inherently safter. I think most people stay out of process because they don't know how to inject.

  8. #8
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by namreeb View Post
    People write out-of-process bots because they have fallen for the fallacy that it is supposedly safer. It is not inherently safter. I think most people stay out of process because they don't know how to inject.
    Injection is scary and dangerous.

  9. #9
    klipeto's Avatar Private
    Reputation
    1
    Join Date
    Jul 2011
    Posts
    4
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, guys.

    I'm just a noob learning some memory stuff first. Later I might try some injection.

    @kouteiheika: I know about the LD_PRELOAD thread. Good info there.

    @flo8464: great lib, thank you. Even I'm not going to use C and I don't need so many features like scanning yet I might get some inspiration

  10. #10
    MaiN's Avatar Elite User
    Reputation
    335
    Join Date
    Sep 2006
    Posts
    1,047
    Thanks G/R
    0/10
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cypher View Post
    Injection is scary and dangerous.
    It's only dangerous if you don't have your ring 0 proxies running.
    [16:15:41] Cypher: caus the CPU is a dick
    [16:16:07] kynox: CPU is mad
    [16:16:15] Cypher: CPU is all like
    [16:16:16] Cypher: whatever, i do what i want

  11. #11
    suicidity's Avatar Contributor
    Reputation
    207
    Join Date
    Oct 2006
    Posts
    1,439
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by MaiN View Post
    It's only dangerous if you don't have your ring 0 proxies running.
    or when you accidentally destroy the peb and kernel ring 3 can't find it. this problem is put best in peterslone's words..

    ..or this image.


  12. #12
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ​Hahahahaha. Epic.

Similar Threads

  1. Reading memory in VB.Net
    By XGenius in forum Programming
    Replies: 6
    Last Post: 02-06-2010, 06:58 PM
  2. Need help reading Memory, Writing too memory
    By Neer in forum Programming
    Replies: 0
    Last Post: 08-17-2009, 12:11 PM
  3. Witch util are you using to read memory ?
    By guillaume76290 in forum WoW Memory Editing
    Replies: 3
    Last Post: 07-19-2009, 07:52 PM
  4. Read Memory Return 0
    By marko002 in forum WoW Memory Editing
    Replies: 3
    Last Post: 12-12-2008, 09:13 PM
  5. [c++] problem with reading memory
    By Lucani in forum WoW Memory Editing
    Replies: 3
    Last Post: 05-08-2008, 03:41 AM
All times are GMT -5. The time now is 02:41 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search