Hiya! I'm a total greenhorn at the MASM thing, so be gentle, k? I'm interested in making a simple little patcher that will strip an arbitrary number of bytes from the beginning of an object file. The number can be set at assemble time via a constant, it doesn't need to be flexible enough to select at runtime. This should be a simple thing, but I'm feeling a little overwhelmed and hope some pointers will also help me in the long run in terms of ASM coding in general. Thanks! Mark
Posted on 2001-03-23 07:15:00 by Mark
You mean remove the first n bytes from a file? Look at Icz's tutorial no.13 (unlucky?) This basically loads a file, maps it (read-only) into memory, then copies the entire file back (under some other name) starting at the begining of that mapped memory. If I understand you correctly, you want to start some distance into this file, so you will need to make the following change to the Tut:

invoke WriteFile,hFileWrite,pMemory,eax,ADDR SizeWritten,NULL
invoke WriteFile, hFileWrite, pMemory + MyConstant, \
                  eax, ADDR SizeWritten, NULL
This is a very basic way of doing what you want. Instead of copying from the begining of the original file (thats what pMemory points to), you add your constant to start that many bytes into that file! However, you will need to add a little check to make sure that your constant is smaller than the size of the file you read in (otherwise you risk trying to access undefined memory passed the end of your file). So you need to: 1) Modify the code so it all takes place in one go (remove the window, cut & paste bits of code etc.). 2) Introduce a check so that an error is raised in a message box when "GetFileSize" returns a number smaller than MY_CONST. Mirno
Posted on 2001-03-23 07:58:00 by Mirno
Don't forget adjusting the file size!! SUB EAX,MyConstant invoke WriteMemory.... Otherwise, you might just get an uncomfortable GPF. :)
Posted on 2001-03-23 09:39:00 by Racso
Yes, well done, you spotted the deliberate mistake :P Rasco: Grade - A+ Mirno
Posted on 2001-03-23 09:47:00 by Mirno