void DataSection::printBytes(uint64_t offset, uint32_t bytesPerWord, uint32_t bytesPerLine){
    fprintf(stdout, "\n");
    PRINT_INFOR("Raw bytes for DATA section %d:", sectionIndex);

    uint32_t printMax = getSectionHeader()->GET(sh_size);
    if (0x400 < printMax){
        printMax = 0x400;
    }
    printBufferPretty(charStream() + offset, printMax, getSectionHeader()->GET(sh_addr) + offset, bytesPerWord, bytesPerLine);
}
示例#2
0
//===================================================================================
uintptr_t CSignature::GetVstdSignature(const char *chPattern)
{
    // we need to do this becuase (i assume that) under the hood, dlopen only
    // loads up the sections that it needs into memory, meaning that we cannot
    // get the string table from the module.
    static int fd              = open(sharedobj::vstdlib().path.c_str(), O_RDONLY);
    static void *module        = mmap(NULL, lseek(fd, 0, SEEK_END), PROT_READ, MAP_SHARED, fd, 0);
    static link_map *moduleMap = sharedobj::vstdlib().lmap;

    // static void *module = (void *)moduleMap->l_addr;

    static Elf32_Shdr *textHeader = getSectionHeader(module, ".text");

    static int textOffset = textHeader->sh_offset;

    static int textSize = textHeader->sh_size;

    // we need to remap the address that we got from the pattern search from our
    // mapped file to the actual memory we do this by rebasing the address
    // (subbing the mmapped one and adding the dlopened one.
    uintptr_t patr = dwFindPattern(((uintptr_t) module) + textOffset, ((uintptr_t) module) + textOffset + textSize, chPattern);
    if (!patr)
        return NULL;
    return patr - (uintptr_t)(module) + moduleMap->l_addr;
}
uint32_t DataSection::read(BinaryInputFile* b){
    ASSERT(sizeInBytes);
    ASSERT(!rawBytes);

    rawBytes = new char[sizeInBytes];
    if (getSectionHeader()->GET(sh_type) == SHT_NOBITS){
        bzero(rawBytes, sizeInBytes);
    } else {
        memcpy(rawBytes, rawDataPtr, sizeInBytes);
    }

    verify();
    return sizeInBytes;
}
void RawSection::dump(BinaryOutputFile* binaryOutputFile, uint32_t offset){ 
    if (getType() != PebilClassType_RawSection && getType() != PebilClassType_no_type &&
        getType() != PebilClassType_DwarfSection && getType() != PebilClassType_DwarfLineInfoSection){
        PRINT_ERROR("You should implement the dump function for class type %d", getType());
    }

    
    if (getSectionHeader()->hasBitsInFile() && getSizeInBytes()){
        char* sectionOutput = getFilePointer();
        
        binaryOutputFile->copyBytes(sectionOutput, getSizeInBytes(), offset); 
        for (uint32_t i = 0; i < dataReferences.size(); i++){
            dataReferences[i]->dump(binaryOutputFile,offset);
        }
    }
}
void RawSection::printBytes(uint64_t offset, uint32_t bytesPerWord, uint32_t bytesPerLine){
    fprintf(stdout, "\n");
    PRINT_INFOR("Raw bytes for RAW section %d:", sectionIndex);
    printBufferPretty(charStream() + offset, getSizeInBytes(), getSectionHeader()->GET(sh_offset) + offset, bytesPerWord, bytesPerLine);
}
char* RawSection::getStreamAtAddress(uint64_t addr){
    uint32_t offset = addr - getSectionHeader()->GET(sh_addr);
    return charStream(offset);
}
void DataSection::setBytesAtAddress(uint64_t addr, uint32_t size, char* content){
    ASSERT(getSectionHeader()->inRange(addr));
    ASSERT(size);
    ASSERT(getSectionHeader()->inRange(addr + size - 1));
    setBytesAtOffset(addr - getSectionHeader()->GET(sh_addr), size, content);
}