Gaming Community
Forum
 
Go Back   D3scene > Software/Hardware > Development
Register Blogs Live view Downloads Marketplace FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

Codecaving Tutorial (Warcraft 3 example)

This is a discussion on Codecaving Tutorial (Warcraft 3 example) within the Development forum part of the Software/Hardware category; ~ Tyrano's Codecaving tutorial ~ Codecaving is, basically, to put a jump before a target offset that needs to be ...


Welcome on D3scene.com! Make sure to register - it's free and very quick! You have to register before you can post and participate in our discussions with 70000 other registered members. Downloads, user profiles and some forums can only be seen by registered members. After you create your free account you will be able to customize many options, you will have the full access to new hacks, latest cheats and last but not least will see no advertisements at all. We would love to see you around in our community!
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 02-26-2009, 03:18 AM
TyranO's Avatar
Codemotion.net




 
Join Date: Aug 2008
Location: Azeroth
Posts: 320
Thanks: 15
Thanked 110 Times in 30 Posts
Reputation: 1064
Rep Power: 7
TyranO has much to be proud ofTyranO has much to be proud ofTyranO has much to be proud ofTyranO has much to be proud ofTyranO has much to be proud ofTyranO has much to be proud ofTyranO has much to be proud ofTyranO has much to be proud of
Arrow Codecaving Tutorial (Warcraft 3 example)

~ Tyrano's Codecaving tutorial ~

Codecaving is, basically, to put a jump before a target offset that needs to be patched to an empty or unimportant zone in memory, put your modified code there, and then jump back under the target address.


What's the point of doing this?

Codecaving allows you to get the effects of modifying an offset that could be blacklisted by poor anti-cheat software (ex: Warden in Warcraft 3), since you never modify it directly.
You could therefore take the offsets of some hack and make them almost "undetectable" (considering you keep that hack private or simply for your
self).

Pseudo example:

Before the code cave and patching:
Quote:
1 Address 1 and its content
2 Target
3 Address 3 and its content

4 Unimportant stuff
5 Unimportant stuff
6 Unimportant stuff
(Unimportant stuff is mostly 00's and INT3's)

After the Code cave and patching:
Quote:
1 JUMP to address 4
2 Target
3 Address 3 and its content

4 Address 1's content
5 Patched target
6 JUMP back to address 3
As you can see, the target code is still being patched, but not at Address 5 instead of Address 2.

Let's do a codecave now!

Things you will need:

- An offset to patch
- A real-time debugger (OllyDBG)


For this example, we are going to use some stupid offset I found while offset-hunting in Warcraft 3:
Code:
6F39B991   BA 08000000      MOV EDX,8
to
Code:
6F39B991   BA 00000000      MOV EDX,0
Effect: Removes ground textures (ground becomes all black).


Let's analyze the bunch of code over that address. Open up Warcraft 3 and get in a custom game. Then start OllyDBG and attach war3.exe, then right click -> go to -> 6F39B991 or CTRL+G -> 6F39B991 (you may need to do this twice to get to the address).


We must first find some empty memory zone in which we will input our code.

By scrolling down to the end of Game.dll, I found out this neat little place:

Code:
6F85BE24   0000             ADD BYTE PTR DS:[EAX],AL
6F85BE26   0000             ADD BYTE PTR DS:[EAX],AL
6F85BE28   0000             ADD BYTE PTR DS:[EAX],AL
6F85BE2A   0000             ADD BYTE PTR DS:[EAX],AL
6F85BE2C   0000             ADD BYTE PTR DS:[EAX],AL
6F85BE2E   0000             ADD BYTE PTR DS:[EAX],AL
6F85BE30   0000             ADD BYTE PTR DS:[EAX],AL
6F85BE32   0000             ADD BYTE PTR DS:[EAX],AL
6F85BE34   0000             ADD BYTE PTR DS:[EAX],AL
6F85BE36   0000             ADD BYTE PTR DS:[EAX],AL
6F85BE38   0000             ADD BYTE PTR DS:[EAX],AL
6F85BE3A   0000             ADD BYTE PTR DS:[EAX],AL
6F85BE3C   0000             ADD BYTE PTR DS:[EAX],AL
6F85BE3E   0000             ADD BYTE PTR DS:[EAX],AL
6F85BE40   0000             ADD BYTE PTR DS:[EAX],AL
6F85BE42   0000             ADD BYTE PTR DS:[EAX],AL
etc.

Then let'a go back to our target address, 6F39B991, and analyse what's around it.

Code:
6F39B974   8D4C24 24        LEA ECX,DWORD PTR SS:[ESP+24]
6F39B978   E8 E3A8C7FF      CALL Game.6F016260
6F39B97D   E8 1E50C7FF      CALL Game.6F0109A0
6F39B982   39AE 30030000    CMP DWORD PTR DS:[ESI+330],EBP
6F39B988   74 07            JE SHORT Game.6F39B991
6F39B98A   8BCE             MOV ECX,ESI
6F39B98C   E8 4FEDFFFF      CALL Game.6F39A6E0
6F39B991   BA 08000000      MOV EDX,8                    // Target offset
6F39B996   8D4C24 5C        LEA ECX,DWORD PTR SS:[ESP+5C]     // Return address
We will use a normal jump to get there.

