-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm2.cs
More file actions
111 lines (91 loc) · 3 KB
/
Form2.cs
File metadata and controls
111 lines (91 loc) · 3 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace ProjectDotNet20
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
txtFileName.Text = "D:\\a.dll";
}
private void button1_Click(object sender, EventArgs e)
{
var result = this.openFileDialog1.ShowDialog();
if (result != DialogResult.OK)
return;
try
{
byte[] buffer = File.ReadAllBytes(openFileDialog1.FileName);
txtResult.Text = Utilities.GetMimeFromBytes(buffer);
//txtResult.Text = BitConverter.ToString(buffer).Replace("-", "");
}
catch (Exception ex)
{
txtResult.Text = ex.Message;
}
}
private void btnBinaryToFile_Click(object sender, EventArgs e)
{
try
{
string bitString = txtResult.Text;
//string bitString = File.ReadAllText("D:\\dll.txt");
BinaryTextToFileDLL(bitString, txtFileName.Text);
MessageBox.Show("Success!");
}
catch (Exception ex)
{
txtResult.Text = ex.Message;
}
}
private void btnFileTextToDll_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog fd = new OpenFileDialog();
var result = fd.ShowDialog();
if (result != DialogResult.OK)
return;
string bitString = File.ReadAllText(fd.FileName);
bitString = bitString.Trim();
if (bitString.StartsWith("FROM"))
{
bitString = bitString.Substring(4);
bitString = bitString.Trim();
}
if (bitString.StartsWith("0x"))
{
bitString = bitString.Substring(2);
bitString = bitString.Trim();
}
BinaryTextToFileDLL(bitString, txtFileName.Text);
MessageBox.Show("Success!");
}
catch (Exception ex)
{
txtResult.Text = ex.Message;
}
}
private void BinaryTextToFileDLL (string bitString, string txtFileName)
{
Int64 length = (bitString.Length) / 2;
byte[] byteArray = new byte[length];
for (int i = 0; i < length; i++)
{
string stringBit = bitString.Substring(i * 2, 2);
byteArray[i] = Convert.ToByte(stringBit, 16);
}
using (var fs = new FileStream(txtFileName, FileMode.Create, FileAccess.Write))
{
fs.Write(byteArray, 0, byteArray.Length);
}
}
}
}