Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Windows on ARM #1502

Merged
merged 19 commits into from
Nov 24, 2021
Merged

Add support for Windows on ARM #1502

merged 19 commits into from
Nov 24, 2021

Conversation

GustavoLCR
Copy link
Contributor

@GustavoLCR GustavoLCR commented Aug 23, 2021

Your checklist for this pull request

  • I've read the guidelines for contributing to this repository
  • I made sure to follow the project's coding style
  • I've added tests that prove my fix is effective or that my feature works (if possible)
  • I've updated the documentation and the rizin book with the relevant information (if needed)

Detailed description

  • Building this requires Meson >= 0.60.1 (mesonbuild/meson@6a1157b)
  • Fixes building for Windows on ARM
  • Some fixes for ARM PE binaries
  • Many fixes for debugging on ARM

Test plan

Manually tested

Closing issues

None

Copy link
Member

@XVilka XVilka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a new file sys/cross-arm64-windows.txt. I wonder if it make sense to document how to use it/build for the Windows ARM64 in BUILDING.md

librz/debug/p/native/windows/windows_debug.c Outdated Show resolved Hide resolved
@XVilka

This comment has been minimized.

librz/bin/p/bin_pe.inc Outdated Show resolved Hide resolved
Copy link
Member

@ret2libc ret2libc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so I can take a bit of time for manual testing as well on my systems :)

@XVilka XVilka changed the title Add support for Windows on Arm Add support for Windows on ARM Aug 23, 2021
@XVilka XVilka added port Support for various OS and environments Windows ARM labels Aug 23, 2021
@ret2libc ret2libc modified the milestones: 0.3.0, 0.4.0 Aug 23, 2021
Copy link
Member

@XVilka XVilka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"cl" "-Ilibrz/debug\rz_debug.dll.p" "-I." "-I.." "-I..\librz\include" "-I..\librz\bin\format\elf" "-I..\shlr\qnx\include" "-I..\shlr\gdb\include" "-I..\shlr\gdb\include\gdbclient" "-I..\shlr\gdb\include\gdbserver" "-I..\shlr\bochs\include" "-I..\shlr\winkd" "-Isubprojects\sdb" "-I..\subprojects\sdb" "-Isubprojects\sdb\src" "-I..\subprojects\sdb\src" "-I..\librz\analysis\arch\gb" "-I..\librz\analysis\arch\hexagon" "-I..\shlr\w32dbg_wrap\include" "/MD" "/nologo" "/showIncludes" "/W2" "/O2" "/Gw" "-DRZ_PLUGIN_INCORE=1" "/Fdlibrz/debug\rz_debug.dll.p\p_debug_gdb.c.pdb" /Folibrz/debug/rz_debug.dll.p/p_debug_gdb.c.obj "/c" ../librz/debug/p/debug_gdb.c
D:\a\rizin\rizin\librz\debug\p\native\bt/windows-all.c(82): error C2065: 'IMAGE_FILE_MACHINE_i386': undeclared identifier

One more thing. This pull request combines both fixes for analysis (and PE binary parsing) and debugger. I suggest to extract the analysis fix to the separate PR and add a new test for it. Then we can include this analysis fix into 0.3.0, while ARM debugger has to wait for 0.4.0, ok? cc @ret2libc

@XVilka
Copy link
Member

XVilka commented Aug 24, 2021

In theory it shouldn't be affected by your code, but it only happens in your branch only (I saw it even before the PR, it appears quite consistently), see:

[XX] C:\projects\rizin\test\db\tools\rz_ax rz-ax -t "1234567890 GMT-1"
ANSICON=1 RZ_NOPLUGINS=1 rizin -escr.utf8=0 -escr.color=0 -escr.interactive=0 -N -Qc '!rz-ax -t "1234567890 GMT-1" | cut -d " " -f 1,2' =
-- stdout
--- expected
+++ actual
@@ -1,1 +1,1 @@
-Fri Feb
+Mon Aug

I guess it's either timezone problem or something unitialized. Might be related to #982 (comment)

@@ -497,16 +497,26 @@ static inline void *rz_new_copy(int size, void *data) {
#endif
#else
#ifdef _MSC_VER
#ifdef _WIN64
#if defined(_M_X64) || defined(_M_AMD64)
#define RZ_SYS_ARCH "x86"
#define RZ_SYS_BITS (RZ_SYS_BITS_32 | RZ_SYS_BITS_64)
#define RZ_SYS_ENDIAN 0
Copy link
Member

@XVilka XVilka Nov 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Meson could get endian value from .endian() function, see:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be done in a separate PR though, obviously.

Copy link
Member

@XVilka XVilka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Code looks OK.
  • Tested on Windows 10 x86_64 - debugging and heap parsing works fine.

@yossizap could you please confirm if these changes are fine?

@XVilka XVilka merged commit 53a7694 into dev Nov 24, 2021
@XVilka XVilka deleted the windows-on-arm branch November 24, 2021 12:13
thestr4ng3r pushed a commit that referenced this pull request Nov 24, 2021
* Support building for Windows on ARM

* Fix usage of reserved function name on ARM
* Fix architecture dependent `CONTEXT` fields access

* Fixes for debugging on Windows on ARM

* Fix breakpoint behavior on windows on ARM
* Fix register profile when debugging
* Remove `drx` error message if not supported
* Add support for hardware breakpoints
* Disable support for hardware single-stepping

* Fix Windows Message breakpoints on ARM

* Fix software single-stepping on return instruction on ARM

* Consider link register as destination for return instructions

* Fix setting debug bits to 16

* Rename `r12` to `ip` for windows arm register profile

* Remove debug bits hardcoding on windows

* Add 32bit registers to Windows ARM64 register profile

* Fix software step breakpoint alignment when entering thumb mode

* Define `RZ_TEST_ARCH` for `arm` and `arm64`

* Use `StackWalk64` API for backtracing on Windows

* Fix software single-stepping ARM in thumb mode

* Sync `asm.bits` with debugger

* Cleanup windows_debug.c

* Add SPDX for cross-arm64-windows.txt

* Add floating point control register flags

* Fix Windows Arm register profile alignment

* Keep `drx` warning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants