apex: mount up apex files into /sbin for library access

This patch uses the loop device to mount files under
/sbin/ from /system/apex in order for the device to
use libraries or other files store inside these files.

Each apex file is mounted over a loop device into a
directory correpsonding to the apex filename under
/sbin/.

Once apex mounting is completed, TWRP will set a
property twrp.apex.loaded to true so that init
can use them as a LD_LIBARY_PATH source.
Change-Id: I69f14a969123ac9cf1afc85b6cf76836cb092fb2

Change-Id: Ica6a7d8e479bcaec8bec4483b5e8d2b45ee105fb
diff --git a/twrpApex.hpp b/twrpApex.hpp
new file mode 100755
index 0000000..fb91675
--- /dev/null
+++ b/twrpApex.hpp
@@ -0,0 +1,35 @@
+
+#ifndef TWRPAPEX_HPP
+#define TWRPAPEX_HPP
+
+#include <string>
+#include <vector>
+#include <filesystem>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <linux/loop.h>
+#include <sys/mount.h>
+#include <sys/sysmacros.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <ziparchive/zip_archive.h>
+#include "twcommon.h"
+
+
+#define APEX_DIR "/system_root/system/apex"
+#define APEX_PAYLOAD "apex_payload.img"
+#define LOOP_BLOCK_DEVICE_DIR "/dev/block/"
+
+class twrpApex {
+public:
+	bool loadApexImages();
+
+private:
+	std::string unzipImage(std::string file);
+	bool createLoopBackDevices(size_t count);
+	bool loadApexImage(std::string fileToMount, size_t loop_device_number);
+};
+#endif