6F39B97D
seems like a good place to start our jump since it is 5 bytes long. Take that address's info down in notepad or w/e.

Code:
6F39B97D   E8 1E50C7FF      CALL Game.6F0109A0
PAUSE OllyDBG and change this line:

Code:
6F39B97D   E8 1E50C7FF      CALL Game.6F0109A0
to

Code:
6F39B97D   E9 A2044C00      JMP Game.6F85BE24
To do this, Select then right click the address -> Assemble or simply press spacebar then type: jmp 6F85BE24 and press enter (don't fill with NOP's)



Now press enter on that address to go the empty zone.

On 6F85BE24, we will place the info of the address we took down in note. It was

CALL Game.6F0109A0

Like we did just a minute ago, we will right click -> assemble.

Type call 6F0109A0 and press enter.



Now that we have added this line, we need to also add everything else that was between it and our target address:
Code:
6F39B982   39AE 30030000    CMP DWORD PTR DS:[ESI+330],EBP
6F39B988   74 07            JE SHORT Game.6F39B991
6F39B98A   8BCE             MOV ECX,ESI
6F39B98C   E8 4FEDFFFF      CALL Game.6F39A6E0
6F39B991   BA 08000000      MOV EDX,8                // target address
So, just like we did before, click on the line below the one we modified and assemble this:



Then, on the next line, assemble this twice:



The reason we are putting 2 NOP's here instead of JE SHORT 6F39B991 is because 6F39B991 is way out of range for the short jump.

Then, on the next line:



Then, on the next line:



Now let's modify MOV EDX,8 to MOV EDX,0 to get the black floor effect in-game.

Assemble at 6F85BE38:



Alright, we are almost done! What we need to do now is jump back to 6F39B996, the address that was just below our target.

Assemble this on the next line:



Your memory should now look like this:

Your jump:



Your code cave:



Alright, now we need to jump to the memory zone we just made.

Assemble this at:



You are now ready to press on PLAY in OllyDBG. Your floor should be black.

Next tutorial: Making this a hack in C++.
Attached Images
File Type: png codecave1.PNG (3.7 KB, 5 views)
File Type: png codecave2.PNG (3.7 KB, 4 views)
File Type: png codecave3.PNG (4.0 KB, 2 views)
File Type: png codecave4.PNG (3.8 KB, 2 views)
File Type: png codecave5.PNG (3.7 KB, 2 views)

Last edited by TyranO; 02-26-2009 at 04:46 PM.
Reply With Quote
The Following 5 Users Say Thank You to TyranO For This Useful Post:
D3scene
Welcome to D3scene - probably the best location for all Gamers.

To participate in our friendly environment you have to register. After completing registration you will have full access to all threads and features. We care about members and try to make your stay as pleasant as possible. We are unique with the following feature for members - you will not see a single Advertisement!


The best: registration is completely free. It will not cost you a single penny or harm you in any way. You will lose nothing except 1 minute of your time. So why not register? We would be happy to see you around!
  #2  
Old 02-26-2009, 07:46 AM
cHeRoL's Avatar
Advanced Hacker

 
Join Date: Nov 2008
Location: Romania
Posts: 352
Blog Entries: 1
Thanks: 3
Thanked 0 Times in 0 Posts
Reputation: 70
Rep Power: 2
cHeRoL will become famous soon enough
Send a message via Yahoo to cHeRoL Send a message via Skype™ to cHeRoL
W00t.
Good Job.
Reply With Quote
  #3  
Old 02-26-2009, 09:32 AM
dog_keeper's Avatar
Teh Sexy One.


 
Join Date: Dec 2007
Location: The one and only person who lives far far away from all the people here on d3scene!
Posts: 2,297
Thanks: 144
Thanked 79 Times in 55 Posts
Reputation: 1129
Rep Power: 8
dog_keeper has much to be proud ofdog_keeper has much to be proud ofdog_keeper has much to be proud ofdog_keeper has much to be proud ofdog_keeper has much to be proud ofdog_keeper has much to be proud ofdog_keeper has much to be proud ofdog_keeper has much to be proud ofdog_keeper has much to be proud of
great guide with pics

thanks
Reply With Quote
  #4  
Old 02-26-2009, 04:11 PM
TyranO's Avatar
Codemotion.net




 
Join Date: Aug 2008
Location: Azeroth
Posts: 320
Thanks: 15
Thanked 110 Times in 30 Posts
Reputation: 1064
Rep Power: 7
TyranO has much to be proud ofTyranO has much to be proud ofTyranO has much to be proud ofTyranO has much to be proud ofTyranO has much to be proud ofTyranO has much to be proud ofTyranO has much to be proud ofTyranO has much to be proud of
Something was wrong with the image order and the memory zone picture. It is fixed now I think. Tell me if there's anything wrong or something unclear.

