[C] nm, readelf, objdump, size

링킹 관련 object file을 다루는 binutils 몇가지를 설명하고 command 예제를 보인다.

nm: object 파일 내의 symbol 을 나열한다.

nm dasomoli.o

readelf: symbol table을 보인다.

readelf -s dasomoli.o
readelf -hSl dasomoli.o

몇가지 옵션은 다음과 같다.

  -h --file-header       Display the ELF file header
  -l --program-headers   Display the program headers
     --segments          An alias for --program-headers
  -S --section-headers   Display the sections' header
     --sections          An alias for --section-headers
  -s --syms              Display the symbol table
     --symbols           An alias for --syms
     --dyn-syms          Display the dynamic symbol table
     --lto-syms          Display LTO symbol tables
     --sym-base=[0|8|10|16]
                         Force base for symbol sizes.  The options are
                         mixed (the default), octal, decimal, hexadecimal.

objdump: object file 내의 machine level 명령 및 그 disassembly를 보인다. macOS에서는 gobjdump를 사용한다.

objdump -d dasomoli.o

다음과 같이 -s -j 옵션으로 section 내용 확인이 가능하다. -s 는 선택된 section의 모든 내용을 보여 준다. -j <section> 은 section의 내용을 모두 표시한다.

objdump -s -j .data dasomoli.out

-S 옵션으로는 source disassembly 내용을 표시한다.

objdump -S dasomoli.out

size: static memory layout에 해당하는 세그먼트를 살펴볼 수 있다. POSIX utility program이다. macOS에도 있다.

size dasomoli.out
size -m dasomoli.out

Transmission SSL 설정하기

토렌트 머신으로 사용할 때 Transmission을 설치해서 사용한다. 우분투에서도 https://blog.dasomoli.org/raspberrypi-torrent-%eb%a8%b8%ec%8b%a0-%eb%a7%8c%eb%93%a4%ea%b8%b0/ 의 내용을 그대로 설정하면 된다. 이대로 설정하면 http 프로토콜을 이용하게 되는데, 여기서 한 단계 더 나아가서 SSL 설정을 통해 https를 쓰도록 설정하자. letsencrypt 인증서를 사용하는 certbot을 사용하면, 설정은 매우 간단하다.

# certbot --apache

실행 예제 화면은 다음과 같다.

root@bamtol:/etc/letsencrypt# certbot --apache
Saving debug log to /var/log/letsencrypt/letsencrypt.log

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: blog.dasomoli.org
2: torrent.dasomoli.org
3: www.dasomoli.org
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 2

Requesting a certificate for torrent.dasomoli.org

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/torrent.dasomoli.org/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/torrent.dasomoli.org/privkey.pem
This certificate expires on 2023-06-07.
These files will be updated when the certificate renews.

Deploying certificate
Successfully deployed certificate for torrent.dasomoli.org to /etc/apache2/sites-available/torrent.dasomoli.org-le-ssl.conf
Congratulations! You have successfully enabled HTTPS on https://torrent.dasomoli.org

NEXT STEPS:
- The certificate will need to be renewed before it expires. Certbot can automatically renew the certificate in the background, but you may need to take steps to enable that functionality. See https://certbot.org/renewal-setup for instructions.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

그럼 /etc/apache2/sites-enabled/torrent.dasomoli.org-le-ssl.conf 파일이 생성되는데 여기에 SSLProxyEngine on 옵션을 추가해준다. 그럼 이렇게 된다.

<IfModule mod_ssl.c>
<VirtualHost *:443>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName torrent.dasomoli.org
        ServerAdmin dasomoli@gmail.com

        ProxyPass / http://localhost:9000/
        ProxyPassReverse / http://localhost:9000/

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/torrent.log
        CustomLog ${APACHE_LOG_DIR}/torrent.access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf


SSLCertificateFile /etc/letsencrypt/live/torrent.dasomoli.org/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/torrent.dasomoli.org/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLProxyEngine on
</VirtualHost>
</IfModule>

이게 끝. apache2 서비스를 재시작한 후 https로 접근한다.

[WordPress] 워드프레스 이전 후 카테고리와 댓글 수 이상 문제 해결 방법

워드프레스를 이전하고 나서, 카테고리가 제대로 나타나지 않는다거나, 카테고리 내의 글 갯수가 이상하게 표시되는 경우, 댓글이 이상한 경우 등이 있다.

