|
132
|
Programación / .NET (C#, VB.NET, ASP) / Leer recursos desde consola. codedom (EmbeddedResources.Add)
|
en: 20 Octubre 2011, 01:14 am
|
De esta forma introdusco el resource, pero no se como leer el resource guardado desde una aplicacion de consola. For Each _ResourceFile As String In _ResourceFiles ' Set the embedded resource file of the assembly. _CompilerParameters.EmbeddedResources.Add(_ResourceFile) Next _ResourceFile
Como podria leer el resource desde una aplicacion de consola? Bueno... es que directamente no se leer el recurso... por que por lo visto ahi que llamarlo desde system.resources.item o algo asi, pero no doy pies con bola
|
|
|
134
|
Programación / .NET (C#, VB.NET, ASP) / Re: my.resources.source.replace(variable, variable) Ayuda, reemplazar variable
|
en: 18 Octubre 2011, 17:50 pm
|
Dim cadena1 As String = my.resources.source1
cadena1 = My.Resources.source1.Replace("cadena", cadena.ToString) En cadena.tostring ahi un exe en formato ascii y me tira errores de carateres no validos en la depuracion. Si puedes ayudar se te agradeceria. Porsierto, muchas gracias por tu explicacion, es algo que no savia. Esta es la llamada a la funcion para crear el exe CompileCode(New Microsoft.VisualBasic.VBCodeProvider(), _VBSourceCode, Nothing, SaveFileDialog1.FileName, Nothing, Nothing, _Errors) Y esta es la funcion para generar el ejecutable Public Function CompileCode(ByVal _CodeProvider As System.CodeDom.Compiler.CodeDomProvider, ByVal _SourceCode As String, ByVal _SourceFile As String, ByVal _ExeFile As String, ByVal _AssemblyName As String, ByVal _ResourceFiles() As String, ByRef _Errors As String) As Boolean ' set interface for compilation Dim _CodeCompiler As System.CodeDom.Compiler.ICodeCompiler = _CodeProvider.CreateCompiler()
' Define parameters to invoke a compiler Dim _CompilerParameters As New System.CodeDom.Compiler.CompilerParameters()
If _ExeFile IsNot Nothing Then ' Set the assembly file name to generate. _CompilerParameters.OutputAssembly = _ExeFile
' Generate an executable instead of a class library. _CompilerParameters.GenerateExecutable = True _CompilerParameters.GenerateInMemory = False ElseIf _AssemblyName IsNot Nothing Then ' Set the assembly file name to generate. _CompilerParameters.OutputAssembly = _AssemblyName
' Generate an executable instead of a class library. _CompilerParameters.GenerateExecutable = False _CompilerParameters.GenerateInMemory = False Else ' Generate an executable instead of a class library. _CompilerParameters.GenerateExecutable = False _CompilerParameters.GenerateInMemory = True End If
' Generate debug information. '_CompilerParameters.IncludeDebugInformation = true;
' Set the level at which the compiler ' should start displaying warnings. _CompilerParameters.WarningLevel = 3 ' Set whether to treat all warnings as errors. _CompilerParameters.TreatWarningsAsErrors = False
' Set compiler argument to optimize output. _CompilerParameters.CompilerOptions = "/optimize" ' Set a temporary files collection. ' The TempFileCollection stores the temporary files ' generated during a build in the current directory, ' and does not delete them after compilation. _CompilerParameters.TempFiles = New System.CodeDom.Compiler.TempFileCollection(".", True)
If _ResourceFiles IsNot Nothing AndAlso _ResourceFiles.Length > 0 Then For Each _ResourceFile As String In _ResourceFiles ' Set the embedded resource file of the assembly. _CompilerParameters.EmbeddedResources.Add(_ResourceFile) Next _ResourceFile End If
Try ' Invoke compilation Dim _CompilerResults As System.CodeDom.Compiler.CompilerResults = Nothing
If _SourceFile IsNot Nothing AndAlso System.IO.File.Exists(_SourceFile) Then ' soruce code in external file _CompilerResults = _CodeCompiler.CompileAssemblyFromFile(_CompilerParameters, _SourceFile) Else ' source code pass as a string _CompilerResults = _CodeCompiler.CompileAssemblyFromSource(_CompilerParameters, _SourceCode) End If
If _CompilerResults.Errors.Count > 0 Then ' Return compilation errors _Errors = "" : For Each CompErr As System.CodeDom.Compiler.CompilerError In _CompilerResults.Errors _Errors &= "Line number " & CompErr.Line & ", Error Number: " & CompErr.ErrorNumber & ", '" & CompErr.ErrorText & ";" & Constants.vbCrLf & Constants.vbCrLf Next CompErr
' Return the results of compilation - Failed Return False Else ' no compile errors _Errors = Nothing End If Catch _Exception As Exception ' Error occurred when trying to compile the code _Errors = _Exception.Message Return False End Try
' Return the results of compilation - Success Return True End Function
|
|
|
137
|
Programación / .NET (C#, VB.NET, ASP) / Ayuda a compilar con codedom, modulo de clase sacado de codedom crypter
|
en: 17 Octubre 2011, 19:06 pm
|
Hola. esto es lo que tengo en el evento button_click Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim open = OpenFileDialog1 open.Filter = "Executables *.exe|*.exe" Dim save = OpenFileDialog1 save.Filter = "Executables *.exe|*.exe"
open.ShowDialog() Save.ShowDialog()
Dim st As System.IO.Stream = System.IO.File.Open(open.FileName, _ System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim br As New System.IO.BinaryReader(st) Dim read() As Byte = br.ReadBytes(st.Length)
br.Close() st.Close()
Dim source As String = My.Resources.source
Dim enc As System.Text.Encoding = System.Text.Encoding.ASCII Dim cadena As String = enc.GetString(read) source = source.Replace("%3%", cadena)
iCompiler.GenerateExecutable(SaveFileDialog1.FileName, source, "") MsgBox("Crypted!", MsgBoxStyle.Information, "Success!") End
End Sub End Class
Y este es el modulo que compila y crea el ejecutable. (SACADO DE CODEDOM CRYPTER) Imports System.CodeDom.Compiler Public Class iCompiler Public Shared Sub GenerateExecutable(ByVal Output As String, ByVal Source As String, ByVal Icon As String) 'On Error Resume Next
Dim Compiler As ICodeCompiler = (New VBCodeProvider).CreateCompiler() Dim Parameters As New CompilerParameters() Dim cResults As CompilerResults
Parameters.GenerateExecutable = True Parameters.OutputAssembly = Output Parameters.ReferencedAssemblies.Add("System.dll") Parameters.ReferencedAssemblies.Add("System.Data.dll") Parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll")
Dim Version = New Dictionary(Of String, String) Version.Add("CompilerVersion", "v2.0")
Dim ICO As String = IO.Path.GetTempPath & "\iCompiler.ico"
If Icon <> "" Then IO.File.Copy(Icon, ICO) Parameters.CompilerOptions &= " /win32icon:" & ICO End If
cResults = Compiler.CompileAssemblyFromSource(Parameters, Source)
If cResults.Errors.Count > 0 Then ElseIf cResults.Errors.Count = 0 Then
End If If Icon <> "" Then : IO.File.Delete(ICO) : End If End Sub End Class
Y esto es lo que pone en el archivo de recursos txt. (LO QUE QUIERO COMPILAR) Imports System, Microsoft.VisualBasic Module uno Sub Main() Dim enc As System.Text.Encoding = System.Text.Encoding.ASCII Dim bytess() As Byte = enc.GetBytes(%3%)
IO.File.WriteAllBytes("c:\archivo.exe", bytess) Call Shell( "c:\archivo.exe") End End Sub
End Module
No tengo ni idea de por que no me lo compila. alguna sugerencia?
|
|
|
138
|
Programación / .NET (C#, VB.NET, ASP) / Aver si alguien puede ayudarme con este codigo. BinaryWriter y BinaryReader
|
en: 1 Octubre 2011, 02:54 am
|
me da un fallo marcado abajo en verdeImports system.io
Public Class Form1
Const count As Integer = 100 * 1048576 ' constante para la capacidad de buffer
Public FileLen As Integer, inputPath As String 'declaro como publicas filelen que es el tamaño del archivo y inputpath que es el 'archivo de entrada
Public Sub escribir(ByVal output1 As String, ByVal buffer() As Byte)
Dim brWriter As System.IO.BinaryWriter Dim brReader As System.IO.BinaryReader Dim buffer(count) As Byte Dim bytesRead() As Integer
FileLen = My.Computer.FileSystem.GetFileInfo(inputPath).Length
While FileLen > 0 ReDim buffer1(count ) bytesRead(StrReverse(FileLen)) = brReader.Read(buffer, 0, (count))<---fallo 'hago una cuenta atras del tamaño del archivo MsgBox(bytesRead) If bytesRead(StrReverse(FileLen)) = 0 Then 'observo si bytesread esta vacio Exit While End If brWriter.Write(buffer, 0, bytesRead(StrReverse(FileLen))) ' escribo en el archivo el buffer que es un array de bytes FileLen = FileLen - bytesRead(StrReverse(FileLen)) ' resto los bytes leidos End While brWriter.Close() brReader.Close() End End Sub End Class Si pudiecen exarme una manita... se escribir en el archivo todos los bytes completos de una, pero lo que quiero es escribir bytes por bytes.
|
|
|
|
|
|
|