EDIT: Memory zone picture is still wrong. One sec.

EDIT2: Ok now everything is fixed.

Last edited by TyranO; 02-26-2009 at 04:16 PM.
Reply With Quote
  #5  
Old 02-26-2009, 04:44 PM
MaRcDk's Avatar
Business Owner




 
Join Date: May 2007
Location: Denmark
Posts: 2,013
Thanks: 37
Thanked 36 Times in 14 Posts
Reputation: 2031
Rep Power: 14
MaRcDk is a rep whoreMaRcDk is a rep whoreMaRcDk is a rep whoreMaRcDk is a rep whoreMaRcDk is a rep whoreMaRcDk is a rep whoreMaRcDk is a rep whoreMaRcDk is a rep whoreMaRcDk is a rep whoreMaRcDk is a rep whoreMaRcDk is a rep whore
Great guide man!

Lots of pictures, just the way i like it
Reply With Quote
  #6  
Old 02-26-2009, 07:24 PM
Serverman's Avatar
Paranoia!

 
Join Date: Jan 2008
Posts: 2,679
Blog Entries: 3
Thanks: 94
Thanked 93 Times in 55 Posts
Reputation: 826
Rep Power: 7
Serverman is a splendid one to beholdServerman is a splendid one to beholdServerman is a splendid one to beholdServerman is a splendid one to beholdServerman is a splendid one to beholdServerman is a splendid one to beholdServerman is a splendid one to behold
Yup, this is great
Reply With Quote
  #7  
Old 05-26-2009, 08:28 AM
Newbie

 
Join Date: Oct 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Reputation: 0
Rep Power: 2
yourallgayfags is an unknown quantity at this point
Great guide Tyrano, looking forward to the next one

Also, are you able to tell me why the offset isn't '6F39B991' for me? At that address I have 'INT 51'
Reply With Quote
  #8  
Old 06-23-2009, 09:49 PM
Wannabe Member

 
Join Date: Mar 2009
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Reputation: 1
Rep Power: 1
oMaNao is an unknown quantity at this point
Quote:
Originally Posted by yourallgayfags View Post
Great guide Tyrano, looking forward to the next one

Also, are you able to tell me why the offset isn't '6F39B991' for me? At that address I have 'INT 51'
my guess whole be you are running a different version of the client.
Reply With Quote
  #9  
Old 08-22-2009, 05:55 AM
Member

 
Join Date: Jun 2009
Posts: 31
Thanks: 0
Thanked 8 Times in 3 Posts
Reputation: 26
Rep Power: 1
yellowsnow is on a distinguished road
Quote:
Originally Posted by yourallgayfags View Post
Great guide Tyrano, looking forward to the next one

Also, are you able to tell me why the offset isn't '6F39B991' for me? At that address I have 'INT 51'

game.dll is just that its a dll, a dynamically liked library. The address space it gets loaded into is dynamic, but the code within the dll is always the same. To fix this you can:

1) close war 3 and close any other runing program and restart, most likely game.dll will be loaded into its defualt memory space. this is the most sensible solution in my eyes. note this should be the recommended solution because a dll that is not loaded into its default mem space adds overhead when accessing it, and for a game that overhead can mean the difference between a laggy game and a responsive game.

2) fuck it and deal with offsets into the dll instead of absolute values. This works fine but when your cracking you dont wanna fuck around with so much overhead.

Last edited by yellowsnow; 08-22-2009 at 06:02 AM.
Reply With Quote
  #10  
Old 08-22-2009, 06:17 AM
Hacker

 
Join Date: Jul 2008
Posts: 171
Thanks: 13
Thanked 3 Times in 3 Posts
Reputation: 40
Rep Power: 2
forgotmylogin is on a distinguished road
it isn't the same because the guide was written for 1.22 and we are now in 1.24. the code gets shifted around slightly with every patch
Reply With Quote
D3scene
Welcome to D3scene - probably the best location for all Gamers.

To participate in our friendly environment you have to register. After completing registration you will have full access to all threads and features. We care about members and try to make your stay as pleasant as possible. We are unique with the following feature for members - you will not see a single Advertisement!


The best: registration is completely free. It will not cost you a single penny or harm you in any way. You will lose nothing except 1 minute of your time. So why not register? We would be happy to see you around!
Reply

Tags
codevaving, tutorial, tyrano, warcraft 3

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Memoirs of World of Warcraft Hallowsend WoW Patches 6 07-12-2009 07:52 AM
a game made after warcraft 2 jphix Warcraft 3 forum 6 06-03-2009 08:28 PM
DDM's Hacking Tool Collection Zend Rakion 3 03-15-2009 11:05 AM
A custom quest tutorial. Batman WoW Private Server Info & Help 13 07-29-2008 06:13 PM
World of Warcraft Model Edit Tutorial Xerxes WoW Modelchanging 4 07-11-2008 08:07 AM


All times are GMT +1. The time now is 10:26 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.0 ©2009, Crawlability, Inc.
vBulletin style developed by Transverse Styles