LoginSignup
1
0

wslで逆アセンブラ

Last updated at Posted at 2024-05-23

概要

逆アセンブラ、見つけたので、WSLでやってみた。

参考にしたページ

環境

windows11
wsl1(wsl2じゃない)
ubuntu 20.04

手順

  • build-essentialをインストールする。
$ sudo apt install build-essential
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  bzip2 dpkg-dev fakeroot libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libdpkg-perl
  libfakeroot libfile-fcntllock-perl lto-disabled-list
Suggested packages:
  bzip2-doc debian-keyring bzr
The following NEW packages will be installed:
  build-essential bzip2 dpkg-dev fakeroot libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl
  libdpkg-perl libfakeroot libfile-fcntllock-perl lto-disabled-list
0 upgraded, 11 newly installed, 0 to remove and 110 not upgraded.
Need to get 1402 kB of archives.
After this operation, 5882 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libdpkg-perl all 1.21.1ubuntu2.3 [237 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy/main amd64 bzip2 amd64 1.0.8-5build1 [34.8 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy/main amd64 lto-disabled-list all 24 [12.5 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 dpkg-dev all 1.21.1ubuntu2.3 [922 kB]
Get:5 http://archive.ubuntu.com/ubuntu jammy/main amd64 build-essential amd64 12.9ubuntu3 [4744 B]
Get:6 http://archive.ubuntu.com/ubuntu jammy/main amd64 libfakeroot amd64 1.28-1ubuntu1 [31.5 kB]
Get:7 http://archive.ubuntu.com/ubuntu jammy/main amd64 fakeroot amd64 1.28-1ubuntu1 [60.4 kB]
Get:8 http://archive.ubuntu.com/ubuntu jammy/main amd64 libalgorithm-diff-perl all 1.201-1 [41.8 kB]
Get:9 http://archive.ubuntu.com/ubuntu jammy/main amd64 libalgorithm-diff-xs-perl amd64 0.04-6build3 [11.9 kB]
Get:10 http://archive.ubuntu.com/ubuntu jammy/main amd64 libalgorithm-merge-perl all 0.08-3 [12.0 kB]
Get:11 http://archive.ubuntu.com/ubuntu jammy/main amd64 libfile-fcntllock-perl amd64 0.22-3build7 [33.9 kB]
Fetched 1402 kB in 2s (563 kB/s)
Selecting previously unselected package libdpkg-perl.
(Reading database ... 29947 files and directories currently installed.)
Preparing to unpack .../00-libdpkg-perl_1.21.1ubuntu2.3_all.deb ...
Unpacking libdpkg-perl (1.21.1ubuntu2.3) ...
Selecting previously unselected package bzip2.
Preparing to unpack .../01-bzip2_1.0.8-5build1_amd64.deb ...
Unpacking bzip2 (1.0.8-5build1) ...
Selecting previously unselected package lto-disabled-list.
Preparing to unpack .../02-lto-disabled-list_24_all.deb ...
Unpacking lto-disabled-list (24) ...
Selecting previously unselected package dpkg-dev.
Preparing to unpack .../03-dpkg-dev_1.21.1ubuntu2.3_all.deb ...
Unpacking dpkg-dev (1.21.1ubuntu2.3) ...
Selecting previously unselected package build-essential.
Preparing to unpack .../04-build-essential_12.9ubuntu3_amd64.deb ...
Unpacking build-essential (12.9ubuntu3) ...
Selecting previously unselected package libfakeroot:amd64.
Preparing to unpack .../05-libfakeroot_1.28-1ubuntu1_amd64.deb ...
Unpacking libfakeroot:amd64 (1.28-1ubuntu1) ...
Selecting previously unselected package fakeroot.
Preparing to unpack .../06-fakeroot_1.28-1ubuntu1_amd64.deb ...
Unpacking fakeroot (1.28-1ubuntu1) ...
Selecting previously unselected package libalgorithm-diff-perl.
Preparing to unpack .../07-libalgorithm-diff-perl_1.201-1_all.deb ...
Unpacking libalgorithm-diff-perl (1.201-1) ...
Selecting previously unselected package libalgorithm-diff-xs-perl.
Preparing to unpack .../08-libalgorithm-diff-xs-perl_0.04-6build3_amd64.deb ...
Unpacking libalgorithm-diff-xs-perl (0.04-6build3) ...
Selecting previously unselected package libalgorithm-merge-perl.
Preparing to unpack .../09-libalgorithm-merge-perl_0.08-3_all.deb ...
Unpacking libalgorithm-merge-perl (0.08-3) ...
Selecting previously unselected package libfile-fcntllock-perl.
Preparing to unpack .../10-libfile-fcntllock-perl_0.22-3build7_amd64.deb ...
Unpacking libfile-fcntllock-perl (0.22-3build7) ...
Setting up lto-disabled-list (24) ...
Setting up libfile-fcntllock-perl (0.22-3build7) ...
Setting up libalgorithm-diff-perl (1.201-1) ...
Setting up bzip2 (1.0.8-5build1) ...
Setting up libfakeroot:amd64 (1.28-1ubuntu1) ...
Setting up fakeroot (1.28-1ubuntu1) ...
update-alternatives: using /usr/bin/fakeroot-sysv to provide /usr/bin/fakeroot (fakeroot) in auto mode
Setting up libdpkg-perl (1.21.1ubuntu2.3) ...
Setting up libalgorithm-diff-xs-perl (0.04-6build3) ...
Setting up libalgorithm-merge-perl (0.08-3) ...
Setting up dpkg-dev (1.21.1ubuntu2.3) ...
Setting up build-essential (12.9ubuntu3) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.4) ...
$ gcc
gcc: fatal error: no input files
compilation terminated.
$ g++
g++: fatal error: no input files
compilation terminated.
$ cc
cc: fatal error: no input files
compilation terminated.
$ gcc
gcc: fatal error: no input files
compilation terminated.
$ gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

  • cmakeをインストールする。
$ sudo apt install cmake
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  cmake-data dh-elpa-helper emacsen-common libarchive13 libjsoncpp25 librhash0
Suggested packages:
  cmake-doc ninja-build cmake-format lrzip
The following NEW packages will be installed:
  cmake cmake-data dh-elpa-helper emacsen-common libarchive13 libjsoncpp25 librhash0
0 upgraded, 7 newly installed, 0 to remove and 110 not upgraded.
Need to get 7518 kB of archives.
After this operation, 32.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 libarchive13 amd64 3.6.0-1ubuntu1 [368 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy/main amd64 libjsoncpp25 amd64 1.9.5-3 [80.0 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy/main amd64 librhash0 amd64 1.4.2-1ubuntu1 [125 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy/main amd64 dh-elpa-helper all 2.0.9ubuntu1 [7610 B]
Get:5 http://archive.ubuntu.com/ubuntu jammy/main amd64 emacsen-common all 3.0.4 [14.9 kB]
Get:6 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 cmake-data all 3.22.1-1ubuntu1.22.04.2 [1913 kB]
Get:7 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 cmake amd64 3.22.1-1ubuntu1.22.04.2 [5010 kB]
Fetched 7518 kB in 13s (563 kB/s)
Selecting previously unselected package libarchive13:amd64.
(Reading database ... 30493 files and directories currently installed.)
Preparing to unpack .../0-libarchive13_3.6.0-1ubuntu1_amd64.deb ...
Unpacking libarchive13:amd64 (3.6.0-1ubuntu1) ...
Selecting previously unselected package libjsoncpp25:amd64.
Preparing to unpack .../1-libjsoncpp25_1.9.5-3_amd64.deb ...
Unpacking libjsoncpp25:amd64 (1.9.5-3) ...
Selecting previously unselected package librhash0:amd64.
Preparing to unpack .../2-librhash0_1.4.2-1ubuntu1_amd64.deb ...
Unpacking librhash0:amd64 (1.4.2-1ubuntu1) ...
Selecting previously unselected package dh-elpa-helper.
Preparing to unpack .../3-dh-elpa-helper_2.0.9ubuntu1_all.deb ...
Unpacking dh-elpa-helper (2.0.9ubuntu1) ...
Selecting previously unselected package emacsen-common.
Preparing to unpack .../4-emacsen-common_3.0.4_all.deb ...
Unpacking emacsen-common (3.0.4) ...
Selecting previously unselected package cmake-data.
Preparing to unpack .../5-cmake-data_3.22.1-1ubuntu1.22.04.2_all.deb ...
Unpacking cmake-data (3.22.1-1ubuntu1.22.04.2) ...
Selecting previously unselected package cmake.
Preparing to unpack .../6-cmake_3.22.1-1ubuntu1.22.04.2_amd64.deb ...
Unpacking cmake (3.22.1-1ubuntu1.22.04.2) ...
Setting up libarchive13:amd64 (3.6.0-1ubuntu1) ...
Setting up emacsen-common (3.0.4) ...
Setting up dh-elpa-helper (2.0.9ubuntu1) ...
Setting up libjsoncpp25:amd64 (1.9.5-3) ...
Setting up librhash0:amd64 (1.4.2-1ubuntu1) ...
Setting up cmake-data (3.22.1-1ubuntu1.22.04.2) ...
Setting up cmake (3.22.1-1ubuntu1.22.04.2) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.4) ...
$ cmake --version
cmake version 3.22.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).
  • git cloneする。
$ git clone https://github.com/Koukyosyumei/MyDisassembler.git
Cloning into 'MyDisassembler'...
remote: Enumerating objects: 804, done.
remote: Counting objects: 100% (55/55), done.
remote: Compressing objects: 100% (44/44), done.
remote: Total 804 (delta 26), reused 26 (delta 11), pack-reused 749
Receiving objects: 100% (804/804), 914.08 KiB | 7.55 MiB/s, done.
Resolving deltas: 100% (494/494), done.
  • cmakeする。
$ cd MyDisassembler
$ ./script/build.sh
-bash: ./script/build.sh: Permission denied
$ cd script
$ chmod 755 build.sh
$ cd ../
$ ./script/build.sh
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMake inatall directory: include
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ore/git/MyDisassembler/build
[ 20%] Building CXX object script/CMakeFiles/mydisas.dir/main.cpp.o
[ 40%] Linking CXX executable mydisas
[ 40%] Built target mydisas
[ 60%] Building CXX object test/CMakeFiles/mydisas-test.dir/main.cpp.o
/home/ore/git/MyDisassembler/test/main.cpp:1:10: fatal error: gtest/gtest.h: No such file or directory
    1 | #include "gtest/gtest.h"
      |          ^~~~~~~~~~~~~~~
compilation terminated.
gmake[2]: *** [test/CMakeFiles/mydisas-test.dir/build.make:76: test/CMakeFiles/mydisas-test.dir/main.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:160: test/CMakeFiles/mydisas-test.dir/all] Error 2
gmake: *** [Makefile:101: all] Error 2

  • エラーでたので、いじる。
$ ./script/build.sh
-- CMake inatall directory: include
-- Found Python: /usr/bin/python3.10 (found version "3.10.12") found components: Interpreter
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ore/git/MyDisassembler/build
Consolidate compiler generated dependencies of target mydisas
[ 15%] Built target mydisas
[ 23%] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[ 30%] Linking CXX static library ../../../lib/libgtest.a
[ 30%] Built target gtest
[ 38%] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[ 46%] Linking CXX static library ../../../lib/libgtest_main.a
[ 46%] Built target gtest_main
[ 53%] Building CXX object test/CMakeFiles/mydisas-test.dir/main.cpp.o
[ 61%] Building CXX object test/CMakeFiles/mydisas-test.dir/decoder.cpp.o
[ 69%] Linking CXX executable mydisas-test
[ 69%] Built target mydisas-test
[ 76%] Building CXX object _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.o
[ 84%] Linking CXX static library ../../../lib/libgmock.a
[ 84%] Built target gmock
[ 92%] Building CXX object _deps/googletest-build/googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.o
[100%] Linking CXX static library ../../../lib/libgmock_main.a
[100%] Built target gmock_main
$ ./build/script/mydisas example/jmp.o
terminate called after throwing an instance of 'std::runtime_error'
  what():  Failed to open object file: example/jmp.o
Aborted

  • exampleのjmp.oがないので、作る。
$ ls
call.s  jmp.s  lock.s  one_byte.s  one_byte_imm.s  rep.s  two_byte_opcode.s
$ as -o jmp.o jmp.s
$ ls
call.s  jmp.o  jmp.s  lock.s  one_byte.s  one_byte_imm.s  rep.s  two_byte_opcode.s
$ cd ../
$ ./build/script/mydisas example/jmp.o

section: .text ----

40 <_start>:
 40: mov  eax 0x00000000                      ( b8 0 0 0 0 )
 45: cmp  eax 0x00                            ( 83 f8 0 )
 48: jz 4e <zero_label> ; relative offset = 4 ( 74 4 )
 4a: jmp 52 <end_label> ; relative offset = 6 ( eb 6 )
 4c: jmp 40 <_start> ; relative offset = -14  ( eb f2 )

4e <zero_label>:
 4e: push  rsp                                ( 54 )
 4f: xor  eax eax                             ( 31 c0 )
 51: ret                                      ( c3 )

52 <end_label>:
 52: push  rdi                                ( 57 )
 53: xor  ecx ecx                             ( 31 c9 )
 55: ret                                      ( c3 )
-------------------
Done!

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0