File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -315,6 +315,9 @@ def clean_decompiled_code(code):
315315 if not code :
316316 return code
317317
318+ # Normalize line endings (Windows CRLF -> LF)
319+ code = code .replace ("\r \n " , "\n " ).replace ("\r " , "\n " )
320+
318321 lines = code .split ("\n " )
319322 cleaned_lines = []
320323 prev_blank = False
Original file line number Diff line number Diff line change @@ -1619,3 +1619,26 @@ def test_nested_braces(self):
16191619 cleaned = clean_decompiled_code (code )
16201620 # Should remove all internal blank lines
16211621 assert "\n \n " not in cleaned .split ("{" , 1 )[1 ].rsplit ("}" , 1 )[0 ]
1622+
1623+
1624+ def test_windows_line_endings (self ):
1625+ """Test handling of Windows CRLF line endings"""
1626+ from ghidra_common import clean_decompiled_code
1627+
1628+ # Simulate Windows CRLF output from Ghidra
1629+ code = "void TestFunc(void)\r \n \r \n {\r \n \r \n int x;\r \n \r \n return;\r \n \r \n }\r \n "
1630+ cleaned = clean_decompiled_code (code )
1631+
1632+ # Should not have any \r characters
1633+ assert "\r " not in cleaned
1634+
1635+ # Should not have blank lines inside function
1636+ lines = cleaned .split ('\n ' )
1637+ inside_braces = False
1638+ for line in lines :
1639+ if '{' in line :
1640+ inside_braces = True
1641+ if '}' in line :
1642+ inside_braces = False
1643+ if inside_braces and not line .strip ():
1644+ assert False , "Found blank line inside function body"
You can’t perform that action at this time.
0 commit comments