473,394 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Generating asm file..

I have written a program in C#...
Now the requirement is that I want an assembly code to be the output rather
than the regular executable output..
Can anyone say how to do it..


Dec 5 '07 #1
13 1793
Rajkiran... I believe you are asking how to look at the generated Common
Intermediate Language (CIL) as assembly opcodes? So if you want to see
ldc.i4 instead of 0x20 you can run the ildasm or il dis-assembler.

http://msdn2.microsoft.com/en-us/library/aa309387.aspx
http://www.geocities.com/jeff_louie/...ng_started.htm

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Dec 5 '07 #2
On Tue, 04 Dec 2007 22:45:13 -0800, Rajkiran R.B.
<ra*********@hotmail.comwrote:
I have written a program in C#...
Now the requirement is that I want an assembly code to be the output
rather than the regular executable output..
Can anyone say how to do it..
It depends on what you mean by "assembly code" and "output". :)

Your C# program wouldn't be represented as x86 assembly, since it gets
compiled to the Microsoft Intermediate Language (MSIL). I don't know how
to get VS to generate that directly, but you can always run your compiled
C# objects or executables through the ildasm.exe tool.

I don't see any command line switch for the C# compiler
(http://msdn2.microsoft.com/en-us/lib...zy(VS.90).aspx) that
provides for the output of alternative types of files, like .asm or
pre-processed .cs (though, because of the nature of C# and .NET, I suppose
those types of files aren't quite as useful or necessary as they would be
with C/C++ or similar).

If you want x86 assembly, I don't know of a straightforward way to do
that. Your code isn't going to be x86 until it's actually running and has
been compiled by the "just-in-time" compiler. I'd guess there's a way to
somehow inspect the resulting compiled code in memory, output that
somehow, and run it through a disassembler. But a) that is likely a lot
more trouble than what you're looking for, and b) I don't know off the top
of my head how you'd go about doing that. :)

Pete
Dec 5 '07 #3
Thanks for your replies...
Let me put in my exact requirement..

