• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 12:15
CET 17:15
KST 01:15
  • 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] Ro24 Preview Pt1: New Chaos0Team Liquid Map Contest #22 - Presented by Monster Energy5ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289
Community News
Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool36Weekly Cups (March 9-15): herO, Clem, ByuN win42026 KungFu Cup Announcement6BGE Stara Zagora 2026 cancelled12Blizzard Classic Cup - Tastosis announced as captains18
StarCraft 2
General
Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Potential Updates Coming to the SC2 CN Server Weekly Cups (March 2-8): ByuN overcomes PvT block Weekly Cups (August 25-31): Clem's Last Straw? Weekly Cups (March 9-15): herO, Clem, ByuN win
Tourneys
World University TeamLeague (500$+) | Signups Open RSL Season 4 announced for March-April Sparkling Tuna Cup - Weekly Open Tournament WardiTV Team League Season 10 KSL Week 87
Strategy
Custom Maps
Publishing has been re-enabled! [Feb 24th 2026]
External Content
The PondCast: SC2 News & Results Mutation # 517 Distant Threat Mutation # 516 Specter of Death Mutation # 515 Together Forever
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ JaeDong's form before ASL [ASL21] Ro24 Preview Pt1: New Chaos ASL21 General Discussion Gypsy to Korea
Tourneys
[Megathread] Daily Proleagues [BSL22] Open Qualifiers & Ladder Tours Small VOD Thread 2.0 IPSL Spring 2026 is here!
Strategy
Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2 Fighting Spirit mining rates
Other Games
General Games
General RTS Discussion Thread Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
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
Five o'clock TL Mafia Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia TL Mafia Community Thread
Community
General
Things Aren’t Peaceful in Palestine YouTube Thread US Politics Mega-thread Canadian Politics Mega-thread Russo-Ukrainian War Thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Movie Discussion! [Req][Books] Good Fantasy/SciFi books [Manga] One Piece
Sports
2024 - 2026 Football Thread Cricket [SPORT] Formula 1 Discussion Tokyo Olympics 2021 Thread General nutrition recommendations
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
Funny Nicknames
LUCKY_NOOB
Money Laundering In Video Ga…
TrAiDoS
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2097 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
LAN Event
16:00
StarCraft Madness Day 2
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
LamboSC2 255
Vindicta 93
MindelVK 6
StarCraft: Brood War
Britney 34974
Calm 3403
Jaedong 2044
Mini 657
Larva 477
Shuttle 443
Soma 418
Light 346
Rush 246
firebathero 222
[ Show more ]
EffOrt 216
BeSt 187
actioN 117
hero 113
JulyZerg 47
Aegong 37
sorry 33
Nal_rA 28
Free 27
ggaemo 21
IntoTheRainbow 20
Shine 19
GoRush 19
Yoon 19
910 15
ivOry 5
eros_byul 1
Dota 2
Gorgc7381
League of Legends
JimRising 524
Reynor38
Counter-Strike
fl0m4376
Fnx 2922
byalli476
Super Smash Bros
hungrybox545
Heroes of the Storm
Khaldor450
Liquid`Hasu414
Other Games
singsing2388
Liquid`RaSZi1165
B2W.Neo1016
Beastyqt374
FrodaN281
Mlord238
Happy233
Hui .201
Grubby66
Organizations
Dota 2
PGL Dota 2 - Main Stream61
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• Berry_CruncH276
• Airneanach6
• LUISG 1
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota243
League of Legends
• Jankos4906
• Shiphtur0
Upcoming Events
BSL
3h 45m
Replay Cast
16h 45m
Afreeca Starleague
17h 45m
Sharp vs Scan
Rain vs Mong
Wardi Open
19h 45m
Monday Night Weeklies
1d
Sparkling Tuna Cup
1d 17h
Afreeca Starleague
1d 17h
Soulkey vs Ample
JyJ vs sSak
Replay Cast
2 days
Afreeca Starleague
2 days
hero vs YSC
Larva vs Shine
Kung Fu Cup
2 days
[ Show More ]
Replay Cast
3 days
KCM Race Survival
3 days
The PondCast
3 days
WardiTV Team League
3 days
Replay Cast
4 days
WardiTV Team League
4 days
RSL Revival
5 days
Cure vs Zoun
herO vs Rogue
WardiTV Team League
5 days
Platinum Heroes Events
5 days
BSL
6 days
RSL Revival
6 days
ByuN vs Maru
MaxPax vs TriGGeR
WardiTV Team League
6 days
Liquipedia Results

Completed

Jeongseon Sooper Cup
WardiTV Winter 2026
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
BSL Season 22
CSL Elite League 2026
CSL Season 20: Qualifier 1
RSL Revival: Season 4
Nations Cup 2026
NationLESS Cup
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

ASL Season 21
Acropolis #4 - TS6
2026 Changsha Offline CUP
CSL Season 20: Qualifier 2
CSL 2026 SPRING (S20)
Acropolis #4
IPSL Spring 2026
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
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.