Skip to content

Commit

Permalink
Update to version 1.1
Browse files Browse the repository at this point in the history
-much faster copy function
-additional checks for zeroed images
-Mode 3 does now work also when no leading 0x00 bytes are available
-summary after stripping
-reworked help
  • Loading branch information
Lostech committed Mar 28, 2014
1 parent c77fb04 commit 5248f4f
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 53 deletions.
Binary file modified Binaries/1.0/Strip-0x00.zip
Binary file not shown.
3 changes: 3 additions & 0 deletions Binaries/1.1/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Strip-0x00 V1.1 binary for Win32

http://www.gnu.org/licenses/gpl-2.0
Binary file added Binaries/1.1/Strip-0x00.zip
Binary file not shown.
129 changes: 81 additions & 48 deletions Strip.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TStrip = class(TCustomApplication)

const
AppTitle: String = 'Strip-0x00';
Version: String = '1.0';
Version: String = '1.1';


{ TStrip }
Expand Down Expand Up @@ -73,22 +73,24 @@ procedure TStrip.DoRun;

// parse parameters
if (HasOption('h','help')) or (ParamCount=0) then
begin
WriteHelp;
Terminate;
Exit;
end;
begin
WriteHelp;
Terminate;
Exit;
end;
if ParamCount=1 then
InputFile:=ParamStr(1);
if HasOption('1','mode1') then
begin
StripMode:=1;
writeln('Mode 1: strip appending 0x00 bytes');
end
else if (HasOption('2','mode2')) or (ParamCount=0) then
else if HasOption('2','mode2') then
begin
StripMode:=2;
writeln('Mode 2: strip leading 0x00 bytes');
end
else if (HasOption('3','mode3')) or (ParamCount=0) then
else if HasOption('3','mode3') then
begin
StripMode:=3;
writeln('Mode 3: strip appending and leading 0x00 bytes');
Expand All @@ -100,7 +102,8 @@ procedure TStrip.DoRun;
end;

