|
If you're trying to stop people from decompiling the .exe or .dll in a readable form, obfuscators are the only thing that's going to do that.
Not all code can be obfuscated. If you're using Reflection, using a library that uses it, in your code, you can't use an obfuscator on it or else the code examining your code will no longer work.
If you can't get the code working after obfuscation, contact the vendor of the obfuscator for support on it.
|
|
|
|
|
Hi Dave
Nope I'm not trying to prevent decompiling, if I could though that would be cool - but with those protection softwares I have tried, de4dot decompiles them all just fine.
I'm only trying to make my code less readable.
But after reading the answer from OriginalGriff I think that I might have used the obfuscator wrong, so I tried once more, and instead of protecting my dll's for them self before they was included into my program, I did it on the whole release, and that worked.
Cheers
LR
|
|
|
|
|
Lupu5R3x wrote: the strip comments and rename part (for me that is). As OriginalGriff already told you, that is a waste of time, since you will not be sending the source code to the people who use your code. I assume this is your first step into working with a compiled language, so you need to understand the difference between source and object code. You are welcome to remove all the comments from your source before compiling it, but that will make no difference to the final executable, since comments are not carried over.
|
|
|
|
|
Hi Richard
As I wrote to Dave, after reading the last answer from OriginalGriff, I found out what went on and what I did wrong
Cheers
LR
|
|
|
|
|
That's not strictly true - it's picking up the comments and such from the PDB file, which it detects from the App GUID (IIRC). Try this: create a new project, comment it, and build it.
copy the Release EXE to a safe place, and delete the original solution folder (as if it was just installed on a new machine).
Open the exe with dotPeek, and it can't find the PDB, so it uses just what's in the file. No comments!
As for readability, use an obfuscator and it should be pretty horrible to look at!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi OriginalGriff
And that my friend was just the correct answer (sort of), it did clue me in onto what I did wrong
Now I only need to rob a bank, so I can afford to by the full edition of the obfuscator
But besides that, I now know why the obfuscation failed, and for that I thank you
Cheers
/LR
|
|
|
|
|
I know that feeling ...
You're welcome!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I've written my own "comment cleaners". It's not that hard if you're consistent.
- Read all lines as strings
- look for leading "//", "/", "", "*/", etc.
- LastIndex of "//" for trailing comments.
- Write clean / accepted lines.
Do a directory at a time; copying from one to the other. Dump what was dropped / clipped for a verification.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi Gerry
My problem is/was that I didn't know where to start.
Cheers
LR
|
|
|
|
|
The problem is you don't really want to do that.
The comments never make it into the code. BUT, if you decompile the executable on the machine that has the project still on it, you'll the the comments from the original source, not from the decompiled executable.
|
|
|
|
|
I didn't follow the "compiled comments" part either; I use my cleaner on (my) source code when "comments" weren't part of the deal (and I'm in "that" mood) when turning it over.
I usually zero on those parts that say "do not change this code even if it does not make sense because it will only work this one way because I tried everything else already".
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
hi, I have my
dictionary1
key values
1 {item 1, 10; item 2, 20; item 3, 40}
2 {item 1, 15; item 2, 28; item 3, 40}
3 {item 1, 15; item 2, 28; item 3, 40}
dictionary2
key values
1 {item 1, 12; item 2, 20; item 3, 40}
2 {item 1, 15; item 2, 25; item 3, 40}
3 {item 1, 15; item 2, 28; item 3, 40}
i need to compare the 2 dictionary and result should be; item 3 dont need to display since there is no changes.
dictionary3
key values
1 {item 1, 12}
2 {item 2, 25}
this is what i used.
var dictionary3 = dictionary2.Where(entry => dictionary1[entry.Key] != entry.Value)
.ToDictionary(entry => entry.Key, entry => entry.Value);
and return
1 {item 1, 12; item 2, 20; item 3, 40}
2 {item 1, 15; item 2, 25; item 3, 40}
thank you
modified 18-Jan-20 13:05pm.
|
|
|
|
|
Easiest way is to write a loop. What have you tried?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
|
Your design in not in "third normal form". This app will always be a pain.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
any idea in mind or best alternative with same output? instead of using dictionary to store and compare data?
|
|
|
|
|
If you "normalize": {key,item,qty} you could "aggregate" files by subtracting one from the other (with same key,item); any items with a "balance" are obviously different.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
You need to specify the result you want in more detail.
0. if each dictionary has an identical key, but the key's values are different, what do you want to do ?
a. keep the value from one of the two dictionaries ? which one ?
b. execute some comparison function you define ?
1. do you assume Key and Value are the same Types ?
2. assuming #1: what if one dictionary has a KVPair with a key 'foo, and the other dictionary has a KVPair with a value of 'foo ?
See if this gives you some ideas:
private Dictionary<int, int> d1 = new Dictionary<int, int> {{1, 10}, {2, 20}, {3, 40}};
private Dictionary<int, int> d2 = new Dictionary<int, int> {{1, 12}, {2, 20}, {5, 40}, {6, 50}};
private Dictionary<T1,T2> GetDictDiff<T1, T2>(Dictionary<T1, T2> d1, Dictionary<T1, T2> d2)
{
Dictionary<T1,T2> kvpDifferences = new Dictionary<T1, T2>();
foreach (KeyValuePair<T1, T2> kvp in d1)
{
if (! d2.Keys.Contains(kvp.Key))
{
kvpDifferences.Add(kvp.Key, d1[kvp.Key]);
}
else
{
if (! Equals(d2[kvp.Key], d1[kvp.Key]))
{
kvpDifferences.Add(kvp.Key, d1[kvp.Key]);
}
}
}
foreach (KeyValuePair<T1, T2> kvp in d2)
{
if (! d1.Keys.Contains(kvp.Key))
{
kvpDifferences.Add(kvp.Key, d2[kvp.Key]);
}
}
return kvpDifferences;
}
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
modified 20-Jan-20 3:28am.
|
|
|
|
|
It's difficult to answer your question without knowing precisely which types you're using.
Assuming you're using a dictionary of dictionaries:
var dictionary1 = new Dictionary<int, Dictionary<int, int>>
{
[1] = new Dictionary<int, int>
{
[1] = 10,
[2] = 20,
[3] = 40,
},
[2] = new Dictionary<int, int>
{
[1] = 15,
[2] = 28,
[3] = 40,
},
[3] = new Dictionary<int, int>
{
[1] = 15,
[2] = 28,
[3] = 40,
},
};
var dictionary2 = new Dictionary<int, Dictionary<int, int>>
{
[1] = new Dictionary<int, int>
{
[1] = 12,
[2] = 20,
[3] = 40,
},
[2] = new Dictionary<int, int>
{
[1] = 15,
[2] = 25,
[3] = 40,
},
[3] = new Dictionary<int, int>
{
[1] = 15,
[2] = 28,
[3] = 40,
},
}; and you want to keep the values from dictionary2 , then something like this should work:
var result = new Dictionary<int, Dictionary<int, int>>();
foreach (var pair in dictionary2)
{
if (!dictionary1.TryGetValue(pair.Key, out var value))
{
result.Add(pair.Key, pair.Value);
}
else
{
var differences = new Dictionary<int, int>();
foreach (var item in pair.Value)
{
if (!value.TryGetValue(item.Key, out var i) || item.Value != i)
{
differences.Add(item.Key, item.Value);
}
}
if (differences.Count != 0)
{
result.Add(pair.Key, differences);
}
}
} NB: Items in the first dictionary (or one of its nested dictionaries) which are not in the second dictionary will be ignored.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
hi Richard,
var dictionary1 = new Dictionary<int, string="">
var dictionary2 = new Dictionary<int, string="">
KeyValue Item
1 {item 1, 10; item 2, 20; item 3, 40}
2 {item 1, 15; item 2, 28; item 3, 40}
3 {item 1, 15; item 2, 28; item 3, 40}
there are 3 pairs each keys has multiple string. main problem is to compare the diff in string. Keys are assumed to be the same.
|
|
|
|
|
If you're storing the value as a string in that format, then you're going to need to write custom code to parse that format to extract the keys and values from it.
For example:
private static readonly Regex ItemPattern = new Regex(@"^\s*{\s*(?<key>[^,]+)\s*,\s*(?<value>[^;]+)(\s*;\s*(?<key>[^,]+)\s*,\s*(?<value>[^;]+))*\s*}\s*$", RegexOptions.ExplicitCapture);
private static Dictionary<string, string> ParseItem(string value)
{
var match = ItemPattern.Match(value);
if (!match.Success) throw new ArgumentException($"Item '{value}' is not in the correct format.", nameof(value));
var keys = match.Groups["key"].Captures.Cast<Capture>();
var values = match.Groups["value"].Captures.Cast<Capture>();
return keys.Zip(values, (k, v) => (key: k.Value, value: v.Value)).ToDictionary(p => p.key, p => p.value);
}
private static string FormatItem(Dictionary<string, string> value)
{
if (value.Count == 0) return null;
return "{" + string.Join("; ", value.Select(p => $"{p.Key}, {p.Value}")) + "}";
}
private static string FindChanges(string source, string target)
{
var sourceItem = ParseItem(source);
var targetItem = ParseItem(target);
var result = new Dictionary<string, string>();
foreach (var pair in targetItem)
{
if (!sourceItem.TryGetValue(pair.Key, out var value) || pair.Value != value)
{
result.Add(pair.Key, pair.Value);
}
}
return FormatItem(result);
} With that in place, you can adapt my previous answer to find the differences:
var dictionary1 = new Dictionary<int, string>
{
[1] = "{item 1, 10; item 2, 20; item 3, 40}",
[2] = "{item 1, 15; item 2, 28; item 3, 40}",
[3] = "{item 1, 15; item 2, 28; item 3, 40}",
};
var dictionary2 = new Dictionary<int, string>
{
[1] = "{item 1, 12; item 2, 20; item 3, 40}",
[2] = "{item 1, 15; item 2, 25; item 3, 40}",
[3] = "{item 1, 15; item 2, 28; item 3, 40}",
};
var result = new Dictionary<int, string>();
foreach (var pair in dictionary2)
{
if (!dictionary1.TryGetValue(pair.Key, out var value))
{
result.Add(pair.Key, pair.Value);
}
else if (value != pair.Value)
{
result.Add(pair.Key, FindChanges(value, pair.Value));
}
} Output:
[1] = "{item 1, 12}"
[2] = "{item 2, 25}"
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have two apps. One converts an Access database into SQL. It uses the Microsoft.ACE.OLEDB.12.0' provider. This works fine.
My second app reads Excel files into SQL. It uses the same Microsoft.ACE.OLEDB.12.0' provider. However, when I run it, I get
'The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine
Access Conversion App
private void ConnectToAccess(string accessDB)
{
try
{
connString = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={accessDB};Persist Security Info = False;";
acccessConn = new OleDbConnection(connString);
acccessConn.Open();
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
}
Excel Conversion App
private static DataSet ToDataSet(string excelFile, int startRecord = 0, int maxRecord = -1, string condition = "")
{
DataSet result = new DataSet();
string connString = connString = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={excelFile};Extended Properties=Excel 12.0;HDR=No;IMEX=1";
using (OleDbConnection connection = new OleDbConnection(connString))
{
try
{
connection.Open();
DataTable schema = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
foreach (DataRow drSheet in schema.Rows)
{
if (drSheet["TABLE_NAME"].ToString().Contains("$"))
{
string s = drSheet["TABLE_NAME"].ToString();
if (s.StartsWith("'"))
{
s = s.Substring(1, s.Length - 2);
}
var command = new OleDbDataAdapter(string.Join("", "SELECT * FROM [", s, "] ", condition), connection);
DataTable dt = new DataTable();
if (maxRecord > -1 && startRecord > -1)
{
command.Fill(startRecord, maxRecord, dt);
}
else
{
command.Fill(dt);
}
result.Tables.Add(dt);
}
}
return result;
}
catch (Exception ex)
{
throw;
}
finally
{
connection.Close();
}
}
}
How can this work for one and not the other??
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Simple: the ACE DB engine comes in to versions: 32 bit and 64 bit. If you have the 64 bit engine installed, a 64 bit app can use it, but a 32 bit version can't - and vice versa.
You can install both versions on the same machine: Installing 32-bit and 64-bit Microsoft Access Drivers next to each other[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: You can install both versions on the same machine
I tried already. The installer for the 64-bit throws
You cannot install the 64-bit version of Microsoft Access Database Engine 2010 because you currently have 32-bit Office producs installed.
The 32 bit installer prompts me to repair.
UPDATE
When I try the 64 bit installation from the command line with Passive, then run my app, I get "Could not find installable ISAM."
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 15-Jan-20 15:42pm.
|
|
|
|
|
Did you try following the link?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|