Change update size for PBA (#419)
[platform/core/dotnet/launcher.git] / NativeLauncher / tool / r2r_checker.cc
index c2847b0..bf8d2dc 100644 (file)
@@ -151,6 +151,7 @@ bool isR2RImage(std::string fileName)
        }
 
        if (fstat(fd, &sb) == -1) {
+               close(fd);
                return false;
        }
 
@@ -167,3 +168,40 @@ bool isR2RImage(std::string fileName)
        close(fd);
        return ret;
 }
+
+unsigned int getSizeOfImage(std::string fileName)
+{
+       int fd;
+       struct stat sb;
+       if ((fd = open(fileName.c_str(), O_RDONLY)) == -1) {
+               _SERR("File Not Found: %s", fileName.c_str());
+               return 0;
+       }
+
+       if (fstat(fd, &sb) == -1) {
+               close(fd);
+               return 0;
+       }
+
+       void* pAddr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+       if (pAddr == MAP_FAILED) {
+               _SERR("Fail to Map File: %s", fileName.c_str());
+               close(fd);
+               return 0;
+       }
+
+       IMAGE_NT_HEADERS* pNTHeaders = getNTHeaders(pAddr);
+       if (!pNTHeaders) {
+               _SERR("Invalid NT Header");
+               munmap(pAddr, sb.st_size);
+               close(fd);
+               return 0;
+       }
+
+       // typedef unsigned int ULONG;
+       unsigned int ret = pNTHeaders->OptionalHeader.SizeOfImage;
+
+       munmap(pAddr, sb.st_size);
+       close(fd);
+       return ret;
+}