Skip to content

Instantly share code, notes, and snippets.

@shibukk
Created December 6, 2021 14:11
Show Gist options
  • Save shibukk/e858f1578aab99aeed7959dcb465f057 to your computer and use it in GitHub Desktop.
Save shibukk/e858f1578aab99aeed7959dcb465f057 to your computer and use it in GitHub Desktop.
str = "Hello, world!"
=> "Hello, world!"
# object_idを確認してみる
str.object_id
=> 47382279417420
# 左にビットシフトしてオブジェクトの実際のポインタ値を確認してみる
str.object_id.<<(1).to_s(16)
=> "563017dddc98"
# https://udzura.hatenablog.jp/entry/2021/07/28/154920
# を参考にアドレスに文字列が格納されているか確認してみる
mem = open("/proc/self/mem")
=> #<File:/proc/self/mem>
# 先ほど確認したポインタ値までseekする
mem.seek 0x0000563017dddc98
=> 0
dump = mem.read 32
=> "e@S\x00\x00\x00\x00\x00\xC8{\xA5\x170V\x00\x00Hello, world!\x00\x00\x00"
dump.unpack "Q! Q! Z*"
=> [5455973, 94764555140040, "Hello, world!"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment