`
cloudhe
  • 浏览: 107394 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

A problem in unpacking strings

阅读更多

If a string to be packed is shorter than its format, it'll be followed by '\x00's when unpacked.

One example, in which every length of the string fits the format:

python 代码
  1. >>> import struct  
  2. >>> fmt = 'c4si5s'   
  3. >>>   
  4. >>> verb = 'have'   
  5. >>> p = struct.pack(fmt, 'i', verb, 2, 'books')   
  6. >>> unp = struct.unpack(fmt, p)   
  7. >>> p   
  8. 'ihave\x00\x00\x00\x02\x00\x00\x00books'   
  9. >>> unp   
  10. ('i', 'have', 2, 'books')   
  11. >>> unp[1] == verb   
  12. True

Here comes another one, in which the verb is changed into 'had':

python 代码
  1. >>> import struct  
  2. >>> fmt = 'c4si5s'   
  3. >>>   
  4. >>> verb = 'had'       
  5. >>> p = struct.pack(fmt, 'i', verb, 2, 'books')       
  6. >>> unp = struct.unpack(fmt, p)       
  7. >>> p       
  8. 'ihad\x00\x00\x00\x00\x02\x00\x00\x00books'       
  9. >>> unp       
  10. ('i', 'had\x00', 2, 'books')       
  11. >>> unp[1] == verb       
  12. False      
  13. >>>       
  14. >>> unp[1].rstrip('\x00') == verb       
  15. True    

 So .rstrip('\x00') in Line14 is needed now.

分享到:
评论

相关推荐

    The art of unpacking

    本文档主要介绍了脱壳的原理及应用,很有研究价值不仅仅是简单的脱壳教程

    REA Unpacking Ebook

    国外的脱壳电子书,This ebook is a collection of unpacking tutorials, papers and documents gathered together by members of Reverse Engineering Association (REA).这是一本逆向工程相关的脱壳教程、论文和...

    unpacking Gie Protector 0.2 by Azmo

    A Shockwave Flash movie tutorial showing a method of unpacking Gie Protector 0.2.

    解决git pull unpacking卡住.rar

    解决git pull的时候卡在unpacking 58%(57/97),网上搜了很多资料,都没有中文的详细解决案例,这里在这里上传一段总结,本来想写blog的。但因为没有分了,坑你们一分吧。但绝对实用。

    snd-reversingwithlena-tutorials-qq664849305.rar

    逆向工程核心原理推荐的初学者入门必学视频。 A collection of tutorials ...39. Inlining a blowfish scheme in a packed & CRC protected dll + unpacking Asprotect SKE 2.2 40. Obfuscation and algorithm hiding

    Python Cookbook, 2nd Edition

    Interpolating Variables in a Stringin Python 2.4 Recipe 1.18. Replacing Multiple Patterns in a Single Pass Recipe 1.19. Checking a String for Any of Multiple Endings Recipe 1.20. Handling ...

    Python Cookbook英文版

    Python Cookbook英文版 Table of Contents Foreword Preface 1. Python Shortcuts ... 10.11 Unpacking a Multipart MIME Message 10.12 Module: PyHeartBeat-Detecting Inactive Computers ...

    ZProtect 1.6 Unpacking(全面分析ZP 1.6)

    该技术资料由cektop大神(ZPfixer作者)编写,非常经典的ZProtect 1.6脱壳教程。

    unpacking-a-string

    unpacking-a-string

    cmake-3.15.0-Linux-x86_64.tar.gz

    cmake 3.15,适合Linux的通用版本。cmake作为跨平台的事实编译构建标准工具,提供了非常便利的功能。可惜官方下载太慢了,这里提供cmake的下载,方便广大c/c++玛侬!

    虚拟声卡-用于服务器电脑

    a problem, enter some words related to the problem and appropriate pages will be displayed. Of course, search feature will not help if you enter a question like "how can I use it?". It only finds ...

    Apress.PHP.7.Solutions.4th.Edition.rar

    The problem is, you're not a programmer and the thought of writing code sends a chill up your spine. Or maybe you've dabbled a bit in PHP and MySQL, but you can't get past baby steps. If this ...

    VMP-unpacking.rar_VMProtect2.46_vmp3 0脱壳_vmp3.0-3.0x脱壳_vmp一键脱壳_v

    VMP脱壳,通过简单几个步骤不需要去研究VMP的原理了。

    Manning.Arduino.in.Action.2013

    You'll start with the basics—unpacking your board and using a simple program to make something happen. Then, you'l attempt progressively more complex projects as you connect Arduino to motors, LCD ...

    Python 元组拆包示例(Tuple Unpacking)

    今天小编就为大家分享一篇Python 元组拆包实例(Tuple Unpacking),具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

    Arduino in Action

    You'll start with the basics—unpacking your board and using a simple program to make something happen. Then, you'l attempt progressively more complex projects as you connect Arduino to motors, LCD ...

    [Arduino.in.Action(2013.5)].Martin.Evans.文字版

    Arduino in Action is a hands-on guide to prototyping and building DIY electronics. You’ll start with the basics—unpacking your board and using a simple program to make something happen. Then, you’...

    脱壳破解工具箱 UnPacKinG & CrAcKinG TooLs v2o12.o1.13

    脱壳破解工具箱 UnPacKinG & CrAcKinG TooLs v2o12.o1.13.rar

    Mastering.Python.Lists.1519586078

    Unpacking a List Iterating Over a List Copying a List Subscripts Ranges Range Slices List Slices List Comprehensions Boolean Operations Processing Multiple Lists Sorting Adding Items To A List ...

    Import REConstructor 1.7 FINAL

    you should be familiar a bit with manual unpacking first (some tutorials are easy to find on internet). <br>Features: <br>- Imports - An original tree view - 2 different methods to find ...

Global site tag (gtag.js) - Google Analytics