UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
syms_pecoff_helpers.c
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
4//~ allen): PE/COFF Sections
5
9 if (1 <= n && sec_hrds_off + n*sizeof(SYMS_CoffSectionHeader) <= data.size){
10 result = (SYMS_CoffSectionHeader*)(data.str + sec_hrds_off + (n - 1)*sizeof(SYMS_CoffSectionHeader));
11 }
12 return(result);
13}
14
17 SYMS_U64Range result = {0};
18
19 // check offset
20 if (sec_hdr_off + 8 <= data.size){
21 SYMS_U8 *name_data = (data.str + sec_hdr_off);
22
23 // scan to end (name + 8 or null terminator)
24 SYMS_U8 *name_ptr = name_data;
26 for (;name_ptr < name_opl && *name_ptr != 0; name_ptr += 1);
27
28 // resolve name
30 SYMS_U8 *name_max = name_ptr;
31 if (name_data[0] == '/'){
32 // ascii -> integer
35
36 // scan string
37 SYMS_U8 *data_opl = data.str + data.size;
38 if (off < data.size){
39 name_min = data.str + off;
41 for (;name_max < data_opl && *name_max != 0; name_max += 1);
42 }
43 }
44
45 // convert ptr range to result
46 result.min = (SYMS_U64)(name_min - data.str);
47 result.max = (SYMS_U64)(name_max - data.str);
48 }
49
50 return(result);
51}
52
55 // locate name
57 // copy range onto arena
58 SYMS_U64 size = range.max - range.min;
59 SYMS_String8 result = {0};
60 result.str = syms_push_array(arena, SYMS_U8, size);
61 result.size = size;
62 syms_memmove(result.str, data.str + range.min, size);
63 return(result);
64}
65
68 SYMS_U64 sec_count){
69 // allocate output
70 SYMS_U64Array result = {0};
71 result.u64 = syms_push_array(arena, SYMS_U64, sec_count);
72 result.count = sec_count;
73
74 // fill output
76 SYMS_U64 *dst = result.u64;
77 for (SYMS_U64 i = 0; i < sec_count; i += 1, src += 1, dst += 1){
78 *dst = src->virt_off;
79 }
80
81 return(result);
82}
83
84
87 SYMS_U64 sec_hdrs_off, SYMS_U64 sec_count){
88 SYMS_SecInfoArray result = {0};
89
90 // check offset
91 if (sec_hdrs_off + sec_count*sizeof(SYMS_CoffSectionHeader) <= data.size){
92
93 // allocate output array
94 result.sec_info = syms_push_array(arena, SYMS_SecInfo, sec_count);
95 result.count = sec_count;
96
97 // fill output array
99 SYMS_CoffSectionHeader *hdr_opl = hdr + sec_count;
100 SYMS_SecInfo *ptr = result.sec_info;
102 for (; hdr < hdr_opl;
103 hdr += 1, ptr += 1, off += sizeof(SYMS_CoffSectionHeader)){
104 ptr->name = syms_pecoff_name_from_hdr_off(arena, data, off);
105 ptr->vrange = syms_make_u64_range(hdr->virt_off, hdr->virt_off + hdr->virt_size);
106 ptr->frange = syms_make_u64_range(hdr->file_off, hdr->file_off + hdr->file_size);
107 }
108 }
109
110 return(result);
111}
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
char * dst
Definition lz4.h:735
Definition syms_meta_coff.h:110
SYMS_U32 virt_off
Definition syms_meta_coff.h:113
Definition syms_debug_info.h:21
SYMS_U64 count
Definition syms_debug_info.h:23
SYMS_SecInfo * sec_info
Definition syms_debug_info.h:22
Definition syms_debug_info.h:15
SYMS_U64Range vrange
Definition syms_debug_info.h:17
SYMS_String8 name
Definition syms_debug_info.h:16
SYMS_U64Range frange
Definition syms_debug_info.h:18
Definition syms_base.h:296
SYMS_U8 * str
Definition syms_base.h:297
SYMS_U64 size
Definition syms_base.h:298
Definition syms_base.h:233
SYMS_U64 * u64
Definition syms_base.h:234
SYMS_U64 count
Definition syms_base.h:235
Definition syms_base.h:264
SYMS_U64 max
Definition syms_base.h:266
SYMS_U64 min
Definition syms_base.h:265
SYMS_API SYMS_String8 syms_str8_range(SYMS_U8 *first, SYMS_U8 *opl)
Definition syms_base.c:184
SYMS_API SYMS_U64Range syms_make_u64_range(SYMS_U64 min, SYMS_U64 max)
Definition syms_base.c:18
SYMS_API SYMS_U64 syms_u64_from_string(SYMS_String8 str, SYMS_U32 radix)
Definition syms_base.c:422
#define syms_push_array(a, T, c)
Definition syms_base.h:561
#define SYMS_API
Definition syms_base.h:29
uint64_t SYMS_U64
Definition syms_crt_overrides.h:39
#define syms_memmove
Definition syms_crt_overrides.h:65
#define SYMS_U64
Definition syms_crt_overrides.h:54
uint8_t SYMS_U8
Definition syms_crt_overrides.h:36
#define SYMS_Arena
Definition syms_default_arena.h:61
SYMS_API SYMS_String8 syms_pecoff_name_from_hdr_off(SYMS_Arena *arena, SYMS_String8 data, SYMS_U64 sec_hdr_off)
Definition syms_pecoff_helpers.c:54
SYMS_API SYMS_U64Range syms_pecoff_name_range_from_hdr_off(SYMS_String8 data, SYMS_U64 sec_hdr_off)
Definition syms_pecoff_helpers.c:16
SYMS_API SYMS_CoffSectionHeader * syms_pecoff_sec_hdr_from_n(SYMS_String8 data, SYMS_U64 sec_hrds_off, SYMS_U64 n)
Definition syms_pecoff_helpers.c:7
SYMS_API SYMS_SecInfoArray syms_pecoff_sec_info_from_coff_sec(SYMS_Arena *arena, SYMS_String8 data, SYMS_U64 sec_hdrs_off, SYMS_U64 sec_count)
Definition syms_pecoff_helpers.c:86
SYMS_API SYMS_U64Array syms_pecoff_voff_array_from_coff_hdr_array(SYMS_Arena *arena, SYMS_CoffSectionHeader *sec_hdrs, SYMS_U64 sec_count)
Definition syms_pecoff_helpers.c:67
SYMS_READ_ONLY SYMS_GLOBAL SYMS_CoffSectionHeader syms_pecoff_sec_hdr_nil
Definition syms_pecoff_helpers.h:10