Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POEX throws immediately #1

Open
alexms2001 opened this issue Jun 25, 2024 · 0 comments
Open

POEX throws immediately #1

alexms2001 opened this issue Jun 25, 2024 · 0 comments

Comments

@alexms2001
Copy link

I built POEX and added a test app pretty much as shown in POEX wiki:

#include
#include "..\POEX\POEX.h" // include POEX header

#ifdef x64_DEBUG
#pragma comment(lib, "../Build/Debug/X64/POEX.lib") // Link with POEX.lib
#else
#pragma comment(lib, "../Build/Debug/X86/POEX.lib") // Link with POEX.lib
#endif

int main()
{
const wchar_t* pathToFile = L"C:\_W\_Wdevelop\BandBroadening\empowermonorepo\Source\UnitTests\ASTRALibraryd.dll"; // Path to the file
POEX::PE pe = POEX::PE(pathToFile);
std::unique_ptr resources = pe.GetImageResourceDirectory();
return 0;
}

I get an exception immediately in a call to GetImageResourceDirectory, which calls GetImageNtHeader, which, in turn, calls GetImageDosHeader. Since the offset for DOS header is 0, this last call throws in WRONG_LONG, which expands to (x <= 0), but macro's argument x is in fact 0, "[ERROR] offset value is wrong." is thrown:

ImageDosHeader::ImageDosHeader(const std::shared_ptr& bFile,
const long& offset) : bFile(bFile), offset(offset)
{
if (WRONG_LONG(this->offset))
THROW_EXCEPTION("[ERROR] offset value is wrong.");
}

Same happens in x86 build.

After changing (in Defines.h)

//#define WRONG_LONG(x) (x <= 0)
#define WRONG_LONG(x) (x < 0)

the code builds and runs.

Please comment and/or fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant