summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2016-12-09 19:54:32 +0100
committerErich Eckner <git@eckner.net>2016-12-09 19:54:32 +0100
commit2b9ede70ab336abad374563dc47bcf3e3a9c7ac3 (patch)
tree3046fc4aa2eba56ad45242287d27c374bb40ee9d
downloadhexfind-master.tar.xz
Initial commitHEADmaster
-rw-r--r--.gitignore7
-rw-r--r--hexfind.lpi63
-rw-r--r--hexfind.lpr78
-rw-r--r--hexfind.lps17
4 files changed, 165 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1f1fb5b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+*.bak
+*.ppu
+*.o
+*.tar.gz
+*~
+hexfind
+lib
diff --git a/hexfind.lpi b/hexfind.lpi
new file mode 100644
index 0000000..0b2d473
--- /dev/null
+++ b/hexfind.lpi
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CONFIG>
+ <ProjectOptions>
+ <Version Value="9"/>
+ <General>
+ <Flags>
+ <MainUnitHasCreateFormStatements Value="False"/>
+ <MainUnitHasTitleStatement Value="False"/>
+ </Flags>
+ <SessionStorage Value="InProjectDir"/>
+ <MainUnit Value="0"/>
+ <Title Value="hexfind"/>
+ <UseAppBundle Value="False"/>
+ <ResourceType Value="res"/>
+ </General>
+ <i18n>
+ <EnableI18N LFM="False"/>
+ </i18n>
+ <VersionInfo>
+ <StringTable ProductVersion=""/>
+ </VersionInfo>
+ <BuildModes Count="1">
+ <Item1 Name="Default" Default="True"/>
+ </BuildModes>
+ <PublishOptions>
+ <Version Value="2"/>
+ </PublishOptions>
+ <RunParams>
+ <local>
+ <FormatVersion Value="1"/>
+ </local>
+ </RunParams>
+ <Units Count="1">
+ <Unit0>
+ <Filename Value="hexfind.lpr"/>
+ <IsPartOfProject Value="True"/>
+ </Unit0>
+ </Units>
+ </ProjectOptions>
+ <CompilerOptions>
+ <Version Value="11"/>
+ <Target>
+ <Filename Value="hexfind"/>
+ </Target>
+ <SearchPaths>
+ <IncludeFiles Value="$(ProjOutDir)"/>
+ <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
+ </SearchPaths>
+ </CompilerOptions>
+ <Debugging>
+ <Exceptions Count="3">
+ <Item1>
+ <Name Value="EAbort"/>
+ </Item1>
+ <Item2>
+ <Name Value="ECodetoolError"/>
+ </Item2>
+ <Item3>
+ <Name Value="EFOpenError"/>
+ </Item3>
+ </Exceptions>
+ </Debugging>
+</CONFIG>
diff --git a/hexfind.lpr b/hexfind.lpr
new file mode 100644
index 0000000..4d129d0
--- /dev/null
+++ b/hexfind.lpr
@@ -0,0 +1,78 @@
+program hexfind;
+
+uses
+ math;
+
+type
+ tByteArray = array of byte;
+
+procedure loadFile(out ar: tByteArray; nam: string);
+var
+ f: file;
+begin
+ assignfile(f,nam);
+ reset(f,1);
+ setlength(ar,filesize(f));
+ blockread(f,ar[0],length(ar));
+ closefile(f);
+end;
+
+function inttohex(b: byte): string;
+const
+ h2s = '0123456789abcdef';
+begin
+ result:=
+ h2s[1 + ((b and $f0) shr 4)]
+ + h2s[1 + (b and $f)];
+end;
+
+var
+ haystack,needle: tByteArray;
+ iHay,iNee,i: longint;
+
+const
+ matchLen = 10;
+
+begin
+ if paramcount<>2 then begin
+ writeln('usage: '+paramstr(0)+' haystack needle');
+ halt(1);
+ end;
+
+ loadFile(haystack,paramstr(1));
+ loadFile(needle,paramstr(2));
+
+ for iHay:=1 to length(haystack)-matchlen do
+ for iNee:=0 to min(length(needle)-1,length(haystack)-iHay) do
+ if haystack[length(haystack)-iHay-iNee] <> needle[length(needle)-1-iNee] then begin
+ if iNee<matchLen then
+ break;
+
+ write('<');
+ for i:=0 to length(haystack)-iHay-iNee do
+ write(' '+inttohex(haystack[i]));
+ writeln;
+
+ write('>');
+ for i:=0 to length(needle)-1-iNee do
+ write(' '+inttohex(needle[i]));
+ writeln;
+
+ for i:=0 to 79 do
+ write('-');
+ writeln;
+
+ write('<');
+ for i:=length(haystack)-iHay+1 to length(haystack)-1 do
+ write(' '+inttohex(haystack[i]));
+ writeln;
+
+ setlength(haystack,0);
+ setlength(needle,0);
+ halt;
+ end;
+
+ setlength(haystack,0);
+ setlength(needle,0);
+end.
+
diff --git a/hexfind.lps b/hexfind.lps
new file mode 100644
index 0000000..ebcfe5a
--- /dev/null
+++ b/hexfind.lps
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CONFIG>
+ <ProjectSession>
+ <Version Value="9"/>
+ <BuildModes Active="Default"/>
+ <Units Count="1">
+ <Unit0>
+ <Filename Value="hexfind.lpr"/>
+ <IsPartOfProject Value="True"/>
+ <IsVisibleTab Value="True"/>
+ <UsageCount Value="20"/>
+ <Loaded Value="True"/>
+ </Unit0>
+ </Units>
+ <JumpHistory HistoryIndex="-1"/>
+ </ProjectSession>
+</CONFIG>