I want to know what to do if i have some content in a text file, i wish to preprocess it by removing certain things. from the file

the text file has content as shown below

sub_401000 proc near ; CODE XREF: sub_4021FD+7Fp

; sub_403366+40Dp ...

loc_401019: ; CODE XREF: sub_401000+20j

I want to remove the content from all those lines that appear after the semicolon. There are multiple statements of different type appearin before the semicolon.

Well, with split, just as the name implies you could split the string,into a list, in this case at the semicolon

>>>a='some;data'
>>>a
'some;data'
>>>a=a.split(';')

>>>a
['some','data']

Edited 5 Years Ago by pyguy62: n/a

following is the content of a binary file

sub_401000 proc near ; CODE XREF: sub_4021FD+7Fp

; sub_403366+40Dp ...

mov eax, [esp+arg_8]

mov ecx, [esp+arg_4]

mov edx, eax

dec eax

test edx, edx

jz short loc_401023

mov edx, [esp+arg_0]

push esi

sub edx, ecx

lea esi, [eax+1]

loc_401019: ; CODE XREF: sub_401000+20j

mov al, [ecx]

mov [ecx+edx], al

inc ecx

dec esi

jnz short loc_401019

pop esi

loc_401023: ; CODE XREF: sub_401000+Dj

mov eax, [esp+arg_0]

retn

sub_401000 endp

sub_401028 proc near ; CODE XREF: sub_4014C5+3Ap

; sub_402F40+190p ...

mov eax, [esp+arg_4]

push esi

mov esi, [esp+4+arg_8]

mov ecx, esi

dec esi

test ecx, ecx

jz short loc_40104D

mov ecx, [esp+4+arg_0]

sub ecx, eax

loc_40103E: ; CODE XREF: sub_401028+23j

mov dl, [eax]

now i need t preserve everything into the new file except what appears after the semicolon, including it .IT must look as given below

sub_401000 proc near


mov eax, [esp+arg_8]

mov ecx, [esp+arg_4]

mov edx, eax

dec eax

test edx, edx

jz short loc_401023

mov edx, [esp+arg_0]

push esi

sub edx, ecx

lea esi, [eax+1]

loc_401019:

mov al, [ecx]

mov [ecx+edx], al

inc ecx

dec esi

I tried what u said but it doesnt work

It does not work is not enough info to do anything about it. Put first it to print out the lines to check you got the splitting right, then take care of saving it to file, one step at the time. When you are stuck post your efforts, remember to put code tags by pushing the CODE before pasting.

Edited 3 Years Ago by happygeek: fixed formatting

Python Syntax (Toggle Plain Text)
>>>a='some;data'
>>>a
'some;data'
>>>a=a.split(';')

>>>a

I can not apply it

This article has been dead for over six months. Start a new discussion instead.