#include<Windows.h>
#include<tchar.h>
#include<Shlwapi.h>
#include"Header.h"
#include"DebugPriv.h"

#pragma	comment(lib, "Shlwapi")

int wmain(int argc, wchar_t *argv[])
{
	EnableDebugAbility();

	DWORD	pid = _wtoi(argv[1]);
	//DWORD pid = 6240;
	LONGLONG	addr;
	CHAR buffer[100];
	SIZE_T bytesRead;

	// Glad this exists!
	// Convert Hex string to 64 int
	//https://msdn.microsoft.com/en-us/library/windows/desktop/bb773450(v=vs.85).aspx

	StrToInt64Ex(argv[2], STIF_SUPPORT_HEX, &addr);



	HANDLE	victimProcess;

	if (!(victimProcess = OpenProcess(PROCESS_VM_READ, false, pid)))
	{
		ErrorDetails(_T("OpenProcess()"), false);
	}
	else
	{
		// Ok got the handle, now let the games begin!
		// ReadProcessMemory()
		// https://msdn.microsoft.com/en-us/library/windows/desktop/ms684880(v=vs.85).aspx
		
		_tprintf(_T("Reading Address: 0x%I64x of PID= %d\n"), addr, pid);

		memset(buffer, 0x0, 100);

		if (!ReadProcessMemory(victimProcess, (LPCVOID)addr, (LPVOID)buffer,95, &bytesRead))
		{
			ErrorDetails(_T("ReadProcessMemory()"), false);
		}
		else
		{
			// its important to note we know the string we are reading is null terminated
			// checks will be required for unknown binaries
			_tprintf(_T("Success! Read:  %hs\n"), buffer);
		}

	}



	return 0;
}

