ida-domain 0.3.6.dev1__tar.gz → 0.3.6.dev2__tar.gz
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.
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/PKG-INFO +1 -1
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain/__init__.py +1 -1
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain/functions.py +226 -16
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain/hooks.py +1 -1
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain.egg-info/PKG-INFO +1 -1
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/pyproject.toml +1 -1
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/LICENSE +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/README.md +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain/base.py +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain/bytes.py +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain/comments.py +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain/database.py +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain/entries.py +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain/flowchart.py +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain/heads.py +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain/instructions.py +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain/names.py +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain/operands.py +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain/segments.py +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain/signature_files.py +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain/strings.py +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain/types.py +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain/xrefs.py +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain.egg-info/SOURCES.txt +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain.egg-info/dependency_links.txt +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain.egg-info/requires.txt +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/ida_domain.egg-info/top_level.txt +0 -0
- {ida_domain-0.3.6.dev1 → ida_domain-0.3.6.dev2}/setup.cfg +0 -0
|
@@ -186,6 +186,71 @@ class FunctionChunk:
|
|
|
186
186
|
"""True if is the function main chunk"""
|
|
187
187
|
|
|
188
188
|
|
|
189
|
+
# ============================================================================
|
|
190
|
+
# Ctree Assignment Detection
|
|
191
|
+
# ============================================================================
|
|
192
|
+
#
|
|
193
|
+
# The hexrays ctree represents decompiled code as nested expression trees.
|
|
194
|
+
# Determining write access requires analyzing the tree structure.
|
|
195
|
+
#
|
|
196
|
+
# Direct assignment: v9 = 10
|
|
197
|
+
#
|
|
198
|
+
# cot_asg
|
|
199
|
+
# ├── x: cot_var (v9) ← variable is direct child of assignment
|
|
200
|
+
# └── y: cot_num (10)
|
|
201
|
+
#
|
|
202
|
+
# Nested assignment: HIWORD(v9) = a1 (helper function wrapping variable)
|
|
203
|
+
#
|
|
204
|
+
# cot_asg
|
|
205
|
+
# ├── x: cot_helper (HIWORD)
|
|
206
|
+
# │ └── a[0]: cot_var (v9) ← variable is nested in left subtree
|
|
207
|
+
# └── y: cot_var (a1)
|
|
208
|
+
#
|
|
209
|
+
# Other nested patterns include casts, pointer dereferences, and array indexing:
|
|
210
|
+
# *ptr = x → cot_ptr wraps the variable
|
|
211
|
+
# arr[i] = x → cot_idx wraps the variable
|
|
212
|
+
# (cast)v = x → cot_cast wraps the variable
|
|
213
|
+
#
|
|
214
|
+
# Problem:
|
|
215
|
+
# A direct parent check (parent.op == cot_asg and parent.x == expr) only
|
|
216
|
+
# handles direct assignments. In nested cases, the variable's immediate
|
|
217
|
+
# parent is the wrapper expression (helper/cast/ptr), not the assignment.
|
|
218
|
+
#
|
|
219
|
+
# Solution:
|
|
220
|
+
# Two-direction traversal:
|
|
221
|
+
# 1. UP: Traverse ancestor chain to locate an assignment operator
|
|
222
|
+
# 2. DOWN: Verify the variable resides in the assignment's left subtree
|
|
223
|
+
#
|
|
224
|
+
# Without this logic, `HIWORD(v9) = a1` incorrectly reports `v9` as READ
|
|
225
|
+
# because the immediate parent is cot_helper. This affects data flow analysis
|
|
226
|
+
# and variable access classification.
|
|
227
|
+
#
|
|
228
|
+
# Performance characteristics:
|
|
229
|
+
# - Up-traversal: O(d) where d = ancestor depth, typically 1-5 levels
|
|
230
|
+
# - Down-traversal: O(n) where n = nodes in left subtree, typically 1-10
|
|
231
|
+
# - Invoked once per variable reference during ctree visitor traversal
|
|
232
|
+
#
|
|
233
|
+
# ============================================================================
|
|
234
|
+
|
|
235
|
+
# All assignment operators in IDA hexrays ctree
|
|
236
|
+
_ASSIGNMENT_OPS = (
|
|
237
|
+
ida_hexrays.cot_asg,
|
|
238
|
+
ida_hexrays.cot_asgadd,
|
|
239
|
+
ida_hexrays.cot_asgmul,
|
|
240
|
+
ida_hexrays.cot_asgsub,
|
|
241
|
+
ida_hexrays.cot_asgsdiv,
|
|
242
|
+
ida_hexrays.cot_asgudiv,
|
|
243
|
+
ida_hexrays.cot_asgsmod,
|
|
244
|
+
ida_hexrays.cot_asgumod,
|
|
245
|
+
ida_hexrays.cot_asgbor,
|
|
246
|
+
ida_hexrays.cot_asgxor,
|
|
247
|
+
ida_hexrays.cot_asgband,
|
|
248
|
+
ida_hexrays.cot_asgsshr,
|
|
249
|
+
ida_hexrays.cot_asgushr,
|
|
250
|
+
ida_hexrays.cot_asgshl,
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
|
|
189
254
|
class _LVarRefsVisitor(ida_hexrays.ctree_parentee_t):
|
|
190
255
|
"""Visitor to find references to a specific local variable in pseudocode.
|
|
191
256
|
|
|
@@ -237,6 +302,110 @@ class _LVarRefsVisitor(ida_hexrays.ctree_parentee_t):
|
|
|
237
302
|
self.refs.append(ref)
|
|
238
303
|
return 0
|
|
239
304
|
|
|
305
|
+
def _is_on_left_side_of_assignment(self, asg_expr: Any, child_expr: Any) -> bool:
|
|
306
|
+
"""Check if child_expr is in the left subtree of an assignment.
|
|
307
|
+
|
|
308
|
+
Performs a depth-first traversal from the assignment's left operand (.x)
|
|
309
|
+
to determine if child_expr is reachable. If reachable, the variable is
|
|
310
|
+
on the write side of the assignment.
|
|
311
|
+
|
|
312
|
+
This handles nested patterns where the variable is wrapped in expressions:
|
|
313
|
+
HIWORD(v9) = a1 → v9 is inside cot_helper, which is in .x
|
|
314
|
+
*ptr = val → ptr is inside cot_ptr, which is in .x
|
|
315
|
+
|
|
316
|
+
Args:
|
|
317
|
+
asg_expr: An assignment expression (cot_asg or compound assignment).
|
|
318
|
+
child_expr: The expression to search for in the left subtree.
|
|
319
|
+
|
|
320
|
+
Returns:
|
|
321
|
+
True if child_expr is found in the left subtree (write side).
|
|
322
|
+
|
|
323
|
+
Performance:
|
|
324
|
+
O(n) where n = number of nodes in left subtree. Typically 1-10 nodes
|
|
325
|
+
for common patterns like helpers, casts, or pointer dereferences.
|
|
326
|
+
"""
|
|
327
|
+
# asg_expr might be a citem_t, we need to access the cexpr_t
|
|
328
|
+
# Check if it's an expression type with x attribute
|
|
329
|
+
if not hasattr(asg_expr, 'x'):
|
|
330
|
+
# Try to get the expression from citem_t
|
|
331
|
+
if hasattr(asg_expr, 'cexpr'):
|
|
332
|
+
asg_expr = asg_expr.cexpr
|
|
333
|
+
else:
|
|
334
|
+
return False
|
|
335
|
+
|
|
336
|
+
# Get the left side of the assignment
|
|
337
|
+
left = asg_expr.x
|
|
338
|
+
if left is None:
|
|
339
|
+
return False
|
|
340
|
+
|
|
341
|
+
# Use a simple BFS/DFS to find if child_expr is in the left subtree
|
|
342
|
+
stack = [left]
|
|
343
|
+
while stack:
|
|
344
|
+
current = stack.pop()
|
|
345
|
+
if current is None:
|
|
346
|
+
continue
|
|
347
|
+
# Check if this is our target expression (by object identity or ea)
|
|
348
|
+
if current == child_expr:
|
|
349
|
+
return True
|
|
350
|
+
if hasattr(current, 'ea') and hasattr(child_expr, 'ea'):
|
|
351
|
+
if current.ea == child_expr.ea and current.op == child_expr.op:
|
|
352
|
+
return True
|
|
353
|
+
# Traverse children based on expression type
|
|
354
|
+
if hasattr(current, 'x') and current.x is not None:
|
|
355
|
+
stack.append(current.x)
|
|
356
|
+
if hasattr(current, 'y') and current.y is not None:
|
|
357
|
+
stack.append(current.y)
|
|
358
|
+
if hasattr(current, 'z') and current.z is not None:
|
|
359
|
+
stack.append(current.z)
|
|
360
|
+
return False
|
|
361
|
+
|
|
362
|
+
def _find_assignment_in_ancestors(self) -> tuple:
|
|
363
|
+
"""Find an assignment operator in the ancestor chain.
|
|
364
|
+
|
|
365
|
+
Traverses from the immediate parent upward through the ancestor chain
|
|
366
|
+
to locate an assignment operator. When found, determines whether the
|
|
367
|
+
current expression is on the left (write) or right (read) side.
|
|
368
|
+
|
|
369
|
+
This enables correct access type detection for nested patterns:
|
|
370
|
+
HIWORD(v9) = a1 → parent of v9 is cot_helper, not assignment
|
|
371
|
+
→ ancestor traversal finds the cot_asg above
|
|
372
|
+
|
|
373
|
+
Uses self.parents vector maintained by ctree_parentee_t during traversal.
|
|
374
|
+
|
|
375
|
+
Returns:
|
|
376
|
+
Tuple of (assignment_expr, is_on_left_side):
|
|
377
|
+
- (expr, True) if in left subtree (write side)
|
|
378
|
+
- (expr, False) if in right subtree (read side)
|
|
379
|
+
- (None, False) if no assignment found in ancestors
|
|
380
|
+
|
|
381
|
+
Performance:
|
|
382
|
+
O(d) where d = ancestor depth. Typically 1-5 levels for common
|
|
383
|
+
patterns. The parents vector is already maintained by the base
|
|
384
|
+
class during tree traversal.
|
|
385
|
+
"""
|
|
386
|
+
num_parents = len(self.parents)
|
|
387
|
+
for i in range(num_parents):
|
|
388
|
+
# Access parents from end (nearest) to beginning (farthest)
|
|
389
|
+
parent_item = self.parents[num_parents - 1 - i]
|
|
390
|
+
if parent_item is None:
|
|
391
|
+
continue
|
|
392
|
+
# Check if this parent is an expression with an assignment op
|
|
393
|
+
if not hasattr(parent_item, 'op'):
|
|
394
|
+
continue
|
|
395
|
+
if parent_item.op in _ASSIGNMENT_OPS:
|
|
396
|
+
# Found an assignment - determine if we're on the left side
|
|
397
|
+
# The item right before this assignment in the parent chain
|
|
398
|
+
# is the child that leads to our expression
|
|
399
|
+
if i == 0:
|
|
400
|
+
# Immediate parent is assignment, use parent_expr()
|
|
401
|
+
child = self.parent_expr()
|
|
402
|
+
else:
|
|
403
|
+
# Get the item that is child of this assignment
|
|
404
|
+
child = self.parents[num_parents - i]
|
|
405
|
+
is_left = self._is_on_left_side_of_assignment(parent_item, child)
|
|
406
|
+
return (parent_item, is_left)
|
|
407
|
+
return (None, False)
|
|
408
|
+
|
|
240
409
|
def _determine_access_type(self, expr: Any, parent: Any) -> LocalVariableAccessType:
|
|
241
410
|
"""Determine how the variable is being accessed."""
|
|
242
411
|
if not parent:
|
|
@@ -245,24 +414,31 @@ class _LVarRefsVisitor(ida_hexrays.ctree_parentee_t):
|
|
|
245
414
|
# Check if this is a write operation (left side of assignment)
|
|
246
415
|
if parent.op == ida_hexrays.cot_asg and parent.x == expr:
|
|
247
416
|
return LocalVariableAccessType.WRITE
|
|
248
|
-
# Check
|
|
249
|
-
elif parent.op
|
|
417
|
+
# Check compound assignments at immediate parent level
|
|
418
|
+
elif parent.op in _ASSIGNMENT_OPS and parent.x == expr:
|
|
419
|
+
return LocalVariableAccessType.WRITE
|
|
420
|
+
# Check if address is taken - but also check ancestors for assignment
|
|
421
|
+
elif parent.op == ida_hexrays.cot_ref:
|
|
422
|
+
# Address is taken - check if this is part of an assignment
|
|
423
|
+
asg, is_left = self._find_assignment_in_ancestors()
|
|
424
|
+
if asg and is_left:
|
|
425
|
+
return LocalVariableAccessType.WRITE
|
|
250
426
|
return LocalVariableAccessType.ADDRESS
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
)
|
|
263
|
-
and parent.x == expr
|
|
427
|
+
|
|
428
|
+
# For calls (including helpers like HIWORD), casts, ptr derefs - check ancestors
|
|
429
|
+
if parent.op in (
|
|
430
|
+
ida_hexrays.cot_call,
|
|
431
|
+
ida_hexrays.cot_helper,
|
|
432
|
+
ida_hexrays.cot_cast,
|
|
433
|
+
ida_hexrays.cot_ptr,
|
|
434
|
+
ida_hexrays.cot_memptr,
|
|
435
|
+
ida_hexrays.cot_memref,
|
|
436
|
+
ida_hexrays.cot_add,
|
|
437
|
+
ida_hexrays.cot_idx,
|
|
264
438
|
):
|
|
265
|
-
|
|
439
|
+
asg, is_left = self._find_assignment_in_ancestors()
|
|
440
|
+
if asg and is_left:
|
|
441
|
+
return LocalVariableAccessType.WRITE
|
|
266
442
|
|
|
267
443
|
return LocalVariableAccessType.READ
|
|
268
444
|
|
|
@@ -273,7 +449,13 @@ class _LVarRefsVisitor(ida_hexrays.ctree_parentee_t):
|
|
|
273
449
|
|
|
274
450
|
if parent.op == ida_hexrays.cot_asg:
|
|
275
451
|
return LocalVariableContext.ASSIGNMENT
|
|
452
|
+
elif parent.op in _ASSIGNMENT_OPS:
|
|
453
|
+
return LocalVariableContext.ASSIGNMENT
|
|
276
454
|
elif parent.op == ida_hexrays.cot_call:
|
|
455
|
+
# Check if there's an assignment ancestor - if so, this is ASSIGNMENT context
|
|
456
|
+
asg, is_left = self._find_assignment_in_ancestors()
|
|
457
|
+
if asg and is_left:
|
|
458
|
+
return LocalVariableContext.ASSIGNMENT
|
|
277
459
|
return LocalVariableContext.CALL_ARG
|
|
278
460
|
elif parent.op in (
|
|
279
461
|
ida_hexrays.cot_eq,
|
|
@@ -297,13 +479,41 @@ class _LVarRefsVisitor(ida_hexrays.ctree_parentee_t):
|
|
|
297
479
|
ida_hexrays.cot_smod,
|
|
298
480
|
ida_hexrays.cot_umod,
|
|
299
481
|
):
|
|
482
|
+
# Check if there's an assignment ancestor
|
|
483
|
+
asg, is_left = self._find_assignment_in_ancestors()
|
|
484
|
+
if asg and is_left:
|
|
485
|
+
return LocalVariableContext.ASSIGNMENT
|
|
300
486
|
return LocalVariableContext.ARITHMETIC
|
|
301
487
|
elif parent.op == ida_hexrays.cot_idx:
|
|
488
|
+
# Check if there's an assignment ancestor
|
|
489
|
+
asg, is_left = self._find_assignment_in_ancestors()
|
|
490
|
+
if asg and is_left:
|
|
491
|
+
return LocalVariableContext.ASSIGNMENT
|
|
302
492
|
return LocalVariableContext.ARRAY_INDEX
|
|
303
493
|
elif parent.op in (ida_hexrays.cot_ptr, ida_hexrays.cot_memptr, ida_hexrays.cot_memref):
|
|
494
|
+
# Check if there's an assignment ancestor
|
|
495
|
+
asg, is_left = self._find_assignment_in_ancestors()
|
|
496
|
+
if asg and is_left:
|
|
497
|
+
return LocalVariableContext.ASSIGNMENT
|
|
304
498
|
return LocalVariableContext.POINTER_DEREF
|
|
305
499
|
elif parent.op == ida_hexrays.cot_cast:
|
|
500
|
+
# Check if there's an assignment ancestor
|
|
501
|
+
asg, is_left = self._find_assignment_in_ancestors()
|
|
502
|
+
if asg and is_left:
|
|
503
|
+
return LocalVariableContext.ASSIGNMENT
|
|
306
504
|
return LocalVariableContext.CAST
|
|
505
|
+
elif parent.op == ida_hexrays.cot_ref:
|
|
506
|
+
# Address taken - check for assignment ancestor
|
|
507
|
+
asg, is_left = self._find_assignment_in_ancestors()
|
|
508
|
+
if asg and is_left:
|
|
509
|
+
return LocalVariableContext.ASSIGNMENT
|
|
510
|
+
return LocalVariableContext.OTHER
|
|
511
|
+
elif parent.op == ida_hexrays.cot_helper:
|
|
512
|
+
# Helper functions like HIWORD - check for assignment ancestor
|
|
513
|
+
asg, is_left = self._find_assignment_in_ancestors()
|
|
514
|
+
if asg and is_left:
|
|
515
|
+
return LocalVariableContext.ASSIGNMENT
|
|
516
|
+
return LocalVariableContext.OTHER
|
|
307
517
|
|
|
308
518
|
return LocalVariableContext.OTHER
|
|
309
519
|
|
|
@@ -2387,7 +2387,7 @@ class ProcessorHooks(_BaseHooks, IDP_Hooks):
|
|
|
2387
2387
|
Returns:
|
|
2388
2388
|
PyObject*: 1 if success, 0 if not implemented or failed.
|
|
2389
2389
|
"""
|
|
2390
|
-
return
|
|
2390
|
+
return 0
|
|
2391
2391
|
|
|
2392
2392
|
def ev_arch_changed(self) -> int:
|
|
2393
2393
|
"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|