Commit graph

70 commits

Author SHA1 Message Date
Giovanni
dfdd062f14
Rewrite of zImage bin parser & new structured data methods (#5893) 2026-02-09 19:00:42 +08:00
Zapper9982
6918e510bd
Add GNS1 binary format loader for C4000 baseband firmware (#5628) 2026-01-15 08:48:45 +00:00
Rot127
d79ff51157
librz/bin: define string search parameters in plugins (#5406)
* Clarify docs of raw_alignment

* Set Go and Rust string encoding for binary string search.

* Add detailed doxygen about string search in bin plugins.

* Add the number string code points as detail to string search hits.

* Add helper to check if string encoding needs scanning.

* Add helper to generate a string wildcard pattern.

The pattern is supposed to match any human readable string.
Before the string search refactor there was no explicit definition
what characters mark the end of a string and which ones don't.

This pattern should match strings of the old interpretation.

* Enable the RzBin plugin to search strings with direct matching instead of scanning.

This significantly speeds up the string search when a binary is opened.
The prerequisite is that the plugin specifies the string encoding.

* Enforce UTF-8 for initial string search.

* Add custom string search for PE files.

* Clean up and document rz_utf8_encode

* Don't demote explicit UTF-8 encoding to ASCII.

* Increase min JIT stack size due to not reproducable search results.

* Simplify wildcard regex pattern.
2025-10-08 10:02:32 +08:00
Giovanni
31537e712d
librz/bin: refactor SNES bin parser (#5246)
* librz/bin: Refactor of SNES plugin
* librz/bin: Fix leak in bin_nin64.c plugin
2025-07-05 21:30:47 +08:00
Giovanni
4f6bd00197
Refactoring of Nintendo 64 ROM parser (#5236) 2025-07-03 23:30:55 +08:00
Rot127
1f6c6147ec Add the Qualcomm Peripheral Image loader (MDT files, 32bit only).
It loads .mdt firmware layout files, searches for the other parts in the same directory and loads them.
It resolves symbols, sections etc automatically, and maps them according to the layout
to the virtual address space.

- The iH command provides details about each firmware part as well.
- Memory maps and segment names are prefixed with the parts file name to make them distinct.
- If a firmware part is an ELF library it loads, and resolves its functions, segments etc.

Due to the design of the ELF binary plugin (code duplication with macros for 32/64bit versions),
this only supports 32bit firmware images for now.
This can relatively easily be fixed, by duplicating this plugin but including the 64bit ELF headers.
This requires more tests though.
2025-06-11 15:41:03 +00:00
Rot127
28bd9cfa24 Expose MBN plugin functions for other Bin plugins. 2025-06-11 15:41:03 +00:00
Rot127
3200b9e836 Expose ELF functions as API for other binary plugins.
It exposes commonly used ELF parsing functions in elf_parser.
They don't rely on RzBinFile but take only the ELF object.
This allows access for other RzBin plugins which rely on ELF files.
2025-06-11 15:41:03 +00:00
Giovanni
ca70341f2b
Refactor and improvements on ELF relocations (#5187)
* Move ARM32 reloc patching into a function

* Move ARM64 reloc patching into a function

* Move PPC64 reloc patching into a function

* Add missing NONE relocs for various archs

* Move Intel 80386 reloc patching into a function

* Move amd64 reloc patching into a function

* Move rx reloc patching into a function

* Move alpha reloc patching into a function

* Handle reloc RZ_X86_64_COPY for amd64

* Move intel 80386 reloc convert into a function

* Move amd64 reloc convert into a function

* Move arm reloc convert into a function

* Move riscv reloc convert into a function

* Move aarch64 reloc convert into a function

* Move ppc reloc convert into a function

* Move mips reloc convert into a function

* Move rx reloc convert into a function

* Move alpha reloc convert into a function

* Move hexagon reloc convert into a function

* Fix wrong rename on ELF format

* Handle reloc R_MIPS_HI16 & R_MIPS_LO16

* Minimal handling of micromips relocs

* Add nanomips initial support for reloc convert

* Minimal handling of intel 80386 missing relocs

* Minimal handling of amd64 missing relocs

* Minimal handling of arm missing relocs

* Minimal handling of riscv missing relocs

* Minimal handling of aarch64 missing relocs

* Minimal handling of ppc missing relocs

* Minimal handling of ppc64 relocs

* Split reloc patching & conv from bin_elf.inc

* Split aarch64 from arm32 in elf_imports.c
2025-06-08 17:46:45 +08:00
Roee Toledano
82b119d253 Implement PE base relocations
1. Everything is based off of Microsoft's PE format documentation [found here](https://learn.microsoft.com/en-us/windows/win32/debug/pe-format)
2. Up until now, imports were used for relocations in the PE & MDMP format,
   which is wrong. PE uses base relocations.
3. PE relocations do not have symbols associated with them, and thus
   have no name. In order to still have flags in relocs flagspace, dummy
   symbols were allocated with generic names composed of the relocation's
   virtual address space.

* Remove old code of setting import entries to PE relocations
* Parse PE base relocations
* Implement converting from the specific RzBinPeRelocEnt type to the
  general RzBinReloc type
* Implement corrent type naming of PE relocations
* Add missing `PE_IMAGE_FILE_MACHINE` types
* Add PE base relocation types
* Fix PE format 'has_canary' function
* Remove 'RzBinPEObj.endian' and use 'RzBinPEObj.big_endian' instead
* Removed a.exe and b.exe tests, as they don't contain base relocations
  and swapped them with correct tests
* Corrected old PE relocation tests
* Add new PE base relocation tests
2024-11-21 08:53:52 +08:00
wargio
d47ceedbd3 Merge rz_asm and rz_analysis into one library but keep deprecated apis.
The tms320c64x has been merged into tms320.
2024-03-07 18:38:49 +08:00
billow
d5d29fcb37
Load symbols in modules from PDB (#4025)
* PDB: add module info parsing
* Refactor PDB component
* Refactor PDB/tpi
* Fix read_pascal_string
* Fix memory leaks
* Add test `Modules from PDB`
2023-12-10 14:14:14 +08:00
billow
bfe19a784b
Create global variables from PDB (#4021) 2023-12-06 13:57:41 +08:00
billow
19c889f690
DWARF loading '.debug_str_offsets', '.debug_line_str' and relocate (#3848)
* Try Load '.debug_str_offsets'
* DWARF unify names
* Add endian_reader.c to process relocate
* Remove RzBinDwarfLineInfoMask RzBinDWARFFlags and RzBinDWARFOption
* Fix debug_line
* Add .debug_line_str
* RzBinReloc: Add section_vaddr
* Fix info->offset_comp_dir
* Fix convert_raw in loclists and rnglists
* Remove macro `UX_OR` and relocate support for read_address
* Add RzBinDwarfLineHdr->encoding
* Remove macro 'OK_None'
* Fix loclists and rnglists
* Allow void typedef
* Fix DW_AT_name reference DW_AT_specification
2023-09-28 10:15:42 +08:00
billow
5999d3e824
DWARF support for load zlib and zstd compressed section (#3795) 2023-08-29 07:23:48 +08:00
billow
8e29b959b8 DWARF improve DWARF5 support and refactor
- `RZ_PROJECT_VERSION` 14
- Add `RzCallable`.has_unspecified_parameters
- Add `RzAnalysis`.debug_info
- Add `RzAnalysisVarStorageType` composite and `eval` `pending`
- Support for parse DWARF section "debug_loclists", "debug_ranges", "debug_rnglists"
- Partial support for eval DWARF expr_loc
- Support for anonymous Type, function variable, struct member
- Cache all DWARF information in `RzAnalysisDebugInfo` and remove `SDB` based caching.
- Add arm32, arm64, TriCore DWARF register name
- Fix same name basetype
2023-08-25 23:32:05 +08:00
Florian Märkl
f4796c5e66 Populate Mach-O relocs from chained fixups
Chained fixups are essentially a new kind of relocs, so it makes sense
to also represent them as RzBinRelocs. Currently the results are
sometimes less meaningful than the reloc info that was parsed before
from indirectsyms in such cases, as chained imports are not parsed yet
and thus the target symbols of bind relocs are not yet known, hence the
temporarily BROKEN tests.
2023-06-25 19:39:56 +08:00
Florian Märkl
4fd9cd7cc1
Extend Mach-O platform recognition (#3599)
Some identical code from both mach-o 32 and 64 has been moved to
mach0_common.c to avoid duplicate compilation.
rz_mach0_platform_to_string() now recognizes all known platforms and the
information is shown as the subsys in the i command.
The "os" value was previously unreliably and ios sometimes showed as
"ios" and sometimes as "darwin" depending on the binary. Now the os is
"darwin" for all platforms. ios-* syscall files have thus been removed
as only darwin-* ones will be used.
2023-06-23 13:28:41 +00:00
wargio
c85b1afa4c Rewrite how bins are loaded into RzBinObject
This commit rewrites completely how RzBinPlugin are used to load info
into the RzBinObject structure.

Main changes are:
- Avoid looping multiple times to set the same data:
  now the data is cycled only once to rebase addresses, demangle strings
  and to make each loaded structure similar to each other.

- rz_bin_demangle is now demangling only strings:
  the old implementation was a hack over a hack to add classes & methods
  into the RzBinObject while demangling a string.
  This allowed methods and classes to be added to RzBinObject when for
  example invoking `is` or other printing commands.
  This was meant to be an "optimization" to avoid looping and doing
  things on-the-fly.

- Now the demangling is done after guessing the language used in the bin.
  This is done to avoid looping to various demanglers hoping that a
  string is going to be correctly demangled.
  After each string is demangled, the string is given to the language
  related function which adds classes, methods and fields into the
  RzBinObject fields.

- Swift handling is a special case, since the demangler can be disabled
  via -Duse_swift_demangler.
  The issue with the swift demangler is that is not correctly demangling
  strings and outputting swift code, but instead is creating something
  that sometimes works, sometimes doesn't.
  Also the old code only added fields and never methods for "reasons",
  and the new code just uses what the old code was doing as is.

- The new code also takes advantage of the language detection, which now
  happens before the demangling of symbols, imports and relocs.
2023-06-01 23:16:09 +08:00
Florian Märkl
4e5857cacf
Meson refactor: collect modules in dict and centralize config (#2945)
Duplicated code for pkg-config and cmake configuration is avoided by
letting every rizin module register itself in a global dictionary
called "modules" which is then iterated in one place to perform any
shared logic, inspired by how qemu handles multiple targets in its meson
build system.

This is an almost pure refactor, so the resulting .pc/.cmake files
should be identical with the following exceptions:
- rz_reg.pc does not have plugindir anymore as rz_reg has no plugins.
- Some other modules have their dependencies in .pc files altered to be
  consistent with cmake.
2022-08-20 19:59:27 +02:00
Riccardo Schirone
a689f0a86e librz: refactor a bit how plugins are built
Rely on RZ_ARRAY_SIZE to add librz plugins instead of NULL terminators.
2022-07-20 22:04:02 +02:00
Riccardo Schirone
fd3a79f9e3 bin: remove Ldr plugins
RzBinLdrPlugins were not used. There was just one for Linux, but it was
not doing anything.
2022-07-20 22:04:02 +02:00
Riccardo Schirone
8939fdbd7d
Use add_global_arguments instead of passing cflags/ldflags all around (#2812)
See also 66a0e22293/docs/TESTING_WITH_SANITIZERS.md (clang)
2022-07-17 21:33:51 +08:00
Giovanni
648882d544
Add libmspack and add idpx to extracts compressed pdb (#2728)
* Add libmspack, cabextract and add idpx to extracts compressed pdb
* Remove cabextract from CIs since it is not anymore required.
2022-06-27 23:52:07 +02:00
Giovanni
6567e6ba4e
Multithread string search (#2665) 2022-06-27 23:34:08 +02:00
Peiwei Hu
f8b6af26f6 Split RzBin PE parser into smaller pieces 2022-06-27 22:17:39 +08:00
Dean
bf2871c7eb
Add dotnet PE support (#2528)
* Add CIL support

* refactor dotnet parsing to pe/dotnet.c
* parse PE CLR metatables (based on yara implementation)
* use CLR methoddefs to add binsymbols (including method namespace/class)
* parse CLR method headers
* CIL disassembler using .NET opcodes.def
* CIL analysis plugin
2022-06-21 09:20:47 +08:00
Anton Kochkov
a1c2ed18d7
rz_buf_{read,write}_XX_offset() API to track the offset (#2604) 2022-05-13 21:54:40 +08:00
Riccardo Schirone
ce6ac3e467 meson: use major/minor only in the lib soversion 2022-05-10 21:04:43 +02:00
wargio
4a06141377 Fix 2128 - Parse go.buildinfo and set compiler value under iI 2022-05-03 12:13:22 +02:00
Giovanni
bfec86a12e
Add option to install sigdb systemwise and custom user location for additional signatures (#2328) 2022-02-28 14:32:38 +01:00
Riccardo Schirone
6f40dfe493
Move remaining things from shlr/ to meson subprojects (#2126)
* Move binrz meson directives to binrz/ dir

* Move rizin-shell-parser to a subproject

* Move bochs to a meson subproject

* Move rzqnx to meson subproject

* Move winkd to a meson subproject

* Move rzar to a meson subproject

* Move rzw32dbg_wrap to a meson subproject

* Move ptrace-wrap to a meson subproject

* Move rzgdb to a meson subproject

* Rename w32dbg_wrap to rzw32dbg_wrap

* Update CODEOWNERS

* Remove old references to shlr

* Move shlr/heap stuff in core and remove shlr/arm

* Move spp to a meson subproject

* Remove last references to shlr

* Remove use_webui option

* Move include files directives to librz/include/meson.build

* Move librz meson directives into librz/meson.build

* Handle d/ directories inside the specific module meson.build

* Move plugins listing to specific module meson.build

* Move rzheap to its own subproject

* Fix js linter and licenses

* Use meson.override_dependency for all rz_ modules
2021-12-22 09:20:39 +08:00
Riccardo Schirone
47e1cb8335
Provide CMake config files for CMake projects (#2057)
* Remove wrong librz.pc.in file
* Add plugindir variable to .pc files to allow easy plugin configuration
* Add CMake config files to find Rizin in CMake projects
* Add CI jobs to check cmake files
* Provide workaround for mesonbuild/meson#9702
* Use .lib suffix and no prefix on MSVC to make CMake files work
* Disable cmake files on static libraries build
2021-12-17 09:16:25 +00:00
Khairul Azhar Kasmiran
906ece4211
Add asan build for clang (#1910) 2021-11-17 21:02:02 +08:00
Florian Märkl
20783f9302
Refactor bin_xnu_kernelcache to use VFiles instead of IO Hacks (#1908) 2021-10-31 09:01:15 +01:00
Alexis Ehret
988202fec4 Refactor and move get_targets_map_base to elf_map.c 2021-10-20 11:12:11 +02:00
Basstorm
19a6a929f9
Rewrite PDB parser ##bin (#1517)
* Rewrite PDB parser to become endianess-independent
* Use type pretty-printing API
* Use `RzCmdStateOutput` instead of `RzOutputMode` to solve invalid JSON issue
* Move PDB-related print functions to `cpdb.c`
* Use flag API instead of calling commands from the code
* Separate printing from parsing and applying the type information
* Delete useless `main.c`
2021-10-09 16:57:29 +08:00
Giovanni
e224ee7b28
Add demangling as plugins and libdemangle as external dependency (#1656)
* Added demangling as plugins and libdemangle as external dependency
* Added iDl to return the list of demanglers
* moved demangling tests into rz-libdemangle and keep only bin tests
2021-10-01 10:45:38 +00:00
Anton Kochkov
f20a449858
Read PE header properly (#1763) 2021-09-29 08:58:49 +08:00
Alexis Ehret
01b6e60775
Refactor elf plugin interface (#1728)
* get_sdb
* check_buffer
* load_buffer
* baddr
* boffset
* binsym
* entries
* headers
* create
* fields
2021-09-28 13:36:46 +08:00
Florian Märkl
d116fe3bdc Refactor macho relocs patching and convert to vfiles 2021-09-26 10:45:40 +02:00
Florian Märkl
abc62b3093 Split off macho relocs code 2021-09-26 10:45:40 +02:00
wargio
7146b3af75 Revert "Added support to swift demangling (#1595)"
This reverts commit b6259bd31f.
2021-09-06 17:09:51 +02:00
Giovanni
b6259bd31f
Added support to swift demangling (#1595) 2021-09-06 15:14:14 +02:00
Alexis Ehret
9dc52e193b
Refactor DT_HASH and DT_GNU_HASH in librz/bin/format/elf_hash.c (#1453) 2021-08-15 12:26:34 +00:00
Alexis Ehret
3b09213cde Move elf arm functions in librz/bin/format/elf/elf_arm.c 2021-08-09 16:55:02 +02:00
Alexis Ehret
f43cc01b99 Refactor symbols and imports loading ##refactor 2021-07-19 12:20:42 +08:00
Alexis Ehret
8ca6d3e598 Refactor how strtab are stored in ELFOBJ ##refactor 2021-06-26 22:24:26 +02:00
Alexis Ehret
ee777302fc Remove RzBinWrite from librz/bin and rz-bin ##refactor 2021-06-22 18:09:56 +02:00
Alexis Ehret
9061691753 Refactor add new type RzBinElfSegment ##refactor 2021-06-18 18:43:11 +02:00