Click here to Skip to main content
15,886,611 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCrystal Reports SDK??????? Pin
javad_20057-Aug-06 7:56
javad_20057-Aug-06 7:56 
QuestionDialog Controls Palette Pin
Reagan Conservative7-Aug-06 6:50
Reagan Conservative7-Aug-06 6:50 
AnswerRe: Dialog Controls Palette Pin
David Crow7-Aug-06 8:40
David Crow7-Aug-06 8:40 
AnswerRe: Dialog Controls Palette Pin
anu_887-Aug-06 18:32
anu_887-Aug-06 18:32 
Questionsetup via CD/web Pin
Tara147-Aug-06 6:45
Tara147-Aug-06 6:45 
AnswerRe: setup via CD/web Pin
Varchas R S7-Aug-06 10:11
Varchas R S7-Aug-06 10:11 
GeneralRe: setup via CD/web Pin
Tara147-Aug-06 20:48
Tara147-Aug-06 20:48 
QuestionHow do i get the full path from a into a exe loaded/injected dll(module)? Pin
kefir0077-Aug-06 6:44
kefir0077-Aug-06 6:44 
I have created a DLL (Hook.dll) in unicode using .net 2003. The builder use vc++. I am loading the dll dynamically with an hook into a target process (Main.exe) with an dll injector.

BOOL APIENTRY DllMain (HMODULE hDll, DWORD reason, PVOID lpReserved)<br />
{<br />
	if(Reason == DLL_PROCESS_ATTACH)<br />
	{<br />
		DisableThreadLibraryCalls(hDll);


I have a function within the DLL(Hook.dll) that tries to get the DLLs(Hook.dll) file name and path (fullpath with filename of Hook.dll).

this is the original code, this code gets and reads the crc32 checksum of the Main.exe:
pEXEFile = fopen(pszEXEFileName, "rb");

now i have changed it to and can fopen and read the dll, when i use::
pDLLFile = fopen("C:\\Documents and Settings\\Shawn\\Desktop\\Hook.dll", "rb");
this code above works, it will open my dll and read it's crc32 checksum, when i place and load the dll from my desktop.

another code that works:
pDLLFile = fopen("\\Hook.dll", "rb");
this last code above works, when i move the Hook.dll into the same folder where the Main.exe is.

I thought that because I used LoadLibrary to load the DLL that it would be
in its own application space. So I figured I could just use the DLLs
Application component to extract the file name using GetModuleFileName

However, I was supprised to find that the returned name was the main
application not the DLL.

Is there another way to get the DLLs files name when dynamically loading it or is their a better way to use GetModuleFileName?

The problem is I do not know what directory the DLL was in when i inject the dll into the main program and I need to figure this out at run time.

what im trying to do is, get the fullpath to the injected dll at runtime, fopen the dll then to read it in binary mode and get a crc32 hash from the dll, check the retrieved crc32 checksum and validate the dll, if the dll was altered, exit the Main.exe.

i got some example code and need now some help, how could i bring the code to give me the fullpath of my loaded module "Hook.dll" from the Main.exe

example codes:
extern HINSTANCE _hInstance;<br />
<br />
const char *OurFileName()<br />
{<br />
static char our_filename[MAX_PATH + 1];<br />
<br />
if (!*our_filename)<br />
{<br />
GetModuleFileName(_hInstance, our_filename, sizeof(our_filename);<br />
}<br />
<br />
return our_filename;<br />
}



You can do something like this to get path of a loaded module:  <br />
  <br />
HMODULE hmod = NULL;  <br />
  <br />
LPCTSTR lpszModuleName = TEXT("MyLibrary.dll");  <br />
  <br />
TCHAR szPath[MAX_PATH + 1] = {0};  <br />
  <br />
hmod = GetModuleHandle(lpszModuleName);  <br />
  <br />
if (!hmod)  <br />
  <br />
// handle error  <br />
  <br />
GetModuleFileName(hmod, szPath, MAX_PATH);  <br />
  <br />
FreeModule(hmod);  <br />
  <br />
This copies path to the module into szPath.


Thanks for every help
Shawn
Questionflushing extra key presses Pin
Biboc7-Aug-06 5:53
Biboc7-Aug-06 5:53 
Questionconverting hex to binary string Pin
flippydeflippydebop7-Aug-06 5:21
flippydeflippydebop7-Aug-06 5:21 
AnswerRe: converting hex to binary string [modified] Pin
flippydeflippydebop7-Aug-06 5:25
flippydeflippydebop7-Aug-06 5:25 
QuestionNT Service - working directory Pin
yoti117-Aug-06 5:20
yoti117-Aug-06 5:20 
AnswerRe: NT Service - working directory Pin
Michael Dunn7-Aug-06 7:26
sitebuilderMichael Dunn7-Aug-06 7:26 
AnswerRe: NT Service - working directory Pin
David Crow7-Aug-06 8:15
David Crow7-Aug-06 8:15 
AnswerRe: NT Service - working directory Pin
Vipin Aravind7-Aug-06 8:59
Vipin Aravind7-Aug-06 8:59 
AnswerRe: NT Service - working directory Pin
Hamid_RT8-Aug-06 6:37
Hamid_RT8-Aug-06 6:37 
QuestionNo browse info in VS2005 Pin
Jim A. Johnson7-Aug-06 5:14
Jim A. Johnson7-Aug-06 5:14 
QuestionCDialogBar with ScrollBar [modified] Pin
hsdjusa7-Aug-06 5:00
hsdjusa7-Aug-06 5:00 
AnswerRe: CDialogBar with ScrollBar Pin
Michael Dunn7-Aug-06 7:28
sitebuilderMichael Dunn7-Aug-06 7:28 
QuestionA trouble question about the dialog Pin
xuwenq887-Aug-06 4:50
xuwenq887-Aug-06 4:50 
AnswerRe: A trouble question about the dialog Pin
Cedric Moonen7-Aug-06 5:05
Cedric Moonen7-Aug-06 5:05 
GeneralRe: A trouble question about the dialog Pin
xuwenq887-Aug-06 17:41
xuwenq887-Aug-06 17:41 
GeneralRe: A trouble question about the dialog Pin
Cedric Moonen7-Aug-06 20:19
Cedric Moonen7-Aug-06 20:19 
GeneralRe: A trouble question about the dialog Pin
xuwenq8812-Aug-06 5:27
xuwenq8812-Aug-06 5:27 
Questionpacket Filtering with Pfbindinterfacetoindex Pin
_tasleem7-Aug-06 4:16
_tasleem7-Aug-06 4:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.