Skip to content

Commit

Permalink
Fix invalid flag names when importing relocs with .ir* ##bin
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Feb 6, 2025
1 parent c9df524 commit bee3e69
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 58 deletions.
6 changes: 4 additions & 2 deletions libr/bin/p/bin_mach0.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static ut64 baddr(RBinFile *bf) {
return MACH0_(get_baddr)(mo);
}

// R2_590 return RVecSegment
// R2_600 return RVecSegment
static RList *sections(RBinFile *bf) {
struct MACH0_(obj_t) *mo = bf->bo->bin_obj;
return MACH0_(get_segments) (bf, mo); // TODO split up sections and segments?
Expand Down Expand Up @@ -465,7 +465,9 @@ static RList* patch_relocs(RBinFile *bf) {
}
r_pvector_push (&ext_relocs, reloc);
}
#if 0
#if 1
// XXX for some reason we are patching this twice as relocs and fixups
// may be good to find out why and comment back this code with an if0
int relocs_count = 0;
// fixups are now considered part of the relocs listing
if (mo->reloc_fixups != NULL) {
Expand Down
7 changes: 5 additions & 2 deletions libr/core/cbin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,8 @@ static void set_bin_relocs(RelocInfo *ri, RBinReloc *reloc, ut64 addr, Sdb **db,
r_io_read_at (r->io, reloc->addend, (ut8*)name, sizeof (name));
name[sizeof (name) - 1] = 0;
if (name[0] && name[1] && isalpha (name[0]) && isalpha (name[1])) {
R_LOG_DEBUG ("Naming fixup reloc with string %s\n", name);
r_name_filter (name, -1);
R_LOG_DEBUG ("Naming fixup reloc with string %s", name);
reloc_name = r_str_newf ("fixup.%s", name);
// add xref from fixup to string
r_anal_xrefs_set (r->anal, reloc->vaddr, reloc->addend, R_ANAL_REF_TYPE_DATA);
Expand Down Expand Up @@ -1977,7 +1978,9 @@ static bool bin_relocs(RCore *r, PJ *pj, int mode, int va) {
}
}
int reloc_size = 4;
char *n = r_name_filter_quoted_shell (name);
// char *n = r_name_filter_quoted_shell (name);
char *n = strdup (name);
r_name_filter (n, -1);
r_cons_printf ("'f %s%s%s %d 0x%08"PFMT64x"\n",
r_str_get_fail (r->bin->prefix, "reloc."),
r->bin->prefix ? "." : "", n, reloc_size, addr);
Expand Down
112 changes: 112 additions & 0 deletions test/db/cmd/cmd_i
Original file line number Diff line number Diff line change
Expand Up @@ -3362,6 +3362,118 @@ DEBUG: (section .data.rel.ro) Cd 8[329] @ 0x21bfc0
DEBUG: (section .dynamic) Cd 8[64] @ 0x21ca08
DEBUG: (section .got) Cd 8[124] @ 0x21cc08
WARN: Relocs has not been applied. Please use `-e bin.relocs.apply=true` or `-e bin.cache=true` next time
DEBUG: Naming fixup reloc with string ATIUSH_H.
DEBUG: Naming fixup reloc with string ATIUHI__S.
DEBUG: Naming fixup reloc with string ATUISH_.
DEBUG: Naming fixup reloc with string ATUISH..
DEBUG: Naming fixup reloc with string always
DEBUG: Naming fixup reloc with string yes
DEBUG: Naming fixup reloc with string force
DEBUG: Naming fixup reloc with string never
DEBUG: Naming fixup reloc with string no
DEBUG: Naming fixup reloc with string none
DEBUG: Naming fixup reloc with string auto
DEBUG: Naming fixup reloc with string tty
DEBUG: Naming fixup reloc with string if_tty
DEBUG: Naming fixup reloc with string atime
DEBUG: Naming fixup reloc with string access
DEBUG: Naming fixup reloc with string use
DEBUG: Naming fixup reloc with string ctime
DEBUG: Naming fixup reloc with string status
DEBUG: Naming fixup reloc with string none
DEBUG: Naming fixup reloc with string time
DEBUG: Naming fixup reloc with string size
DEBUG: Naming fixup reloc with string extension
DEBUG: Naming fixup reloc with string version
DEBUG: Naming fixup reloc with string verbose
DEBUG: Naming fixup reloc with string long
DEBUG: Naming fixup reloc with string commas
DEBUG: Naming fixup reloc with string horizontal
DEBUG: Naming fixup reloc with string across
DEBUG: Naming fixup reloc with string vertical
DEBUG: Naming fixup reloc with string single_column
DEBUG: Naming fixup reloc with string all
DEBUG: Naming fixup reloc with string escape
DEBUG: Naming fixup reloc with string directory
DEBUG: Naming fixup reloc with string dired
DEBUG: Naming fixup reloc with string full_time
DEBUG: Naming fixup reloc with string group_directories_first
DEBUG: Naming fixup reloc with string human_readable
DEBUG: Naming fixup reloc with string inode
DEBUG: Naming fixup reloc with string kibibytes
DEBUG: Naming fixup reloc with string numeric_uid_gid
DEBUG: Naming fixup reloc with string no_group
DEBUG: Naming fixup reloc with string hide_control_chars
DEBUG: Naming fixup reloc with string reverse
DEBUG: Naming fixup reloc with string size
DEBUG: Naming fixup reloc with string width
DEBUG: Naming fixup reloc with string almost_all
DEBUG: Naming fixup reloc with string ignore_backups
DEBUG: Naming fixup reloc with string classify
DEBUG: Naming fixup reloc with string file_type
DEBUG: Naming fixup reloc with string si
DEBUG: Naming fixup reloc with string dereference_command_line
DEBUG: Naming fixup reloc with string dereference_command_line_symlin
DEBUG: Naming fixup reloc with string hide
DEBUG: Naming fixup reloc with string ignore
DEBUG: Naming fixup reloc with string indicator_style
DEBUG: Naming fixup reloc with string dereference
DEBUG: Naming fixup reloc with string literal
DEBUG: Naming fixup reloc with string quote_name
DEBUG: Naming fixup reloc with string quoting_style
DEBUG: Naming fixup reloc with string recursive
DEBUG: Naming fixup reloc with string format
DEBUG: Naming fixup reloc with string show_control_chars
DEBUG: Naming fixup reloc with string sort
DEBUG: Naming fixup reloc with string tabsize
DEBUG: Naming fixup reloc with string time
DEBUG: Naming fixup reloc with string time_style
DEBUG: Naming fixup reloc with string color
DEBUG: Naming fixup reloc with string block_size
DEBUG: Naming fixup reloc with string context
DEBUG: Naming fixup reloc with string author
DEBUG: Naming fixup reloc with string help
DEBUG: Naming fixup reloc with string version
DEBUG: Naming fixup reloc with string lc
DEBUG: Naming fixup reloc with string rc
DEBUG: Naming fixup reloc with string ec
DEBUG: Naming fixup reloc with string rs
DEBUG: Naming fixup reloc with string no
DEBUG: Naming fixup reloc with string fi
DEBUG: Naming fixup reloc with string di
DEBUG: Naming fixup reloc with string ln
DEBUG: Naming fixup reloc with string pi
DEBUG: Naming fixup reloc with string so
DEBUG: Naming fixup reloc with string bd
DEBUG: Naming fixup reloc with string cd
DEBUG: Naming fixup reloc with string mi
DEBUG: Naming fixup reloc with string or
DEBUG: Naming fixup reloc with string ex
DEBUG: Naming fixup reloc with string do
DEBUG: Naming fixup reloc with string su
DEBUG: Naming fixup reloc with string sg
DEBUG: Naming fixup reloc with string st
DEBUG: Naming fixup reloc with string ow
DEBUG: Naming fixup reloc with string tw
DEBUG: Naming fixup reloc with string ca
DEBUG: Naming fixup reloc with string mh
DEBUG: Naming fixup reloc with string cl
DEBUG: Naming fixup reloc with string none
DEBUG: Naming fixup reloc with string slash
DEBUG: Naming fixup reloc with string file_type
DEBUG: Naming fixup reloc with string classify
DEBUG: Naming fixup reloc with string full_iso
DEBUG: Naming fixup reloc with string long_iso
DEBUG: Naming fixup reloc with string iso
DEBUG: Naming fixup reloc with string locale
DEBUG: Naming fixup reloc with string human_readable
DEBUG: Naming fixup reloc with string si
DEBUG: Naming fixup reloc with string literal
DEBUG: Naming fixup reloc with string shell
DEBUG: Naming fixup reloc with string shell_always
DEBUG: Naming fixup reloc with string escape
DEBUG: Naming fixup reloc with string locale
DEBUG: Naming fixup reloc with string clocale
DEBUG: Cannot resolve symbol address __progname
DEBUG: Cannot resolve symbol address _ITM_deregisterTMCloneTable
DEBUG: Cannot resolve symbol address stdout
Expand Down
32 changes: 19 additions & 13 deletions test/db/cmd/cmd_pd2
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ EXPECT=<<EOF
,=< 0x000041e0 je 0x421a
| 0x000041e2 mov ecx, 4
| 0x000041e7 lea rdx, [0x0001b980]
| 0x000041ee lea rsi, [0x00021a40]
| 0x000041ee lea rsi, reloc.fixup.literal ; 0x21a40 ; "1\x8d\x01"
| 0x000041f5 mov rdi, rax
| 0x000041f8 call 0xc660
| 0x000041fe test eax, eax
Expand All @@ -685,14 +685,15 @@ EXPECT=<<EOF
| ; [0x232b0:8]=0
| 0x00004225 lea rdi, str.COLUMNS ; 0x18a22 ; "COLUMNS"

0x000041ee lea rsi, [rip + 0x1d84b] ; 0x21a40
0x000041ee lea rsi, [rip + 0x1d84b] ; reloc.fixup.literal
; 0x21a40 ; "1\x8d\x01"
0x00004225 lea rdi, [rip + 0x147f6] ; str.COLUMNS
; 0x18a22 ; "COLUMNS"

,=< 0x000041e0 je 0x421a
| 0x000041e2 mov ecx, 4
| 0x000041e7 lea rdx, [0x0001b980]
| 0x000041ee lea rsi, [0x00021a40]
| 0x000041ee lea rsi, reloc.fixup.literal ; 0x21a40 ; "1\x8d\x01"
| 0x000041f5 mov rdi, rax
| 0x000041f8 call 0xc660
| 0x000041fe test eax, eax
Expand All @@ -706,14 +707,15 @@ EXPECT=<<EOF
|  ; [0x232b0:8]=0
| 0x00004225 lea rdi, str.COLUMNS ; 0x18a22 ; "COLUMNS"

0x000041ee lea rsi, [rip + 0x1d84b] ; 0x21a40
0x000041ee lea rsi, [rip + 0x1d84b] ; reloc.fixup.literal
 ; 0x21a40 ; "1\x8d\x01"
0x00004225 lea rdi, [rip + 0x147f6] ; str.COLUMNS
 ; 0x18a22 ; "COLUMNS"

,=< 0x000041e0 je 0x421a
| 0x000041e2 mov ecx, 4
| 0x000041e7 mov rax, qword [0x0001b980] ; [0x1b980:8]=0x100000000
| 0x000041ee mov rax, qword [0x00021a40] ; [0x21a40:8]=0x18d31 str.literal
| 0x000041ee mov rax, qword [reloc.fixup.literal] ; [0x21a40:8]=0x18d31 str.literal ; "1\x8d\x01"
| 0x000041f5 mov rdi, rax
| 0x000041f8 call 0xc660
| 0x000041fe test eax, eax
Expand All @@ -727,14 +729,15 @@ EXPECT=<<EOF
| ; [0x232b0:8]=0
| 0x00004225 mov rax, qword [str.COLUMNS] ; [0x18a22:8]=0x534e4d554c4f43 ; "COLUMNS"

0x000041ee mov rax, qword [rip + 0x1d84b] ; [0x21a40:8]=0x18d31 str.literal
0x000041ee mov rax, qword [rip + 0x1d84b] ; reloc.fixup.literal
; [0x21a40:8]=0x18d31 str.literal ; "1\x8d\x01"
0x00004225 mov rax, qword [rip + 0x147f6] ; str.COLUMNS
; [0x18a22:8]=0x534e4d554c4f43 ; "COLUMNS"

,=< 0x000041e0 je 0x421a
| 0x000041e2 mov ecx, 4
| 0x000041e7 mov rax, qword [0x0001b980] ; [0x1b980:8]=0x100000000
| 0x000041ee mov rax, qword [0x00021a40] ; [0x21a40:8]=0x18d31 str.literal
| 0x000041ee mov rax, qword [reloc.fixup.literal] ; [0x21a40:8]=0x18d31 str.literal ; "1\x8d\x01"
| 0x000041f5 mov rdi, rax
| 0x000041f8 call 0xc660
| 0x000041fe test eax, eax
Expand All @@ -748,14 +751,15 @@ EXPECT=<<EOF
|  ; [0x232b0:8]=0
| 0x00004225 mov rax, qword [str.COLUMNS] ; [0x18a22:8]=0x534e4d554c4f43 ; "COLUMNS"

0x000041ee mov rax, qword [rip + 0x1d84b] ; [0x21a40:8]=0x18d31 str.literal
0x000041ee mov rax, qword [rip + 0x1d84b] ; reloc.fixup.literal
 ; [0x21a40:8]=0x18d31 str.literal ; "1\x8d\x01"
0x00004225 mov rax, qword [rip + 0x147f6] ; str.COLUMNS
 ; [0x18a22:8]=0x534e4d554c4f43 ; "COLUMNS"

,=< 0x000041e0 je 0x421a
| 0x000041e2 mov ecx, 4
| 0x000041e7 cmp rdx, qword [0x0001b980] ; [0x1b980:8]=0x100000000
| 0x000041ee cmp rsi, qword [0x00021a40] ; [0x21a40:8]=0x18d31 str.literal
| 0x000041ee cmp rsi, qword [reloc.fixup.literal] ; [0x21a40:8]=0x18d31 str.literal ; "1\x8d\x01"
| 0x000041f5 mov rdi, rax
| 0x000041f8 call 0xc660
| 0x000041fe test eax, eax
Expand All @@ -769,14 +773,15 @@ EXPECT=<<EOF
| ; [0x232b0:8]=0
| 0x00004225 cmp rdi, qword [str.COLUMNS] ; [0x18a22:8]=0x534e4d554c4f43 ; "COLUMNS"

0x000041ee cmp rsi, qword [rip + 0x1d84b] ; [0x21a40:8]=0x18d31 str.literal
0x000041ee cmp rsi, qword [rip + 0x1d84b] ; reloc.fixup.literal
; [0x21a40:8]=0x18d31 str.literal ; "1\x8d\x01"
0x00004225 cmp rdi, qword [rip + 0x147f6] ; str.COLUMNS
; [0x18a22:8]=0x534e4d554c4f43 ; "COLUMNS"

,=< 0x000041e0 je 0x421a
| 0x000041e2 mov ecx, 4
| 0x000041e7 cmp rdx, qword [0x0001b980] ; [0x1b980:8]=0x100000000
| 0x000041ee cmp rsi, qword [0x00021a40] ; [0x21a40:8]=0x18d31 str.literal
| 0x000041ee cmp rsi, qword [reloc.fixup.literal] ; [0x21a40:8]=0x18d31 str.literal ; "1\x8d\x01"
| 0x000041f5 mov rdi, rax
| 0x000041f8 call 0xc660
| 0x000041fe test eax, eax
Expand All @@ -790,7 +795,8 @@ EXPECT=<<EOF
|  ; [0x232b0:8]=0
| 0x00004225 cmp rdi, qword [str.COLUMNS] ; [0x18a22:8]=0x534e4d554c4f43 ; "COLUMNS"

0x000041ee cmp rsi, qword [rip + 0x1d84b] ; [0x21a40:8]=0x18d31 str.literal
0x000041ee cmp rsi, qword [rip + 0x1d84b] ; reloc.fixup.literal
 ; [0x21a40:8]=0x18d31 str.literal ; "1\x8d\x01"
0x00004225 cmp rdi, qword [rip + 0x147f6] ; str.COLUMNS
 ; [0x18a22:8]=0x534e4d554c4f43 ; "COLUMNS"
EOF
Expand Down Expand Up @@ -822,7 +828,7 @@ EXPECT=<<EOF
je 0x421a
mov ecx, 4
lea rdx, [0x0001b980]
lea rsi, [0x00021a40]
lea rsi, reloc.fixup.literal
mov rdi, rax
call 0xc660
test eax, eax
Expand Down
Loading

0 comments on commit bee3e69

Please sign in to comment.