Skip to content

POEX throws immediately #1

Description

@alexms2001

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions