patching icon indicating copy to clipboard operation
patching copied to clipboard

Crash: if insn.address != ea: -- AttributeError: 'NoneType' object has no attribute 'address'

Open advokat11 opened this issue 3 years ago • 3 comments

Traceback (most recent call last): File "C:\Users/user/AppData/Roaming/Hex-Rays/IDA Pro/plugins\patching\actions.py", line 127, in activate wid = PatchingController(self.core, get_current_ea(ctx)) File "C:\Users/user/AppData/Roaming/Hex-Rays/IDA Pro/plugins\patching\ui\preview.py", line 47, in init self.refresh() File "C:\Users/user/AppData/Roaming/Hex-Rays/IDA Pro/plugins\patching\ui\preview.py", line 223, in refresh self.select_address(self.address) File "C:\Users/user/AppData/Roaming/Hex-Rays/IDA Pro/plugins\patching\ui\preview.py", line 68, in select_address if insn.address != ea: AttributeError: 'NoneType' object has no attribute 'address'

advokat11 avatar Apr 11 '22 06:04 advokat11

This is indeed a bug and I can understand why it would crash, but I can't actually seem to figure out how you triggered it. Even deleting segments.

The fix seems like I shouldn't be giving the user the ability to launch the assembly window in some special context, but I'm already pretty strict about where it even exposes the Assemble action anyway.

It seems rare enough that it's not a big deal, but I'm curious if anyone comes up with a way to reproduce this.

gaasedelen avatar Nov 23 '24 23:11 gaasedelen

I often run into this error too. I think it has to do with segment boundaries and trying to assemble function right after a boundary, the self.instructions array containing InstructionLines from the end of the previous segment, but none from the current one.

Here is an idb to replicate it, just go to the OEP which is .pseudo:00B60000, and try to 'Assemble'. psobb.idb.zip

anzz1 avatar Mar 24 '25 11:03 anzz1

.text:00401000 .text:00401000 mov eax, [esp+argc] .text:00401004 sub esp, 0C4h .text:0040100A cmp eax, 3 .text:0040100D push esi ...... .text:00401028 mov edi, [esp+0D8h+argv] <<< 'NoneType' object has no attribute 'address' .text:0040102F mov eax, [edi+4] <<< 'NoneType' object has no attribute 'address' .text:00401032 mov ebx, ds:strncpy <<< 'NoneType' object has no attribute 'address' .text:00401038 push 6 ; Count <<< 'NoneType' object has no attribute 'address' .text:0040103A push eax ; Source <<< 'NoneType' object has no attribute 'address' .text:0040103B lea ecx, [esp+0E0h+AA] <<< 'NoneType' object has no attribute 'address' .text:0040103F push ecx ; Dest <<< 'NoneType' object has no attribute 'address' .text:00401040 call ebx ; strncpy <<< 'NoneType' object has no attribute 'address' .text:00401042 mov edx, [edi+8] <<< 'NoneType' object has no attribute 'address' .text:00401045 push 50h ; 'P' ; Count <<< 'NoneType' object has no attribute 'address' .text:00401047 push edx ; Source <<< 'NoneType' object has no attribute 'address' .text:00401048 lea eax, [esp+0ECh+BB] <<< 'NoneType' object has no attribute 'address' .text:0040104F push eax ; Dest <<< 'NoneType' object has no attribute 'address' .text:00401050 mov [esp+0F0h+var_BF], 0 <<Disassembling the address and the previous code will result in an error .text:00401055 call ebx ; strncpy <<It's OK to disassemble the code for that address and later .text:00401057 add esp, 20h .text:0040105A mov [esp+0D0h+var_1], 0 .text:00401062 pop ebx

patching\ui\preview.py PREV_INSTRUCTIONS = 50 NEXT_INSTRUCTIONS = 50

It may be related to the following code, the program reads 50 bytes forward and backward, and when the first 50 bytes of a program are modified, the first 50 bytes exceed the code range of the program base address, so there is an error.

july008 avatar May 30 '25 16:05 july008