|
Thanks, I am familiar with these (actually wrote one myself for Java).
Unfortunately, even these tools with very advanced logic can only rename and scramble a little... this is certainly not the case with a C++ application, there you have to actually know ASM to understand the code, or use a disassembler that gets no-where close the original code.
I reviewed numerous obfuscators during the last weekend. Salamander is not expensive compared to others, but it has a very mediocre UI. I understand that its most valuable (advertised) feature is its ability to convert the code to what you would have gotten, had you used C++ (or other not managed language) to begin with...
It seems that Microsofties themselves are using Dotfuscator (which is bundled with DevStudio).
Still, I see no way to protect your *private* (not the public interfaces) code with managed code, and hence no reason to use it for project that you want to keep as inconspicuous as possible (like encryption libraries etc).
|
|
|
|
|
I was going to mention that even C++ can't hide your data, but you already know that. Well, I guess you can just create an unmanaged library for your most important functions and then use interop. If you need to release this as a component then create a wrapper library.
|
|
|
|
|
You set the plan as it will be
Obfuscation for the code, unmanaged library for the encryption related code. This will (hopefully) shift the culprit's gain-loss balance towards the loss column.
Thanks for your suggesions.
|
|
|
|
|
hi,
Please check this site for obfuscation and reverse engi:.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dotfuscator/dotf49m6.asp
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
I have a custom install action where I need to have the user browse for a folder. I'm using the 1.1. framework. I set the RootDirectory and the SelectedDirectory, but when I run the dialog it does not show a browse window. Every property I set shows up. It just does not let me select a directory. The browse window is gone!!!
Has anyone else experienced this?
This signature left intentionally blank
|
|
|
|
|
Check if the COM threading model for your application is single-threaded apartment.
[STAThread]
static void Main()
{
...
}
Don't know why, but if it's multithreaded apartment, you get the described behaviour.
www.troschuetz.de
|
|
|
|
|
so i guess there's two camps; the java people who required all exceptions to be caught, or result in a compile error, and the C# people who decided it won't be enforced, and let you ignore exceptions all you want. i personally was divided and thought with the proper documentation, catching exceptions when you wanted is rather convenient than to have to write try-catch blocks EVERYWHERE necessary. well, i've only been programming C# a few months now, and it seems these uncaught exceptions are creeping up everywhere. i have noticed two things that has been happening, one bad and the other REALLY bad, but not sure what causes one to happen instead of the other. in the bad case, an uncaught exception percolates all the way to the top and you see it while running the app. that info can be used to solve the problem relatively easily. however, in the really bad case, which i just had happend to me, was when an exception was thrown and was uncaught but silently went unnoticed! on my mainform control, i was calling a listview.item.remove and sending in accidentally a null value. this was not in a try catch block and the exception seems to just vanish since i never saw anything happen at runtime; a silent and sometimes very hard to find bug, wouldn't you say?
i am a little confused. don't ALL exceptions uncaught eventually travel all the way up the call stack and out to the user? i know many hard to find bugs will happen if someone just puts a try-catch block around somerthing and does nothing useful with the exception, then it will have that silently disappearing effect. but in my case, how come an uncaught exception isn't thrown out to the user with some message box, like they usually do? i tried catcuhign it and rethrowing it, and still nothing happened.
|
|
|
|
|
An exception will continue to travel up the call stack until it is caught.
However, there are so many people that just catch general exceptions like
catch(Exception ex) that it will catch everything. These are notoriously bad to trackdown - I heard a story of a guy who specialises in tracking down that sort of thing and makes a fortune out of it.
Something that might help though, is to deliberately send in a null value, set the breakpoint on the Remove method call then attempt to step-into it. Obviously you cannot step-into the framework code, so the code will stop again at the next line of your code, hopefully from this point you should be able to see what is going on.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
Dude. what so hard about tracking down a general exception. All you have to do is set a breakpoint. When the exception is hit you then check the inner exception, actual type of the exception, and look into the details. Take a look at the call stack. No problem at all.
What's hard to debug is when there is unreliable code from a third party that you have to depend on. Sometimes the code fails and there is little or no way of telling if something went south.
|
|
|
|
|
AK wrote:
Dude. what so hard about tracking down a general exception.
If you don't know what is throwing it and what is catching without handling it, but the bug it generates doesn't appear until later it can be very difficult to even know where to set the breakpoint.
AK wrote:
Sometimes the code fails and there is little or no way of telling if something went south.
I've had that one before. It was an absolute nightmare because it just failed without returning an error code or throwing an exception. I had to write extra code after it to ensure that file had been written to disk.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
> what so hard about tracking down a general exception.
There are some general exceptions that can occur just about any time, for example. Think of an ExecutionEngineException, a StackOverflowException ThreadAbortException or OutOfMemoryException. It's almost impossible to handle some of these exceptions so that your application will run as expected afterwards (for some, even your finally-blocks will NOT be executed). But even if we're talking about not so "serious" exceptions: Often a single call to some method may result in one of five or more different exceptions. A general catch-block will handle all of these. But I think that often it's almost impossible to be sure such a catch-block can handle all of these exceptions properly. What you may get is unexpected behavior of your application. You may not even notice that something's wrong the time the error occurs, but maybe hundreds of lines of code later, and then these exceptions ARE hard to track down.
So I agree with Colin: using a general catch (Exception)-block may be a not so good idea. Instead, trying to catch specialized exceptions is the way to go. On the one hand, you can be sure what has to be done to get your application into a defined state. On the other hand, if any exception occurs you don't expect, you instantly will see that something's wrong (unhandled exception). Your way (setting a breakpoint) requires that you KNOW something went wrong. Handling general exception, this may not be the case, you may just get very unexpected behavior of your application afterwards, not knowing where the actual problem lies.
Just my 2 cents...
|
|
|
|
|
vista27 wrote:
well, i've only been programming C# a few months now, and it seems these uncaught exceptions are creeping up everywhere.
There's your problem right there
vista27 wrote:
don't ALL exceptions uncaught eventually travel all the way up the call stack and out to the user?
As far as I am concerned, that is the case, yes.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Are you sure that the exception that is being thrown is on the main application thread. I think that exception created on worker threads don't automaticly bubble up to the default exception handler. I remember reading somewhere how to redirect worker thread exception back to the main thread exception handler. You will have to check the documentation for this though.
Hope this helps.
BTW There is an artical somewhere on the web about why they did not require exception catching in C#. I think it was on the desware site.
Anyway....
Forever Developing
|
|
|
|
|
To answer your questions:
(1) No. NET does not mandate exception handling like Java. One reason I can think of is the performance, try-catch blocks involve extra code being inserted by the compiler around your own code and it has certain performance cost to pay.
(2) Your case about a thrown exception vanishing is very odd. Are you sure it is an exception and not just a logic error? Can you debug and find out where the exception is being ‘eaten out’? Somewhere down the stack an empty catch block like the following must be eating your exception.
catch<br />
{<br />
}
(3) I think there is a simple rule of thumb for exception handling:
a. Handle the logic errors with error codes and conditional statements.
b. For exceptional errors with high probability (Internet connection not available for example) have *specific* exception handling logic.
catch(System.Web.HttpException ehttp)<br />
{<br />
return false;<br />
}<br />
catch(System.Web.SomeotherException eother)<br />
{<br />
return false;<br />
}
c. For exceptional errors with remote probability (e.g. disk out of space) a *universal* exception handler in the main() function or major functions in the code will work well.
catch(Exception e)<br />
{<br />
return false;<br />
}<br />
catch<br />
{<br />
return false;<br />
}
This approach will ensure a balance between performance and stability. Any suggestion, friends?
|
|
|
|
|
Also it is a nice idea to print the StackTrace in a log file in case of major exceptions. (Point 3 c above) Thats helps shoot down production environment problems.
|
|
|
|
|
Requiring exceptions to be caught will eventually make people code with bad habits. Most of the time you dont want to catch the exception anyway, because you cant do anything about it at that level. I ask myself two questions about a block of code, when it comes to exceptions being thrown by it: 1. Can I recover from it? If yes, then catch and write recovery code. 2. Can I provide useful information about the context in which the exception was thrown? If yes then catch, and throw a new exception with the catched as inner exception.
Most code blocks will not fall under these categories, and should not have enforced catches. Forcing people to write catches will bloat the code so it's not readable (catches everywhere, the meaningful catches dont stand out). MS did a good design choice to leave out enforced catches.
BTW, to me exceptions are thrown mainly because of reasons out of your control: failures in the platform, execution engine, 3'd party library, etc. Or bugs in your code (arguments out of range, asserts gone bad, etc). They should never be used for general error handling.
Regards,
Björn Morén
Stockholm, Sweden
|
|
|
|
|
Actually I believe not enforcing exception handling is what make people code with bad habits. With
unchecked exceptions it's just too easy to ignore exception handling all together! You call a method on an object, you don't really know what exceptions it *might* throw, you don't have time to find out and you just forget exceptions even exists. The compiler won't complain, the code will run and everyone's happy.
MyObject myObject = new MyObject();
myObject.doSomething();
If I don't know what doSomething throws at me, in the best case scenario I could catch the generic Exception. But that still isn't good practice, right? Maybe I just leave it and let it propagate to my caller, who will be even more clueless about the exceptions that could generate inside doSomething.
But if you had doSomething throwing checked exceptions you wouldn't have a choice but to deal with them. And if you consider you can't do anything about it, Java will let you propagate it using the throws statement in your method declaration. The difference is it's all explicit and clearer. You know what's coming at you and you can decide to handle it or explicitly tell your caller to do it.
Cheers.
|
|
|
|
|
Sorry I forgot about Java's ability of exception propagation in the method declaration. That's an improvement for sure.
I agree that checked exceptions makes sense at the API level, but not inside the actual code library. It will be counter productive, due to reasong I wrote about earlier.
The ideal situation for me would be: Some way of getting information about possible exceptions being thrown by a method. And at the same time not forcing me to write checked exceptions Java-style.
Suggestion: the C# compiler inserts meta-information (method attributes) into the dll about what exceptions can be thrown by a method. It ought to be able to figure that out at compile time. As a code library user Visual studio can then inform me about those exceptions by use of intellisense or similar. When typing three slashes to generate my method documentation skeleton, VS could also automatically insert exception information and make that a part of the documentation (no need for the programmer to write anything).
Maybe something to suggest to the VS2005 team.
Regards,
Björn Morén
Stockholm, Sweden
|
|
|
|
|
my application uses buttons and listview item.And a textfield that I made.Its not a component , I made it with using drawing classes and it catches the keys that pressed then draws them to screen.Main problem is I need to use arrow keys to move the cursor that I made for my textfield.but listview or butons catch them before me ,items in the listview gets focus when I press the arrow keys if I disable the lisview then focus on the butons moves.After a few move my cursor starts to work becouse listview gains the focus for the last item in the row. .I need to make them disable only for the arrow keys.They gotto be enabled for mouse action....
any help?
|
|
|
|
|
Can anyone help me out with this and tell me what I'm doing wrong?
1. I have a form with a ListView control which will hold items for me...
2. I have declared a private variable of type ListViewItem ie.
private ListViewItem lvi = null;
3. In the ListView's MouseDown Event Handler, I check if the right mouse button is pressed, and to popup a context menu to delete the selected item.
private void ListView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
try{
if (e.Button == MouseButtons.Right && this.ListView.Items.Count >= 1){
this.ListView.Focus();
this.lvi = this.ListView.GetItemAt(e.X, e.Y);
if (this.lvi != null) this.lvi.Selected = true;
this.cntxtMenu.Show(this.ListView, new System.Drawing.Point(e.X, e.Y);
} /* if (e.Button == .....) */
}/*end try */
catch{}
}
4. cntxtMenu contains a Caption 'Delete' and the menu-item is called cntxtMenuDelete.
5. In the cntxtMenuDelete Click Event I have the following
private void cntxtMenuDelete_Click(object sender, System.EventArgs e)
{
try{
this.ListView.Items.Remove(this.lvi); /* THIS LINE CRASHES! */
}/* end try */
catch{}
}
I have omitted the Exception code for brevity here, in the comment above where I've highlighted the line that causes a crash...the message I get from the Exception handler is, mind you, it doesn't even tell me what kind of exception is it - "Specified argument was out of the range of valid values. Parameter name '0' is not valid for 'displayIndex'." It even cut across the exception handler and therefore it did not catch the problem. I loaded this code into the CLR debugger and got it to trap all Exceptions and got a ArgumentOutOfRangeException - guess where, not in my code but in system.windows.dll....weird! the CLR debugger says it crashed when the Listview was making a call to get_item(int displayIndex) based on the stack dump from the debugger. ie a LVM_GETITEM message, something went funny there....I even derived the Listview and added a custom WndProc override to trap the LVM_GETITEM message and to ignore it....thinking that would solve it but no...Any ideas? Is this a bug?
Thanks in Advance,
Tom.
|
|
|
|
|
Hello Tom.
I hope write well!! because i'm from Argentina and a have 2 works to do, think the answer and translate it! .
I copy your code in a project that i use for test.
In the only case that happends, is when the listview remove the last lisviewitem, because for dafault, take focus the next listviewitem.
if after de "line crashes" write something like that
MessageBox.Show(" there are " + this.listView1.Items.Count.ToString());
the message take focus, and the error don't happends.
I dont know if this is a bug, I never have it because i ever confirm the delete.
I use a CommandButton near the listview (with a "-" icon)
and the code is
if (this.listView1.SelectedItems.Count >0)
{
if (MessageBox.Show (this, "¿Are you agree, for delete the item
selected?"," ",System.Windows.Forms.MessageBoxButtons.OKCancel)==
DialogResult.OK)
{
this.listView1.Items[this.listView1.FocusedItem.Index].Remove();
}
}
Bye
|
|
|
|
|
Many Thanks,
On Closer inspection after debugging, the call stack shows that with the code at hand, it somehow thinks it was initiating a drag and drop operation, Bizarre!! There's a few lines in the call trace that was calling WM_NOTIFY message, then calls LVN_BEGINDRAG, which in turn calls the ListView_getItem(displayIndex) and since the listitem was the only one, removing it, and boom, system.windows.forms.dll crash! I cured it by changing the event to a MouseUp Event which begs the following questions,
1) What is the real difference between MouseUp/MouseDown event handler apart from the fact that the button is released and the button is down respectively?
2) What situations would I use the MouseDown/MouseUp event handler and what would be a good reason to do so?
2) Why did it work with the MouseUp event handler? I used my hunch on this and changed the event handler, for some inexplicable reason, the listview control wasn't expecting a drag and drop and so it happily removed it!
Many thanks again!
Tom
|
|
|
|
|
1) What is the real difference between MouseUp/MouseDown event handler apart from the fact that the button is released and the button is down respectively?
Vanesa: if you click with the mouse and you do it on the wron place... using the MouseUp event you cant move the mouse (without relese the button) to another place and do nothing, while if you use the MouseDown, the event run when you click the mouse. This is the diference that I note.
2) What situations would I use the MouseDown/MouseUp event handler and what would be a good reason to do so?
Vanesa: I use MouseUp for example when I search address for a customer name, if datatable (returned for the sql query) contains more than 1 row, I send it to a especial form with a datagrid, and the user can select the customer to view his address,
private void dataGrid1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
System.Drawing.Point pt = new Point(e.X, e.Y);
DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt);
if(hti.Type == DataGrid.HitTestType.Cell)
{
dataGrid1.CurrentCell = new DataGridCell(hti.Row, hti.Column);
dataGrid1.Select(hti.Row);
// this is a control that "public" the selected id to the others forms
this.textBox1.Text = dataGrid1.CurrentRowIndex.ToString();
this.Close();
}
}
and the program return to the form that call the grid
Bye
Vanesa Addicted To DJ Tiësto's Trance
|
|
|
|
|
Many thanks for that insight! Certainly clarified everything!
|
|
|
|
|
Remove this line
this.cntxtMenu.Show(this.ListView, new System.Drawing.Point(e.X, e.Y);
attache your contect menu like below in your in your InitializeComponent() method
this.ListView.ContextMenu = this.cntxtMenu;
Sandeep Naik
|
|
|
|
|