logotype

What is BoxedApp SDK?

BoxedApp SDK is a developer library that provides a set of functions for emulating a file system and a system registry for an application. Using these functions, you can create virtual files, fake registry entries, keys and values.

32-bit and x64 are supported.

Samples for C++, Delphi, VB6, C#, VB.Net are available

BoxedApp SDK is available in the following forms:

  • DLL - for all environments: VC++, VB6, C#, VB.Net, Delphi / Builder C++ and so on;
  • Static library (full version only) - for all VC++ versions;
  • OBJ file (for static linking) - for all Delphi / Builder C++ versions;

Features

Use cases

Why and when is it useful?

  • When an application must run properly even if it doesn't have the right to write to the system registry and to the file system
  • When an application uses DLL and files, which are to be kept secure, and because of that you can't save them to disk
  • When an application needs ActiveX but doesn't have an installer because it must run instantly, without the installation (for example, when it's a portable application that runs from a flash card)

Just a quick example: suppose, your application uses a Flash ActiveX player to display a Flash movie or video. The end users would need a Flash player ActiveX to allow your application work properly. Also, keep in mind that Flash player is not capable of loading files directly from memory. That exposes two major problems: first, you would have to install a Flash player ActiveX, and second, you would have to have the movie in a file. BoxedApp SDK solves these problems: you simply create a virtual file that contains the flash movie, another virtual file that contains the Flash player ActiveX DLL, and virtual registry entries that point to that virtual file. That's it. Now the application "thinks" that that the Flash player ActiveX is actually installed, so the Flash player works just as if the movie file was actually there.

In other words, you can now embed all DLL and content files, all ActiveX and OCX components, which your application uses, into a single EXE file. BoxedApp SDK doesn't unpack these files to disk; it doesn't use temporary files either.

Would like to see BoxedApp SDK in action? Download the demo right now! It includes many examples:

  • The basic example that explains how to create virtual files and registry keys
  • Embedding Flash player and Flash movies
and more!

Features

Use cases

Creating Virtual Files

[ Download sample code ]

Here's an example of how to create a virtual file:

[ Download sample code ]

[ C++ ]
HANDLE hVirtualFile = 
	BoxedAppSDK_CreateVirtualFile(
			_T("C:\\1.swf"), 
			GENERIC_READ, 
			FILE_SHARE_READ, 
			NULL, 
			CREATE_NEW, 
			0, 
			NULL);

HMODULE hModule = GetModuleHandle(NULL);
HRSRC hResInfo = FindResource(hModule, _T("BIN1"), _T("BIN"));
HGLOBAL hResData = LoadResource(hModule, hResInfo);
LPVOID lpData = LockResource(hResData);
DWORD dwSize = SizeofResource(hModule, hResInfo);

DWORD dwTemp;
WriteFile(hVirtualFile, lpData, dwSize, &dwTemp, NULL);

CloseHandle(hVirtualFile);

[ Download sample code ]

Back to top | Ask a question

Creating Virtual Registry Keys

[ Download sample code ]

Here's an example of how to create a virtual registry entry:

[ Download sample code ]

[ C++ ]
// Create hKey_Classes to work well even under registry reflection
HKEY hKey_Classes;
RegOpenKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes"), &hKey_Classes);

HKEY hVirtualKey;
DWORD dwDisposition;

LONG lResult = 
	BoxedAppSDK_CreateVirtualRegKey(
		hKey_Classes, 
		_T("Typelib\\{D27CDB6B-AE6D-11CF-96B8-444553540000}"), 
		0, 
		NULL, 
		REG_OPTION_NON_VOLATILE, 
		KEY_ALL_ACCESS, 
		NULL, 
		&hVirtualKey, 
		&dwDisposition
	);

	HKEY hVirtualKey__10;

lResult = 
	BoxedAppSDK_CreateVirtualRegKey(
		hKey_Classes, 
		_T("Typelib\\{D27CDB6B-AE6D-11CF-96B8-444553540000}\\1.0"), 
		0, 
		NULL, 
		REG_OPTION_NON_VOLATILE, 
		KEY_ALL_ACCESS, 
		NULL, 
		&hVirtualKey__10, 
		&dwDisposition
	);

