Jump to content

TheDcoder

Active Members
  • Posts

    7,103
  • Joined

  • Days Won

    88

Everything posted by TheDcoder

  1. Windows won't allow this as long as there is a program with a open handle to a file... Option C is probably your best bet if you force the operation.
  2. Just posted this question over at StackOverflow in hopes of getting answers: https://stackoverflow.com/questions/54416116/readfile-does-not-return-while-reading-stdout-from-a-child-process-after-it-ends
  3. @Earthshine Yup, was one of the first results that I got a few weeks back when investigating how output redirection works in POSIX. Sadly it only talks about the POSIX functions to do this, Windows doesn't provide this functionality as far as I am aware. My code for POSIX works like a charm, the issue is only on Windows . The ReadFile documentation mentions: This does not happen when the process ends... it just never returns! I wonder how the internal AutoIt functions like Run and StdoutRead work... I am especially keen on how StdoutRead can be non-blocking, does AutoIt use multi-threading to maintain to retrieve the output later? I might use this method, but I would like to avoid it if possible.
  4. Nope, not true. The error indicates that your array is out of bounds, i.e either the element index is out of the defined range or the variable itself is not an array. Nothing to do with the library. I suggest you thorougly sanitize any input from the user and see if that error still happens
  5. Hi, I thought I would never post a C/WinAPI related question in this forum ever, but here we are after a few years and me having learnt enough of C to write a basic console program My issue is that I am trying to read my child process's stdout output but ReadFile never returns if the child exits or if it is killed... very strange , I have been trying to work my way around this. The options I can think of are: Create a new thread and check for existance of the process constantly while reading Somehow make the pipe asynchronous (overlapped) so that I can read it in a non-blocking manner Fix ReadFile to return when the process ends Obviously I would prefer No. 3, I just want to make my program work. Here is my code if you guys want to take a look: // No text highlighting for C/C++ but we have it for C#? Blasphemy! bool allium_start(struct TorInstance *instance, char *config, allium_pipe *output_pipes) { char *cmd; // Figure out the command string for execution if (config) { char *parameters = " -f -"; cmd = malloc(strlen(instance->tor_path) + strlen(parameters) + 1); if (!cmd) return false; strcpy(cmd, instance->tor_path); strcat(cmd, parameters); } else cmd = instance->tor_path; // Prepare startup info with appropriate information SecureZeroMemory(&instance->startup_info, sizeof instance->startup_info); instance->startup_info.dwFlags = STARTF_USESTDHANDLES; SECURITY_ATTRIBUTES pipe_secu_attribs = {sizeof(SECURITY_ATTRIBUTES), NULL, true}; HANDLE pipes[2]; if (output_pipes == NULL) { CreatePipe(&pipes[0], &pipes[1], &pipe_secu_attribs, 0); output_pipes = pipes; } instance->startup_info.hStdOutput = output_pipes[1]; instance->startup_info.hStdError = output_pipes[1]; instance->stdout_pipe = output_pipes[0]; // Stored for internal reference if (config) { // Reuse the pipes array to store standard input pipes CreatePipe(&pipes[0], &pipes[1], &pipe_secu_attribs, 0); instance->startup_info.hStdInput = pipes[0]; } // Create the process bool success = CreateProcessA( NULL, cmd, NULL, NULL, config ? true : false, 0, NULL, NULL, &instance->startup_info, SecureZeroMemory(&instance->process, sizeof instance->process) ); // Free command string if needed if (config) free(cmd); // Write config to Tor's standard input unsigned long bytes_written; if (success) { WriteFile(pipes[1], config, strlen(config), &bytes_written, NULL); // Work around for simulating Ctrl + Z which sends the substitution character (ASCII 26), // this is needed in order for Tor to detect EOT/EOF while reading the config WriteFile(pipes[1], &(char){26}, 1, &bytes_written, NULL); } CloseHandle(pipes[1]); // Return on failure if (!success) return false; } char *allium_read_stdout_line(struct TorInstance *instance) { char *buffer = instance->buffer.data; // Check for valid buffer and allocate if needed if (instance->buffer.size == 0 || !buffer) { buffer = instance->buffer.data = malloc(instance->buffer.size = 80 + 1); if (!buffer) return NULL; } // Process the input unsigned int read_len = 0; while (true) { // Read data unsigned long bytes_read; if (ReadFile(instance->stdout_pipe, buffer, 1, &bytes_read, NULL) == false || bytes_read == 0) return NULL; // Check if we have reached end of line if (buffer[0] == '\n') break; // Proceed to the next character ++buffer; ++read_len; // Resize buffer if it is full if (read_len == instance->buffer.size) { char *new_buffer = malloc(instance->buffer.size += 50); if (new_buffer) memcpy(new_buffer, instance->buffer.data, read_len); free(instance->buffer.data); if (!new_buffer) return NULL; instance->buffer.data = new_buffer; buffer = instance->buffer.data + read_len; } } // Terminate the new line with null character and return // Special handling for Windows, terminate at CR if present buffer[read_len >= 2 && buffer[-1] == '\r' ? -1 : 0] = '\0'; } The allium_start function creates the redirection pipes and the child process, the other allium_read_stdout_line function reads from the stdout pipe created by the first function, ReadFile in this function does not return when the child ends or gets killed. I appriciate the help of the WinAPI gurus here, thanks in advance!
  6. For those who are interestd in go a little bit deeper, I think Khan academy has done a topic (with videos) about it, that is where I learned about how RSA works and how it was independently rediscovered. A little bit of math logic and prime numbers you can have a good way to encrypt data without a single shared key. Asymmetrical encryption they call it I think ... I found the topic: Journey into cryptography, it covers RSA in the modern cryptography section: https://www.khanacademy.org/computing/computer-science/cryptography#modern-crypt
  7. ProxAllium ProxAllium is a GUI frontend to Tor, it aims to make the usage of Tor easier by directly exposing its SOCK5 proxy which can be used to access the Tor network. The GUI is designed to be simple and user-friendly and it has a few other features... namely: Fully portable - doesn't write outside its own directory Integrated with Tor via the controller interface and properly communicates with it Minimize to tray Option to start with Windows Interface to configure bridges if Tor is censored in your region Many customization options are available via the config.ini file Screenshots: The code is made with pure AutoIt, is fully open source and you are free to adapt it to your needs The GitHub repository hosts all the releases and code. As a bonus it has a somewhat sparsely documented Tor UDF which can be used to control Tor, the code also demonstrates the proper usage of my Process UDF which might be interesting if you want to deal with processes. As some of my friends know, I no longer use Windows as my main operating system. I switched to Linux a few months back as my primary operating system and haven't looked back since. Unfortunately that meant I could no longer use my own program due to it being Windows only... after a few months of playing around with C and making a basic program, I have decided to rewrite all of ProxAllium into C and make it cross-platform. Sadly this means that the AutoIt version of ProxAllium will not receive any major updates now. Let me know if this is something you guys would use, I used it daily with my IRC client to connect via Tor (to protect my I.P). I hope you enjoy using my program!
  8. @Acanis Generally you would want to implement error checking in your code as much as possible, so that your script does't stop because of an error like that. There is no easy way (as far as I am aware) to capture these error without getting AutoIt interrupted... Yes, you are right about this.
  9. @FrancescoDiMuro Done, in the end I wrote my own code to keep it simple but also linked to your post
  10. @FrancescoDiMuro Good example, I will try to adapt it for my OP and edit it in
  11. @FrancescoDiMuro Yes, you are right, it would be indeed useful to explain the use of Step keyword in the For loop. It has been a while since I have updated the main post and I now see multiple issues with it... I am too busy with other work at the moment so I cannot really take out time now. Maybe someone else can take up the task?
  12. @KaFu I have added your software at AlternativeTo as an alternative to some programs, please update the icon there and check other details to make sure that they are correct (I copy pasted them from your website) ...now I am going to add my software as an alternative to HMW
  13. I did for Microsoft Defender and they pretty quickly unflagged it after analysis, but I don't think this is relevant to OP's original question/issue. @DJ143 Your best option is to ask your system administrator to add an exception, or you can try to report the false positive to whatever AV you use. If I understand correctly, the AV isn't actively interfering (by showing an alert or deleting the file), so it may not be related to anti-virus at all. Please verify the issue and let us know in order to help you.
  14. @ericyeoh You will probably have to use the DllCall and friends available in AutoIt to call the available functions inside the library, this will also involve manually replicating the structures found inside the header (.h) file using DllStructCreate Also there is another thing which might prevent you from using the DLLs, they will need to use the same runtime as AutoIt or else they would not work... I think. I am not really sure on this part but it shouldn't really matter unless you get very strange errors.
  15. Any chance that you are running on a non x86 platform? (ARM, Itanium etc.)
  16. Or you can go the adlib route if your code is too complicated to be in a event loop or if you are extra lazy: AdlibRegister(ThreeMinuteExit, 60 * 3 * 1000) ; 3 minutes in milliseconds Func ThreeMinuteExit() MsgBox(0, "3 minutes", "Hey mate your time is up, now it is time to quit") Exit EndFunc @Xandy You used 3 seconds instead of the 3 minutes OP asked for by the way
  17. If you are able to do it from command prompt, did you check the location using the where command? Also try calling the executable directly instead of doing it via ComSpec.
  18. I don't think you can have a visible browser window (atleast a proper one) with multiple tabs when you are using web driver interface. I did not use it before so I do not know much about it.
  19. You may want to control chrom/firefox via the Web Driver interface, which is a W3C wed standard There is an excellent Web Driver UDF (library) made for using just that by @Danp2 You will have to directly refer to the code and comments in the included scripts
  20. Yes. you can use data url in the img tag as the source , @mLipok has already mentioned this and has linked to useful pages.
  21. Maybe it is something related to encoding, and MS Word seems to be using the correct encoding You can also use an embedded IE control (COM Object) to display HTML as @Subz has suggested. This opens up more opportunities to you, as the ability to use JavaScript to make the page interactive. To sum it up: Use IE if you want a more feature rich document which can display HTML or if you just need to display some formatted text in a simple manner, stick to Rich Edit controls Rich Edit controls are lighter and are less likely to break across different versions than IE (which has gone through it's fair share of script breaking major changes)
  22. @timmy2 You can use a Rich Edit control and use _GUICtrlRichEdit_StreamFromFile with an RTF file to display the rich text All of the functions related to Rich Edit controls are in the User Defined Function Reference -> GUI -> GuiRichEdit section of the help file
  23. Hello @odaylton, while I am not qualified to speak about the specifics about window GUI messages, I can offer you some general advice: Case 1: It would be most efficient as you are using AutoIt's native Bit operation functions Case 2: This would actually be more relevant since the NHMDR tag (structure) is designed to contain information about a message, but how efficient or safe it is depends on how the struct is populated... Case 3: I think this would be your safest option if you want to get the Hi and Low words, as it is a direct call to the Windows API Take my advice with a pinch of salt
  24. You can use Run to execute mspaint.exe and it would return the PID of the process
  25. @Arlen Nope, there isn't a good way to do multi-threading in AutoIt because it wasn't designed for this. The closest thing you could do is run multiple instances of your script which can do multiple jobs for you, but you need to handle the communication between the instances yourself... maybe mail slots are a good way but it depends on your use case
×
×
  • Create New...