View Single Post
Old 12.12.2006, 15:08   #4
HongK
Архивный участник
 
Join Date: Jun 2005
Posts: 258
Default

Ok so I managed to finally figure out how to overwrite some data without crashing the server :P

First off, what you need to do is add a .asm file to your sources and call it whatever you want. I called mine FirstPatch.asm since it was the first thing I tried. Next create a custom build step so that your asm file is compiled and linked in to the dll. You'll need to add the function prototype to your header file. It should just be void since you're not doing anything but overwriting some bytes. Here's what my asm file looks like:

Code:
PUBLIC FirstPatch
.DATA

sMessage	word	"C","o","n","g","r","a","t","s",","," ","Y","o","u"," ","O","v","e","r","w","r","o","t","e"," ","I","t",0
lastFunc	dq	0064DC60h
returnAdd	dq	006362EFh
.CODE

FirstPatch:

	lea r8, sMessage
	call qword ptr [lastFunc]
	jmp returnAdd

END
Whether or not that call instruction is the best way of doing it, I'm not sure. I'm not really an assembler guru, but it compiles ok and works so atm that was all I cared about :P

The string up there is defined as Unicode since that's what the function you're calling is expecting the string to be in. If you do it in ASCII you will just see junk on the console window. Also, to get it so you don't have a prologue and epilogue just create the function label and leave it as is like I did.

So what this does is simply overwrite what's already in r8, which was "Load QuestItem" with my string defined by sMessage. Why change that? It just happened to be one of the first unicode strings I came across while messing around in l2server. I used it as an example to myself to test whether or not this method would work.

Anyway, if you go back to your dll, I was having problems with writeprocessmemory writing just a byte for the the jmp instruction, so I changed the bytes like in L2Extension project using pointers and it seems to be working fine. I kept crashing the server originally before I realized it was probably crashing on leaving my firstpatch function. You used to be able to push a return address on the stack and call retn, but that's obviously not the case anymore. Instead I just jmped back to the return address and everything went smoothly.
HongK is offline