File: errno.py

package info (click to toggle)
pwntools 4.15.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,508 kB
  • sloc: python: 59,870; ansic: 48,351; asm: 45,047; sh: 396; makefile: 256
file content (49 lines) | stat: -rw-r--r-- 941 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from __future__ import absolute_import, print_function

import argparse
import os
import errno

from pwnlib.commandline import common

parser = common.parser_commands.add_parser(
    'errno',
    help = 'Prints out error messages',
    description = 'Prints out error messages'
)

parser.add_argument(
    'error', help='Error message or value', type=str
)

def main(args):
  try:
    value = int(args.error, 0)

    if value < 0:
      value = -value

    if 0x100000000 - value < 0x200:
      value = 0x100000000 - value

    if value not in errno.errorcode:
      print("No errno for %s" % value)
      return

    name = errno.errorcode[value]

  except ValueError:
    name = args.error.upper()

    if not hasattr(errno, name):
      print("No errno for %s" % name)
      return

    value = getattr(errno, name)


  print('#define', name, value)
  print(os.strerror(value))

if __name__ == '__main__':
    common.main(__file__, main)