Network: WoW Gold | WoW Accounts | MPS Games | FPSowned
MMOwned - World of Warcraft Exploits, Hacks, Bots and Guides
Homepage »      Register »      Hall of Fame »      Ranks And Awards »      Advertise »      Marketplace »
 
Sign up



Do you like this excellent information? Then Donate HERE to remove ads and support the MMOwned community.


Go Back   MMOwned - World of Warcraft Exploits, Hacks, Bots and Guides > Discussions > Programming

Programming Discuss all your programming needs here.

Reply
 
LinkBack Thread Tools
  #16  
Old 11-19-2009
corderoy is offline.
Corporal
  
 
Join Date: May 2008
Posts: 17
Reputation: 7
Points: 393, Level: 1
Points: 393, Level: 1 Points: 393, Level: 1 Points: 393, Level: 1
Level up: 99%, 7 Points needed
Level up: 99% Level up: 99% Level up: 99%
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%

Code:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <errno.h>

int main(int argc, char **argv)
{
    pid_t pid;
    unsigned long addr1;
    int buf;

    pid = 11316;
    addr1 = 0x00CEF5D0;
    ptrace(PTRACE_ATTACH, pid, NULL, NULL);
    wait(NULL);
    buf = ptrace(PTRACE_PEEKDATA, pid, (void *)addr1, NULL);

    printf("pid: %d, addr: %lx, value: %d \n", pid, addr1, buf);

    ptrace(PTRACE_DETACH, pid, NULL, NULL);
    return(0);
}
just a prove of concept code, it should work.
As I wrote earlier, I switched to python so I don't have more C code. I might consider sharing some python code if someone find it interesting.

ptrace gives possibility to read/write program data, as well as code, read and manipulation of registers. One of possible scenarios is to stop program execution, store processor context (registers), inject some code into stack (reading esp we have stack pointer), redirecting program execution (eip - register) restore processor context and resume program execution
Reply With Quote


Donate to remove ads, get your "DONATOR title, and get access to the MMOwned community's elite Shoutbawx.

  #17  
Old 11-20-2009
Sednogmah's Avatar
Sednogmah is offline.
Sergeant
  
 
Join Date: Oct 2009
Location: Undercity
Posts: 59
Reputation: 50
Points: 721, Level: 1
Points: 721, Level: 1 Points: 721, Level: 1 Points: 721, Level: 1
Level up: 65%, 179 Points needed
Level up: 65% Level up: 65% Level up: 65%
Activity: 3.2%
Activity: 3.2% Activity: 3.2% Activity: 3.2%

Essay

Thanks for contributing to this thread, corderoy! Python is an excellent choice for writing bots, I'm sure. It's one of my favorite languages because it's so elegant and kind to the eyes of the reader.

Back to the topic, memory reading:

What corderoy posted is the standard POSIX way for reading another process' memory. It works and is portable. On Linux, there's a faster way:

