• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 06:58
CEST 12:58
KST 19:58
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL21] Ro4 Preview: On Course12Code S Season 1 - RO8 Preview7[ASL21] Ro8 Preview Pt2: Progenitors8Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun13[ASL21] Ro8 Preview Pt1: Inheritors16
Community News
Weekly Cups (May 4-10): Clem, MaxPax, herO win1Maestros of The Game 2 announcement and schedule !10Weekly Cups (April 27-May 4): Clem takes triple0RSL Revival: Season 5 - Qualifiers and Main Event12Code S Season 1 (2026) - RO12 Results1
StarCraft 2
General
MaNa leaves Team Liquid Weekly Cups (May 4-10): Clem, MaxPax, herO win Code S Season 1 - RO8 Preview Behind the Blue - Team Liquid History Book Weekly Cups (April 27-May 4): Clem takes triple
Tourneys
2026 GSL Season 2 Qualifiers Maestros of The Game 2 announcement and schedule ! SC2 INu's Battles#16 <BO.9> Master Swan Open (Global Bronze-Master 2) GSL Code S Season 1 (2026)
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players
External Content
Mutation # 525 Wheel of Misfortune The PondCast: SC2 News & Results Mutation # 524 Death and Taxes Mutation # 523 Firewall
Brood War
General
ASL Tickets to Live Event Finals? Pros React To: Leta vs Tulbo (ASL S21, Ro.8) Flashes ASL S21 Ro8 Review BW General Discussion [ASL21] Ro4 Preview: On Course
Tourneys
[ASL21] Semifinals B [ASL21] Semifinals A [Megathread] Daily Proleagues [BSL22] RO16 Group Stage - 02 - 10 May
Strategy
[G] Hydra ZvZ: An Introduction Simple Questions, Simple Answers Fighting Spirit mining rates Muta micro map competition
Other Games
General Games
Starcraft Tabletop Miniature Game Warcraft III: The Frozen Throne Stormgate/Frost Giant Megathread PC Games Sales Thread Path of Exile
Dota 2
The Story of Wings Gaming
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread UK Politics Mega-thread YouTube Thread European Politico-economics QA Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [Req][Books] Good Fantasy/SciFi books
Sports
2024 - 2026 Football Thread McBoner: A hockey love story Formula 1 Discussion
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
How EEG Data Can Predict Gam…
TrAiDoS
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1801 users

C++ project help

Blogs > atmablade
Post a Reply
atmablade
Profile Blog Joined July 2007
United States334 Posts
Last Edited: 2008-05-13 19:37:18
May 13 2008 19:25 GMT
#1
Ok, here's the dire situation. For my project I have to make a very basic virus scanner that takes in two arguments, the directory to start searching files in (then recursively traverse down) and the signature file (just a normal text file formatted however I want it). We can write it in any code (C,C++,Java,Perl) except shell since that would take like 4 lines of code. So I decided to start it in C++ since I'm more familiar with that.

For each file, the program will test if it contains a binary substring than matches a signature listed in the input file.
Then the output of the program is a report that indicates which files in the directory contain which signatures in the list.

The signature file I have setup right now is very basic and looks like this:

abc
1a2a3a

Now onto my plead. From what I get, I have to compare both files on a byte to byte level, but how does this work? I'm not sure what the code/pseudo-code looks like for this whole compare part.

The next problem is the recursion. I have never messed with directory traversing much so the code for that is also pretty murky.

Can anyone point me in the right direction and help me out?



zdd
Profile Blog Joined October 2004
1463 Posts
Last Edited: 2008-05-13 21:04:25
May 13 2008 19:55 GMT
#2
you basically just want a function that you can put a directory into and loop through each file
convert your search pattern to binary and then to a string for easy comparison (or you can just do binary to binary)

bin_file = to_string(convert_to_binary(input_file))
matches = empty string

