#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <string>
#include <Windows.h>
#include <tlhelp32.h>
#include <vector>
#include <sstream>
#include <iomanip>
#include "cepluginsdk.h"
 
 
using namespace std;
ExportedFunctions Exported;
BOOL APIENTRY DllMain(HANDLE hModule, DWORD_PTR ul_reason_for_call, LPVOID lpReserved)
{
	AllocConsole();
	freopen("CONOUT$", "w", stdout);
	printf("works\n");
	return TRUE;
}
 
void PatchRET(LPVOID target)
{
	if (!target)
	{
		Exported.ShowMessage("Something broken Bypass Might be not work.");
		return;
	}
	
 
	DWORD oldp;
	VirtualProtect(target, 0x1000, PAGE_EXECUTE_READWRITE, &oldp);
	*(BYTE*)(target) = 0xC3;
	VirtualProtect(target, 0x1000, oldp, NULL);
}
void DisableUnusedAPI()
{
	auto kernelbase = GetModuleHandleA("KERNELBASE");
	auto ntdll = GetModuleHandleA("ntdll");
 
	auto pOutputDebugStringA = GetProcAddress(kernelbase, "OutputDebugStringA");
	auto pOutputDebugStringW = GetProcAddress(kernelbase, "OutputDebugStringW");
	auto pDbgPrint = GetProcAddress(ntdll, "DbgPrint");
 
	PatchRET(pOutputDebugStringA);
	PatchRET(pOutputDebugStringW);
	PatchRET(pDbgPrint);
 
}
 
#pragma comment(linker, "/EXPORT:CEPlugin_GetVersion=?CEPlugin_GetVersion@@YAHPEAU_PluginVersion@@H@Z")
__declspec(dllexport) BOOL __stdcall CEPlugin_GetVersion(PPluginVersion pv, int sizeofpluginversion)
{
	pv->version = CESDK_VERSION;
	pv->pluginname = "PackerMan Bypass v1.0 by LeftSpace(SDK version 4: 6.0+)";
	return TRUE;
}
 
#pragma comment(linker, "/EXPORT:CEPlugin_InitializePlugin=?CEPlugin_InitializePlugin@@YAHPEAU_ExportedFunctions@@H@Z")
__declspec(dllexport) BOOL __stdcall CEPlugin_InitializePlugin(PExportedFunctions ef, int pluginid)
{
	BOOL bResult;
 
	int ContextPluginID;
 
	DISASSEMBLERCONTEXT_INIT init6;
 
 
	Exported = *ef;
	bResult = TRUE;
 
	DisableUnusedAPI();
	return bResult;
}
 
#pragma comment(linker, "/EXPORT:CEPlugin_DisablePlugin=?CEPlugin_DisablePlugin@@YAHXZ")
__declspec(dllexport) BOOL __stdcall CEPlugin_DisablePlugin()
{
	return TRUE;
}