angr 9.2.174__cp310-abi3-win_amd64.whl → 9.2.176__cp310-abi3-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of angr might be problematic. Click here for more details.

Files changed (55) hide show
  1. angr/__init__.py +1 -1
  2. angr/__main__.py +32 -2
  3. angr/analyses/calling_convention/calling_convention.py +12 -0
  4. angr/analyses/cfg/cfg_base.py +1 -1
  5. angr/analyses/cfg/cfg_fast.py +27 -8
  6. angr/analyses/complete_calling_conventions.py +39 -26
  7. angr/analyses/decompiler/ail_simplifier.py +13 -11
  8. angr/analyses/decompiler/ccall_rewriters/rewriter_base.py +5 -1
  9. angr/analyses/decompiler/clinic.py +54 -40
  10. angr/analyses/decompiler/optimization_passes/ite_region_converter.py +3 -3
  11. angr/analyses/decompiler/optimization_passes/lowered_switch_simplifier.py +2 -2
  12. angr/analyses/decompiler/peephole_optimizations/__init__.py +4 -4
  13. angr/analyses/decompiler/peephole_optimizations/{inlined_wstrcpy.py → inlined_wcscpy.py} +16 -8
  14. angr/analyses/decompiler/peephole_optimizations/{inlined_wstrcpy_consolidation.py → inlined_wcscpy_consolidation.py} +13 -13
  15. angr/analyses/decompiler/ssailification/rewriting_engine.py +14 -1
  16. angr/analyses/decompiler/structured_codegen/c.py +6 -5
  17. angr/analyses/decompiler/structuring/dream.py +2 -2
  18. angr/analyses/decompiler/structuring/phoenix.py +101 -23
  19. angr/analyses/decompiler/utils.py +1 -1
  20. angr/analyses/smc.py +1 -1
  21. angr/analyses/stack_pointer_tracker.py +4 -3
  22. angr/analyses/typehoon/lifter.py +29 -18
  23. angr/analyses/typehoon/simple_solver.py +157 -50
  24. angr/analyses/typehoon/translator.py +34 -34
  25. angr/analyses/typehoon/typeconsts.py +33 -15
  26. angr/analyses/typehoon/typevars.py +9 -2
  27. angr/analyses/variable_recovery/engine_ail.py +4 -2
  28. angr/analyses/variable_recovery/engine_base.py +4 -1
  29. angr/analyses/variable_recovery/variable_recovery_fast.py +3 -1
  30. angr/calling_conventions.py +2 -1
  31. angr/engines/icicle.py +4 -4
  32. angr/engines/vex/claripy/ccall.py +3 -3
  33. angr/knowledge_plugins/functions/function.py +18 -1
  34. angr/misc/bug_report.py +11 -2
  35. angr/procedures/definitions/__init__.py +88 -20
  36. angr/procedures/definitions/common/glibc.json +3516 -0
  37. angr/procedures/definitions/parse_glibc.py +78 -0
  38. angr/procedures/libc/fgets.py +2 -1
  39. angr/procedures/posix/pthread.py +4 -4
  40. angr/procedures/stubs/format_parser.py +3 -3
  41. angr/rustylib.pyd +0 -0
  42. angr/sim_type.py +73 -11
  43. angr/simos/windows.py +1 -1
  44. angr/storage/memory_mixins/paged_memory/page_backer_mixins.py +1 -1
  45. angr/unicornlib.dll +0 -0
  46. angr/utils/constants.py +1 -1
  47. angr/utils/library.py +1 -0
  48. angr/utils/strings.py +20 -0
  49. {angr-9.2.174.dist-info → angr-9.2.176.dist-info}/METADATA +5 -5
  50. {angr-9.2.174.dist-info → angr-9.2.176.dist-info}/RECORD +54 -52
  51. angr/procedures/definitions/glibc.py +0 -8372
  52. {angr-9.2.174.dist-info → angr-9.2.176.dist-info}/WHEEL +0 -0
  53. {angr-9.2.174.dist-info → angr-9.2.176.dist-info}/entry_points.txt +0 -0
  54. {angr-9.2.174.dist-info → angr-9.2.176.dist-info}/licenses/LICENSE +0 -0
  55. {angr-9.2.174.dist-info → angr-9.2.176.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,78 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+ import sys
5
+ import os
6
+ import json
7
+ from collections import OrderedDict
8
+
9
+ from angr.sim_type import parse_file, ALL_TYPES
10
+
11
+ l = logging.getLogger(name="parse_glibc")
12
+
13
+
14
+ def main():
15
+
16
+ with open(sys.argv[1], encoding="utf-8") as f:
17
+ glibc_decls = f.readlines()
18
+
19
+ protos = {}
20
+ for c_decl in glibc_decls:
21
+ c_decl = c_decl.strip("\n")
22
+
23
+ # preprocessing
24
+ c_decl = c_decl.replace("FILE *", "FILE_t *")
25
+ c_decl = c_decl.replace("const ", "")
26
+ c_decl = c_decl.replace("*restrict ", "* ")
27
+
28
+ try:
29
+ parsed = parse_file(c_decl, predefined_types=ALL_TYPES)
30
+ except Exception as ex: # pylint: disable=broad-exception-caught
31
+ l.warning("Cannot parse the function prototype for %s: %s.", c_decl, str(ex))
32
+ continue
33
+ parsed_decl = parsed[0]
34
+ if not parsed_decl:
35
+ l.warning("Cannot parse the function prototype for %s.", c_decl)
36
+ continue
37
+
38
+ func_name, func_proto = next(iter(parsed_decl.items()))
39
+ protos[func_name] = func_proto
40
+
41
+ # build the dictionary
42
+ d = {
43
+ "_t": "lib",
44
+ "library_names": [
45
+ "libc.so.0",
46
+ "libc.so.1",
47
+ "libc.so.2",
48
+ "libc.so.3",
49
+ "libc.so.4",
50
+ "libc.so.5",
51
+ "libc.so.6",
52
+ "libc.so.7",
53
+ "libc.so",
54
+ ],
55
+ "non_returning": [
56
+ "exit_group",
57
+ "exit",
58
+ "abort",
59
+ "pthread_exit",
60
+ "__assert_fail",
61
+ "longjmp",
62
+ "siglongjmp",
63
+ "__longjmp_chk",
64
+ "__siglongjmp_chk",
65
+ ],
66
+ "functions": OrderedDict(),
67
+ }
68
+ for func_name in sorted(protos):
69
+ proto = protos[func_name]
70
+ d["functions"][func_name] = {"proto": json.dumps(proto.to_json()).replace('"', "'")}
71
+
72
+ os.makedirs("common", exist_ok=True)
73
+ with open("common/glibc.json", "w", encoding="utf-8") as f:
74
+ f.write(json.dumps(d, indent="\t"))
75
+
76
+
77
+ if __name__ == "__main__":
78
+ main()
@@ -10,7 +10,8 @@ class fgets(angr.SimProcedure):
10
10
  # pylint:disable=arguments-differ
11
11
 
12
12
  def run(self, dst, size, file_ptr):
13
- size = size.zero_extend(self.arch.bits - self.arch.sizeof["int"])
13
+ if size.size() < self.arch.bits:
14
+ size = size.zero_extend(self.arch.bits - self.arch.sizeof["int"])
14
15
 
15
16
  # let's get the memory back for the file we're interested in and find the newline
16
17
  fd_offset = io_file_data_for_arch(self.state.arch)["fd"]
@@ -52,20 +52,20 @@ class pthread_cond_signal(angr.SimProcedure):
52
52
 
53
53
  class pthread_mutex_lock(angr.SimProcedure):
54
54
  """
55
- A no-op.
55
+ Always returns 0 (SUCCESS).
56
56
  """
57
57
 
58
58
  def run(self, arg):
59
- pass
59
+ return 0
60
60
 
61
61
 
62
62
  class pthread_mutex_unlock(angr.SimProcedure):
63
63
  """
64
- A no-op.
64
+ Always returns 0 (SUCCESS).
65
65
  """
66
66
 
67
67
  def run(self, arg):
68
- pass
68
+ return 0
69
69
 
70
70
 
71
71
  class pthread_once(angr.SimProcedure):
@@ -99,11 +99,11 @@ class FormatString:
99
99
  elif fmt_spec.spec_type == b"c":
100
100
  s_val = chr(c_val & 0xFF)
101
101
  elif fmt_spec.spec_type == b"x":
102
- s_val = hex(c_val)[2:]
102
+ s_val = f"{c_val:x}"[2:]
103
103
  elif fmt_spec.spec_type == b"o":
104
- s_val = oct(c_val)[2:]
104
+ s_val = f"{c_val:o}"[2:]
105
105
  elif fmt_spec.spec_type == b"p":
106
- s_val = hex(c_val)
106
+ s_val = f"{c_val:x}"
107
107
  else:
108
108
  raise SimProcedureError(f"Unimplemented format specifier '{fmt_spec.spec_type}'")
109
109
 
angr/rustylib.pyd CHANGED
Binary file
angr/sim_type.py CHANGED
@@ -872,6 +872,8 @@ class SimTypePointer(SimTypeReg):
872
872
  self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
873
873
  ): # pylint: disable=unused-argument
