|
Inlining is ages old, but in the old days, there were compilers / debuggers that couldn't handle it properly. If you wanted to step line by line through an inlined function, you had to turn off that feature while debugging. Maybe this applied only to a few compilers. I don't know if the limitation was in the compiler, the debugger or the debug format - it could be either.
There were other optimzing features that you had to turn off while debugging. E.g. an optimizer may detect that you are doing the same calculations twice, arguments being unchanged from the first to the second calculation. So it decides to rather store the first result in a register or temporary variable, and skip the second calculation. Now you set a breakpoint in the middle of second calculation (but not in the first) - but there is no code where the breakpoint can be inserted! It takes some juggling of instructions and breakpoint analysis to handle such situations.
A (true) story from the old days - not directly connected to optimization, but illustrating simlar issues:
This debugger could single step at the function call level (which was more useful than you think - I wish we had it in moder debuggers!), or at the source line level. There was a fatal crash in this 2000 lines(!) function when stepping call by call. When line-level stepping was enabled, the code worked perfectly fine. It took some effort to discover why, and it illustrates the issues when making a debugger:
In line mode, the debugger replaces the first instruction generated by each source line with at BPT instruction, saving the original instruction in its own buffer. When the BPT is reached, the original instruction is re-inserted into the code, the PC decremented to execute the same address again (this time with the original instruction rather than the BPT), the cpu is told to single step at the machine instruction level, and the BPT is re-inserted for the next time this point is reached.
As so often is the case: The culprit was a wild pointer, writing into code memory (the machine did not have separate spaces for code and data), overwriting an instruction. But in line mode, the debugger had a saved copy of the instruction, protected from the wild pointer. So the debugger replaced the destroyed instruction with the correct one; that is why the code didn't crash in line stepping mode.
|
|
|
|
|
Hi I have the following code:
public static string Decrypt(string encrypted)
{
byte[] encryptedbytes = Convert.FromBase64String(encrypted);
AesCryptoServiceProvider aes = new AesCryptoServiceProvider();
aes.BlockSize = 128;
aes.KeySize = 256;
aes.Key = System.Text.ASCIIEncoding.ASCII.GetBytes(Key);
aes.IV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV);
aes.Padding = PaddingMode.PKCS7;
aes.Mode = CipherMode.CBC;
ICryptoTransform crypto = aes.CreateDecryptor(aes.Key, aes.IV);
byte[] secret = crypto.TransformFinalBlock(encryptedbytes, 0, encryptedbytes.Length);
crypto.Dispose();
return System.Text.ASCIIEncoding.ASCII.GetString(secret);
}
When it decrypts the first string decrypts fine but the second string gives the error "The input data is not a complete block" if the second string is in quick procession. Example decrypting a column on a datagridview, Searching online the error brings up forums where people say that padding is needed or that Dispose closes to early. However as you can see padding is set to PKCS7 and the call for dispose is as late as it can be. So I really don't understand why it is giving the error.
Thanks in advance for any help
modified 7-Jan-20 6:34am.
|
|
|
|
|
Setting the padding mode doesn't pad existing data - you need to start by getting the raw encrypted data (before it's translated to Base64 and feeding that into your decryptor.
If that works - and produces an output that is identical to the original input - then do the base 64 conversion each way and check that works. Then compare the Base64 strings against the string passed to your method.
If all of that is right, check the Key and IV byte values against those you used for encryption.
The debugger will give you all that - but we can't do any of that for you - we have no access to any of the information you are passing to the decryptor!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I have found the problem using debug and it was my own silly mistake.
I was using the code:
for(int i = 0; i < DataGridView1.Rows.Count; i++)
{
DataGridView1.Rows[i].Cells[1].Value = Decrypt(DataGridView1.Rows[0].Cells[1].Value.ToString());
}
As you can see each row was getting the value of the first row. So on the first row it was decrypting the string but on the second line it was trying to decrypt the first row that it had already decrypted. Hence the error.
I think I need a break that was quite embarrassing.
Thanks again for your help.
|
|
|
|
|
We all do it - I read what I meant to write all the damn time ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
|
Hey!
It would be great if you can share the document that is being fed to the ChatBot — the root cause for the "html" is not declared. It is hard to debug it this way, you can read the output of that request and share it here.
And never share the credential on the internet (your SO thread has the credential of your MVP-based profile), and avoid sharing the email address unless you want spam in your inbox.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
From the Error,
Still had one page of Login Page
|
|
|
|
|
Right, so it was at login attempt?
Consider using AD or something to delegate the authentication programmatically.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
any sample source code for AD login?
|
|
|
|
|
|
On Premise can use Azure AD?
|
|
|
|
|
|
On Premise AD and Azure AD had integrated. But how to retrieve the data from SharePoint?
from ChatBot?
|
|
|
|
|
The below code i found in some websites but it always return error
multicast_id":6719893729607364541,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
Code is:
WebRequest tRequest = WebRequest.Create("https:
tRequest.Method = "post";
tRequest.Headers.Add(string.Format("Authorization: key={0}", "Server key"));
tRequest.Headers.Add(string.Format("Sender: id={0}", "Sender Id"));
tRequest.ContentType = "application/json";
var payload = new
{
to = "//topics//news",
priority = "high",
content_available = true,
notification = new
{
body = "Test",
title = "Test",
badge = 1
},
data = new
{
key1 = "value1",
key2 = "value2"
}
};
string postbody = JsonConvert.SerializeObject(payload).ToString();
Byte[] byteArray = Encoding.UTF8.GetBytes(postbody);
tRequest.ContentLength = byteArray.Length;
using (Stream dataStream = tRequest.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
using (WebResponse tResponse = tRequest.GetResponse())
{
using (Stream dataStreamResponse = tResponse.GetResponseStream())
{
if (dataStreamResponse != null) using (StreamReader tReader = new StreamReader(dataStreamResponse))
{
String sResponseFromServer = tReader.ReadToEnd();
this.Label.Text = sResponseFromServer;
}
}
}
|
|
|
|
|
Quote: it always return error
What error?
Is there any message?
Where does the error occur?
What have you done to find out why?
What did the debugger show you was happening?
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
This the error:
multicast_id":6719893729607364541,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
Success 0
Failure 1
|
|
|
|
|
Member 4773987 wrote: The below code i found in some websites but it always return error Then I suggest you throw it away and use the Google documentation to understand how to use their API correctly.
|
|
|
|
|
Doesn't that mean ... learning stuff? Nobody does that any more, bro - just grab what you need from SO and chuck it together.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
Thank you for your Help
🤣🤣🤣
|
|
|
|
|
I am trying to make two clients behind NAT communicates each other using a server with port forward working, my scenario:
Server start listering on port 45000 for Client_A connection;
Server Start listering on port 45001 for Client_B connection;
Client_A connect to server on port 45000 and send hello message;
Client_B connect to server on port 45001 and send hello message;
Server Receive hello message from Client_B and send message with Client_B external port (ex 56000) to Client_B;
Client_B receive external port and start listering on port 56000;
Server Receive hello message from Client_A and send message with Client_B IP and port to Client_A;
Client_A receive IP and Port of Client_B;
Client_A connect to Client_B and send hello message
The problem:
Client_B does not receive message from Client_A;
Here is code:
Server:
static int server_A_Port = 45000;
static int server_B_Port = 45001;
static UdpClient server_A;
static UdpClient server_B;
static bool client_B_Connected = false;
static string client_A_Ip = "";
static string client_B_Ip = "";
static int client_A_Port = 0;
static int client_B_Port = 0;
static Thread Server_A_Thread = new Thread(Start_Server_A);
static Thread Server_B_Thread = new Thread(Start_Server_B);
static void Main(string[] args)
{
Server_A_Thread.Start();
Server_B_Thread.Start();
}
static void Start_Server_A()
{
Console.WriteLine("Starting Server_A on port: " + server_A_Port);
server_A = new UdpClient();
IPEndPoint client_A_IpEp = new IPEndPoint(IPAddress.Any, server_A_Port);
server_A.Client.Bind(client_A_IpEp);
Console.WriteLine("Server Started. Waiting Client_A Message");
string c_a = "";
while (string.IsNullOrEmpty(c_a))
{
try
{
c_a = ReceiveMessageFromClient(server_A, ref client_A_IpEp);
Console.WriteLine("Message received from Client_A: " + c_a);
client_A_Ip = ((IPEndPoint)client_A_IpEp).Address.ToString();
client_A_Port = ((IPEndPoint)client_A_IpEp).Port;
server_A.Connect(client_A_IpEp);
}
catch(Exception err)
{
Thread.Sleep(1000);
}
}
Console.WriteLine("Waiting Client_B connection");
bool sended = false;
while (!sended)
{
if(client_B_Connected)
{
Console.WriteLine("Client_B connected, sending Client_B IP and Port to Client_A");
SendMessageToClient(server_A, client_B_Ip + ":" + client_B_Port);
sended = true;
Console.WriteLine("Message Sended to Client_A");
break;
}
Thread.Sleep(1000);
}
Console.ReadLine();
}
static void Start_Server_B()
{
Console.WriteLine("Starting Server_B on port: " + server_B_Port);
server_B = new UdpClient();
IPEndPoint client_B_IpEp = new IPEndPoint(IPAddress.Any, server_B_Port);
server_B.Client.Bind(client_B_IpEp);
Console.WriteLine("Server Started. Waiting Client_B Message");
string c_b = "";
while (string.IsNullOrEmpty(c_b))
{
try
{
c_b = ReceiveMessageFromClient(server_B, ref client_B_IpEp);
Console.WriteLine("Message received from Client_B: " + c_b);
client_B_Ip = ((IPEndPoint)client_B_IpEp).Address.ToString();
client_B_Port = ((IPEndPoint)client_B_IpEp).Port;
server_B.Connect(client_B_IpEp);
client_B_Connected = true;
}
catch (Exception err)
{
Thread.Sleep(1000);
}
}
Console.WriteLine("Sending external Port to Client_B start listering");
SendMessageToClient(server_B,client_B_Port + "");
}
static void SendMessageToClient(UdpClient client, string message)
{
byte[] data = Encoding.GetEncoding(28591).GetBytes(message);
client.Send(data, data.Length);
}
static string ReceiveMessageFromClient(UdpClient client, ref IPEndPoint ep)
{
byte[] data = client.Receive(ref ep);
string receivedString = Encoding.GetEncoding(28591).GetString(data);
return receivedString;
}
Client_A:
static string serverIp = "X.X.X.X";
static int serverPort = 45000;
static string otherClientIp = "0.0.0.0";
static int otherClientPort = 0;
static UdpClient client = new UdpClient();
static void Main(string[] args)
{
Console.WriteLine("Connecting to server...");
client.Connect(serverIp, serverPort);
Console.WriteLine("Connected. Sending request message...");
SendMessageToServer();
Console.WriteLine("Sended. Waiting response...");
string s = "";
while (string.IsNullOrEmpty(s))
{
try
{
s = ReceiveMessageFromServer();
Console.WriteLine("Response received from server.");
}
catch (Exception err)
{
Thread.Sleep(1000);
}
}
string[] otherClientInfo = s.Split(':');
otherClientIp = otherClientInfo[0];
otherClientPort = int.Parse(otherClientInfo[1]);
Console.WriteLine("Other Client info: " + otherClientIp + ":" + otherClientPort);
Thread.Sleep(2000);
Console.WriteLine("Connecting to Client_B...");
client.Connect(otherClientIp, otherClientPort);
Console.WriteLine("Connected. Sending hello hessage...");
SendMessageToClient();
Console.WriteLine("Sended. Waiting response...");
string c = "";
while (string.IsNullOrEmpty(c))
{
try
{
IPEndPoint ep = (IPEndPoint)client.Client.RemoteEndPoint;
c = ReceiveMessageFromClient(client,ref ep);
Console.WriteLine("Response received from Client_B.");
Console.WriteLine("Response: " + c);
Console.ReadLine();
}
catch (Exception err)
{
Thread.Sleep(1000);
}
}
}
static void SendMessageToServer()
{
byte[] data = Encoding.GetEncoding(28591).GetBytes("FROM CLIENT TO SERVER");
client.Send(data, data.Length);
}
static void SendMessageToClient()
{
byte[] data = Encoding.GetEncoding(28591).GetBytes("FROM CLIENT_A TO CLIENT_B");
client.Send(data, data.Length);
}
static string ReceiveMessageFromServer()
{
IPEndPoint serverIpEp = new IPEndPoint(IPAddress.Parse(serverIp), serverPort);
byte[] data = client.Receive(ref serverIpEp);
string receivedString = Encoding.GetEncoding(28591).GetString(data);
return receivedString;
}
static string ReceiveMessageFromClient(UdpClient server, ref IPEndPoint ep)
{
byte[] data = server.Receive(ref ep);
string receivedString = Encoding.GetEncoding(28591).GetString(data);
return receivedString;
}
Client_B:
static string serverIp = "X.X.X.X";
static int serverPort = 45001;
static UdpClient client = new UdpClient();
static void Main(string[] args)
{
Console.WriteLine("Connecting to server...");
client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
client.Connect(serverIp, serverPort);
Console.WriteLine("Connected. Sending request message...");
SendMessageToServer();
Console.WriteLine("Sended. Waiting response...");
string s = "";
while (string.IsNullOrEmpty(s))
{
try
{
s = ReceiveMessageFromServer();
Console.WriteLine("Response received from server.");
}
catch (Exception err)
{
Thread.Sleep(1000);
}
}
Console.WriteLine("My External Port: " + s);
IPEndPoint ep = new IPEndPoint(IPAddress.Any, int.Parse(s));
Console.WriteLine("Start Binding on Extenal Port: " + ep.Port);
UdpClient server = new UdpClient();
server.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
server.Client.Bind(ep);
Console.WriteLine("Started. Waiting hello message...");
string c = "";
while (string.IsNullOrEmpty(c))
{
try
{
c = ReceiveMessageFromClient(server, ref ep);
Console.WriteLine("Response received from Client_A.");
Console.WriteLine("Response: " + c);
client.Connect(ep);
Console.ReadLine();
}
catch (Exception err)
{
}
}
Console.WriteLine("Sending message to Client_A...");
SendMessageToClient();
Console.WriteLine("Sended.");
Console.ReadLine();
var myRule = FirewallManager.Instance.Rules.SingleOrDefault(r => r.Name == "TEST_RULE");
FirewallManager.Instance.Rules.Remove(myRule);
}
static void SendMessageToServer()
{
byte[] data = Encoding.GetEncoding(28591).GetBytes("FROM CLIENT TO SERVER");
client.Send(data, data.Length);
}
static void SendMessageToClient()
{
byte[] data = Encoding.GetEncoding(28591).GetBytes("FROM CLIENT_B TO CLIENT_A");
client.Send(data, data.Length);
}
static string ReceiveMessageFromServer()
{
IPEndPoint serverIpEp = new IPEndPoint(IPAddress.Parse(serverIp), serverPort);
byte[] data = client.Receive(ref serverIpEp);
string receivedString = Encoding.GetEncoding(28591).GetString(data);
return receivedString;
}
static string ReceiveMessageFromClient(UdpClient server, ref IPEndPoint ep)
{
byte[] data = server.Receive(ref ep);
string receivedString = Encoding.GetEncoding(28591).GetString(data);
return receivedString;
}
modified 4-Jan-20 23:46pm.
|
|
|
|
|
It's "empty" on Client A as "server". (I think you should have just "one" server)
static void OnClientConnect(object obj)
{
}
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
|
|
|
|
|
Sorry i have posted wrong code, now are correct.
|
|
|
|
|