Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow

    [Tutorial] String collections and settings. I think so.

    Specialized Strings Collection, where do they stand?

    Introduction

    Hey guys, been really bored lately and I was stuck at home for the whole day for a family thing so I was looking for something to do. I was racking my brains for a tutorial I could write and I started a massive 'Settings' tutorial, 15 pages later I abandoned it because it had horrible structure and I just couldn't condense it so everyone would "TL;DR" the shit out of it.

    However, I did learn one valuable thing from writing that tut and that was of string collections and their power as a settings saver! No joke these badboys can be used to replace a basic ini document and hence remove the need of an external file. As it's a child of the My.Settings class it's built into VB and saved internally. So yeah, I'll endeavour to explain as much as i can about String Collections today and how YOU can use them to replace your annoying .inis

    The Tutorial

    Alrighty, first off: how the hell do I make this "Specialized String Collection"? Simple, go to add a setting as you normally would and for the "type" choose "Specialized.StringCollection" and hit ok, you now have a string collection. NOTE: In this tutorial I named my StringCollection setting "StrCollect" orginal right?

    Now, it's theory time so you understand the basics of a String Collection and what it's capable of. I'll try and compare a string collection with an external file as much as I can so that you can compare it with something most people are familiar with.

    I find it hard to explain the concept of a string collection without writing 30,000 lines trying to explain the details. But basically a string collection contains a collection of string, each separate entry is indexed within the collection with an index number, starting at 0 and continuing for as long as you want. To retrieve a specific entry you just have to tell the collection which index you want to look at. Adding new entries is as simple as an ".add" whacked on the end.
    So how can we use this to simulate an XML or an INI? Well, try and image that each index is similar to each separate line of an ini/XML/dat or whatever, and go from there. Here's a brief example of adding 3 separate "lines" to a string collection:

    Firstly you need to add this to your Form_Load or you'll get null reference errors aplenty, thank you to the guy from MSDN that solved this problem for me!

    Snippet #1
    [php]
    If My.Settings.StrCollect Is Nothing Then
    My.Settings.StrCollect = New System.Collections.Specialized.StringCollection
    End If
    [/php]

    Basically that says that if the String Collection has no contents, define it as a new stringcollection which will substantiate the object and stop those damn null reference errors!

    Alrighty, now let's also add 3 items to the collection like so: (Put this in the form_load event AFTER the previous snippet (gotta substantiate the collection before we add to it!))

    Snippet #2
    [php]
    My.Settings.StrCollect.Add("Hello")
    My.Settings.StrCollect.Add("Welcome to")
    My.Settings.StrCollect.Add("My tutorial")
    [/php]

    Okay now we have 3 sets of string in our collection, all contained within seperate indexes. Remember, the first index starts at 0, not 1! Now, let's try extracting one of these lines, it's pretty simple. Add this to a button_click event or something similar.

    Snippet #3
    [php]
    MsgBox(My.Settings.StrCollect(1))
    [/php]

    This will pop-up a messagebox with whatever was contained in index "1", remembering that the indexes start at 0, we should expect this to return the seconds line, "Welcome to" and lo and behold, it does just that! Neat huh? So hopefully now you get the concept of each line having its own index which can be easily accessed. Now we'll move on to adding a bunch of separate lines as the contents of a listbox!

    Snippet #4
    [php]
    For each s As String in ListBox1.Items
    My.Settings.StrCollect.Add(s)
    Next
    My.Settings.Save() 'DON'T FORGET TO SAVE!
    My.Settings.Reload()
    [/php]

    Now we want to add each of these items back again!

    Snippet #5
    [php]
    For i as integer = 0 to My.Settings.StrCollec*****unt
    ListBox1.Items.Add(My.Settings.StrCollect(i))
    Next
    [/php]

    What do you know, that added all the items! By doing "For i as integer = 0 to My.Settings.StrCollec*****unt" we’re executing the code contained between “For” and “Next” with an integer “i” that increases by one each time it loops through until it reaches the total number of currently used indices in the StringCollection, cool.
    But this method may not work for retrieving settings very effectively, how are you going to know that those 3 lines need to be added to a listbox is you have 100 lines to choose from? Well firstly, let's condense those 3 entries into a single line with a nice separator between each entry. We can condense them all to one line with a simple for-next block, such as this:

    Snippet #6
    [php]
    Dim TotalString As String = “” ‘first we declare a string variable to hold the info until we need it
    For each s As String in Listbox1.Items
    If TotalString <> “” then
    TotalString &= (“,” & s) ‘if this is not the first entry into “TotalString” it will add a separator “,” between the previous entry and the current entry
    Else
    TotalString &= s
    End if
    Next
    If Not TotalString = “” then ‘if there are items in the listbox
    My.Settings.StrCollect.Add(TotalString)
    My.Settings.Save()
    My.Settings.Reload()
    Else: Exit sub
    [/php]

    Okay with this little bit of code, we add each item to a string variable with a “,” between entries so it looks like this “item1,item2,item3,item4”. Now, you may ask, “why do we add it all to one line, won’t that make it harder to get the values we need!?” The answer is no, with basic string manipulation we can separate each entry, this is why I added the “,” separator between each item. So, this is how we would get each entry back again.

    Snippet #7
    [php]
    For each item As String in My.Settings.StrCollect(0).Split(“,”)
    ListBox1.Items.Add(item)
    Next
    [/php]

    Okay I used the index “0” for My.Settings.StrCollect because I only had one index in the collection so I knew it was going to be stored in the first index. Later in the tut I’ll explain looping through all the indexes and getting only what we need (it’s similar to "Snippet #5). By using the “Split” function you can split a line of string into separate items by using a common separator, in this case “,” was common. I then added them all to the textbox.

    That might be all fine and dandy, but we still need to make it UNIQUE so we can find it easily in amongst dozens of other lines. This is where wrappers(?) come in handy, I prefer to call them headers and footers just because it makes sense to me but call them what you will. By header I mean the section of string that precedes the content and by footer I meant the section of string that comes after contents ie:
    Code:
    <HEADER>CONTENTLALALA</FOOTER>
    I personally use headers for the unique factor (i.e “<ListBox1></ListBox>”, “<MiscInfo></ListBox>”) In both cases I left the footer as </ListBox> to illustrate the fact that both are listboxes but changed the header to something unique. This an example of me creating a sub procedure that will generate a unique header and save a listboxes content:

    Snippet #8
    [php]
    Private Sub SaveListBox(ByVal lbox As ListBox)

    Dim TotalString As String = ""

    For Each item As String In lbox.Items
    If TotalString = "" Then
    TotalString &= item
    Else
    TotalString &= ("," & item)
    End If
    Next

    If Not TotalString = "" Then 'if there are entries in the listbox, add them else exit.

    Dim header As String = "<" & lbox.Name & ">"
    Dim footer As String = "</ListBox>"
    Dim output As String = header & TotalString & footer

    My.Settings.StrCollect.Add(output)
    My.Settings.Save()
    My.Settings.Reload()

    Else
    Exit Sub
    End If

    End Sub

    'EXAMPLE HERE:

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    SaveListBox(ListBox1)
    End Sub
    [/php]

    As you can see, I make the programmer pass which ListBox they want to save into the parameters of the sub-procedure. Because no control can have the same name in a form generating the header as the ListBox.Name ensures a nice unique header, it also makes it easy to retrieve again. Although we covered the basics of splitting in "Snippet #6", we didn’t factor in the header and footer. In light of this we need to extract the contents as a line, then split that. Here’s my LoadListBox Sub (note the programmer must pass which listbox to load)

    Snippet #9
    [php]
    Private Sub LoadListBox(ByVal lBox As ListBox)

    Dim header As String = "<" & lBox.Name & ">"
    Dim contents As String = ""
    Dim footer As String = "</ListBox>"
    Dim footerIndex As Integer

    For i As Integer = 0 To My.Settings.StrCollec*****unt
    If My.Settings.StrCollect(i).StartsWith(header) Then
    footerIndex = My.Settings.StrCollect(i).LastIndexOf(footer)
    contents = My.Settings.StrCollect(i).Substring((header.Length ), footerIndex - header.Length)

    For Each entry As String In contents.Split(",")
    lBox.Items.Add(entry)
    Next
    End If
    Next

    End Sub

    'EXAMPLE HERE:

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    LoadListBox(ListBox1)
    End Sub

    [/php]

    And that’s all there is to it! Now to go more in depth, I first define all the needed sections of string for ease of use as well as an integer for where the index of the footer is. I'm not going to explain that any further because if i start getting into all the little tidbits I'm never going to finish! Next up, we loop through all the indexes contained withing My.Settings.StrCollect looking for one that starts with our unique header. If we find one, we extract the contents between the header and footer and then split that into individual items, then add to the listbox.

    Well that about concludes the tutorial for today, I'll leave you with a similar method for adding a textbox to the collection, it's much the same except you don't need to split it because you only have one entry to consider.

    Snippet #10
    [php]
    Private Sub SaveTextBox(ByVal tBox As TextBox)

    Dim header As String = "<" & tBox.Name & ">"
    Dim footer As String = "</TextBox>"
    Dim contents As String = tBox.Text
    Dim output As String = header & contents & footer

    If contents <> "" Then
    My.Settings.StrCollect.Add(output)
    My.Settings.Save()
    My.Settings.Reload()
    Else
    Exit Sub
    End If

    End Sub

    'EXAMPLE HERE:

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    SaveTextBox(TextBox1)
    End Sub
    [/php]

    Snippet #10
    [php]
    Private Sub LoadTextBox(ByVal tBox As TextBox)

    Dim header As String = "<" & tBox.Name & ">"
    Dim footer As String = "</TextBox>"
    Dim contents As String = ""
    Dim footerIndex As Integer

    For i As Integer = 0 To My.Settings.StrCollec*****unt

    If My.Settings.StrCollect(i).StartsWith(header) Then
    footerIndex = My.Settings.StrCollect(i).LastIndexOf(footer)
    contents = My.Settings.StrCollect(i).Substring(header.Length, footerIndex - header.Length)
    End If

    Next

    If contents <> "" Then
    tBox.Text = contents
    End If

    End Sub

    'EXAMPLE HERE

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    LoadTextBox(TextBox1)
    End Sub

    [/php]

    That concludes my contribution for today, I hope someone learns something from this. If you have any questions please feel free to ask and I'll try explain to the best of my ability.

    Cheers

    J-Deezy

    P.S this tutorial is reserved for the sole use of MPGH and it's users, if i see it leaked on another site (which is doubtful but whatever) I will be mighty pissed off.

    Lat0rz

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  2. The Following 7 Users Say Thank You to Jason For This Useful Post:

    'Bruno (09-11-2010),-Away Alt (03-20-2011),bbhing987 (09-12-2010),Blubb1337 (09-10-2010),Invidus (09-12-2010),Lolland (09-11-2010),Maniac101 (09-11-2010)

  3. #2
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    Make a .pdf out of it.



  4. #3
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by Blubb1337 View Post
    Make a .pdf out of it.
    Nou .

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  5. #4
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed
    Good Job . .


     


     


     



    The Most complete application MPGH will ever offer - 68%




  6. #5
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by NextGen1 View Post
    Good Job . .
    Thanks NG , Did I make any big errors?

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  7. #6
    ubanooba's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Posts
    35
    Reputation
    10
    Thanks
    1
    My Mood
    Confused
    Cool, this is really helpful! Does this mean I don't need to use ini in my injector!? I am a little bit noob I dont fully understnad

  8. #7
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by ubanooba View Post
    Cool, this is really helpful! Does this mean I don't need to use ini in my injector!? I am a little bit noob I dont fully understnad
    If you structure it correctly and make sure to follow the way I explained to save unique entries for each control, then yes, you can remove your programs dependence on an external file.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  9. #8
    mizzer3's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    MPGH.net
    Posts
    888
    Reputation
    7
    Thanks
    171
    My Mood
    Sleepy
    Omg, nice work man !
    Heal Ur Allies, And You Will Win The War.



    RESPECT LIST :

    - Very Good Friend - Sn0wn00b
    - All the Mpgh minions ( special m3 )
    - th3reaper
    - respeckt52
    - s3liskar
    - thecamels8

  10. #9
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by mizzer3 View Post
    Omg, nice work man !
    Cheers...though I wonder how many people are actually going to read it all and use it in their programs... <1 is my bet

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  11. #10
    mizzer3's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    MPGH.net
    Posts
    888
    Reputation
    7
    Thanks
    171
    My Mood
    Sleepy
    Quote Originally Posted by J-Deezy View Post


    Cheers...though I wonder how many people are actually going to read it all and use it in their programs... <1 is my bet
    i think many peps gonna do it man
    Heal Ur Allies, And You Will Win The War.



    RESPECT LIST :

    - Very Good Friend - Sn0wn00b
    - All the Mpgh minions ( special m3 )
    - th3reaper
    - respeckt52
    - s3liskar
    - thecamels8

  12. #11
    Lolland's Avatar
    Join Date
    Feb 2009
    Gender
    male
    Location
    Lolland!
    Posts
    3,156
    Reputation
    49
    Thanks
    868
    My Mood
    Inspired
    Added to tuts.

  13. #12
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by lolland View Post
    Added to tuts.
    Cheers broham.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  14. #13
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Very good job
    Now that I am back, I am thinking to create some string formatting tutorials =P

  15. #14
    Invidus's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    2,167
    Reputation
    23
    Thanks
    650
    My Mood
    Bored
    HASSAN ISS BACK!!!
    WELCOME BACK!!
    Man i been waiting for you to get back so you can give me a hand
    J-deezy, you're a fucking legend..
    Excuse my language ↑↑

  16. #15
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by Xscapism View Post
    Very good job
    Now that I am back, I am thinking to create some string formatting tutorials =P
    OMG, PEDO DADDY IS BACK <333



    Thanks andrew

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

Page 1 of 2 12 LastLast

Similar Threads

  1. [Question] String Collections
    By |-|3|_][({}PT3R12 in forum Visual Basic Programming
    Replies: 21
    Last Post: 01-24-2010, 10:54 AM
  2. [Tutorial] String Manipulation
    By NextGen1 in forum Visual Basic Programming
    Replies: 3
    Last Post: 01-19-2010, 11:57 PM
  3. Replies: 33
    Last Post: 07-28-2009, 04:38 AM
  4. [Tutorial] CE's and Address's - hao do i mayke h4ck?
    By Iwin in forum Combat Arms Hacks & Cheats
    Replies: 29
    Last Post: 09-22-2008, 05:27 PM
  5. tons of addreses :) everything accept invisible and opk i think :)
    By george567 in forum WarRock - International Hacks
    Replies: 10
    Last Post: 07-01-2007, 05:42 PM