`
cloudhe
  • 浏览: 107670 次
  • 性别: 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脱壳教程。

    cmake-3.15.0-Linux-x86_64.tar.gz

    CMake是一款强大的跨平台构建系统,它用于管理软件项目的构建过程。CMake并不是一个实际的编译器,而是一个生成构建脚本的工具,这些脚本可以被各种平台上的构建工具(如Make、Visual Studio、Ninja等)理解和执行。...

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

    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的原理了。

    Python 元组拆包示例(Tuple Unpacking)

    元组拆包(Tuple Unpacking)是Python中的一项特性,允许将元组的元素分别赋值给多个变量。例如,如果有元组 `(x, y, z)`,可以通过 `a, b, c = x, y, z` 的方式同时赋值给多个变量,实现元组元素的快速分配。这在...

    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 ...

    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-a-string

    标题中的"unpacking-a-string"通常指的是在编程中将一个字符串分解或解析成多个部分的过程。在Java中,这可以通过各种方法实现,如使用split()函数、正则表达式或者手动遍历字符数组。让我们深入探讨一下这个主题。 ...

    脱壳破解工具箱 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