//set files
InputFile:=GetOptionValue('i', 'input');
if InputFile='' then
InputFile:=GetOptionValue('i', 'input');
if FileExists(InputFile)=false then
begin
writeln('');
Expand All @@ -120,7 +123,7 @@ procedure TStrip.DoRun;
//check offset for last leading 0x00 byte in input file
if StripMode<>1 then
begin
write('Checking offset for last leading 0x00 byte in input file...');
write('Checking offset for last leading 0x00 byte in input file... ');
InputPos:=0;
WorkByte:=$0;
while InputPos<InputStream.Size do
Expand All @@ -130,22 +133,26 @@ procedure TStrip.DoRun;
if Workbyte<>$0 then break;
inc(InputPos);
end;
write(' 0x'+IntToHex(InputPos,8)+#13#10);
if InputPos=$0 then
write('0x'+IntToHex(InputPos,8)+#13#10);
//quit when in mode2 no leading 0x00 bytes are found
if (InputPos=$0) or (InputPos>=InputStream.Size) then
begin
writeln('');
writeln('Error: no leading 0x00 bytes found!');
writeln('');
Terminate;
Exit;
if StripMode=2 then
begin
writeln('');
writeln('Error: can not strip empty image!');
write('Error: Last leading 0x00 byte at file end postion 0x'+IntToHex(InputPos,8)+' = zeroed file'+#13#10);
writeln('');
Terminate;
Exit;
end;
end;
end;


//check offset for first appended 0x00 byte in input file
if StripMode<>2 then
begin
write('Checking offset for first appended 0x00 byte in input file...');
write('Checking offset for first appended 0x00 byte in input file... ');
InputPos2:=InputStream.Size-1;
WorkByte:=$0;
while InputPos2>0 do
Expand All @@ -155,7 +162,7 @@ procedure TStrip.DoRun;
if Workbyte<>$0 then break;
dec(InputPos2);
end;
write(' 0x'+IntToHex(InputPos2,8)+#13#10);
write('0x'+IntToHex(InputPos2,8)+#13#10);
if InputPos2=InputStream.Size-1 then
begin
writeln('');
Expand All @@ -166,47 +173,68 @@ procedure TStrip.DoRun;
end;
end;

//prevent 1 byte size file in strip mode 1 in case the source image is full of 0x00 bytes
if StripMode=1 then
begin
if InputPos2=0 then
begin
writeln('');
writeln('Error: can not strip empty image!');
write('Error: First appended 0x00 byte at start postion 0x'+IntToHex(0,8)+' = zeroed file'+#13#10);
writeln('');
Terminate;
Exit;
end;
end;

//prevent zero size file in strip mode 3 in case the source image is full of 0x00 bytes or when both position are equal
if StripMode=3 then
begin
if InputPos2-InputPos+1<=0 then
begin
writeln('');
writeln('Error: can not strip empty image!');
writeln('Error: completely zeroed file!');
writeln('');
Terminate;
Exit;
end;
if InputPos2=InputPos then
begin
writeln('');
writeln('Error: position of appended and leading 0x00 bytes equal! Set leading position back to 0x00!');
writeln('');
InputPos:=0;
end;
end;

//Create new output file
if FileExists(OutputFile) then
DeleteFile(OutputFile);
OutputStream:=TFileStream.Create(OutputFile,fmCreate);

//copy content from input file to output file without appended 0x00 bytes
//copy content from input file to output file without appended or leading 0x00 bytes
StreamPos:=0;
write('Create output file without stripped 0x00 bytes...');
write('Create output file without stripped 0x00 bytes... ');
if StripMode=1 then
begin
while StreamPos<InputPos2+1 do
begin
InputStream.Seek(StreamPos,0);
OutputStream.Seek(StreamPos,0);
OutputStream.CopyFrom(InputStream,1);
inc(StreamPos);
end;
InputStream.Seek(StreamPos,0);
OutputStream.Seek(0,0);
OutputStream.CopyFrom(InputStream,InputPos2+1);
end;
if StripMode=2 then
begin
StreamPos:=InputPos;
while StreamPos<InputStream.Size do
begin
InputStream.Seek(StreamPos,0);
OutputStream.Seek(StreamPos-InputPos,0);
OutputStream.CopyFrom(InputStream,1);
inc(StreamPos);
end;
InputStream.Seek(InputPos,0);
OutputStream.Seek(0,0);
OutputStream.CopyFrom(InputStream,InputStream.Size-InputPos);
end;
if StripMode=3 then
begin
StreamPos:=InputPos;
while StreamPos<InputPos2+1 do
begin
InputStream.Seek(StreamPos,0);
OutputStream.Seek(StreamPos-InputPos,0);
OutputStream.CopyFrom(InputStream,1);
inc(StreamPos);
end;
InputStream.Seek(InputPos,0);
OutputStream.Seek(0,0);
OutputStream.CopyFrom(InputStream,InputPos2-InputPos+1);
end;
write(' done'+#13#10);
write('done'+#13#10);

//compare image sizes
writeln('Old image size 0x'+IntToHex(InputStream.Size,8));
Expand Down Expand Up @@ -241,10 +269,15 @@ procedure TStrip.WriteHelp;
{ add your help code here }
writeln(AppTitle+' removes all appended 0x00 bytes of a file for e.g. ROM dumps');
writeln('');
writeln('Usage: (mode option)',ExtractFileName(ExeName),' inputfile (outputfile)');
writeln('Usage: ',ExtractFileName(ExeName),' (mode) -i inputfile (-o outputfile)');
writeln(' ',ExtractFileName(ExeName),' inputfile');
writeln('');
writeln('Options:');
writeln('Arguments:');
writeln('-h or --help this help page');
writeln('-i or --input inputfile');
writeln('-o or --output outputfile (optional)');
writeln('');
writeln('Mode (optional):');
writeln('-1 or --mode1 remove appended 0x00 bytes (default)');
writeln('-2 or --mode2 remove leading 0x00 bytes');
writeln('-3 or --mode3 remove appended and leading 0x00 bytes');
Expand Down
22 changes: 17 additions & 5 deletions Strip.lps
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<IsVisibleTab Value="True"/>
<EditorIndex Value="0"/>
<WindowIndex Value="0"/>
<TopLine Value="178"/>
<CursorPos X="27" Y="205"/>
<UsageCount Value="20"/>
<TopLine Value="254"/>
<CursorPos X="53" Y="272"/>
<UsageCount Value="24"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
Expand All @@ -23,14 +23,14 @@
<WindowIndex Value="0"/>
<TopLine Value="41"/>
<CursorPos X="16" Y="63"/>
<UsageCount Value="10"/>
<UsageCount Value="12"/>
<Loaded Value="True"/>
</Unit1>
</Units>
<General>
<ActiveWindowIndexAtStart Value="0"/>
</General>
<JumpHistory Count="25" HistoryIndex="24">
<JumpHistory Count="28" HistoryIndex="27">
<Position1>
<Filename Value="Strip.lpr"/>
<Caret Line="69" Column="57" TopLine="39"/>
Expand Down Expand Up @@ -131,6 +131,18 @@
<Filename Value="Strip.lpr"/>
<Caret Line="71" Column="29" TopLine="52"/>
</Position25>
<Position26>
<Filename Value="Strip.lpr"/>
<Caret Line="36" Column="27" TopLine="1"/>
</Position26>
<Position27>
<Filename Value="Strip.lpr"/>
<Caret Line="217" Column="16" TopLine="186"/>
</Position27>
<Position28>
<Filename Value="Strip.lpr"/>
<Caret Line="80" Column="1" TopLine="71"/>
</Position28>
</JumpHistory>
</ProjectSession>
</CONFIG>

0 comments on commit 5248f4f

Please sign in to comment.