{
IMAGE_NT_HEADERS* pNTHeaders = getNTHeaders(pAddr);
if (!pNTHeaders) {
- _SERR("Invalid NT Header");
return false;
}
return false;
}
-bool isR2RImage(std::string fileName)
+bool isR2RImage(const 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 false;
}
if (fstat(fd, &sb) == -1) {
+ close(fd);
return false;
}
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 false;
}
close(fd);
return ret;
}
+
+unsigned int getSizeOfImage(const std::string& fileName)
+{
+ int fd;
+ struct stat sb;
+ if ((fd = open(fileName.c_str(), O_RDONLY)) == -1) {
+ 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) {
+ close(fd);
+ return 0;
+ }
+
+ IMAGE_NT_HEADERS* pNTHeaders = getNTHeaders(pAddr);
+ if (!pNTHeaders) {
+ 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;
+}