Reversing Gobs

xuanbao · · 45 次点击    
<p>The other day I had to read gob data that I didn&#39;t actually know the structure for. I looked around and there wasn&#39;t a particularly good tool that I could find for easily recreating a gob (there is a Debug function hidden in the encoding/gob package that you can get to if you rebuild the package, but it doesn&#39;t print values correctly and it is kinda ugly with type definitions), so I wrote this and figured I&#39;d share it just in case anyone else runs into that problem. <a href=""></a> It should work on valid gobs, but I haven&#39;t tested too much with anything very complex as my use case was pretty straightforward.</p> <hr/>**评论:**<br/><br/>robpike: <pre><p>The last time I used Debug, which was quite a while ago I admit, it worked fine. If it&#39;s broken I&#39;d like to see it fixed. Please file an issue with a reproducible example at <a href=""></a>.</p></pre>my_dev_acct: <pre><p>Interesting. It definitely doesn&#39;t work correctly with the gobs I was trying to read. It was only confusing numeric values (as far as I could tell). uints were being printed as ints. I&#39;ll see if I can find an example. I didn&#39;t think to file a bug report because I assume the Go authors were already tepid about exposing it since you have to remove the build guard from the file (EDIT: oh oops I didn&#39;t realize I was responding to Rob Pike, I guess I&#39;ll file a report).</p> <p>EDIT2: Here is a much more stripped down one, these bytes: <code>0x3 0x6 0x0 0xa</code> should decode as a uint 10 but they print as 5 (they&#39;re being decoded as an int, <code>10 &gt;&gt; 1</code>).</p> <pre><code>Start of debugging 5 </code></pre></pre>sh41: <pre><p>Please file it, as Rob asked:</p> <blockquote> <p>Please file an issue with a reproducible example at <a href="" rel="nofollow"></a>.</p> </blockquote></pre>my_dev_acct: <pre><p>Yep, I will.</p></pre>sh41: <pre><p>Thanks, this can be useful.</p> <p>I&#39;ve always known it&#39;s possible. From <code>encoding/gob</code> doc:</p> <blockquote> <p>A stream of gobs is self-describing. Each data item in the stream is preceded by a specification of its type, expressed in terms of a small set of predefined types.</p> </blockquote> <p>So it&#39;s always been just a matter of implementing that. I&#39;m surprised it wasn&#39;t done earlier. But thanks for your work doing it now.</p></pre>my_dev_acct: <pre><p>I guess it isn&#39;t a particularly common need. The only other reference I even saw to someone wanting to do it was met with mostly silence a couple years ago.</p> <p>I thought it was a little odd that <a href="" rel="nofollow">Debug</a> function that I found in the Go source didn&#39;t work correctly, but I guess that is why you have to rebuild the package yourself to use it.</p></pre>hobbified: <pre><p>Thank you, this is genuinely useful.</p></pre>
45 次点击  
加入收藏 微博
0 回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传