874
874
  # if pts_to is SimTypeBottom, we return a void*
875
+ if self.label is not None and name is not None:
876
+ return super().c_repr(name=name, full=full, memo=memo, indent=indent, name_parens=name_parens)
875
877
  if isinstance(self.pts_to, SimTypeBottom):
876
878
  out = "void*"
877
879
  if name is None:
@@ -2192,10 +2194,10 @@ class SimTypeRef(SimType):
2192
2194
  ) -> str: # pylint: disable=unused-argument
2193
2195
  prefix = "unknown"
2194
2196
  if self.original_type is SimStruct:
2195
- prefix = "struct"
2197
+ prefix = "struct "
2196
2198
  if name is None:
2197
2199
  name = ""
2198
- return f"{prefix}{name} {self.name}"
2200
+ return f"{prefix}{self.label} {name}"
2199
2201
 
2200
2202
  def _init_str(self) -> str:
2201
2203
  original_type_name = self.original_type.__name__.split(".")[-1]
@@ -2289,7 +2291,10 @@ STDINT_TYPES = {
2289
2291
  "ssize_t": SimTypeLength(True),
2290
2292
  "ssize": SimTypeLength(False),
2291
2293
  "uintptr_t": SimTypeLong(False),
2292
- "wchar_t": SimTypeShort(True),
2294
+ # wide-char types
2295
+ "wchar_t": SimTypeShort(True, label="wchar_t"),
2296
+ "wint_t": SimTypeInt(True, label="wint_t"),
2297
+ "wctype_t": SimTypeInt(True, label="wctype_t"),
2293
2298
  }
