• R/O
  • SSH
  • HTTPS

eirsamples: Commit


Commit MetaInfo

Revision17 (tree)
Time2019-02-14 04:56:17
Authorquiret

Log Message

- finished the "peresembed_export_sample" project

Change Summary

Incremental Difference

--- peresembed_export_sample/src/main.cpp (revision 16)
+++ peresembed_export_sample/src/main.cpp (revision 17)
@@ -1,8 +1,66 @@
11 #include <CFileSystem.h>
22
3+// We only work on Win32 for now.
4+#ifndef _WIN32
5+#error Platform not supported.
6+#endif //_WIN32
7+
8+// This is an example for the "peresembed" tool in the "-zipfldr" embedding option.
9+// We provide an export called "_export_to_resolve" which points to the special structure holding a pointer and a size.
10+// That structure must be binary-initialized to zeroes.
11+struct embedded_export
12+{
13+ void *dataloc;
14+ size_t datasize;
15+};
16+
17+// It is important to use "volatile" because otherwise the compiler would REALLY assume that nobody modified this variable.
18+extern "C" __declspec(dllexport) volatile const embedded_export _export_to_resolve = { 0 };
19+
320 int main( int argc, char *argv[] )
421 {
5- // TODO.
22+ if ( _export_to_resolve.dataloc == nullptr )
23+ {
24+ printf( "no export embedded\n" );
25+ return -1;
26+ }
627
28+ printf( "found embedded data (ptr: %p, size: %u)\n", _export_to_resolve.dataloc, _export_to_resolve.datasize );
29+
30+ // We treat the embedded export as ZIP archive.
31+ FileSystem::fileSysInstance fileSys;
32+
33+ FileSystem::filePtr userBufFile = fileSys->CreateUserBufferFile( _export_to_resolve.dataloc, _export_to_resolve.datasize );
34+
35+ FileSystem::archiveTrans archiveRoot = fileSys->OpenZIPArchive( *userBufFile );
36+
37+ if ( archiveRoot.is_good() == false )
38+ {
39+ printf( "invalid embedded ZIP archive\n" );
40+ return -2;
41+ }
42+
43+ // Prints stats.
44+ size_t contentSize = archiveRoot->Size( "content.txt" );
45+
46+ printf( "content.txt size: %zu\n", contentSize );
47+
48+ eir::Vector <char, CRTHeapAllocator> fileContent;
49+
50+ bool gotContent = FileSystem::TranslatorReadToBuffer( archiveRoot, "content.txt", fileContent );
51+
52+ if ( !gotContent )
53+ {
54+ printf( "could not read 'content.txt'\n" );
55+ return -3;
56+ }
57+
58+ printf( "found input file (content.txt):\n" );
59+
60+ // Need to add a zero-terminator.
61+ fileContent.AddToBack( '\0' );
62+
63+ printf( "%s\n", fileContent.GetData() );
64+
765 return 0;
866 }
\ No newline at end of file
Show on old repository browser