Jump to content
The Dark Mod Forums

Thelvyn's Thread


New Horizon

Recommended Posts

VirtualQuery and VirtualProtect are used to get information on the page and to set the page to and from writable so there is no exception when you try to write there which is the only thing the two approaches share in common really.

 

Your way is a lot more error prone unfortunately at least in my experience, probably need a new version any time the binary compatibility changes between dll version don't you ?

 

ImageDirectoryEntryToData is what you use for finding and replacing the function pointer.

 

I believe it is possible to do this for non-exported functions as well.

 

The following are availabe

 

Value Meaning

IMAGE_DIRECTORY_ENTRY_ARCHITECTURE 7 Architecture-specific data

IMAGE_DIRECTORY_ENTRY_BASERELOC 5 Base relocation table

IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 11 Bound import directory

IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 14 COM descriptor table

IMAGE_DIRECTORY_ENTRY_DEBUG 6 Debug directory

IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT 13 Delay import table

IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 Exception directory

IMAGE_DIRECTORY_ENTRY_EXPORT 0 Export directory

IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 Relative virtual address of global pointer

IMAGE_DIRECTORY_ENTRY_IAT 12 Import address table

IMAGE_DIRECTORY_ENTRY_IMPORT 1 Import directory

IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 Load configuration directory

IMAGE_DIRECTORY_ENTRY_RESOURCE 2 Resource directory

IMAGE_DIRECTORY_ENTRY_SECURITY 4 Security directory

IMAGE_DIRECTORY_ENTRY_TLS 9 Thread local storage directory

I haven't lost my mind. It's backed up on disk!

Oops bad sectors damn floppy's!

Link to comment
Share on other sites

  • Replies 157
  • Created
  • Last Reply

Top Posters In This Topic

Your way is a lot more error prone unfortunately at least in my experience, probably need a new version any time the binary compatibility changes between dll version don't you ?

 

Nope. That's the beauty of it. It works in all circumstances. The only drawback is that it might need an update if a function is handwritten, and the mnemonics are not know at that time. Then you would have to update the dissassembler.

 

ImageDirectoryEntryToData is what you use for finding and replacing the function pointer.

 

Yeah, but this works only for functions that are called via a functionpointer. My version works for all functions, as long as you know the address, which you obviously always have.

 

For example, I used this method, to track malloc calls because I was looking for a memory leak. Since malloc is usally linked via a static library, and not called through a dll, I think your method wouldn't work in this case, right? It all depends on what you need. As I said, the dissassembler is really an overkill, but I haven't found a better solution, though I must say, that your method is quite nice, if you know that a pointer is used, because it's more elegant.

 

Still it, was a nice experience, because as a sidenote, I can use this dissassembler for other things as well. :)

Gerhard

Link to comment
Share on other sites

I have never used that method but I have heard horror stories about it breaking apps quite frequently.

 

I was under the impression that there is ALWAYS a pointer to the function not just for exports/imports.

I could be wrong of course.

 

If I could have gotten the calling convention squabble fixed I would have implemented that as a class btw.

Every time I tried doom3 would crash on the second call it seems.

I was putting it in... when I changed from the class version it worked fine again.

 

What I ended up with was no better then doing it by hand so why bother increasing the complexity for no good reason says I.

I haven't lost my mind. It's backed up on disk!

Oops bad sectors damn floppy's!

Link to comment
Share on other sites

Help me understand this please.

idAi::Collide receives two arguments const trace_t &collision and const idVec3 &oldVelocity

 

These are just samples.

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = -280 -784 -255.75 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 0 0 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = 304 -432 368.25 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 0 0 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = -280 -784 -255.75 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 0 0 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = 304 -432 368.25 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 0 0 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = 304 -432 368.25 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 0.06 -0 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = -280 -784 -255.75 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 0.06 0 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = 304.01 -432 368.25 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 0.45 -0.05 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = -279.99 -784 -255.75 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 0.45 0 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = -1616.63 -2865.63 -125.75 fraction = 0.002197"