TCHAR buf[1024] = _T("Shockwave Flash");
RegSetValueEx(hVirtualKey__10, _T(""), 0, REG_SZ, (CONST BYTE*)buf, (lstrlen(buf) + 1) * sizeof(TCHAR));

[ Download sample code ]

Back to top | Ask a question

API for intercepting functions

[ Download sample code ]

To create a virtual file system / registry, BoxedApp SDK (this, by the way, is exactly what applications created with BoxedApp Packer use) uses the interception of system functions technique. A number of original ideas have allowed us to create an interception system compatible with any environment, and now the part of SDK that is in charge of the interception has become accessible to developers - SDK users.

Here's an example of how to disable creating and opening the file named "1.txt":

[ Download sample code ]

[ C++ ]
typedef HANDLE (WINAPI *P_CreateFileW)(
	LPCWSTR lpFileName,
	DWORD dwDesiredAccess,
	DWORD dwShareMode,
	LPSECURITY_ATTRIBUTES lpSecurityAttributes,
	DWORD dwCreationDisposition,
	DWORD dwFlagsAndAttributes,
	HANDLE hTemplateFile);
P_CreateFileW g_pCreateFileW;

HANDLE WINAPI My_CreateFileW(
	LPCWSTR lpFileName,
	DWORD dwDesiredAccess,
	DWORD dwShareMode,
	LPSECURITY_ATTRIBUTES lpSecurityAttributes,
	DWORD dwCreationDisposition,
	DWORD dwFlagsAndAttributes,
	HANDLE hTemplateFile)
{
	if (0 == lstrcmpiW(lpFileName, L"1.txt"))
	{
		SetLastError(ERROR_FILE_EXISTS);
		return INVALID_HANDLE_VALUE;
	}
	else
		return g_pCreateFileW(
				lpFileName,
				dwDesiredAccess,
				dwShareMode,
				lpSecurityAttributes,
				dwCreationDisposition,
				dwFlagsAndAttributes,
				hTemplateFile);
}
...
BoxedAppSDK_Init();

PVOID pCreateFileW = GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "CreateFileW");

HANDLE hHook__CreateFileW = BoxedAppSDK_HookFunction(pCreateFileW, &My_CreateFileW, TRUE);

g_pCreateFileW = (P_CreateFileW)BoxedAppSDK_GetOriginalFunction(hHook__CreateFileW);

FILE* f = fopen("1.txt", "r");

// f is NULL
...

BoxedAppSDK_UnhookFunction(hHook__CreateFileW);

[ Download sample code ]

Back to top | Ask a question

Delphi version of the same idea:

[ Delphi ]
type
TCreateFileW = 
   function(lpFileName: PWideChar;
            dwDesiredAccess, dwShareMode: Integer;
            lpSecurityAttributes: PSecurityAttributes;
            dwCreationDisposition, dwFlagsAndAttributes: DWORD;
            hTemplateFile: THandle): THandle; stdcall;

var
   OriginalCreateFileW: TCreateFileW;

function My_CreateFileW(
         lpFileName: PWideChar;
         dwDesiredAccess, dwShareMode: Integer;
         lpSecurityAttributes: PSecurityAttributes;
         dwCreationDisposition, dwFlagsAndAttributes: DWORD;
         hTemplateFile: THandle): THandle; stdcall;
begin
   if 0 = lstrcmpiW(lpFileName, '1.txt') then
   begin
      Result := INVALID_HANDLE_VALUE;
      SetLastError(ERROR_ALREADY_EXISTS);
   end
   else
      Result := 
        OriginalCreateFileW(
           lpFileName, 
           dwDesiredAccess,
           dwShareMode, 
           lpSecurityAttributes, 
           dwCreationDisposition, 
           dwFlagsAndAttributes, 
           hTemplateFile);
end;

var
   pCreateFileW: Pointer;
   hHook__CreateFileW: THandle;

begin
  Application.Initialize;

  BoxedAppSDK_Init;

  pCreateFileW := GetProcAddress(GetModuleHandle('kernel32.dll'), 'CreateFileW');
  hHook__CreateFileW := BoxedAppSDK_HookFunction(pCreateFileW, @My_CreateFileW, TRUE);
  OriginalCreateFileW := BoxedAppSDK_GetOriginalFunction(hHook__CreateFileW);

  // This line produces an exception because we prevent creating / opening '1.txt'
  TFileStream.Create('1.txt', fmCreate or fmOpenRead);

  BoxedAppSDK_UnhookFunction(hHook__CreateFileW);
