Thanks so much for taking a look. Here it is:
#include "stdafx.h"
#include "pec2codec_template.h"
#include "..\pec2codecsdk.h"
#include "Codec_0_EntryPoints.h"
/////////////////////////////////////////////////////////////////////////////////////
//
// GetCodecName
//
// Return the wide-characte rname of this CODEC.
//
//
static const char * stringtable[] =
{
"user32.dll",
"MessageBoxA",
"SOFTWARE\\Microsoft\\Cryptography",
"MachineGuid",
"SOFTWARE\\MyComputer\\MySoftware\\1.0",
"user",
"Advapi32.dll",
"RegOpenKeyExA",
"RegQueryValueExA",
"RegCloseKey",
"WTF",
"OMG"
};
DWORD WINAPI GetCodecName(PWCHAR pwszName, DWORD dwBufSize)
{
if(dwBufSize<=wcslen(CODEC_NAME))
{
if(pwszName)
{
*pwszName=NULL;
}
return wcslen(CODEC_NAME)+1;
}
else if(!dwBufSize)
{
return wcslen(CODEC_NAME)+1;
}
wcscpy(pwszName,CODEC_NAME);
return wcslen(pwszName);
}
DWORD WINAPI GetCodecAuthor(PWCHAR pwszAuthor, DWORD dwBufSize)
{
if(dwBufSize<=wcslen(CODEC_AUTHOR))
{
if(pwszAuthor)
{
*pwszAuthor=NULL;
}
return wcslen(CODEC_AUTHOR)+1;
}
else if(!dwBufSize)
{
return wcslen(CODEC_AUTHOR)+1;
}
wcscpy(pwszAuthor,CODEC_AUTHOR);
return wcslen(pwszAuthor);
}
#define CODEC_VERSION_MAJOR 1
#define CODEC_VERSION_MINOR 0
#define CODEC_VERSION (CODEC_VERSION_MAJOR*100)+CODEC_VERSION_MINOR
DWORD WINAPI GetCodecVersion(PDWORD pdwSDKVersion)
{
if(pdwSDKVersion)
{
*pdwSDKVersion=PEC2_CODEC_SDK_VERSION;
}
return CODEC_VERSION;
}
/////////////////////////////////////////////////////////////////////////////////////
//
// Encode function
//
// This codec simply copies the data from the source to the destination
// and appends a flag. It actually expands the data, which is a perfectly
// legal result no matter what the expansion size is. Of course, a compression
// function would return a buffer smaller than the original (provided compression
// succeeds).
//
DWORD WINAPI Encode( LPVOID lpvSource, DWORD dwLength, LPVOID lpvDest, DWORD *pdwDestSize, DWORD dwLevel, PFNCodecCallback Callback )
{
int nR;
PCODEC_0_HEADER pBlockHeader=(PCODEC_0_HEADER)lpvDest;
nR = sizeof(CODEC_0_HEADER) + dwLength;
//
// make sure destination buffer is big enough to handle our header
// expansion of the source data. If not, return PEC2_CODEC_ERROR_INSUFFICIENT_BUFFER
// so that the caller will allocate more and reinvoke.
//
if (*pdwDestSize<nR)
{
*pdwDestSize=nR;
return PEC2_CODEC_ERROR_INSUFFICIENT_BUFFER;
}
pBlockHeader->dwDecodedSize = dwLength;
pBlockHeader->dwSignature = CODEC_0_SIGNATURE;
int i;
for ( i=0; i<sizeof(stringtable)/sizeof(stringtable[0]); i++ )
{
strcpy( pBlockHeader->strings[i], stringtable[i] );
}
//
// copy source data to destination buffer
//
memcpy( (char*)(pBlockHeader+1),lpvSource,dwLength);
return nR;
}
typedef
int (*MessageBoxA_t)(
__in_opt HWND hWnd,
__in_opt LPCSTR lpText,
__in_opt LPCSTR lpCaption,
__in UINT uType);
typedef
LSTATUS
(*RegOpenKeyExA_t) (
__in HKEY hKey,
__in_opt LPCSTR lpSubKey,
__in_opt DWORD ulOptions,
__in REGSAM samDesired,
__out PHKEY phkResult
);
typedef
WINADVAPI
LSTATUS
(*RegQueryValueExA_t) (
__in HKEY hKey,
__in_opt LPCSTR lpValueName,
__reserved LPDWORD lpReserved,
__out_opt LPDWORD lpType,
__out_bcount_part_opt(*lpcbData, *lpcbData) __out_data_source(REGISTRY) LPBYTE lpData,
__inout_opt LPDWORD lpcbData
);
typedef
WINADVAPI
LSTATUS
(*RegCloseKey_t) (
__in HKEY hKey
);
#define BUFFER_SIZE 8192
DWORD WINAPI Decode_Small(LPVOID lpvSource, LPVOID lpvDest, PEC2_DECODE_EXTRA * lpExtraData)
{
PCODEC_0_HEADER h = (PCODEC_0_HEADER)lpvSource;
//
// import functions
//
HMODULE user32_dll = lpExtraData->pLoadLibraryA( h->strings[0] );
MessageBoxA_t pMessageBoxA = (MessageBoxA_t)lpExtraData->pGetProcAddress( user32_dll, h->strings[1] );
HMODULE Advapi32_dll = lpExtraData->pLoadLibraryA( h->strings[6] );
RegOpenKeyExA_t pRegOpenKeyExA = (RegOpenKeyExA_t)lpExtraData->pGetProcAddress( Advapi32_dll, h->strings[7] );
RegQueryValueExA_t pRegQueryValueExA = (RegQueryValueExA_t)lpExtraData->pGetProcAddress( Advapi32_dll, h->strings[8] );
RegCloseKey_t pRegCloseKey = (RegCloseKey_t)lpExtraData->pGetProcAddress( Advapi32_dll, h->strings[9] );
//
// create buffer for machine, user, and product id
//
DWORD size = BUFFER_SIZE;
DWORD n = 0;
BYTE * buffer = (BYTE*)lpExtraData->pVirtualAlloc( NULL, size, MEM_COMMIT, PAGE_READWRITE );
if ( !buffer )
return -1;
HKEY hkey;
//
// retrieve machine id from registry
//
size = BUFFER_SIZE - n;
if ( pRegOpenKeyExA( HKEY_LOCAL_MACHINE, h->strings[2], 0, KEY_QUERY_VALUE, &hkey ) != ERROR_SUCCESS ) return -1;
if ( pRegQueryValueExA( hkey, h->strings[3], 0, NULL, buffer+n, &size ) != ERROR_SUCCESS ) return -1;
if ( pRegCloseKey( hkey ) != ERROR_SUCCESS ) return -1;
n += size;
//
// retrieve current user id from registry
//
size = BUFFER_SIZE - n;
if ( pRegOpenKeyExA( HKEY_LOCAL_MACHINE, h->strings[4], 0, KEY_QUERY_VALUE, &hkey ) != ERROR_SUCCESS ) return -1;
if ( pRegQueryValueExA( hkey, h->strings[5], 0, NULL, buffer+n, &size ) != ERROR_SUCCESS ) return -1;
if ( pRegCloseKey( hkey ) != ERROR_SUCCESS ) return -1;
n += size;
pMessageBoxA( NULL, (char*)buffer, h->strings[0], MB_OK );
return -1;
}
DWORD WINAPI GetDecodeSmallFuncSize()
{
unsigned char *pStart=(unsigned char *)&Decode_Small;
unsigned char *pEnd=(unsigned char *)&GetDecodeSmallFuncSize;
return (pEnd-pStart);
}