.\game\ai\ai.cpp(853) :"oldVelocity = 0 0 -17.02"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = -294 355 -223.75 fraction = 0.725220"

.\game\ai\ai.cpp(853) :"oldVelocity = 0 0 -51.17"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = -448 -1080 352.25 fraction = 0.725220"

.\game\ai\ai.cpp(853) :"oldVelocity = 0 0 -51.17"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = 304.02 -432 368.25 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 0.87 -0.11 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = -279.98 -784 -255.75 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 0.87 0 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = -1616.62 -2865.63 -125.75 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 0.87 -0.1 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = 304.07 -432.01 368.25 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 3.08 -0.42 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = -279.93 -784 -255.75 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 3.11 0 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = -1616.57 -2865.64 -125.75 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 3.06 -0.54 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = 304.19 -432.03 368.25 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 7.71 -0.99 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = -279.8 -784 -255.75 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 7.78 0 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = -1616.45 -2865.67 -125.75 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 7.55 -1.85 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = 304.35 -432.04 368.25 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 9.64 -1.03 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = -279.65 -784 -255.75 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 9.69 0 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

.\game\ai\ai.cpp(851) :"idAI::Collide Arguments follow"

.\game\ai\ai.cpp(852) :"collision - endAxis = 1 0 0 0 1 0 0 0 1 endpos = -1616.3 -2865.72 -125.75 fraction = 0.000000"

.\game\ai\ai.cpp(853) :"oldVelocity = 9.21 -3 0"

.\game\ai\ai.cpp(878) :"gravityNormal x = 0.000000 y = 0.000000 z = -1.000000"

 

Any hints so I understand this better ?

I haven't lost my mind. It's backed up on disk!

Oops bad sectors damn floppy's!

Link to comment
Share on other sites

I hope that Isht or SZ looks at this thread. You really shouldn't post in this thread anymore, apart from idle talk maybe, because it might not be read. :) If you want to have a personal thread, you can open a journaling thread in the programmer forum. This is what we also did, to keep our ideas somewhere or record progress and such things.

Gerhard

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recent Status Updates

    • taffernicus

      i am so euphoric to see new FMs keep coming out and I am keen to try it out in my leisure time, then suddenly my PC is spouting a couple of S.M.A.R.T errors...
      tbf i cannot afford myself to miss my network emulator image file&progress, important ebooks, hyper-v checkpoint & hyper-v export and the precious thief & TDM gamesaves. Don't fall yourself into & lay your hands on crappy SSD
       
      · 2 replies
    • OrbWeaver

      Does anyone actually use the Normalise button in the Surface inspector? Even after looking at the code I'm not quite sure what it's for.
      · 7 replies
    • Ansome

      Turns out my 15th anniversary mission idea has already been done once or twice before! I've been beaten to the punch once again, but I suppose that's to be expected when there's over 170 FMs out there, eh? I'm not complaining though, I love learning new tricks and taking inspiration from past FMs. Best of luck on your own fan missions!
      · 4 replies
    • The Black Arrow

      I wanna play Doom 3, but fhDoom has much better features than dhewm3, yet fhDoom is old, outdated and probably not supported. Damn!
      Makes me think that TDM engine for Doom 3 itself would actually be perfect.
      · 6 replies
    • Petike the Taffer

      Maybe a bit of advice ? In the FM series I'm preparing, the two main characters have the given names Toby and Agnes (it's the protagonist and deuteragonist, respectively), I've been toying with the idea of giving them family names as well, since many of the FM series have named protagonists who have surnames. Toby's from a family who were usually farriers, though he eventually wound up working as a cobbler (this serves as a daylight "front" for his night time thieving). Would it make sense if the man's popularly accepted family name was Farrier ? It's an existing, though less common English surname, and it directly refers to the profession practiced by his relatives. Your suggestions ?
      · 9 replies
×
×
  • Create New...