|
Does Windows provide any control for this? No, not directly. I don't know of any O/S that does.
If the app is just shelling out to a URL, you really cannot stop an app from doing that. The shell will take commands from anything and there's nothing you can do to stop it.
Firewall rules will not help because the URL is being launched by the shell and the browser is the registered handler for HTTP/HTTPS. Your game isn't involved in handling the URL itself so there's no process-based firewall rule that will prevent the launch of it.
Writing up a rule to prevent access to the URL or IP will still bring up a browser window, but with a failure message.
|
|
|
|
|
|
I know the way I stopped it from happening with the game that I had.
I paid for the game, rather than just continuing to use the free demo.
|
|
|
|
|
Are there any .onnx Modules that are included already or plans to have them included?
The only ones I'm interested in are a .pt file format and the YOLOv5 6.2 doesn't work very well at all. (Probably because I don't have a GPU)
|
|
|
|
|
What does your question have to do with this forum? If you're asking about something you saw in an article, you should ask in the article itself.
|
|
|
|
|
It's related to the YOLOv5 .NET model.
|
|
|
|
|
|
Thank you, I'll post it there instead.
|
|
|
|
|
Hello guys,
I have an issue related to dependency injection in the Program.cs of a .Net 7 application.
In this case it's an API, but that does not really matter.
Before calling the line:
var app = builder.Build();
I am adding a few singletons normally with :
builder.Services.AddSingleton<IMyConfig, MyConfig>();
builder.Services.AddSingleton<IMyHttpClient, MyHttpClient>();
My issue is that the HTTP client singleton requires info from the config singleton, and it's not a simple case of injecting the former into the latter.
We can't use appsettings.json to manage our configuration, that would be too easy, and because the second one is an HTTP client, I have this code :
builder.Services.AddSingleton<IMyHttpClient, MyHttpClient>();
builder.Services.AddHttpClient<IMyHttpClient, MyHttpClient>(client =>
{
client.BaseAddress = new Uri(myConfig.myURI);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}).ConfigurePrimaryHttpMessageHandler(() =>
{
return new HttpClientHandler()
{
UseDefaultCredentials = true
};
});
.. all this still before I call builder.Build();
I have already googled and chatGPT'd the problem, but the solutions I get are for .Net 6 at best, and do not apply.
My current solution is to use builder.Services.BuildServiceProvider().GetService<imyconfig>() to get an instance of myConfig, but then the builder is called twice, so this instance is lost, and after the builder.Build(), I have to read my config again.
Technically, this works, but it's ugly and triggers my OCD.
If there's any DI god out there, what am I missing ?
Thanks in advance
Fred
modified 28-Apr-23 9:43am.
|
|
|
|
|
If you're "stuck" with a given framework, count yourself lucky if you get something to work. When it does, move on instead of thinking about "ugly"; it's a waste of time.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
If you want a singleton then you have to inject it into a thread flow that does not depend on requests but rather something like the start up method.
But as with the other reply, the point it to deliver something. And you need to have a realistic view about what might actually need to be easily replaced in the future. So does it actually need to be injected. Configuration might be it but you can do that with a standard factory idiom also.
|
|
|
|
|
|
Ok, a few months late admittedly. I'm not a fan of all this functional style boostrapping in ASP.NET core. I find the whole thing obfuscated and difficult to work with and often grapple just to do something simple like config or logging.
Anyway, I have this in my code:
services.AddHttpClient<IMyClient, MyClient>((serviceProvider, httpClient) =>
{
var opts = serviceProvider.GetRequiredService<IOptions<MyHttpOptions>>();
httpClient.BaseAddress = opts.Value.BaseUrl;
})
So, if you just want to get access to config, I think you can just retrieve it from the service provider given as the second parameter to the lambda, no BuildServiceProvider() required.
Regards,
Rob Philpott.
|
|
|
|
|
I'm in the process of building a HTML server using vb.net which dose the job quite well. Currently I'm trying to add a function for downloading files. The sending of plain text works without a glitch (see code 1). However sending files such as executables (*.exe) or Excel (*.xls) files dosen't work (see code 2).
The file once downloaded simply wont run. Upon closer examination (by opening the downloaded file in Notepad) signs of incorrect encoding are typically seen. there are a lot of question mark characters and when compared 1 on 1 with the original file it is clear that the encoding is the problem. Simply said I have no idea on how to resolve this and internet research isn't proving to be a reliable bron of information. Since the problem is one of encoding what I have tried is to read the exe file through a file stream-read and convert its context (probably binary) to text and send that with result that there there is an inprovment but the problem still persists and ultimatlhy the file still dosen't work.
How do I resolve this?
CODE 1
With My404HtmlPage
.Append("HTTP/1.1 200 OK" & Environment.NewLine)
.Append("Content-Type: text/plain & Environment.NewLine)
.Append("Content-Disposition: attachment; filename=" & Chr(34) & "Download.exe" & Chr(34) & Environment.NewLine)
.Append(Environment.NewLine)
.Append("Hello World!")
End With
CODE 2
With My404HtmlPage
.Append("HTTP/1.1 200 OK" & Environment.NewLine)
.Append("Content-Type: application/octet-stream & Environment.NewLine)
.Append("Content-Disposition: attachment; filename=" & Chr(34) & "Download.exe" & Chr(34) & Environment.NewLine)
.Append(Environment.NewLine)
Dim bytes = My.Computer.FileSystem.ReadAllBytes("C:\Original.exe")
Dim MyString As String = Encoding.UTF8.GetString(bytes)
.Append("content-bytes:" & MyString)
End With
|
|
|
|
|
Umm... There is NO encoding for any binary file.
Encoding means "interpet the bytes as this", which will change how the bytes are interpreted, changing them when read. You absolutely do NOT want to change a single byte. You should be just sending the bytes, not creating a string out of them.
|
|
|
|
|
Dim MyString As String = Encoding.UTF8.GetString(bytes)
You just destroyed the content of the file.
Any file that is non-text based is pure binary and should only be read and written as such.
|
|
|
|
|
Bart van Tuijl wrote: Dim MyString As String = Encoding.UTF8.GetString(bytes) No, apply them bytes?
That's what Dave says and he is right. Bytes are that.
No encoding. Write them bytes directly.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Okay I get how that should work. I'm not all to sure on how to achieve this and I've given it a shot but it dosn't work as expected all the downloaded file now says when opened in notepad is 77
Here's my attempt.
With My404HtmlPage
.Append("HTTP/1.1 200 OK" & Environment.NewLine)
.Append("Content-Type: application/octet-stream" & Environment.NewLine)
.Append("Content-Disposition: attachment; filename=" & Chr(34) & "Bilandted.exe" & Chr(34) & Environment.NewLine)
.Append(Environment.NewLine)
Dim array() As Byte = File.ReadAllBytes("C:\Test\TestFile.exe")
Using memory As MemoryStream = New MemoryStream(array)
Using reader As BinaryReader = New BinaryReader(memory)
.Append((reader.ReadByte()))
End Using
End Using
End With
Im thinking I need to do something with the byte length but have now landed outside of my field of knowledge?
|
|
|
|
|
What type is your My404HtmlPage variable? Hopefully, it should support writing more than one byte at a time...
If not, you'll need to loop over the bytes and copy them all to the output one by one.
NB: There's no need for the MemoryStream and BinaryReader , since you already have an array of the bytes you need to send.
Dim array() As Byte = File.ReadAllBytes("C:\Test\TestFile.exe")
For i As Integer = 0 To array.Length - 1
.Append(array(i))
Next
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
There is indeed a lot of data now in the downloaded file but its still all in numbers (It dosent look like binary too me but more like decimal without the hyphens) what am I missing here I'm assuming that the browser would know how to handle this data and reproduce a valid file from it (perhaps I'm wrong)?
also to answer the type of variable for My404HtmlPage is
Dim My404HtmlPage As New System.Text.StringBuilder()
which then is passed on to a variable named MyHtmlServerResponse as follows
MyHtmlServerResponse = (My404HtmlPage.ToString)
MyHtmlServerResponse is a string variable as can be seen below
Dim MyHtmlServerResponse As String
EDIT:
Just as extra Info the actual sending is done through TCP/ IP as follows
For Each c As TcpClient In MyClientList
If c Is MyClient Then
Dim nns As NetworkStream = c.GetStream()
nns.Write(Encoding.ASCII.GetBytes(MyHtmlServerResponse), 0, MyHtmlServerResponse.Length)
MyClient.Dispose()
End If
modified 3-Apr-23 12:01pm.
|
|
|
|
|
It does not matter what the content of the file looks like. If you do not understand how to handle binary data without corrupting it then you will never pass go or collect your $200. So stop trying to convdert the content into printable/displayable strings, that just destroys it (as I said in my previous message). You must read and write the content as pure binary bytes, nothing else.
|
|
|
|
|
Bart van Tuijl wrote: also to answer the type of variable for My404HtmlPage is
Dim My404HtmlPage As New System.Text.StringBuilder()
Well, there's your problem. You cannot treat binary data as a string!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This My404HtmlPage being a string I had suspected, though Im at a dilemma because my http header information is sent as string and my file as bytes yet they belong to eachother.
Is there a way I can convert my HTTP header to bytes and add my file to it as bytes and then send it or will that not work?
(Sorry guys Im just a hobbyist so my knowledge is limited)
|
|
|
|
|
Yes as I suggested in my other post.
You need to learn what hexadecimal is ('hex').
You need to get a hexadecimal editor (it will be called a hex editor.)
You need to compile a SMALL project and then look at the exe (which is a binary file) using the hex editor. Not notepad.
You need to then look at an image using a hex editor.
You need to then find the specification ('spec') for that type of image and use the hex editor (not notepad) to figure out the parts of the image.
I would also suggest that you write a program parse an image file. NOT display it. Just read it and print out the parts.
1. Read the file with a stream
2. Use the spec to figure out how to read the file.
3. Print out the various pieces. For example there is likely a size (x and y) so print that out as integers.
|
|
|
|
|
Bart van Tuijl wrote: I'm in the process of building a HTML server using vb.ne
Reading through this and your other posts.
You need to come to a full stop on your code and first learn how http and the browser works.
And additionally what a 'binary' file is.
------------------------------------------
Binary file - if is an executable and you open it in notepad will always look like you found. Does not matter where it came from.
Notepad takes data and then transforms it in to characters.
That can only work if the data is in fact characters.
A binary, especially an executable will never consist solely of characters. So of course notepad will never display it because it cannot. Notepad displays a '?' for data that is not actually characters.
Some (most) executables will have data in them that you will be able to read. Doesn't mean the rest is wrong just that an executable has text in it.
And all of that depends on what character set notepad expects to see (I suspect you might want to research that also.)
You can experiment with this by using notepad to open various files on your computer. I suggest
1. Executable
2. Image file
3. Write your own program, put text in it (a string), compile it, then open that.
Do NOT save anything in Notepad to those above files. Unless you want to destroy them (try it if you wish but only if you expect to lose it.)
If you really want to modify a binary file manually then you need to find a 'hex editor'.
If you want to do that then you will need to learn what 'hex' means.
------------------------------------------
A browser sends a request to a web server and the web server then responds to that request.
You should learn about the HTTP protocol.
Your browser will have a 'developer tool' which allows you to inspect both requests and responses.
The HTTP protocol itself does not support file downloads in anyway.
A specific request might result in some content which originates from files being downloaded.
1. A html response (from a request) might have tags in it which the browser which will then use to make another request to the web server, and the response body with have data which is an image. The request defines this not the HTTP protocol.
Browsers used to support a 'ftp' protocol that allowed files to be downloaded. Rather than 'http' it started with 'ftp'
However apparently newer versions (Chrome, Firefox) no longer support that at all. So you would need to get an older version if you wanted to implement that protocol.
|
|
|
|