Question My functions aren't working

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

MoneM

Newbie
Aug 11, 2017
3
264
0
I started studying assembly since I was interested in starting to make a polymorphic engine. I started writing some functions I'd be needing but they don't seem to do what they're supposed to. They both are supposed to do the same thing just that the second one has an extra loop. My guess is that I made some weird casting there that messed things up.

C++:
#include <iostream>
#include <windows.h>
#include <Tlhelp32.h>

#include <detours.h>
#pragma comment(lib, "detours.lib")

#include <ntdll.h>
#pragma comment(lib, "ntdll.lib")

#pragma region defines

#define word WORD
#define dword DWORD
#define qword unsigned __int64
#define llong long long
#define int8 __int8
#define int16 __int16
#define int32 __int32
#define int64 __int64

#define safedw_cast *reinterpret_cast<dword*>
#define safevoid_cast reinterpret_cast<void*>

#define reca(_type) reinterpret_cast<_type>
#define stca(_type) static_cast<_type>
#define saca(_type) safe_cast<_type>
#define dyca(_type) dynamic_cast<_type>

#pragma endregion

#pragma region patches

bool _patchloop(void *_addr, dword _end, byte _bytes[], int32 _siz)
{
	byte *towrite = new byte[_siz];
	memset(towrite, reca(int)(_bytes), _siz);

	dword tempaddr = safedw_cast(_addr);

	for (tempaddr; tempaddr < _end; ++tempaddr)
	{
		dword old{ 0 };
		if (!VirtualProtect(safevoid_cast(_addr), _siz, PAGE_EXECUTE_READWRITE, &old))
			return false;

		memcpy(safevoid_cast(_addr), towrite, _siz);

		if (!VirtualProtect(safevoid_cast(_addr), _siz, old, &old))
			return false;
	}

	delete[] _bytes;
	delete[] towrite;
	return true;
}

bool _patchadd(void *_addr, byte _bytes[], int32 _siz)
{
	byte *towrite = new byte[_siz];
	memset(towrite, reca(int)(_bytes), _siz);

	dword old{ 0 };
	if (!VirtualProtect(safevoid_cast(_addr), _siz, PAGE_EXECUTE_READWRITE, &old))
		return false;

	memcpy(safevoid_cast(_addr), towrite, _siz);

	if (!VirtualProtect(safevoid_cast(_addr), _siz, old, &old))
		return false;
	
	delete[] _bytes;
	delete[] towrite;
	return true;
}

#pragma endregion
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods