13 ut64 addr_beg, addr_end, new_section_size, new_perm, base_addr;
19 new_section_size =
bin->size;
20 new_section_size -=
entry->paddr >
bin->size ? 0 :
entry->paddr;
32 if (
entry->paddr < addr_beg ||
entry->paddr > addr_end) {
38 if (
entry->vaddr < addr_beg ||
entry->vaddr > addr_end) {
42 for (j = 0; !
sections[j].last; j++) {
44 addr_end = addr_beg +
sections[j].size;
45 if (addr_beg <= entry->
paddr &&
entry->paddr < addr_end) {
49 addr_beg =
sections[j].vaddr + base_addr;
50 addr_end = addr_beg +
sections[j].vsize;
51 if (addr_beg <= entry->
vaddr ||
entry->vaddr < addr_end) {
54 RZ_LOG_ERROR(
"Found entrypoint in non-executable section.\n");
81 if (addr_beg <= entry->
paddr &&
entry->paddr < addr_end) {
87 if (
entry->vaddr < addr_beg ||
entry->vaddr > addr_end) {
99 i =
bin->num_sections;
213 ut8 buf[
sizeof(
PE_(image_section_header))];
229 ut8 buf[
sizeof(
PE_(image_section_header))];
245 PE_(image_section_header) * shdr;
246 int i, j, section_count = 0;
248 if (!
bin || !
bin->nt_headers) {
251 shdr =
bin->section_header;
252 for (
i = 0;
i <
bin->num_sections;
i++) {
254 if (shdr[
i].SizeOfRawData || shdr[
i].Misc.VirtualSize) {
263 for (
i = 0, j = 0;
i <
bin->num_sections;
i++) {
264 if (!shdr[
i].SizeOfRawData && !shdr[
i].Misc.VirtualSize) {
267 if (shdr[
i].Name[0] ==
'\0') {
271 }
else if (shdr[
i].Name[0] ==
'/') {
273 int idx = atoi((
const char *)shdr[
i].Name + 1);
274 ut64 sym_tbl_off =
bin->nt_headers->file_header.PointerToSymbolTable;
275 int num_symbols =
bin->nt_headers->file_header.NumberOfSymbols;
277 if (
off > 0 && sym_tbl_off &&
278 sym_tbl_off +
off + idx < bin->
size &&
281 char *
buf[64] = { 0 };
293 sections[j].vaddr = shdr[
i].VirtualAddress;
294 sections[j].size = shdr[
i].SizeOfRawData;
295 if (shdr[
i].Misc.VirtualSize) {
296 sections[j].vsize = shdr[
i].Misc.VirtualSize;
298 sections[j].vsize = shdr[
i].SizeOfRawData;
300 sections[j].paddr = shdr[
i].PointerToRawData;
301 sections[j].flags = shdr[
i].Characteristics;
302 if (
bin->optional_header) {
303 ut32 sa =
bin->optional_header->SectionAlignment;
310 RZ_LOG_INFO(
"section %s not aligned to SectionAlignment.\n",
314 const ut32 fa =
bin->optional_header->FileAlignment;
324 sections[j].perm = shdr[
i].Characteristics;
329 bin->num_sections = section_count;
334 bin->num_sections =
bin->nt_headers->file_header.NumberOfSections;
335 if (
bin->num_sections < 1) {
338 ut64 sections_size =
sizeof(
PE_(image_section_header)) *
bin->num_sections;
339 if (sections_size >
bin->size) {
340 sections_size =
bin->size;
341 bin->num_sections =
bin->size /
sizeof(
PE_(image_section_header));
346 if (!(
bin->section_header =
malloc(sections_size))) {
350 bin->section_header_offset =
bin->dos_header->e_lfanew + 4 +
sizeof(
PE_(image_file_header)) +
351 bin->nt_headers->file_header.SizeOfOptionalHeader;
353 for (
i = 0;
i <
bin->num_sections;
i++) {
355 bin->section_header +
i)) {
365 ================================================================
366 COFF SYMBOL
TABLE RECORDS (18 BYTES)
367 ================================================================
385 ------------------------------------------------------ -
386 0 | 8 -
char symbol
name |
387 | or 32 -
bit zeroes followed by 32 -
bit |
388 | index into
string table |
389 ------------------------------------------------------ -
391 ------------------------------------------------------ -
393 ------------------------------------------------------ -
394 10
h | sym
class |
num aux |
395 -------------------------- -
401 bin->num_sections = 0;
RzList * sections(RzBinFile *bf)
const lzma_allocator const uint8_t * in
RZ_API void Ht_() free(HtName_(Ht) *ht)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
void * realloc(void *ptr, size_t size)
void * malloc(size_t size)
void * calloc(size_t number, size_t size)
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
static const struct names names[]
#define IMAGE_SCN_ALIGN_256BYTES
#define IMAGE_SCN_MEM_NOT_CACHED
#define IMAGE_SCN_ALIGN_2048BYTES
#define IMAGE_SCN_MEM_LOCKED
#define IMAGE_SCN_ALIGN_32BYTES
#define IMAGE_SCN_MEM_PURGEABLE
#define IMAGE_SCN_MEM_NOT_PAGED
#define IMAGE_SCN_LNK_INFO
#define IMAGE_SCN_TYPE_NO_PAD
#define IMAGE_SCN_LNK_COMDAT
struct rz_bin_pe_addr_t *PE_() rz_bin_pe_get_entrypoint(RzBinPEObj *bin)
#define IMAGE_SCN_MEM_PRELOAD
#define IMAGE_SCN_CNT_INITIALIZED_DATA
#define IMAGE_SCN_ALIGN_512BYTES
#define IMAGE_SCN_ALIGN_8192BYTES
#define IMAGE_SCN_ALIGN_128BYTES
#define IMAGE_SCN_CNT_CODE
#define IMAGE_SCN_MEM_DISCARDABLE
ut64 PE_() rz_bin_pe_get_image_base(RzBinPEObj *bin)
#define IMAGE_SCN_LNK_OTHER
#define IMAGE_SCN_ALIGN_16BYTES
#define IMAGE_SCN_ALIGN_1024BYTES
#define PE_SCN_ALIGN_MASK
#define IMAGE_SCN_LNK_REMOVE
#define IMAGE_SCN_ALIGN_4BYTES
#define IMAGE_SCN_ALIGN_4096BYTES
#define IMAGE_SCN_ALIGN_1BYTES
#define IMAGE_SCN_CNT_UNINITIALIZED_DATA
#define IMAGE_SCN_ALIGN_2BYTES
#define IMAGE_SCN_LNK_NRELOC_OVFL
#define IMAGE_SCN_ALIGN_8BYTES
#define PE_READ_STRUCT_FIELD(var, struct_type, field, size)
#define IMAGE_SCN_ALIGN_64BYTES
#define IMAGE_SCN_MEM_16BIT
void PE_() rz_bin_pe_check_sections(RzBinPEObj *bin, struct rz_bin_pe_section_t **sects)
RzList *PE_() section_flag_to_rzlist(ut64 flag)
void PE_() write_image_section_header(RzBuffer *b, ut64 addr, PE_(image_section_header) *section_header)
int PE_() bin_pe_init_sections(RzBinPEObj *bin)
bool PE_() read_image_section_header(RzBuffer *b, ut64 addr, PE_(image_section_header) *section_header)
struct rz_bin_pe_section_t *PE_() rz_bin_pe_get_sections(RzBinPEObj *bin)
#define PE_IMAGE_SIZEOF_SHORT_NAME
#define PE_IMAGE_SCN_MEM_EXECUTE
#define PE_IMAGE_SCN_MEM_WRITE
#define PE_IMAGE_SCN_MEM_READ
int stored(struct state *s)
RZ_API st64 rz_buf_write_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL const ut8 *buf, ut64 len)
Write len bytes of the buffer at the specified address.
RZ_API st64 rz_buf_read_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
Read len bytes of the buffer at the specified address.
static void rz_write_at_le16(void *dest, ut16 val, size_t offset)
static void rz_write_at_le32(void *dest, ut32 val, size_t offset)
#define RZ_LOG_INFO(fmtstr,...)
#define RZ_LOG_ERROR(fmtstr,...)
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
if(dbg->bits==RZ_SYS_BITS_64)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()