2294
2299
  ALL_TYPES.update(STDINT_TYPES)
2295
2300
 
@@ -2313,6 +2318,8 @@ GLIBC_INTERNAL_BASIC_TYPES = {
2313
2318
  # https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/sysdeps/unix/sysv/linux/x86/bits/siginfo-arch.h#L12
2314
2319
  "__clock_t": ALL_TYPES["uint32_t"],
2315
2320
  "__suseconds_t": ALL_TYPES["int64_t"],
2321
+ "socklen_t": ALL_TYPES["uint32_t"],
2322
+ "mode_t": ALL_TYPES["unsigned int"],
2316
2323
  }
2317
2324
  ALL_TYPES.update(GLIBC_INTERNAL_BASIC_TYPES)
2318
2325
 
@@ -2340,6 +2347,22 @@ GLIBC_EXTERNAL_BASIC_TYPES = {
2340
2347
  "rlim64_t": ALL_TYPES["uint64_t"],
2341
2348
  # https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/bits/types/error_t.h#L22
2342
2349
  "error_t": ALL_TYPES["int"],
2350
+ "sigset_t": ALL_TYPES["int"],
2351
+ "sem_t": ALL_TYPES["int"],
2352
+ "sighandler_t": SimTypePointer(ALL_TYPES["void"], label="sighandler_t"),
2353
+ "comparison_fn_t": SimTypePointer(ALL_TYPES["void"], label="comparison_fn_t"),
2354
+ "DIR": SimStruct({}, name="DIR"),
2355
+ "glob_t": SimStruct({}, name="glob_t"),
2356
+ "glob64_t": SimStruct({}, name="glob64_t"),
2357
+ "__free_fn_t": SimTypePointer(ALL_TYPES["void"], label="__free_fn_t"),
2358
+ "__action_fn_t": SimTypePointer(ALL_TYPES["void"], label="__action_fn_t"),
2359
+ "__ftw_func_t": SimTypePointer(ALL_TYPES["void"], label="__ftw_func_t"),
2360
+ "mbstate_t": SimStruct({}, name="mbstate_t"),
2361
+ "fpos_t": SimStruct({}, name="fpos_t"),
2362
+ "fpos64_t": SimStruct({}, name="fpos64_t"),
2363
+ "regex_t": SimStruct({}, name="regex_t"),
2364
+ "fd_set": SimStruct({}, name="fd_set"),
2365
+ "dev_t": ALL_TYPES["int"],
2343
2366
  }
2344
2367
  ALL_TYPES.update(GLIBC_EXTERNAL_BASIC_TYPES)
2345
2368
 