I need a program that would read a file and either encrypt it or decrypt it
using the base 64 algorithm.. For that purpose I used C# to code it.. Here
is the code I wrote..

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace fbase64
{
class fbase64
{
static string srcfile, destfile, operation;
static void Main(string[] args)
{
if (args.Length == 3)
{
int flag = 0;
operation = args[0];
srcfile = args[1];
destfile = args[2];
if(operation!="e" && operation!="d")
{
Console.WriteLine("\nEnter Valid Options");
Console.WriteLine("\nOptions:\ne - encoding\nd -
decoding");
flag = 1;
}
if (File.Exists(srcfile) == false)
{
Console.WriteLine("\nSource File Not Present.");
flag = 1;
}
if (flag == 0)
{
doProcess();
}

}
else
{
Console.WriteLine("\nInvalid Parameters\n");
Console.WriteLine("\nSyntax:\n\nfbase64.exe [options]
[Source File Name] [Destination Filename]");
Console.WriteLine("\nOptions:\ne - encoding\nd - decoding");
}

}

public static void doProcess()
{

if (operation == "e")
{
doEncoding();
}
else
{
doDecoding();
}

}

public static void doEncoding()
{
try
{
//Code To Read The Source File into a byte array
FileStream fs = new FileStream(srcfile, FileMode.Open,
FileAccess.Read);
byte[] src = new byte[fs.Length];
fs.Read(src, 0, Convert.ToInt32(fs.Length));
fs.Close();
//Code to encode the read data
string dest = Convert.ToBase64String(src);
//code to write the encoded data
FileStream fd = new FileStream(destfile, FileMode.Create,
FileAccess.Write);
StreamWriter sr = new StreamWriter(fd);
sr.Write(dest);
sr.Close();
fd.Close();
Console.WriteLine("\nEncoding Complete");
}
catch (Exception ex)
{
Console.WriteLine("Error While Encoding File\n" +
ex.Message);
System.Environment.Exit(0);
}
}
public static void doDecoding()
{
try
{
//Code To Read The Source File into a string
FileStream fs = new FileStream(srcfile, FileMode.Open,
FileAccess.Read);
StreamReader sd = new StreamReader(fs);
string src = sd.ReadToEnd();
sd.Close();
fs.Close();
//Code to decode The file
byte[] dest = Convert.FromBase64String(src);
//code to write the decoded information into the destination
file
FileStream fd = new FileStream(destfile, FileMode.Create,
FileAccess.Write);
fd.Write(dest, 0, dest.Length);
fd.Close();
Console.WriteLine("\nDecoding Complete");
}
catch (Exception ex)
{
Console.WriteLine("Error While Decoding File\n" +
ex.Message);
System.Environment.Exit(0);
}
}
}
}

Now I need the same thing to be done using an assembly language program.. So
is it possible for me to convert the program to an unmanaged c++ code so
that I can generate an x86 assembly file using the gcc compiler..

Dec 5 '07 #4
Liz

"Rajkiran R.B." <ra*********@hotmail.comwrote in message
news:7D**********************************@microsof t.com...
Thanks for your replies...
Let me put in my exact requirement..

I need a program that would read a file and either encrypt it or decrypt
it using the base 64 algorithm.. For that purpose I used C# to code it..
Here is the code I wrote..
.....
Now I need the same thing to be done using an assembly language program..
So is it possible for me to convert the program to an unmanaged c++ code
so that I can generate an x86 assembly file using the gcc compiler..
of course you can convert this to c++ ... you can re-write it; but I
wouldn't call that "an assembly language program"

>
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace fbase64
{
class fbase64
{
static string srcfile, destfile, operation;
static void Main(string[] args)
{
if (args.Length == 3)
{
int flag = 0;
operation = args[0];
srcfile = args[1];
destfile = args[2];
if(operation!="e" && operation!="d")
{
Console.WriteLine("\nEnter Valid Options");
Console.WriteLine("\nOptions:\ne - encoding\nd -
decoding");
flag = 1;
}
if (File.Exists(srcfile) == false)
{
Console.WriteLine("\nSource File Not Present.");
flag = 1;
}
if (flag == 0)
{
doProcess();
}

}
else
{
Console.WriteLine("\nInvalid Parameters\n");
Console.WriteLine("\nSyntax:\n\nfbase64.exe [options]
[Source File Name] [Destination Filename]");
Console.WriteLine("\nOptions:\ne - encoding\nd -
decoding");
}

}

public static void doProcess()
{

if (operation == "e")
{
doEncoding();
}
else
{
doDecoding();
}

}

public static void doEncoding()
{
try
{
//Code To Read The Source File into a byte array
FileStream fs = new FileStream(srcfile, FileMode.Open,
FileAccess.Read);
byte[] src = new byte[fs.Length];
fs.Read(src, 0, Convert.ToInt32(fs.Length));
fs.Close();
//Code to encode the read data
string dest = Convert.ToBase64String(src);
//code to write the encoded data
FileStream fd = new FileStream(destfile, FileMode.Create,
FileAccess.Write);
StreamWriter sr = new StreamWriter(fd);
sr.Write(dest);
sr.Close();
fd.Close();
Console.WriteLine("\nEncoding Complete");
}
catch (Exception ex)
{
Console.WriteLine("Error While Encoding File\n" +
ex.Message);
System.Environment.Exit(0);
}
}
public static void doDecoding()
{
try
{
//Code To Read The Source File into a string
FileStream fs = new FileStream(srcfile, FileMode.Open,
FileAccess.Read);
StreamReader sd = new StreamReader(fs);
string src = sd.ReadToEnd();
sd.Close();
fs.Close();
//Code to decode The file
byte[] dest = Convert.FromBase64String(src);
//code to write the decoded information into the
destination file
FileStream fd = new FileStream(destfile, FileMode.Create,
FileAccess.Write);
fd.Write(dest, 0, dest.Length);
fd.Close();
Console.WriteLine("\nDecoding Complete");
}
catch (Exception ex)
{
Console.WriteLine("Error While Decoding File\n" +
ex.Message);
System.Environment.Exit(0);
}
}
}
}

Dec 5 '07 #5
On Dec 5, 7:43 am, "Rajkiran R.B." <rajkiran...@hotmail.comwrote:

<snip>
Now I need the same thing to be done using an assembly language program.. So
is it possible for me to convert the program to an unmanaged c++ code so
that I can generate an x86 assembly file using the gcc compiler..
Given that you won't be able to use .NET from the unmanaged code
(without hosting the CLR, which pretty much defeats the point), you
basically need to rewrite from scratch using the unmanaged crypto
APIs.

Why do you have this requirement anyway?

Jon
Dec 5 '07 #6
Yes I know that it wouldn't be an assembly language program...
But there is a compiler option in gcc compiler to generate an equivalent
assembly file from the code..
Im familiar with C# but not with c++..
so is there a code converter to do that..
or can anyone provide me with the code snippets so that I can build the c++
code which does the same job as this..

of course you can convert this to c++ ... you can re-write it; but I
wouldn't call that "an assembly language program"

Dec 5 '07 #7
Well this base64 algorithm needs to be implemented in an electronic project
and it uses a microprocessor.. so I need to burn the program in a chip..
for that I need the assembly program...
And this program is also to be implemented in an older machine which uses
..386 processor

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:0f**********************************@i12g2000 prf.googlegroups.com...
On Dec 5, 7:43 am, "Rajkiran R.B." <rajkiran...@hotmail.comwrote:

<snip>
>Now I need the same thing to be done using an assembly language program..
So
is it possible for me to convert the program to an unmanaged c++ code so
that I can generate an x86 assembly file using the gcc compiler..

Given that you won't be able to use .NET from the unmanaged code
(without hosting the CLR, which pretty much defeats the point), you
basically need to rewrite from scratch using the unmanaged crypto
APIs.

Why do you have this requirement anyway?

Jon
Dec 5 '07 #8
"Rajkiran R.B." <ra*********@hotmail.comwrote in message
news:7D**********************************@microsof t.com...
[...]
I need a program that would read a file and either encrypt it or decrypt
it using the base 64 algorithm.
Note that the base 64 algorithm does NOT _encrypt_, it merely _encodes_
the file. Anyone will be able to decode it back, since it doesn't use any
kind of cryptography.
For that purpose I used C# to code it.
[...]
string dest = Convert.ToBase64String(src);
[...] Now I need the same thing to be done using an assembly language
program. So is it possible for me to convert the program to an unmanaged
c++ code so that I can generate an x86 assembly file using the gcc
compiler.
Even if you could turn your own code into assembly, the encoding itself
is done by a library in the .Net Framework (the call to
Convert.ToBase64String(...)), so the assembly language generated in this way
would not contain the code for performing the base 64 encoding.

Dec 5 '07 #9
On Dec 5, 8:56 am, "Rajkiran R.B." <rajkiran...@hotmail.comwrote:
Well this base64 algorithm needs to be implemented in an electronic project
and it uses a microprocessor.. so I need to burn the program in a chip..
for that I need the assembly program...
And this program is also to be implemented in an older machine which uses
.386 processor
And what operating system is this using? There may well be a base 64
routine in whatever platform you're targeting, but without saying what
the platform actually is, there's no way of knowing.

Base64 isn't too hard to implement from scratch, but your C# code is
going to be no use to you at all, except to verify results.

Jon
Dec 5 '07 #10
Well the operating system is Ms dos 6.22

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:ce**********************************@o42g2000 hsc.googlegroups.com...
On Dec 5, 8:56 am, "Rajkiran R.B." <rajkiran...@hotmail.comwrote:
>Well this base64 algorithm needs to be implemented in an electronic
project
and it uses a microprocessor.. so I need to burn the program in a chip..
for that I need the assembly program...
And this program is also to be implemented in an older machine which uses
.386 processor

And what operating system is this using? There may well be a base 64
routine in whatever platform you're targeting, but without saying what
the platform actually is, there's no way of knowing.

Base64 isn't too hard to implement from scratch, but your C# code is
going to be no use to you at all, except to verify results.

Jon
Dec 5 '07 #11
On Wed, 05 Dec 2007 00:56:18 -0800, Rajkiran R.B.
<ra*********@hotmail.comwrote:
Well this base64 algorithm needs to be implemented in an electronic
project and it uses a microprocessor.. so I need to burn the program in
a chip.. for that I need the assembly program...
And this program is also to be implemented in an older machine which
uses .386 processor
Well, here's the thing. The code you posted, all of the interesting stuff
is implemented in .NET. So unless you've got a way to run the .NET
framework on your electronic project, it doesn't matter _what_ you compile
that code to, it's not going to work.

Base64 isn't all that hard to implement yourself. It barely qualifies as
encryption, IMHO. Sort of like ROT-13 is encryption.

The basic functionality you're trying to implement would be relatively
easy even in C++. So that's certainly an option. I would guess that a
little Googling would probably even turn up a handful or so of existing
implementations for Base64 in C or C++.

Not that you asked, but it seems to me that you have the additional
problem of what other services are available on the eletronic project.
The code you posted not only does Base64 encoding, it also assumes a
console with standard input and output, and some sort of file i/o API.
The standard CRT includes these things, but it's not clear from your post
that you could even use the standard CRT on your electronic project.

Basically, it seems pretty clear that whatever you're trying to do, .NET
isn't going to help you. You can't write .NET code to implement
functionality unless you can run the resulting executable in an
environment where .NET is supported. It doesn't sound like that's the
case here.

Pete
Dec 5 '07 #12
On Dec 5, 9:10 am, "Rajkiran R.B." <rajkiran...@hotmail.comwrote:
Well the operating system is Ms dos 6.22
Okay. You need to find a C or C++ Base64 implementation then. I'm sure
there are plenty on the NET.

Just as a side-note, it would have been *much* more useful to explain
all of this to start with.

Jon
Dec 5 '07 #13
Rajkiran R.B. wrote:
Now I need the same thing to be done using an assembly language
program.. So is it possible for me to convert the program to an
unmanaged c++ code so that I can generate an x86 assembly file using the
gcc compiler..
As many other have stated: no, because you can not use
..NET IO or Base64 functions.

You open your C++ IDE with an empty file and start coding.

I happen to have some Base64 code on the shelf:

http://www.vajhoej.dk/arne/eksperten/b64/b64.h
http://www.vajhoej.dk/arne/eksperten/b64/b64.cpp

(just remove all the DLL related stuff)

Arne
Dec 8 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: skn | last post by:
Hello., Does the python compiler provide an option to generate a .pyo(optimized byte code file) from a .py (source file)? For generating .pyc I know that I only have to pass the source file...
7
by: eric.gagnon | last post by:
In a program randomly generating 10 000 000 alphanumeric codes of 16 characters in length (Ex.: "ZAZAZAZAZAZAZ156"), what would be an efficient way to ensure that I do not generate duplicates? ...
10
by: Al Christoph | last post by:
Please forgive me if this is the wrong place to post this. The last place I posted got me a fairly rude response. I guess vb.db people just don't want to think about XML as database. At any rate,...
3
by: daniele.balducci | last post by:
Hi All, I'm generating XLS files from ASP(.Net) code using the usual code chunks ... Response.ContentType = "application/vnd.ms-excel" Response.AppendHeader("Content-Disposition", "attachment;...
0
by: manas589 | last post by:
Hi Can any one tell me how to use binding.xml while generating castor bean from an xsd file. i have one xsd file where two element are conflicting. so i thought to use binding file while...
2
by: bizt | last post by:
Hi, Is it possible to obtain the width/ height of an image when that image is dyanically created using a PHP script and passing GET attributes. For example: <img...
7
by: Nathan Sokalski | last post by:
I am an ASP.NET developer, and Visual Studio 2005 seems to have stopped declaring the controls that I add in the *.designer.vb files, therefore forcing me to manually add them before I can use them...
1
by: Nathan Sokalski | last post by:
Visual Studio 2005 recently stopped generating the *.designer.vb files for my *.aspx and *.ascx files. I am using Service Pack 1, and do not believe I did anything differently than normal prior to...
1
by: csharpula csharp | last post by:
Hello, I need to generate cs files from XSD files. I would like to do it automatically. What is the best way to do it? Is it better be done with PreBuild inside VS (before compilation) or to...
2
by: veer | last post by:
hi i made program in which i am generating the report of a ms-table database it works fine only on my computer and generatin the reports but when i run this exe on any computer the whole programe...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.