Skip to content

Commit c8ad912

Browse files
committed
fix: fix blank line cleanup not working on win platform
1 parent 303c02d commit c8ad912

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

ghidra_common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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

tests/test_libsurgeon.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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"

0 commit comments

Comments
 (0)