@@ -3578,6 +3601,15 @@ def _decl_to_type(
3578
3601
  if struct is not None:
3579
3602
  from_global = True
3580
3603
  struct = struct.with_arch(arch)
3604
+ if struct is None:
3605
+ # fallback to using decl.name as key directly
3606
+ struct = ALL_TYPES.get(decl.name)
3607
+ if struct is not None and isinstance(struct, SimStruct):
3608
+ from_global = True
3609
+ struct = struct.with_arch(arch)
3610
+ else:
3611
+ # give up
3612
+ struct = None
3581
3613
  if struct is not None and not isinstance(struct, SimStruct):
3582
3614
  raise AngrTypeError("Provided a non-SimStruct value for a type that must be a struct")
3583
3615
 
@@ -3722,7 +3754,7 @@ def _cpp_decl_to_type(
3722
3754
  for idx, param in enumerate(the_func.parameters):
3723
3755
  arg_type = param.type
3724
3756
  args.append(_cpp_decl_to_type(arg_type, extra_types, opaque_classes=opaque_classes))
3725
- arg_name = param.name if param.name is not None else f"unknown_{idx}"
3757
+ arg_name = param.name if param.name is not None else f"arg_{idx}"
3726
3758
  arg_names.append(arg_name)
3727
3759
 
3728
3760
  args = tuple(args)
@@ -3769,7 +3801,7 @@ def _cpp_decl_to_type(
3769
3801
  for idx, param in enumerate(the_func.parameters):
3770
3802
  arg_type = param.type
3771
3803
  args.append(_cpp_decl_to_type(arg_type, extra_types, opaque_classes=opaque_classes))
3772
- arg_name = param.name if param.name is not None else f"unknown_{idx}"
3804
+ arg_name = param.name if param.name is not None else f"arg_{idx}"
3773
3805
  arg_names.append(arg_name)
3774
3806
 
3775
3807
  args = tuple(args)
@@ -3791,8 +3823,11 @@ def _cpp_decl_to_type(
3791
3823
  elif lbl in ALL_TYPES:
3792
3824
  t = ALL_TYPES[lbl]
3793
3825
  elif opaque_classes is True:
3794
- # create a class without knowing the internal members
3795
- t = SimCppClass(unique_name=lbl, name=lbl, members={}, size=32)
3826
+ # create a struct or a class without knowing the internal members
3827
+ if decl.typename.classkey == "struct":
3828
+ t = SimTypeRef(lbl.removeprefix("struct "), SimStruct)
3829
+ else:
3830
+ t = SimCppClass(unique_name=lbl, name=lbl, members={}, size=32)
3796
3831
  else:
3797
3832
  raise TypeError(f'Unknown type "{lbl}"')
3798
3833
 
@@ -3833,15 +3868,42 @@ def _cpp_decl_to_type(
3833
3868
 
3834
3869
 
3835
3870
  def normalize_cpp_function_name(name: str) -> str:
3836
- # strip access specifiers
3837
- prefixes = ["public:", "protected:", "private:"]
3838
- for pre in prefixes:
3839
- name = name.removeprefix(pre)
3871
+ stripped_any = True
3872
+ while stripped_any:
3873
+ stripped_any = False
3874
+ # strip virtual/static/inline/friend keywords
3875
+ prefixes = ["virtual", "static", "inline", "friend"]
3876
+ for pre in prefixes:
3877
+ new_name = name.removeprefix(pre + " ")
3878
+ if new_name != name:
3879
+ name = new_name
3880
+ stripped_any = True
3881
+
3882
+ # strip access specifiers
3883
+ prefixes = ["public:", "protected:", "private:", "[thunk]:"]
3884
+ for pre in prefixes:
3885
+ new_name = name.removeprefix(pre)
3886
+ if new_name != name:
3887
+ name = new_name
3888
+ stripped_any = True
3889
+
3890
+ new_name = name.strip()
3891
+ if new_name != name:
3892
+ name = new_name
3893
+ stripped_any = True
3894
+
3895
+ if "void (__cdecl *)" in name:
3896
+ name = name.replace("void (__cdecl *)", "void ")
3840
3897
 
3841
3898
  if name.startswith("operator"):
3842
3899
  # the return type is missing; give it a default type
3843
3900
  name = "int " + name
3844
3901
 
3902
+ if " __int" in name:
3903
+ name = name.replace(" __int64 ", " long long ")
3904
+ name = name.replace(" __int32 ", " int ")
3905
+ name = name.replace(" __int16 ", " short ")
3906
+
3845
3907
  return name.removesuffix(";")
3846
3908
 
3847
3909
 
angr/simos/windows.py CHANGED
@@ -440,7 +440,7 @@ class SimWindows(SimOS):
440
440
  :param state: The state to get the syscall number from
441
441
  :param allow_unsupported: Whether to return a "dummy" sycall instead of raising an unsupported exception
442
442
  """
443
- if state.block(state.history.jump_source).bytes.hex() == "cd29": # int 29h
443
+ if state.history.jump_source and state.block(state.history.jump_source).bytes.hex() == "cd29": # int 29h
444
444
  return self.fastfail
445
445
  return None
446
446
 
@@ -192,7 +192,7 @@ class ConcreteBackerMixin(ClemoryBackerMixin):
192
192
 
193
193
  try:
194
194
  backer_iter = self._clemory_backer.backers(addr)
195
- backer_start, backer = next(backer_iter)
195
+ backer_start, _backer = next(backer_iter)
196
196
  except StopIteration:
197
197
  return super()._initialize_page(pageno, permissions=permissions, **kwargs)
198
198
 
angr/unicornlib.dll CHANGED
Binary file
angr/utils/constants.py CHANGED
@@ -6,4 +6,4 @@ MAX_POINTSTO_BITS = -1330 * 8
6
6
 
7
7
 
8
8
  def is_alignment_mask(n):
9
- return n in {0xFFFFFFFFFFFFFFE0, 0xFFFFFFFFFFFFFFF0, 0xFFFFFFE0, 0xFFFFFFF0, 0xFFFFFFFC, 0xFFFFFFF8}
9
+ return n in {0xFFFFFFFFFFFFFFE0, 0xFFFFFFFFFFFFFFF0, 0xFFFFFFC0, 0xFFFFFFE0, 0xFFFFFFF0, 0xFFFFFFFC, 0xFFFFFFF8}
angr/utils/library.py CHANGED
@@ -206,6 +206,7 @@ def get_cpp_function_name(demangled_name: str) -> str:
206
206
  :param demangled_name: The demangled C++ function name.
207
207
  :return: The qualified function name, excluding return type and parameters.
208
208
  """
209
+ demangled_name = demangled_name.strip()
209
210
  func_decls, _ = parse_cpp_file(demangled_name)
210
211
  if func_decls and len(func_decls) == 1:
211
212
  return next(iter(func_decls))
angr/utils/strings.py ADDED
@@ -0,0 +1,20 @@
1
+ from __future__ import annotations
2
+
3
+
4
+ def decode_utf16_string(data: bytes) -> str:
5
+ """
6
+ Decode a UTF-16 encoded string from a bytes object in a resilient manner.
7
+
8
+ :param data: The bytes object containing the UTF-16 encoded string.
9
+ :param errors: The error handling scheme. Default is 'strict'.
10
+ Other options include 'ignore', 'replace', etc.
11
+ :return: The decoded string.
12
+ """
13
+ if len(data) % 2 == 1:
14
+ data = data[:-1] # Trim off the last byte if the length is odd
15
+
16
+ # If no BOM, try to decode as little-endian first
17
+ try:
18
+ return data.decode("utf-16-le")
19
+ except UnicodeDecodeError:
20
+ return "<utf16-decode-error>"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: angr
3
- Version: 9.2.174
3
+ Version: 9.2.176
4
4
  Summary: A multi-architecture binary analysis toolkit, with the ability to perform dynamic symbolic execution and various static analyses on binaries
5
5
  License: BSD-2-Clause
6
6
  Project-URL: Homepage, https://angr.io/
@@ -16,12 +16,12 @@ Description-Content-Type: text/markdown
16
16
  License-File: LICENSE
17
17
  Requires-Dist: cxxheaderparser
18
18
  Requires-Dist: GitPython
19
- Requires-Dist: archinfo==9.2.174
19
+ Requires-Dist: archinfo==9.2.176
20
20
  Requires-Dist: cachetools
21
21
  Requires-Dist: capstone==5.0.3
22
22
  Requires-Dist: cffi>=1.14.0
23
- Requires-Dist: claripy==9.2.174
24
- Requires-Dist: cle==9.2.174
23
+ Requires-Dist: claripy==9.2.176
24
+ Requires-Dist: cle==9.2.176
25
25
  Requires-Dist: msgspec
26
26
  Requires-Dist: mulpyplexer
27
27
  Requires-Dist: networkx!=2.8.1,>=2.0
@@ -31,7 +31,7 @@ Requires-Dist: pycparser>=2.18
31
31
  Requires-Dist: pydemumble
32
32
  Requires-Dist: pyformlang
33
33
  Requires-Dist: pypcode<4.0,>=3.2.1
34
- Requires-Dist: pyvex==9.2.174
34
+ Requires-Dist: pyvex==9.2.176
35
35
  Requires-Dist: rich>=13.1.0
36
36
  Requires-Dist: sortedcontainers
37
37
  Requires-Dist: sympy