- Open the "virtual" file /proc/PID/mem that represents the process' virtual memory map
- Attach to the process (like in corderoy's example)
- wait() for the process (like in corderoy's example)
- Use the POSIX function "pread" (man 2 pread) to read an arbitrary memory area
- Detach (like in corderoy's example)

The difference is that ptrace(PTRACE_PEEKDATA,...) only reads one word at a time while pread allows you to read large chunks at once.

Sidenote:
ptrace(PTRACE_PEEKDATA) is also the reason why OllyDbg isn't very fast in WINE, because WINE uses exactly this function to "emulate" the Windows facilities for reading another process' memory. The WINE developers seem to have chosen portability over performance in this case. Reference: [Only registered and activated users can see links. ]
__________________
WTB [TP]

Last edited by Sednogmah; 11-20-2009 at 10:06 PM.
Reply With Quote
  #18  
Old 11-21-2009
Molleren's Avatar
Molleren is offline.
New User
  
 
Join Date: Nov 2007
Posts: 63
Reputation: 2
Points: 629, Level: 1
Points: 629, Level: 1 Points: 629, Level: 1 Points: 629, Level: 1
Level up: 46%, 271 Points needed
Level up: 46% Level up: 46% Level up: 46%
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%

Okay, so I've made this function:
pid is a global variable.
Code:
int readMemory(unsigned long addr1)
{
    int buf;

    //addr1 = 0x00CEF5D0;
    ptrace(PTRACE_ATTACH, pid, NULL, NULL);
    wait(NULL);
    buf = ptrace(PTRACE_PEEKDATA, pid, (void *)addr1, NULL);

    printf("pid: %d, addr: %lx, value: %d \n", pid, addr1, buf);

    ptrace(PTRACE_DETACH, pid, NULL, NULL);
    return(0);
}
How would I edit it to return a string? I mean, what if the address is a string, how would I redo this to make it return a string?
EDIT: And does anyone have a WoW address which I could use to test if it works? Without offsets
Reply With Quote
  #19  
Old 11-21-2009
corderoy is offline.
Corporal
  
 
Join Date: May 2008
Posts: 17
Reputation: 7
Points: 393, Level: 1
Points: 393, Level: 1 Points: 393, Level: 1 Points: 393, Level: 1
Level up: 99%, 7 Points needed
Level up: 99% Level up: 99% Level up: 99%
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%

@Sednogmah

I knew /proc/PID/mem approach as well but for some reason I've chosen ptrace way (maybe becouse it was quite easy to implement, and while botting most often program has to access certain words of memory than larger chunks). I can confirm that ptrace is kinda slow but it was fast enough for me.

@Molleren

You need to understand how things works first. Ptrace lets you read single word in memory at a time. Then you need to realize how this string which you want to read is represented in memory. Strings are a long story, could be UTF-8, UTF-16 or simple c string (ascii). Given a word on 32-bit machines are 32 bit long and in c string you have one char stored in one byte, you need to read as many words as needed looking for '\0' character in it (assuming its a null terminated string). So basicaly, you read one word (4 bytes) - this are your first 4 chars of string assuming no byte has value of 0x00, and repeat this procedure till you find 0x00 appending consecutive bytes to your string. Check out also BIG ENDIAN and LITTLE ENDIAN terms on the internet because you need to understand how bytes are ordered in memory.

Here is my high level python code for it:

Code:
while True:
        data = readWord_(pid,  address)
        str = binToString(data)
        result = result + str
        if len(str)<4: 
            break
        else:
            address = address +4

Hopes this helps, I'm not good in explaining things.

Last edited by corderoy; 11-21-2009 at 09:11 AM.
Reply With Quote
  #20  
Old 11-21-2009
Sednogmah's Avatar
Sednogmah is offline.
Sergeant
  
 
Join Date: Oct 2009
Location: Undercity
Posts: 59
Reputation: 50
Points: 721, Level: 1
Points: 721, Level: 1 Points: 721, Level: 1 Points: 721, Level: 1
Level up: 65%, 179 Points needed
Level up: 65% Level up: 65% Level up: 65%
Activity: 3.2%
Activity: 3.2% Activity: 3.2% Activity: 3.2%

Quote:
Originally Posted by corderoy View Post
@Sednogmah
I knew /proc/PID/mem approach as well but for some reason I've chosen ptrace way (maybe becouse it was quite easy to implement, and while botting most often program has to access certain words of memory than larger chunks). I can confirm that ptrace is kinda slow but it was fast enough for me.
Yeah, that's perfectly reasonable of course. I just thought I'd mention it before anyone tries to do complete memory dumps with PEEKDATA ,-)

@Molleren: Note that PTRACE_ATTACH suspends the process, so you want to DETACH as soon as possible after you're done with reading.
__________________
WTB [TP]

Last edited by Sednogmah; 11-21-2009 at 11:10 AM.
Reply With Quote
  #21  
Old 11-21-2009
Molleren's Avatar
Molleren is offline.
New User
  
 
Join Date: Nov 2007
Posts: 63
Reputation: 2
Points: 629, Level: 1
Points: 629, Level: 1 Points: 629, Level: 1 Points: 629, Level: 1
Level up: 46%, 271 Points needed
Level up: 46% Level up: 46% Level up: 46%
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%

Ah okay! Thanks a lot (:
Reply With Quote
  #22  
Old 12-18-2009
rootguy is offline.
New User
  
 
Join Date: Aug 2008
Posts: 23
Reputation: 3
Points: 362, Level: 1
Points: 362, Level: 1 Points: 362, Level: 1 Points: 362, Level: 1
Level up: 91%, 38 Points needed
Level up: 91% Level up: 91% Level up: 91%
Activity: 1.2%
Activity: 1.2% Activity: 1.2% Activity: 1.2%

Using ptrace to read large blocks of memory is just too much of a performance hit. Easiest solution is to alter the kernel source to be able to read/write from/to /proc/pid/mem file.
I don't remember exactely what file it was but it was changing a function to always return 1 instead of returning 1 when you're root or the program itself.
Reply With Quote
  #23  
Old 12-18-2009
Sednogmah's Avatar
Sednogmah is offline.
Sergeant
  
 
Join Date: Oct 2009
Location: Undercity
Posts: 59
Reputation: 50
Points: 721, Level: 1
Points: 721, Level: 1 Points: 721, Level: 1 Points: 721, Level: 1
Level up: 65%, 179 Points needed
Level up: 65% Level up: 65% Level up: 65%
Activity: 3.2%
Activity: 3.2% Activity: 3.2% Activity: 3.2%

Quote:
Originally Posted by rootguy View Post
Using ptrace to read large blocks of memory is just too much of a performance hit. Easiest solution is to alter the kernel source to be able to read/write from/to /proc/pid/mem file.
Yes, using ptrace to read is slow. However you can read large chunks quickly without modifying the kernel if you use ptrace just to attach to the target process but instead of using ptrace's "PEEK" to actually read something, you open /proc/pid/mem and read with the pread(2) function.

Quote:
I don't remember exactely what file it was but it was changing a function to always return 1 instead of returning 1 when you're root or the program itself.
If you use ptrace(PTRACE_ATTACH) on the target process that runs under the same UID as you are, the kernel opens /proc/PID/mem for reading.
__________________
WTB [TP]

Last edited by Sednogmah; 12-18-2009 at 12:00 PM.
Reply With Quote
  #24  
Old 12-19-2009
rootguy is offline.
New User
  
 
Join Date: Aug 2008
Posts: 23
Reputation: 3
Points: 362, Level: 1
Points: 362, Level: 1 Points: 362, Level: 1 Points: 362, Level: 1
Level up: 91%, 38 Points needed
Level up: 91% Level up: 91% Level up: 91%
Activity: 1.2%
Activity: 1.2% Activity: 1.2% Activity: 1.2%

It has been a while since i used ptrace etc but isn't it so that you need to detach after you're done reading to continue the program?
With the kernel mod you just open the device with open or fopen and read/write whenever you need to without any performance loss.

After the kernel mod dependend bot i switched to a much better solution.
Loading a shared lib with LD_PRELOAD, hooking the iat PeekMessage function effectively creating a loader to load and unload other libs on demand.

I'm derailing the thread a little i think, so i have to say it's very informational. It took me a good while learning everything about X11 to get my first bot running with mouse movement and key presses.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On



All times are GMT -4. The time now is 08:13 AM.




Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524