function loop_directory(dir) {
      for each file in dir {
            if (file = directory) { loop_directory(file) } //recurse through any subdirectories
             else {
                    file_to_search = open(file)
                    for each character in file_to_search {
                    loop_this_many_times = length(bin_file)-1 //loop through character spot + length of bin_file - 1
                    while loop_this_many_times>0 {
                    active_bin_string[loop_this_many_times] = file_to_search[character+loop_this_many_times]
                    loop_this_many_times--
                    }
                     active_bin_string = reverse(active_bin_string) //reverse it because you searched backwards
                    if bin_file = to_string(active_bin_string) {
                    matches += to_string(file)
                     }
             }
      }
}
print matches
All you need in life is a strong will to succeed and unrelenting determination. If you meet these prerequisites, you can become anything you want with absolutely no luck, fortune or natural ability.
FreeZEternal
Profile Joined January 2003
Korea (South)3396 Posts
Last Edited: 2008-05-13 20:02:50
May 13 2008 20:02 GMT
#3
is it just me or suddenly we have lots of programming questions. I would have done this in Java or Ruby.
MasterOfChaos
Profile Blog Joined April 2007
Germany2896 Posts
Last Edited: 2008-05-13 20:38:08
May 13 2008 20:33 GMT
#4
for matching the signature you can use a simple binary safe StringPos function. If you want to code it yourself you can use sth like the following:
function CheckForSig(File:String;Sig:String);
var i,j:integer;
hit:boolean;
for i:=0 to length(file)-1 do
hit:=true;
for j:=0 to min(length(file)-1-i,length(sig)-1) do
if file[i+j]!=sig[j]then hit:=false;break;end;
end;
if hit then return true; end;
end;
return false;
end;

of cause that is not the fastest possible way of doing it, for a large signature set.

edit: Pos function used by Delphi (asmcode )
+ Show Spoiler +
(* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The implementation of function Pos is subject to the
* Mozilla Public License Version 1.1 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Fastcode
*
* The Initial Developer of the Original Code is Fastcode
*
* Portions created by the Initial Developer are Copyright (C) 2002-2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Aleksandr Sharahov
*
* ***** END LICENSE BLOCK ***** *)
function Pos(const substr, str: AnsiString): Integer; overload;
asm
push ebx
push esi
add esp, -16
test edx, edx
jz @NotFound
test eax, eax
jz @NotFound
mov esi, [edx-4] //Length(Str)
mov ebx, [eax-4] //Length(Substr)
cmp esi, ebx
jl @NotFound
test ebx, ebx
jle @NotFound
dec ebx
add esi, edx
add edx, ebx
mov [esp+8], esi
add eax, ebx
mov [esp+4], edx
neg ebx
movzx ecx, byte ptr [eax]
mov [esp], ebx
jnz @FindString

sub esi, 2
mov [esp+12], esi

@FindChar2:
cmp cl, [edx]
jz @Matched0ch
cmp cl, [edx+1]
jz @Matched1ch
add edx, 2
cmp edx, [esp+12]
jb @FindChar4
cmp edx, [esp+8]
jb @FindChar2
@NotFound:
xor eax, eax
jmp @Exit0ch

@FindChar4:
cmp cl, [edx]
jz @Matched0ch
cmp cl, [edx+1]
jz @Matched1ch
cmp cl, [edx+2]
jz @Matched2ch
cmp cl, [edx+3]
jz @Matched3ch
add edx, 4
cmp edx, [esp+12]
jb @FindChar4
cmp edx, [esp+8]
jb @FindChar2
xor eax, eax
jmp @Exit0ch

@Matched2ch:
add edx, 2
@Matched0ch:
inc edx
mov eax, edx
sub eax, [esp+4]
@Exit0ch:
add esp, 16
pop esi
pop ebx
ret

@Matched3ch:
add edx, 2
@Matched1ch:
add edx, 2
xor eax, eax
cmp edx, [esp+8]
ja @Exit1ch
mov eax, edx
sub eax, [esp+4]
@Exit1ch:
add esp, 16
pop esi
pop ebx
ret

@FindString4:
cmp cl, [edx]
jz @Test0
cmp cl, [edx+1]
jz @Test1
cmp cl, [edx+2]
jz @Test2
cmp cl, [edx+3]
jz @Test3
add edx, 4
cmp edx, [esp+12]
jb @FindString4
cmp edx, [esp+8]
jb @FindString2
xor eax, eax
jmp @Exit1

@FindString:
sub esi, 2
mov [esp+12], esi
@FindString2:
cmp cl, [edx]
jz @Test0
@AfterTest0:
cmp cl, [edx+1]
jz @Test1
@AfterTest1:
add edx, 2
cmp edx, [esp+12]
jb @FindString4
cmp edx, [esp+8]
jb @FindString2
xor eax, eax
jmp @Exit1

@Test3:
add edx, 2
@Test1:
mov esi, [esp]
@Loop1:
movzx ebx, word ptr [esi+eax]
cmp bx, word ptr [esi+edx+1]
jnz @AfterTest1
add esi, 2
jl @Loop1
add edx, 2
xor eax, eax
cmp edx, [esp+8]
ja @Exit1
@RetCode1:
mov eax, edx
sub eax, [esp+4]
@Exit1:
add esp, 16
pop esi
pop ebx
ret

@Test2:
add edx,2
@Test0:
mov esi, [esp]
@Loop0:
movzx ebx, word ptr [esi+eax]
cmp bx, word ptr [esi+edx]
jnz @AfterTest0
add esi, 2
jl @Loop0
inc edx
@RetCode0:
mov eax, edx
sub eax, [esp+4]
add esp, 16
pop esi
pop ebx
end;
LiquipediaOne eye to kill. Two eyes to live.
FreeZEternal
Profile Joined January 2003
Korea (South)3396 Posts
Last Edited: 2008-05-13 20:45:03
May 13 2008 20:38 GMT
#5
holy shit lol. Haven't seen asm for a long!!!!! time
LastWish
Profile Blog Joined September 2004
2015 Posts
May 13 2008 21:21 GMT
#6
Use google to find examples on anything something like : "C++ find file".
And combine it together.

You may easily read the file into String (delphi, java or ruby, lil harder in C++) and use some substring or pos or whatever function.
Really easy task.

Delphi code :
use FindFirst and FindNext functions(see help)
use
S : String;
AssignFile(F,FileName);
SetLength(S,FileSize(F));
BlockRead(F, S[1], FileSize(F));
CloseFile(F);

use Pos function to find whether there is an appropriate match
- It's all just treason - They bring me down with their lies - Don't know the reason - My life is fire and ice -
yenta
Profile Blog Joined April 2006
Poland1142 Posts
Last Edited: 2008-05-14 00:02:59
May 13 2008 23:56 GMT
#7
What you're describing can be written very simply in perl.

pseudo code:

@signatures = <SIGNATURE_FILE>
foreach $file in recursive_glob(PARENT_DIRECTORY) {
@contents = <$file>
foreach $chunk in @contents {
if $chunk in @signatures warn "virus"
}
}

just make sure you use binmode
Trutacz Practice Discord - https://discord.gg/PWF7Pv
Please log in or register to reply.
Live Events Refresh
Afreeca Starleague
10:00
Ro4 Match 2
Light vs Flash
Afreeca ASL 18506
StarCastTV_EN559
Liquipedia
CranKy Ducklings
10:00
Master Swan Open #103
CranKy Ducklings79
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
ProTech139
StarCraft: Brood War
Britney 45606
Calm 10624
Sea 8552
Bisu 3917
Jaedong 2183
BeSt 1719
Rush 1119
Horang2 705
EffOrt 643
Pusan 506
[ Show more ]
actioN 244
Larva 166
Mind 118
ToSsGirL 108
Hyun 96
Sharp 91
Mong 79
Killer 68
HiyA 61
Sexy 53
NaDa 19
soO 19
GoRush 17
Bale 17
JulyZerg 17
Terrorterran 16
[sc1f]eonzerg 16
ajuk12(nOOB) 12
SilentControl 9
scan(afreeca) 9
Hm[arnc] 8
hero 6
Dota 2
XcaliburYe187
Counter-Strike
olofmeister4411
shoxiejesuss1483
x6flipin263
markeloff59
edward45
Other Games
singsing1114
Happy253
monkeys_forever168
crisheroes116
B2W.Neo65
ToD52
Organizations
Counter-Strike
PGL60460
Other Games
gamesdonequick670
StarCraft: Brood War
UltimateBattle 296
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 17 non-featured ]
StarCraft 2
• StrangeGG 75
• CranKy Ducklings SOOP16
• Kozan
• sooper7s
• Migwel
• LaughNgamezSOOP
• IndyKCrew
• intothetv
• AfreecaTV YouTube
StarCraft: Brood War
• iopq 4
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis3162
• Jankos843
• Stunt499
Other Games
• WagamamaTV298
Upcoming Events
INu's Battles
2m
ByuN vs herO
IntoTheiNu 105
PiGosaur Cup
13h 2m
Replay Cast
22h 2m
Replay Cast
1d 13h
The PondCast
1d 23h
OSC
1d 23h
Replay Cast
2 days
RSL Revival
2 days
OSC
3 days
Korean StarCraft League
3 days
[ Show More ]
RSL Revival
3 days
BSL
4 days
GSL
4 days
Cure vs herO
SHIN vs Maru
BSL
5 days
Replay Cast
5 days
Replay Cast
6 days
The PondCast
6 days
Liquipedia Results

Completed

Proleague 2026-05-11
WardiTV TLMC #16
Nations Cup 2026

Ongoing

BSL Season 22
ASL Season 21
IPSL Spring 2026
KCM Race Survival 2026 Season 2
Acropolis #4
KK 2v2 League Season 1
BSL 22 Non-Korean Championship
SCTL 2026 Spring
RSL Revival: Season 5
2026 GSL S1
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2

Upcoming

Escore Tournament S2: W7
YSL S3
Escore Tournament S2: W8
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
BLAST Bounty Summer 2026: Closed Qualifier
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.