https://www.wpbeginner.com/wp-tutorials/how-to-fix-category-and-comment-count-after-wordpress-import/ 의 방법을 따르면 된다.

요약하면 UpdraftPlus를 이용해서 사이트 백업 후, 다음 파일을 wordpress 디렉토리 내부에 comments-fix.php로 저장한 후 이를 브라우저에서 로딩해서 실행한다. 내부의 DB_HOST, DB_USER, DB_PASSWORD, DB_NAME 등을 바꾼다. 나의 경우, “localhost”, “dasomoli”, “PASSWORD”, “wordpress” 로 바꿔주었다.

<?php
include("wp-config.php");
$myConnection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD)) {  die('Could not connect: ' . mysqli_error());  }
if (!mysqli_select_db($myConnection, DB_NAME)) {  die('Could not connect: ' . mysqli_error());  }
  
$result = mysqli_query($myConnection, "SELECT term_taxonomy_id FROM ".$table_prefix."term_taxonomy");
while ($row = mysqli_fetch_array($result)) {
  $term_taxonomy_id = $row['term_taxonomy_id'];
  echo "term_taxonomy_id: ".$term_taxonomy_id." count = ";
  $countresult = mysqli_query($myConnection, "SELECT count(*) FROM ".$table_prefix."term_relationships WHERE term_taxonomy_id = '$term_taxonomy_id'");
  $countarray = mysqli_fetch_array($countresult);
  $count = $countarray[0];
  echo $count."<br />";
 mysqli_query($myConnection, "UPDATE ".$table_prefix."term_taxonomy SET count = '$count' WHERE term_taxonomy_id = '$term_taxonomy_id'");
        }
  
$result = mysqli_query($myConnection, "SELECT ID FROM ".$table_prefix."posts");
while ($row = mysqli_fetch_array($result)) {
  $post_id = $row['ID'];
  echo "post_id: ".$post_id." count = ";
  $countresult = mysqli_query($myConnection, "SELECT count(*) FROM ".$table_prefix."comments WHERE comment_post_ID = '$post_id' AND comment_approved = 1");
  $countarray = mysqli_fetch_array($countresult);
  $count = $countarray[0];
  echo $count."<br />";
  mysqli_query($myConnection, "UPDATE ".$table_prefix."posts SET comment_count = '$count' WHERE ID = '$post_id'");
        }
?>

dd로 disk 전체 백업하기

$ sudo apt-get install ntfs-3g
$ sudo fdisk -l
$ sudo mkdir /mnt/sdb5 && sudo mount.ntfs-3g /dev/sdb5 /mnt/sdb5
$ sudo dd if=/dev/sdc of=/mnt/sdb5/IMAGE_NAME_HERE.img bs=64K status=progress

미니 PC를 하나 샀다. SATA M.2 SSD 안에 Windows 10 Pro 정품이 깔려 있다. 이미지로 만들어서 백업하고 우분투 깔아야겠다.

[Mac] 여러 사용자로 Homebrew 사용하기

https://www.codejam.info/2021/11/homebrew-multi-user.html 에서 설명하는 바로는 multi user 로서 사용하는 것은 좋지 않다고 한다. 한 사용자로 통일해서 사용하는 것이 좋다고 한다. 나는 첫번째 사용자로 dasomoli를 사용하므로 이에 맞춰서 설정하였다. alias 설정을 다음처럼 한다.

~/.zshrc 아래의 plugins 에 brew를 추가한다.

plugins=(
        git
        brew
)

그리고 ~/.zshrc 가장 아래에 alias를 추가한다.

alias brew='sudo -Hu dasomoli brew'

[WordPress] json 파일을 업로드하고 싶을 때

아래 플러그인을 설치하면 된다.

설치 후 “설정” 메뉴에 보면, “MIME 유형 설정”이 생긴다.

그 후 아래처럼 “json = application/json”을 추가한 후 “저장” 하면 된다. “보안 옵션”도 켰다.

[Windows 10] Sandbox 켜기

  1. “제어판” / “프로그램” / “프로그램 및 기능” 에서 “Windows 기능 켜기/끄기” 선택
Windows 기능 켜기/끄기를 선택

2. “Windows 샌드박스”에 체크 후 “확인”

Windows 샌드박스를 체크

3. 다시 시작