|
-
Apr 10th, 2013, 02:44 AM
#1
Thread Starter
Member
File IO help!
So I am using this to put information into a file:
Code:
Dim Stub, text1, text2, PW As String
Const FileSplit = "@#$%SWAGDAYZ%$#@"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Input As String = Nothing
Dim q As String = FileSplit
text1 = TextBox1.Text
text2 = Encrypt(TextBox2.Text, TextBox3.Text)
TextBox3.Text = text2
PW = TextBox3.Text
Input = Stub & q & text1 & q & text2 & q & PW
FileOpen(1, Application.StartupPath & "\Stub.exe", OpenMode.Binary, OpenAccess.Read, OpenShare.Default)
Stub = Space(LOF(1))
FileGet(1, Stub)
FileClose(1)
If File.Exists(Application.StartupPath + "\Server.exe") Then
My.Computer.FileSystem.DeleteFile(Application.StartupPath + "\Server.exe")
End If
FileOpen(1, Application.StartupPath & "\Stub.exe", OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.Default)
FilePut(1, Input)
FileClose(1)
MsgBox("Server made successfully", MsgBoxStyle.OkOnly, "Success")
End Sub
And this to pull it from that file and use the information:
Code:
Dim stub, text1, text2, PW As String
Dim user, pass As String
Const FileSplit = "@#$%SWAGDAYZ%$#@"
Dim options() As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ShowInTaskbar = False
FileOpen(1, Application.ExecutablePath, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.Default)
text1 = Space(LOF(1))
text2 = Space(LOF(1))
PW = Space(LOF(1))
FileGet(1, text1) ' options(1)
FileGet(1, text2) ' options(2)
FileGet(1, PW) 'options(3)
FileClose(1)
options = Split(text1, FileSplit)
passBox.Text = text1
'options = text1.Split(FileSplit)
'text2 = Decrypt(text2, PW)
'passBox.Text = text2
'Check1()
End Sub
I am getting so much fail it hurts. Can you guys look over it and tell me how to fix it?
-
Apr 10th, 2013, 03:38 AM
#2
Re: File IO help!
Ugg that is so ugly. We don't do files like that anymore. We use serializable classes. Describe what it is you want to do in detail and lets start from scratch with a proper and easy to maintain method.
-
Apr 10th, 2013, 03:48 AM
#3
Thread Starter
Member
Re: File IO help!
I have a program. It has a textbox. I need it to open a file, put the information in the file. Then it needs to be able to (when you open that file) take the information put in the file, and put it into a textbox in the second program. There are 3 textboxes it needs to do this for.
-
Apr 10th, 2013, 09:21 AM
#4
Hyperactive Member
Re: File IO help!
I think I can see what you want but your directions are not clear. When you say "into a textbox in the second program" are you referring to another textbox or another textbox in another form...or as you say, another textbox in another program.
I would look at using StreamReader and StreamWriter classes for this. Granted that reading and writing to text files is not as easy as it use to be in the old QBASIC days, but if you look at these methods you should find what you're looking for.
-
Apr 10th, 2013, 09:52 AM
#5
Thread Starter
Member
Re: File IO help!
Ok, here is how it goes. 100% literal. 1st Program:
Text1 = TextBox1.Text
Text2 = TextBox2.Text
PW = TextBox3.Text
I need this to open a file(Stub.exe), put Text1, Text2, and PW into that file, then make a new files using stub.exe with the Text1, Text2, and PW inside it. When the new file open, it needs to pull this information.
So I can do this in the second program:
TextBox1.Text = Text1
TextBox2.Text = Text2
TextBox3.Text = PW
When I say program, I mean a .exe program. Not another Form.
-
Apr 10th, 2013, 09:53 AM
#6
Re: File IO help!
OMG I almost forgot about this. Sorry about that.....Anyways:-
vbnet Code:
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.IO
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
'We save our data by placing the data
'into this object
Dim info As New PersonInfo
Dim bf As New BinaryFormatter
'Create or trucate a file to save the data and opens
'it for writing
Dim fs As New FileStream("c:\PersonInfo.bin", FileMode.Create, FileAccess.Write)
'We put our information from the TextBoxes
'into the PersonInfo object
info.Name = txtName.Text
info.Age = nudAge.Value
info.Address = txtAddr.Text
'Writes the data into the FileStream using the object
bf.Serialize(fs, info)
'Writes the information to the file on disk
'and closes the stream
fs.Close()
End Sub
Private Sub btnLoad_Click(sender As System.Object, e As System.EventArgs) Handles btnLoad.Click
'Open the file
Dim fs As New FileStream("C:\PersonInfo.bin", FileMode.OpenOrCreate, FileAccess.Read)
Dim bf As New BinaryFormatter
'Get the information from the file which
'would be placed into a PersonInfo object
Dim info As PersonInfo = DirectCast(bf.Deserialize(fs), PersonInfo)
'Put the data in the PersonInfo object
'into the TextBoxes
txtAddr.Text = info.Address
txtName.Text = info.Name
nudAge.Value = info.Age
'Close the file
fs.Close()
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.txtName = New System.Windows.Forms.TextBox()
Me.nudAge = New System.Windows.Forms.NumericUpDown()
Me.txtAddr = New System.Windows.Forms.TextBox()
Me.btnSave = New System.Windows.Forms.Button()
Me.btnLoad = New System.Windows.Forms.Button()
CType(Me.nudAge, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(12, 9)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(35, 13)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Name"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(12, 100)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(45, 13)
Me.Label2.TabIndex = 1
Me.Label2.Text = "Address"
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(12, 56)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(26, 13)
Me.Label3.TabIndex = 2
Me.Label3.Text = "Age"
'
'txtName
'
Me.txtName.Location = New System.Drawing.Point(63, 6)
Me.txtName.Name = "txtName"
Me.txtName.Size = New System.Drawing.Size(195, 20)
Me.txtName.TabIndex = 3
'
'nudAge
'
Me.nudAge.Location = New System.Drawing.Point(63, 54)
Me.nudAge.Name = "nudAge"
Me.nudAge.Size = New System.Drawing.Size(70, 20)
Me.nudAge.TabIndex = 4
'
'txtAddr
'
Me.txtAddr.Location = New System.Drawing.Point(63, 97)
Me.txtAddr.Name = "txtAddr"
Me.txtAddr.Size = New System.Drawing.Size(195, 20)
Me.txtAddr.TabIndex = 5
'
'btnSave
'
Me.btnSave.Location = New System.Drawing.Point(15, 137)
Me.btnSave.Name = "btnSave"
Me.btnSave.Size = New System.Drawing.Size(86, 32)
Me.btnSave.TabIndex = 6
Me.btnSave.Text = "Save"
Me.btnSave.UseVisualStyleBackColor = True
'
'btnLoad
'
Me.btnLoad.Location = New System.Drawing.Point(107, 137)
Me.btnLoad.Name = "btnLoad"
Me.btnLoad.Size = New System.Drawing.Size(86, 32)
Me.btnLoad.TabIndex = 7
Me.btnLoad.Text = "Load"
Me.btnLoad.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(297, 181)
Me.Controls.Add(Me.btnLoad)
Me.Controls.Add(Me.btnSave)
Me.Controls.Add(Me.txtAddr)
Me.Controls.Add(Me.nudAge)
Me.Controls.Add(Me.txtName)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.nudAge, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents txtName As System.Windows.Forms.TextBox
Friend WithEvents nudAge As System.Windows.Forms.NumericUpDown
Friend WithEvents txtAddr As System.Windows.Forms.TextBox
Friend WithEvents btnSave As System.Windows.Forms.Button
Friend WithEvents btnLoad As System.Windows.Forms.Button
End Class
'The Serializable attribute marks a file as
'serializable
<Serializable()> _
Public Class PersonInfo
Public Property Name As String
Public Property Address As String
Public Property Age As Integer
End Class
Create a new Windows Forms project overwrite Form1's code with the above and run it. It demonstrates how to save to, and load from, a file.
-
Apr 10th, 2013, 10:03 AM
#7
Thread Starter
Member
Re: File IO help!
I think you may be able to help me better 1on1. Can you add me on Skype? I'm at school now, but I will be home at 5. My username is DestrohGFX
-
Apr 10th, 2013, 10:17 AM
#8
Re: File IO help!
Err....have you at least tried it ? That code only looks complicated. That's only because I included all the code for putting the controls on the Form but the meat of it is only this:-
vbnet Code:
'
Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
'We save our data by placing the data
'into this object
Dim info As New PersonInfo
Dim bf As New BinaryFormatter
'Create or trucate a file to save the data and opens
'it for writing
Dim fs As New FileStream("c:\PersonInfo.bin", FileMode.Create, FileAccess.Write)
'We put our information from the TextBoxes
'into the PersonInfo object
info.Name = txtName.Text
info.Age = nudAge.Value
info.Address = txtAddr.Text
'Writes the data into the FileStream using the object
bf.Serialize(fs, info)
'Writes the information to the file on disk
'and closes the stream
fs.Close()
End Sub
Private Sub btnLoad_Click(sender As System.Object, e As System.EventArgs) Handles btnLoad.Click
'Open the file
Dim fs As New FileStream("C:\PersonInfo.bin", FileMode.OpenOrCreate, FileAccess.Read)
Dim bf As New BinaryFormatter
'Get the information from the file which
'would be placed into a PersonInfo object
Dim info As PersonInfo = DirectCast(bf.Deserialize(fs), PersonInfo)
'Put the data in the PersonInfo object
'into the TextBoxes
txtAddr.Text = info.Address
txtName.Text = info.Name
nudAge.Value = info.Age
'Close the file
fs.Close()
End Sub
And this class:-
vbnet Code:
'The Serializable attribute marks a file as
'serializable
<Serializable()> _
Public Class PersonInfo
Public Property Name As String
Public Property Address As String
Public Property Age As Integer
End Class
-
Apr 10th, 2013, 11:07 AM
#9
Hyperactive Member
Re: File IO help!
DesignLife,
We'd like to help you. That's what this forum is all about. But what you're describing here is really off-the-wall.
First off, you can create a text file and give it an .exe extension, although why you'd want to do that is unknown. If you give a file an .exe extension, your operating system will treat it in a certain way when you go access it. On the other hand, if you're actually wanting to insert text into an exe file, then now you're talking about a binary insertion of data into an existing file, which again is not what we really think you want.
It does sound like what you need is some one-on-one tutoring for this to better explain your requirements. Believe me there are plenty of people on this forum who can help you. The task you want sounds simple enough but what you're explaining takes it off into another area of programming.
If I've misinterpreted your intentions, I apologize. And I see from your original post that perhaps you are trying to write binary data to an exe file. But exe files are usually not the place to store data...not usually.
Last edited by Vladamir; Apr 10th, 2013 at 11:13 AM.
-
Apr 10th, 2013, 03:34 PM
#10
Lively Member
Re: File IO help!
Hi Niya,
Serialization is brand new to me, and I'm interested in this topic. So, I went ahead and practiced a run of your serialization coding. It gave me an exception more advanced then I can understand for this line in the BtnSave method:
Code:
bf.Serialize(fs, info) <--------
SerializationException was unhandled: Type 'WindowsApplication1.Personinfo' in Assembly 'WindowsApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable."
Would you help me understand what happened? The entire sub was copied verbatum, and I also have a Public Class for Personinfo with the necessary properties.
-
Apr 10th, 2013, 04:40 PM
#11
Re: File IO help!
Are you sure you copied everything ?:-
vbnet Code:
' 'The Serializable attribute marks a type as 'serializable <Serializable()> _ Public Class PersonInfo Public Property Name As String Public Property Address As String Public Property Age As Integer End Class
That error indicates that you may not have copied the Serializable attribute atop the PersonInfo class.
-
Apr 10th, 2013, 04:58 PM
#12
Re: File IO help!
Niya i am pretty sure i have seen this user posting to make a keylogger just look at the exe name stub.exe also. DesignLife this forum does not help in black hat activities.
-
Apr 10th, 2013, 05:01 PM
#13
Lively Member
Re: File IO help!
 Originally Posted by Niya
That error indicates that you may not have copied the Serializable attribute atop the PersonInfo class.
You're right. I missed that line! Works like a charm.
I don't quite understand it's full purpose yet, or when I would utilize this. It's still nice to know. Seems like it works like an encoder/decoder.
Rep +1!
-
Apr 10th, 2013, 05:28 PM
#14
Re: File IO help!
This whole thread would make a lot more sense if it was Stub.txt rather than Stub.exe. It sounds like a rather typical dead-drop transfer of information from one program to another where one writes a textfile and another reads it. That bit about writing to an .exe is bizarre, but it could also just be a typo. Frankly, I would say that the key question is whether or not both programs are expected to be running at the same time, as there are solutions that don't involve files to that problem.
My usual boring signature: Nothing
 
-
Apr 10th, 2013, 05:55 PM
#15
Re: File IO help!
 Originally Posted by ident
Niya i am pretty sure i have seen this user posting to make a keylogger just look at the exe name stub.exe also. DesignLife this forum does not help in black hat activities.
Well...he can't hack an EXE using the code I posted so its not a total loss.
-
Apr 11th, 2013, 12:44 AM
#16
Re: File IO help!
Writing stuff to the end of an EXE file is an old common trick for all things nasty and it wont work because anti-virus applications will mark it as a virus.
I want you to tell us exactly what your up to and why you want to do this. If you have legit reasons to do what you want there might be a better way of doing it and people here can provide you with more information about it. However if you're trying to create something like a keylogger you wont get any help from our members since it goes against all we believe in when it comes to what software should be doing.
Before you have replied with an answer and a full description on what you want to create I hereby formally ask, as a moderator, that nobody else replies to this question.
-
Apr 11th, 2013, 03:18 AM
#17
Thread Starter
Member
Re: File IO help!
The reason I am looking into this is simply to experiment. I have no set goal other then to learn the code better in all aspects.
-
Apr 11th, 2013, 03:41 AM
#18
Re: File IO help!
I'm sorry but that explanation just doesn't cut it. Why do you want to learn how to create malicious software? Why not learn how to create useful software instead?
-
Apr 11th, 2013, 04:36 AM
#19
Thread Starter
Member
Re: File IO help!
I never said I was using it maliciously, I simply said I wish to learn the code better. I will admit I am using the source code to a crypter, but I am using it to learn.
-
Apr 11th, 2013, 12:56 PM
#20
Re: File IO help!
 Originally Posted by DesignLife
I never said I was using it maliciously
-
Apr 11th, 2013, 01:25 PM
#21
Re: File IO help!
lol....hand in the cookie jar and all that
-
Apr 11th, 2013, 02:02 PM
#22
-
Apr 11th, 2013, 03:37 PM
#23
Re: File IO help!
 Originally Posted by DesignLife
I never said I was using it maliciously, I simply said I wish to learn the code better.
If you want to learn to code better then don't try to change a compiled EXE file because that is never good programming. Since you've posted the exact same question in another forum, admitting that you tried to create a keylogger and I've given you the opportunity to explain exactly what you wanted to do which you declined to do, I'm going to close this thread. Please become a better coder by coding something that is productive instead of things that aren't.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|