skip to main content
article
Public Access

Polymorphic type inference for machine code

Published:02 June 2016Publication History
Skip Abstract Section

Abstract

For many compiled languages, source-level types are erased very early in the compilation process. As a result, further compiler passes may convert type-safe source into type-unsafe machine code. Type-unsafe idioms in the original source and type-unsafe optimizations mean that type information in a stripped binary is essentially nonexistent. The problem of recovering high-level types by performing type inference over stripped machine code is called type reconstruction, and offers a useful capability in support of reverse engineering and decompilation. In this paper, we motivate and develop a novel type system and algorithm for machine-code type inference. The features of this type system were developed by surveying a wide collection of common source- and machine-code idioms, building a catalog of challenging cases for type reconstruction. We found that these idioms place a sophisticated set of requirements on the type system, inducing features such as recursively-constrained polymorphic types. Many of the features we identify are often seen only in expressive and powerful type systems used by high-level functional languages. Using these type-system features as a guideline, we have developed Retypd: a novel static type-inference algorithm for machine code that supports recursive types, polymorphism, and subtyping. Retypd yields more accurate inferred types than existing algorithms, while also enabling new capabilities such as reconstruction of pointer const annotations with 98% recall. Retypd can operate on weaker program representations than the current state of the art, removing the need for high-quality points-to information that may be impractical to compute.

