Skip to content

Instantly share code, notes, and snippets.

@moohax
Created August 9, 2018 19:12
Show Gist options
  • Save moohax/182c1140d58985d8d5cb7e6980a999c8 to your computer and use it in GitHub Desktop.
Save moohax/182c1140d58985d8d5cb7e6980a999c8 to your computer and use it in GitHub Desktop.
// enclave.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "Windows.h"
#include "Winbase.h"
#include "enclaveapi.h"
#include <iostream>
#pragma comment(lib, "Kernel32.lib")
int main()
{
LPVOID pEnclave;
LPVOID pMem;
SIZE_T bSize = 1024;
BOOL iEnclave;
ENCLAVE_CREATE_INFO_VBS lpEnclaveInformation = {0};
DWORD err;
DWORD pid = 20416; //GetCurrentProcessId();
HANDLE rProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
lpEnclaveInformation.Flags = ENCLAVE_VBS_FLAG_DEBUG;
lpEnclaveInformation.OwnerID;
std::cout << "[+] Creating the enclave \n";
pEnclave = CreateEnclave(rProc, NULL, bSize, 0, ENCLAVE_TYPE_VBS, &lpEnclaveInformation, sizeof(ENCLAVE_CREATE_INFO_VBS), NULL);
if (!pEnclave) {
std::cout << GetLastError();
return 0;
}
std::cout << "[+] Allocating memory \n";
pMem = VirtualAllocEx(rProc, pEnclave, bSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (!pMem) {
std::cout << GetLastError();
return 0;
}
std::cout << "[+] Initializing the enclave \n";
iEnclave = InitializeEnclave(rProc, pEnclave, &lpEnclaveInformation, sizeof(ENCLAVE_INIT_INFO_VBS), &err);
if (!iEnclave) {
std::cout << GetLastError();
return 0;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment