# Path: apiscout/utility.py
# def get_word(buf, start):
#     return _get_binary_data(buf, start, 2)


import logging
import struct
from .utility import get_word
    @staticmethod
    def getBitness(binary):
        bitness_id = 0
        pe_offset = PeTools.getPeOffset(binary)
        if pe_offset:
            if pe_offset and len(binary) >= pe_offset + 0x6:
                bitness_id = struct.unpack("H", binary[pe_offset + 0x4:pe_offset + 0x6])[0]
        return PeTools.BITNESS_MAP.get(bitness_id, 0)

    @staticmethod
    def getBaseAddressFromPeHeader(binary):
        pe_offset = PeTools.getPeOffset(binary)
        if pe_offset:
            if pe_offset and len(binary) >= pe_offset + 0x38:
                base_addr = struct.unpack("I", binary[pe_offset + 0x34:pe_offset + 0x38])[0]
                LOG.debug("Changing base address from 0 to: 0x%x for inference of reference counts (based on PE header)", base_addr)
                return base_addr
        return 0

    @staticmethod
    def getPeOffset(binary):
        if len(binary) >= 0x40:
            pe_offset = get_word(binary, 0x3c)
            return pe_offset
        return 0

    @staticmethod
    def checkPe(binary):
        pe_offset = PeTools.getPeOffset(binary)
        if pe_offset and len(binary) >= pe_offset + 6:

# Path: apiscout/utility.py
# def get_word(buf, start):
#     return _get_binary_data(buf, start, 2)


# Path: apiscout/PeTools.py
import logging
import struct
from .utility import get_word

    @staticmethod
    def getBitness(binary):
        bitness_id = 0
        pe_offset = PeTools.getPeOffset(binary)
        if pe_offset:
            if pe_offset and len(binary) >= pe_offset + 0x6:
                bitness_id = struct.unpack("H", binary[pe_offset + 0x4:pe_offset + 0x6])[0]
        return PeTools.BITNESS_MAP.get(bitness_id, 0)

    @staticmethod
    def getBaseAddressFromPeHeader(binary):
        pe_offset = PeTools.getPeOffset(binary)
        if pe_offset:
            if pe_offset and len(binary) >= pe_offset + 0x38:
                base_addr = struct.unpack("I", binary[pe_offset + 0x34:pe_offset + 0x38])[0]
                LOG.debug("Changing base address from 0 to: 0x%x for inference of reference counts (based on PE header)", base_addr)
                return base_addr
        return 0

    @staticmethod
    def getPeOffset(binary):
        if len(binary) >= 0x40:
            pe_offset = get_word(binary, 0x3c)
            return pe_offset
        return 0

    @staticmethod
    def checkPe(binary):
        pe_offset = PeTools.getPeOffset(binary)
        if pe_offset and len(binary) >= pe_offset + 6:

            bitness = get_word(binary, pe_offset + 4)