• Welcome to Valhalla Legends Archive.
 

SFile* APIs

Started by Hdx, July 11, 2008, 08:32 PM

Previous topic - Next topic

Hdx


DWORD WINAPI SFileGetFileSizeHook(IN HANDLE hFile, OUT DWORD *dwSize){
  SFileGetFileSizeType OldFn = (SFileGetFileSizeType)STRMHook.Functions[STRM_SFileGetFileSize].OrigFn;
  BOOL ret = OldFn(hFile, dwSize);
  fprintf(log, "SFileGetFileSize(0x%p, %d) = %d\n", hFile, dwSize, ret);
  return ret;
}

BOOL WINAPI SFileOpenFileHook(IN LPCSTR lpFileName, OUT HANDLE *lphFile){
  SFileOpenFileType OldFn = (SFileOpenFileType)STRMHook.Functions[STRM_SFileOpenFile].OrigFn;
  BOOL ret = OldFn(lpFileName, lphFile);
  fprintf(log, "SFileOpenFile(%s, 0x%p)\n", lpFileName, &lphFile);
  return ret;
}

BOOL WINAPI SFileReadFileHook(HANDLE hFile, void *lpBuffer, IN DWORD nNumberOfBytesToRead, OUT DWORD *lpNumberOfBytesRead, OUT OVERLAPPED *lpOverlap){

  SFileReadFileType OldFn = (SFileReadFileType)STRMHook.Functions[STRM_SFileReadFile].OrigFn;
  BOOL ret = OldFn(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlap);
  fprintf(log, "SFileReadFile(0x%p, 0x%p, %d, %d)\n", hFile, lpBuffer, nNumberOfBytesToRead, &lpNumberOfBytesRead);
  fprintf(log, "\tEvent: %d\n", &lpOverlap->hEvent);
  fprintf(log, "\tOffset: 0x%p%p\n", &lpOverlap->OffsetHigh, &lpOverlap->Offset);
  fprintf(log, "\tInternal: 0x%p%p\n", &lpOverlap->InternalHigh, &lpOverlap->Internal);
  }
  return ret;
}
BOOL WINAPI SFileCloseFileHook(IN HANDLE hFile){
  fprintf(log, "SFileCloseFile(0x%p)\n", &hFile);
  SFileCloseFileType OldFn = (SFileCloseFileType)STRMHook.Functions[STRM_SFileCloseFile].OrigFn;
  return OldFn(hFile);
}


QuoteSFileOpenFileEx(0x0012FAB4, font\font.ccd, 0x00000000, 0x0012FACC)
SFileGetFileSize(0x003D007C, 0) = 72
SFileReadFile(0x003D007C, 0x00820088, 72, 1243832)
Event: 16
Offset: 0x0000000C00000008
Internal: 0x0000000400000000
SFileCloseFile(0x0012FABC)
Note how the File handle changes from 0x0012FACC -> 0x003D007C -> 0x0012FABC, and I don't think i'm printing the struct out correctly

Its probably a obvious mistake that I jsut need someone to point out to me.
This is simple IAT redirecting no biggie.

I've sucessfully hijacked SReg* to make it 'portable' I'm working on killing the god forsaken MPQs now.

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

brew

The "handle" that you deal with in the Storm MPQ functions are not exactly the same kind of 'handles' used in win32 api- They are actually raw pointers to the class instance. As for your handle changing, your values were correct the entire time! Take a look at what you print out and what you pass to SFileOpen. You pass lphFile to the original function, which is say, the address of a variable you allocated in the parent function. Then, you pass &lphFile to fprintf- Effectively, the address of the address where another address is written to! The function storm!SFileGetFileSize is "working" just fine in the sense that you get your expected value (whatever was allocated from storm!SMemAlloc), because you're actually printing the raw handle that was written into lphFile in the first function. If you would like to print out the actual handle written by SFileOpen, try passing *lphFile to fprintf. I haven't taken a look at your other two functions but I'm pretty sure you've been just passing the wrong values to fprintf by mistake as well.
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Hdx

Humm odly what you just said makes sense.
I'm not quite sure why i'm printing the address ....
I think it was throwing compile errors when I tried to print the *. So i said fucket.
BUT, it seems to be compiling now. And I will give it a shot once SC finishes downloading. [I'm at work]
I am really curious about the structure of these classes.
Mainly how to maker the game not spazzout by properly emulating them.

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status