Hi all,
here is my code to find the LoadlibraryA address from an exe, I want to write the return value to text file , but I cant figure out how to do that.Any help would be greatly appreciated.

#include <windows.h>
#include <tlhelp32.h>
#include <iostream>
#include <conio.h>
using namespace std;
char exe[MAX_PATH];


DWORD GetProcessIDFromName(LPSTR szProcName)
{
	PROCESSENTRY32 procEntry;
	HANDLE hSnapshot;
	BOOL bFound;

	if(!(hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0))) return 0;
	procEntry.dwSize = sizeof(PROCESSENTRY32);

	bFound = Process32First(hSnapshot, &procEntry);
	while(bFound) {
		if(!lstrcmp(procEntry.szExeFile, szProcName)) {
			CloseHandle(hSnapshot);
			return procEntry.th32ProcessID;
		}
		bFound = Process32Next(hSnapshot, &procEntry);
	}

	CloseHandle(hSnapshot);
	return 0;
}


int main()
{
	HANDLE hProc;	
	cout<<"EXE NAME := ";
	cin>>exe;
	DWORD dwPid = GetProcessIDFromName(exe);
	hProc = OpenProcess(PROCESS_ALL_ACCESS, false, dwPid);
	HANDLE address=GetProcAddress(GetModuleHandle("KERNEL32.DLL"), "LoadLibraryA");
	CloseHandle(address);
	cout<<address<<endl;	




	getch();
	return 0;
}

Why would you want to write an address to a text file? It isn't useful for anything after the program that gets the address is finished.

Why would you want to write an address to a text file? It isn't useful for anything after the program that gets the address is finished.

I just want to edit the entry point of that exe and create a load dll function there using the LoadLibraryA function address to auto load an extrenal dll whenever the exe executes.
I also know that the LoadLibraryA address never change for any application.
here is an example what is I am trying to achieve after getting the LoadLibraryA address.

1800217D > $ 68 62210018    PUSH aplication.18002162   ; /FileName = "lol.dll"
18002182   . FF15 9C000218  CALL DWORD PTR DS:[1802009C] ; \LoadLibraryA

Edited 6 Years Ago by kk33: n/a

>>I just want to edit the entry point of that exe
I'm not sure you can do that. The entry point is somewhere in the compiller's startup code that it attaches to the program during link time. We have no idea what that address is because the address is not resolved until the os loads the program into memory.

>>I also knew that the LoadLibraryA address never change for any application.

Whatever gave you that impression? The address returned by LoadLibrary() is the address within the calling process's address space which can change every time the process is loaded into memory. There is no guarentee that the address will remain constant from one run of the process to another.

Any attempts to hack that address could have serious consequences for the operating system and even possibly harm computer hardware.

Edited 6 Years Ago by Ancient Dragon: n/a

>>I also knew that the LoadLibraryA address never change for any application.

Whatever gave you that impression? The address returned by LoadLibrary() is the address within the calling process's address space which can change every time the process is loaded into memory. There is no guarentee that the address will remain constant from one run of the process to another.

Any attempts to hack that address could have serious consequences for the operating system and even possibly harm computer hardware.

Sorry I am not that expert lol, cant you just show me how do I write the return value into text file :P , thanks.

For watever good it will do you, it just this simple:

ofstream out("filename.txt");
out << address;
out.close();

Awesome thanks, works perfect , also thanks for clearing up my confusion about finding out the Load library address of an application. But at least now I know how to write txt in files :D.

This article has been dead for over six months. Start a new discussion instead.