end.

[ Download sample code ]

Back to top | Ask a question

Embedding DLL

[ Download sample code ]

Here's an example of how to embed a DLL and use it:

[ Download sample code ]

[ C++ ]
HANDLE hFile__DLL1 = 
	BoxedAppSDK_CreateVirtualFile(
		_T("Z:\\DLL1.dll"), 
		GENERIC_WRITE, 
		FILE_SHARE_READ, 
		NULL, 
		CREATE_NEW, 
		0, 
		NULL
	);

DWORD dwTemp;
WriteFile(hFile__DLL1, pBuffer, dwSize, &dwTemp, NULL);

CloseHandle(hFile__DLL1);

// ...

HMODULE hModule = LoadLibrary(_T("Z:\\DLL1.dll"));

typedef void (WINAPI *P_Function)();
P_Function pFunction = (P_Function)GetProcAddress(hModule, "Function");

pFunction();

FreeLibrary(hModule);

[ Download sample code ]

Back to top | Ask a question

Embedding ActiveX / OCX

[ Download sample code ]

Here's an example of how to embed an ActiveX into application (of course, it works not only with Flash ActiveX):

[ Download sample code ]

[ C++ ]
LPVOID pBuffer;
DWORD dwSize;
LoadResourceHelper(MAKEINTRESOURCE(IDR_BIN_FLASH_OCX), _T("BIN"), pBuffer, dwSize);

HANDLE hVirtualFile1 = 
	BoxedAppSDK_CreateVirtualFile(
		_T("C:\\Flash9e.ocx"), 
		GENERIC_READ, 
		FILE_SHARE_READ, 
		NULL, 
		CREATE_NEW, 
		0, 
		NULL);

DWORD dwTemp;
WriteFile(hVirtualFile1, pBuffer, dwSize, &dwTemp, NULL);

CloseHandle(hVirtualFile1);

BoxedAppSDK_RegisterCOMLibraryInVirtualRegistry(_T("C:\\Flash9e.ocx"));

[ Download sample code ]

Back to top | Ask a question

Launching a virtual file-based process

[ Download sample code ]

Having created a virtual file with an embedded exe, you can launch a process upon that file:

[ C++ ]
BoxedAppSDK_Init();

HMODULE hModule = GetModuleHandle(NULL);
HRSRC hResInfo = FindResource(hModule, _T("BIN1"), _T("BIN"));
HGLOBAL hResData = LoadResource(hModule, hResInfo);
LPVOID lpData = LockResource(hResData);
DWORD dwSize = SizeofResource(hModule, hResInfo);

HANDLE hFile = 
   BoxedAppSDK_CreateVirtualFile(
      _T("app1.exe"), 
      GENERIC_WRITE, 
      FILE_SHARE_READ, 
      NULL, 
      CREATE_NEW, 
      0, 
      NULL);

DWORD temp;
WriteFile(hFile, lpData, dwSize, &temp, NULL);

CloseHandle(hFile);

ShellExecute(NULL, NULL, _T("app1.exe"), NULL, NULL, SW_SHOW);

[ Download sample code ]

Back to top | Ask a question

Using virtual file system by several processes simultaneously

[ Download sample code ]

Several processes can access the shared virtual file system. To connect a third-party process, use the BoxedAppSDK_AttachToProcess function. It embeds BoxedApp SDK in the specified process, which will then get the access to the virtual file system. Thus, any number of processes can be connected.

Besides that, you can "tell" BoxedApp SDK whether or not it should embed itself to each new process created by the application:

[ C++ ]
// yes, embed in child processes
BoxedAppSDK_EnableOption(
   DEF_BOXEDAPPSDK_OPTION__EMBED_BOXEDAPP_IN_CHILD_PROCESSES, 
   TRUE);
...
// no, do not embed in child processes
BoxedAppSDK_EnableOption(
   DEF_BOXEDAPPSDK_OPTION__EMBED_BOXEDAPP_IN_CHILD_PROCESSES, 
   FALSE);

[ Download sample code ]

Back to top | Ask a question

  Copyright © 2004 – 2009 Softanics. All rights reserved.
BoxedApp is a trademark of Softanics