References

  1. ISO/IEC TR 19768:2007: Technical report on C++ library extensions, 2007.Google ScholarGoogle Scholar
  2. O. Agesen. Constraint-based type inference and parametric polymorphism. In Static Analysis Symposium, pages 78–100, 1994.Google ScholarGoogle ScholarCross RefCross Ref
  3. R. M. Amadio and L. Cardelli. Subtyping recursive types. ACM Transactions on Programming Languages and Systems, 15(4):575–631, 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. L. O. Andersen. Program analysis and specialization for the C programming language. PhD thesis, University of Cophenhagen, 1994.Google ScholarGoogle Scholar
  5. G. Balakrishnan, R. Gruian, T. Reps, and T. Teitelbaum. CodeSurfer/x86 – a platform for analyzing x86 executables. In Compiler Construction, pages 250–254, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. G. Balakrishnan and T. Reps. Analyzing Memory Accesses in x86 Executables, in Compiler Construction, pages 5–23, 2004.Google ScholarGoogle ScholarCross RefCross Ref
  7. A. Carayol and M. Hague. Saturation algorithms for modelchecking pushdown systems. In International Conference on Automata and Formal Languages, pages 1–24, 2014.Google ScholarGoogle Scholar
  8. D. Caucal. On the regular structure of prefix rewriting. Theoretical Computer Science, 106(1):61–86, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. J. Eifrig, S. Smith, and V. Trifonov. Sound polymorphic type inference for objects. In Object-Oriented Programming, Systems, Languages, and Applications, pages 169–184, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. K. ElWazeer, K. Anand, A. Kotha, M. Smithson, and R. Barua. Scalable variable and data type detection in a binary rewriter. In Programming Language Design and Implementation, pages 51–60, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. J. S. Foster, R. Johnson, J. Kodumal, and A. Aiken. Flowinsensitive type qualifiers. ACM Transactions on Programming Languages and Systems, 28(6):1035–1087, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. M. Fähndrich and A. Aiken. Making set-constraint program analyses scale. In Workshop on Set Constraints, 1996.Google ScholarGoogle Scholar
  13. D. Gopan, E. Driscoll, D. Nguyen, D. Naydich, A. Loginov, and D. Melski. Data-delineation in software binaries and its application to buffer-overrun discovery. In International Conference on Software Engineering, pages 145–155, 2015. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. D. Greenfieldboyce and J. S. Foster. Type qualifier inference for Java. In Object-Oriented Programming, Systems, Languages, and Applications, pages 321–336, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Hex-Rays. Hex-Rays IdaPro. http://www.hex-rays.com/ products/ida/, 2015.Google ScholarGoogle Scholar
  16. D. Kozen, J. Palsberg, and M. I. Schwartzbach. Efficient recursive subtyping. Mathematical Structures in Computer Science, 5(01):113–125, 1995.Google ScholarGoogle ScholarCross RefCross Ref
  17. J. Lee, T. Avgerinos, and D. Brumley. TIE: Principled reverse engineering of types in binary programs. In Network and Distributed System Security Symposium, pages 251–268, 2011.Google ScholarGoogle Scholar
  18. J. Lim and T. Reps. TSL: A system for generating abstract interpreters and its application to machine-code analysis. ACM Transactions on Programming Languages and Systems, 35(1): 4, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Z. Lin, X. Zhang, and D. Xu. Automatic reverse engineering of data structures from binary execution. In Network and Distributed System Security Symposium, 2010.Google ScholarGoogle Scholar
  20. S. Marlow, A. R. Yakushev, and S. Peyton Jones. Faster laziness using dynamic pointer tagging. In International Conference on Functional Programming, pages 277–288, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. L. Mauborgne and X. Rival. Trace partitioning in abstract interpretation based static analyzers. In Programming Languages and Systems, pages 5–20, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. M. Noonan, A. Loginov, and D. Cok. Polymorphic type inference for machine code (extended version). URL http: //arxiv.org/abs/1603.05495. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. J. Palsberg and P. O’Keefe. A type system equivalent to flow analysis. ACM Transactions on Programming Languages and Systems, 17(4):576–599, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. J. Palsberg, M. Wand, and P. O’Keefe. Type inference with non-structural subtyping. Formal Aspects of Computing, 9(1): 49–67, 1997.Google ScholarGoogle ScholarCross RefCross Ref
  25. F. Pottier and D. Rémy. The essence of ML type inference. In B. C. Pierce, editor, Advanced Topics in Types and Programming Languages, chapter 10. MIT Press, 2005.Google ScholarGoogle Scholar
  26. J. Rehof and M. Fähndrich. Type-based flow analysis: From polymorphic subtyping to cfl-reachability. In Principles of Programming Languages, pages 54–66, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. J. Richard Büchi. Regular canonical systems. Archive for Mathematical Logic, 6(3):91–111, 1964.Google ScholarGoogle ScholarCross RefCross Ref
  28. E. Robbins, J. M. Howe, and A. King. Theory propagation and rational-trees. In Principles and Practice of Declarative Programming, pages 193–204, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. M. Robertson. A Brief History of InvSqrt. PhD thesis, University of New Brunswick, 2012.Google ScholarGoogle Scholar
  30. E. J. Schwartz, J. Lee, M. Woo, and D. Brumley. Native x86 decompilation using semantics-preserving structural analysis and iterative control-flow structuring. In USENIX Security Symposium, pages 353–368, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. M. Siff, S. Chandra, T. Ball, K. Kunchithapadam, and T. Reps. Coping with type casts in C. In Software Engineering—ESEC/FSE’99, pages 180–198, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. A. Slowinska, T. Stancescu, and H. Bos. Howard: A dynamic excavator for reverse engineering data structures. In Network and Distributed System Security Symposium, 2011.Google ScholarGoogle Scholar
  33. B. Steensgaard. Points-to analysis in almost linear time. In Principles of Programming Languages, pages 32–41, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Z. Su, A. Aiken, J. Niehren, T. Priesnitz, and R. Treinen. The first-order theory of subtyping constraints. In Principles of Programming Languages, pages 203–216, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Polymorphic type inference for machine code

              Recommendations

              Comments

              Login options

              Check if you have access through your login credentials or your institution to get full access on this article.

              Sign in

              Full Access

              • Published in

                cover image ACM SIGPLAN Notices
                ACM SIGPLAN Notices  Volume 51, Issue 6
                PLDI '16
                June 2016
                726 pages
                ISSN:0362-1340
                EISSN:1558-1160
                DOI:10.1145/2980983
                • Editor:
                • Andy Gill
                Issue’s Table of Contents
                • cover image ACM Conferences
                  PLDI '16: Proceedings of the 37th ACM SIGPLAN Conference on Programming Language Design and Implementation
                  June 2016
                  726 pages
                  ISBN:9781450342612
                  DOI:10.1145/2908080
                  • General Chair:
                  • Chandra Krintz,
                  • Program Chair:
                  • Emery Berger

                Copyright © 2016 ACM

                Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

                Publisher

                Association for Computing Machinery

                New York, NY, United States

                Publication History

                • Published: 2 June 2016

                Check for updates

                Qualifiers

                • article

              PDF Format

              View or Download as a PDF file.

              PDF

              eReader

              View online with eReader.

              eReader