{"id":3838,"date":"2021-09-16T19:13:54","date_gmt":"2021-09-16T19:13:54","guid":{"rendered":"https:\/\/nenadnoveljic.com\/blog\/?p=3838"},"modified":"2021-09-16T19:21:58","modified_gmt":"2021-09-16T19:21:58","slug":"converting-offsets-in-disassembled-code-to-hexadecimal-notation","status":"publish","type":"post","link":"https:\/\/nenadnoveljic.com\/blog\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\/","title":{"rendered":"Converting Offsets in Disassembled Code to Hexadecimal Notation"},"content":{"rendered":"<p>gdb disassembler prints program offsets in decimal notation, for example:<\/p>\n<pre><code>gdb <a href=\"https:\/\/raw.githubusercontent.com\/nenadnoveljic\/blogs\/master\/converting_high_resolution_time_to_a_human_readable_format\/get_t_hr0.c\">get_t_hr0<\/a> &lt;&lt;&lt; \"disas main\"\n\n...\n0x0000000000400ff8 &lt;+54&gt;:      jle    0x400fd3 <main+17>\n0x0000000000400ffa &lt;+56&gt;:      mov    -0x30(%rbp),%rax\n0x0000000000400ffe &lt;+60&gt;:      cvtsi2sd %rax,%xmm0\n0x0000000000401003 &lt;+65&gt;:      movsd  -0x27b(%rip),%xmm1        # 0x400d90\n0x000000000040100b &lt;+73&gt;:      mulsd  %xmm0,%xmm1\n0x000000000040100f &lt;+77&gt;:      mov    -0x28(%rbp),%rax\n0x0000000000401013 &lt;+81&gt;:      cvtsi2sd %rax,%xmm0\n0x0000000000401018 &lt;+86&gt;:      addsd  %xmm1,%xmm0\n0x000000000040101c &lt;+90&gt;:      cvttsd2si %xmm0,%rax\n0x0000000000401021 &lt;+95&gt;:      mov    %rax,-0x18(%rbp)\n0x0000000000401025 &lt;+99&gt;:      cvtsi2sdq -0x18(%rbp),%xmm0\n0x000000000040102b &lt;+105&gt;:     cvtsi2sdq -0x8(%rbp),%xmm1\n0x0000000000401031 &lt;+111&gt;:     movsd  -0x2a1(%rip),%xmm2        # 0x400d98\n0x0000000000401039 &lt;+119&gt;:     divsd  %xmm2,%xmm1\n0x000000000040103d &lt;+123&gt;:     subsd  %xmm1,%xmm0\n0x0000000000401041 &lt;+127&gt;:     cvttsd2si %xmm0,%rax\n0x0000000000401046 &lt;+132&gt;:     mov    %rax,-0x20(%rbp)\n0x000000000040104a &lt;+136&gt;:     mov    -0x20(%rbp),%rax\n0x000000000040104e &lt;+140&gt;:     mov    %rax,%rsi\n0x0000000000401051 &lt;+143&gt;:     mov    $0x400d88,%edi\n0x0000000000401056 &lt;+148&gt;:     mov    $0x0,%eax\n0x000000000040105b &lt;+153&gt;:     callq  0x400e10 <printf@plt>\n0x0000000000401060 &lt;+158&gt;:     mov    $0x0,%eax\n0x0000000000401065 &lt;+163&gt;:     leaveq\n0x0000000000401066 &lt;+164&gt;:     retq<\/printf@plt><\/main+17><\/code><\/pre>\n<p>All other OS diagnostic tools, like pstack, DTrace, etc. use hexadecimal notation, e.g.:<\/p>\n<pre><code> $ pstack 7633\n7633:   ora_lgwr_DB1\n 00007ffc40b7741a portfs   (5, 4, 7fffbfff8400, 2, 3b9aba60, 7fffbfff8420)\n 00000000061dc6bd sskgpwwait () + dd\n 00000000061dc2a3 skgpwwait () + c3\n 00000000063de2c4 ksliwat () + 9b4\n 00000000063dd4af kslwaitctx () + af\n 00000000073094b7 ksarcv () + 167\n 00000000073082b9 ksbabs () + 2b9\n 00000000073064b1 ksbrdp () + 561\n 0000000006f0e779 opirip () + 2b9\n 00000000061277b0 opidrv () + 160\n 00000000061275c7 sou2o () + 97\n 0000000006127394 opimai_real () + a4\n 0000000006126eeb ssthrdmain () + 26b\n 0000000006126c59 main () + a9\n 0000000007787eb4 ???????? ()<\/code><\/pre>\n<p>This mismatch is inconvenient when reverse engineering and troubleshooting.<\/p>\n<p>I wrote a one-liner that converts the offsets in disassembled code to hexadecimal notation:<\/p>\n<pre><code>gdb <a href=\"https:\/\/raw.githubusercontent.com\/nenadnoveljic\/blogs\/master\/converting_high_resolution_time_to_a_human_readable_format\/get_t_hr0.c\">get_t_hr0<\/a> &lt;&lt;&lt; \"disas main\" | perl -pe 's\/\\+[0-9]+&gt;\/sprintf \"+0x%x&gt;\", $&amp;\/ge'\n...\n0x0000000000400ff8 &lt;+0x36&gt;:  jle    0x400fd3 <main+0x11>\n0x0000000000400ffa &lt;+0x38&gt;:  mov    -0x30(%rbp),%rax\n0x0000000000400ffe &lt;+0x3c&gt;:  cvtsi2sd %rax,%xmm0\n0x0000000000401003 &lt;+0x41&gt;:  movsd  -0x27b(%rip),%xmm1        # 0x400d90\n0x000000000040100b &lt;+0x49&gt;:  mulsd  %xmm0,%xmm1\n0x000000000040100f &lt;+0x4d&gt;:  mov    -0x28(%rbp),%rax\n0x0000000000401013 &lt;+0x51&gt;:  cvtsi2sd %rax,%xmm0\n0x0000000000401018 &lt;+0x56&gt;:  addsd  %xmm1,%xmm0\n0x000000000040101c &lt;+0x5a&gt;:  cvttsd2si %xmm0,%rax\n0x0000000000401021 &lt;+0x5f&gt;:  mov    %rax,-0x18(%rbp)\n0x0000000000401025 &lt;+0x63&gt;:  cvtsi2sdq -0x18(%rbp),%xmm0\n0x000000000040102b &lt;+0x69&gt;:  cvtsi2sdq -0x8(%rbp),%xmm1\n0x0000000000401031 &lt;+0x6f&gt;:  movsd  -0x2a1(%rip),%xmm2        # 0x400d98\n0x0000000000401039 &lt;+0x77&gt;:  divsd  %xmm2,%xmm1\n0x000000000040103d &lt;+0x7b&gt;:  subsd  %xmm1,%xmm0\n0x0000000000401041 &lt;+0x7f&gt;:  cvttsd2si %xmm0,%rax\n0x0000000000401046 &lt;+0x84&gt;:  mov    %rax,-0x20(%rbp)\n0x000000000040104a &lt;+0x88&gt;:  mov    -0x20(%rbp),%rax\n0x000000000040104e &lt;+0x8c&gt;:  mov    %rax,%rsi\n0x0000000000401051 &lt;+0x8f&gt;:  mov    $0x400d88,%edi\n0x0000000000401056 &lt;+0x94&gt;:  mov    $0x0,%eax\n0x000000000040105b &lt;+0x99&gt;:  callq  0x400e10 <printf@plt>\n0x0000000000401060 &lt;+0x9e&gt;:  mov    $0x0,%eax\n0x0000000000401065 &lt;+0xa3&gt;:  leaveq\n0x0000000000401066 &lt;+0xa4&gt;:  retq\n<\/printf@plt><\/main+0x11><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Perl one-liner for converting offsets in gdb output to hex <a href=\"https:\/\/nenadnoveljic.com\/blog\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\/\" class=\"more-link\">Continue Reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[27],"tags":[],"class_list":["post-3838","post","type-post","status-publish","format-standard","hentry","category-gdb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Converting Offsets in Disassembled Code to Hexadecimal Notation - All-round Database Topics<\/title>\n<meta name=\"description\" content=\"Perl one-liner for converting offsets in gdb output to hex\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/nenadnoveljic.com\/blog\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Converting Offsets in Disassembled Code to Hexadecimal Notation - All-round Database Topics\" \/>\n<meta property=\"og:description\" content=\"Perl one-liner for converting offsets in gdb output to hex\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nenadnoveljic.com\/blog\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\/\" \/>\n<meta property=\"og:site_name\" content=\"All-round Database Topics\" \/>\n<meta property=\"article:published_time\" content=\"2021-09-16T19:13:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-09-16T19:21:58+00:00\" \/>\n<meta name=\"author\" content=\"Nenad Noveljic\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@NenadNoveljic\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nenad Noveljic\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\\\/\"},\"author\":{\"name\":\"Nenad Noveljic\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\"},\"headline\":\"Converting Offsets in Disassembled Code to Hexadecimal Notation\",\"datePublished\":\"2021-09-16T19:13:54+00:00\",\"dateModified\":\"2021-09-16T19:21:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\\\/\"},\"wordCount\":55,\"commentCount\":0,\"articleSection\":[\"gdb\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\\\/\",\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\\\/\",\"name\":\"Converting Offsets in Disassembled Code to Hexadecimal Notation - All-round Database Topics\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#website\"},\"datePublished\":\"2021-09-16T19:13:54+00:00\",\"dateModified\":\"2021-09-16T19:21:58+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\"},\"description\":\"Perl one-liner for converting offsets in gdb output to hex\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Converting Offsets in Disassembled Code to Hexadecimal Notation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/\",\"name\":\"All-round Database Topics\",\"description\":\"Nenad Noveljic\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\",\"name\":\"Nenad Noveljic\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g\",\"caption\":\"Nenad Noveljic\"},\"sameAs\":[\"nenad-noveljic-9b746a6\",\"https:\\\/\\\/x.com\\\/NenadNoveljic\"],\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/author\\\/nenad\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Converting Offsets in Disassembled Code to Hexadecimal Notation - All-round Database Topics","description":"Perl one-liner for converting offsets in gdb output to hex","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/nenadnoveljic.com\/blog\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\/","og_locale":"en_US","og_type":"article","og_title":"Converting Offsets in Disassembled Code to Hexadecimal Notation - All-round Database Topics","og_description":"Perl one-liner for converting offsets in gdb output to hex","og_url":"https:\/\/nenadnoveljic.com\/blog\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\/","og_site_name":"All-round Database Topics","article_published_time":"2021-09-16T19:13:54+00:00","article_modified_time":"2021-09-16T19:21:58+00:00","author":"Nenad Noveljic","twitter_card":"summary_large_image","twitter_creator":"@NenadNoveljic","twitter_misc":{"Written by":"Nenad Noveljic","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/nenadnoveljic.com\/blog\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\/#article","isPartOf":{"@id":"https:\/\/nenadnoveljic.com\/blog\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\/"},"author":{"name":"Nenad Noveljic","@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa"},"headline":"Converting Offsets in Disassembled Code to Hexadecimal Notation","datePublished":"2021-09-16T19:13:54+00:00","dateModified":"2021-09-16T19:21:58+00:00","mainEntityOfPage":{"@id":"https:\/\/nenadnoveljic.com\/blog\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\/"},"wordCount":55,"commentCount":0,"articleSection":["gdb"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/nenadnoveljic.com\/blog\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/nenadnoveljic.com\/blog\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\/","url":"https:\/\/nenadnoveljic.com\/blog\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\/","name":"Converting Offsets in Disassembled Code to Hexadecimal Notation - All-round Database Topics","isPartOf":{"@id":"https:\/\/nenadnoveljic.com\/blog\/#website"},"datePublished":"2021-09-16T19:13:54+00:00","dateModified":"2021-09-16T19:21:58+00:00","author":{"@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa"},"description":"Perl one-liner for converting offsets in gdb output to hex","breadcrumb":{"@id":"https:\/\/nenadnoveljic.com\/blog\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nenadnoveljic.com\/blog\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/nenadnoveljic.com\/blog\/converting-offsets-in-disassembled-code-to-hexadecimal-notation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/nenadnoveljic.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Converting Offsets in Disassembled Code to Hexadecimal Notation"}]},{"@type":"WebSite","@id":"https:\/\/nenadnoveljic.com\/blog\/#website","url":"https:\/\/nenadnoveljic.com\/blog\/","name":"All-round Database Topics","description":"Nenad Noveljic","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/nenadnoveljic.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa","name":"Nenad Noveljic","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g","caption":"Nenad Noveljic"},"sameAs":["nenad-noveljic-9b746a6","https:\/\/x.com\/NenadNoveljic"],"url":"https:\/\/nenadnoveljic.com\/blog\/author\/nenad\/"}]}},"_links":{"self":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/3838","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/comments?post=3838"}],"version-history":[{"count":1,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/3838\/revisions"}],"predecessor-version":[{"id":3913,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/3838\/revisions\/3913"}],"wp:attachment":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/media?parent=3838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/categories?post=3838"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/tags?post=3838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}