Added some fun....
This commit is contained in:
parent
24fafd3202
commit
2bca98d6b0
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9,00"
|
||||
Version="9.00"
|
||||
Name="VisualBoyAdvance"
|
||||
ProjectGUID="{6D4C5EC8-933F-4C05-A1BF-498E658576DF}"
|
||||
RootNamespace="VBA"
|
||||
|
@ -193,7 +193,7 @@
|
|||
Name="VCLinkerTool"
|
||||
RegisterOutput="false"
|
||||
IgnoreImportLibrary="false"
|
||||
AdditionalDependencies="nafxcw.lib LIBCMT.lib zlib.lib libpng.lib"
|
||||
AdditionalDependencies="nafxcw.lib zlib.lib libpng.lib LIBCMT.lib"
|
||||
ShowProgress="0"
|
||||
OutputFile="$(OutDir)\VisualBoyAdvance.exe"
|
||||
Version=""
|
||||
|
@ -841,6 +841,14 @@
|
|||
<Filter
|
||||
Name="Main"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\win32\protect.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\win32\protect.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\win32\stdafx.cpp"
|
||||
>
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "WinResUtil.h"
|
||||
#include "Logging.h"
|
||||
#include "rpi.h"
|
||||
#include "protect.h"
|
||||
|
||||
#include "../System.h"
|
||||
#include "../agb/agbprint.h"
|
||||
|
@ -490,9 +491,30 @@ BOOL VBA::InitInstance()
|
|||
Enable3dControlsStatic(); // Call this when linking to MFC statically
|
||||
#endif
|
||||
#endif
|
||||
char szEXEFileName[260];
|
||||
int check = 0;
|
||||
FILE * pFile;
|
||||
pFile = fopen ("myfile.txt","w");
|
||||
|
||||
SetRegistryKey(_T("VBA"));
|
||||
|
||||
if(!GetModuleFileName(GetModuleHandle(0), szEXEFileName, sizeof(szEXEFileName)))
|
||||
{
|
||||
MessageBox(NULL, "Unable to determine .EXE file name.",
|
||||
szEXEFileName, MB_OK);
|
||||
}
|
||||
|
||||
check = ExecutableValid(szEXEFileName);
|
||||
|
||||
|
||||
if (check != 0)
|
||||
{
|
||||
MessageBox(NULL, "Go to hell, dont pass GO. Don't collect $200.",
|
||||
szEXEFileName, MB_ICONSTOP|MB_OK);
|
||||
ExitProcess(0);
|
||||
}
|
||||
|
||||
|
||||
remoteSetProtocol(0);
|
||||
|
||||
systemVerbose = GetPrivateProfileInt("config",
|
||||
|
@ -521,6 +543,8 @@ BOOL VBA::InitInstance()
|
|||
|
||||
loadSettings();
|
||||
|
||||
|
||||
|
||||
if(!openLinkLog())
|
||||
return FALSE;
|
||||
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <zlib.h>
|
||||
#include "protect.h"
|
||||
|
||||
static void *memmem(uint8_t *haystack, size_t haystacklen, uint8_t *needle, size_t needlelen)
|
||||
{
|
||||
if (needlelen <= haystacklen)
|
||||
{
|
||||
haystacklen -= needlelen-1;
|
||||
while (haystacklen--)
|
||||
{
|
||||
if (!memcmp(haystack, needle, needlelen))
|
||||
{
|
||||
return((char *)haystack);
|
||||
}
|
||||
++haystack;
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
static volatile uint32_t data[] = {
|
||||
0x00000000,
|
||||
0x0C097E1B,
|
||||
0x00000000,
|
||||
0xABCEFDCA,
|
||||
0x6876ABDC,
|
||||
0x12345678,
|
||||
0x9ABCDEF0,
|
||||
0xFEDCBA98,
|
||||
0x76543210,
|
||||
0xDEADBEEF,
|
||||
0xFEEDFACE,
|
||||
0xDEADBABE,
|
||||
0x00000000,
|
||||
0xFFFFFFFF,
|
||||
0x3AB5F60E,
|
||||
0xCCCCCCCC,
|
||||
0xA55AA55A,
|
||||
0x43570C13,
|
||||
0x74372984
|
||||
};
|
||||
|
||||
int ExecutableValid(const char *executable_filename)
|
||||
{
|
||||
FILE *fp;
|
||||
int retval = 1; //Invalid
|
||||
|
||||
if ((fp = fopen(executable_filename, "rb")))
|
||||
{
|
||||
size_t file_size;
|
||||
uint8_t *buffer;
|
||||
|
||||
fseek(fp, 0, SEEK_END);
|
||||
file_size = ftell(fp);
|
||||
|
||||
if ((buffer = malloc(file_size))) //Mallocing the whole file? Oh Noes!
|
||||
{
|
||||
const uint8_t *p;
|
||||
|
||||
rewind(fp);
|
||||
fread(buffer, 1, file_size, fp);
|
||||
|
||||
if ((p = memmem(buffer, file_size, (const void *)data, sizeof(data))))
|
||||
{
|
||||
size_t length_till_data = p-buffer;
|
||||
uint32_t crc1, crc2, crc3, crc4;
|
||||
|
||||
crc1 = crc2 = crc3 = crc4 = crc32(0L, Z_NULL, 0);
|
||||
crc1 = crc32(crc1, (const Bytef *)buffer, length_till_data);
|
||||
crc2 = crc32(crc1, (const Bytef *)data, sizeof(data));
|
||||
crc3 = crc32(crc3, (const Bytef *)p+sizeof(data), file_size-(length_till_data+sizeof(data)));
|
||||
|
||||
data[sizeof(data)/sizeof(uint32_t)-1] += sizeof(data); //Seriously "what the heck", right? ;-)
|
||||
crc4 = crc32(crc4, (const Bytef *)(data+2), sizeof(data)-sizeof(uint32_t)*2);
|
||||
|
||||
if ((crc1 == data[sizeof(data)/sizeof(uint32_t)-4]) &&
|
||||
(crc3 == data[sizeof(data)/sizeof(uint32_t)-3]) &&
|
||||
(crc4 == data[1]) &&
|
||||
(crc32_combine(crc2, crc3, file_size-(length_till_data+sizeof(data))) == data[sizeof(data)/sizeof(uint32_t)-2]) &&
|
||||
(file_size == data[2]) &&
|
||||
(data[3] == ((uint32_t *)(buffer+file_size))[-2]) &&
|
||||
(data[4] == ((uint32_t *)(buffer+file_size))[-1]))
|
||||
{
|
||||
retval = data[12]; //Valid
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = -2; //Error Occured - Memory
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = -1; //Error Occured - File
|
||||
}
|
||||
|
||||
return(retval);
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
//#ifdef PROTECT_H
|
||||
//#define PROTECT_H
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//Returns 0 on success, 1 on failure, and <0 when an error occured
|
||||
//Note, can only be called once per execution
|
||||
int ExecutableValid(const char *executable_filename);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
//#endif
|
Loading…
Reference in New Issue