Created
January 16, 2022 12:57
-
-
Save Inndy/07a920bf16d729d5cf983d2232935869 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmd = C:\Users\User\Downloads\arduino-1.8.19\hardware\tools\avr/bin/avr-g++ -c -g | |
-Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections | |
-fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p | |
-DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Users\User\Downloads\arduino-1.8.19\hardware\arduino\avr\cores\arduino | |
-IC:\Users\User\Downloads\arduino-1.8.19\hardware\arduino\avr\variants\standard | |
sketch\test.ino.cpp -o | |
preproc\ctags_target_for_gcc_minus_e.cpp | |
cmd = C:\Users\User\Downloads\arduino-1.8.19\hardware\tools\avr/bin/avr-g++ -c -g | |
-Os -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections | |
-fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L | |
-DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Users\User\Downloads\arduino-1.8.19\hardware\arduino\avr\cores\arduino | |
-IC:\Users\User\Downloads\arduino-1.8.19\hardware\arduino\avr\variants\standard | |
sketch\test.ino.cpp -o | |
sketch\test.ino.cpp.o | |
cmd = C:\Users\User\Downloads\arduino-1.8.19\hardware\tools\avr/bin/avr-gcc @C:\Users\User\AppData\Local\Temp\ccy18fuF | |
--- Content Of C:\Users\User\AppData\Local\Temp\ccy18fuF:--- | |
-xlto | |
-c | |
-fmath-errno | |
-fsigned-zeros | |
-ftrapping-math | |
-fno-trapv | |
-fno-openmp | |
-fno-openacc | |
-mn-flash=1 | |
-mmcu=avr5 | |
-Os | |
-mn-flash=1 | |
-mno-skip-bug | |
-fno-exceptions | |
-Os | |
-g | |
-fuse-linker-plugin | |
-L | |
C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_989838 | |
-specs=device-specs/specs-atmega328p | |
-mmcu=avr5 | |
-dumpdir | |
C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_989838/ | |
-dumpbase | |
test.ino.elf.wpa | |
-fltrans-output-list=C:\\Users\\User\\AppData\\Local\\Temp\\ccRA9cPp.ltrans.out | |
-fwpa | |
-fresolution=C:\\Users\\User\\AppData\\Local\\Temp\\ccvrrsEj.res | |
-flinker-output=exec | |
C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_989838\\sketch\\test.ino.cpp.o | |
C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_989838/core\\core.a@0x524a | |
C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_989838/core\\core.a@0x10c6e | |
C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_989838/core\\core.a@0x15b66 | |
C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_989838/core\\core.a@0x1f20a | |
C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_989838/core\\core.a@0x4f3fe | |
C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_989838/core\\core.a@0x501f2 | |
C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_989838/core\\core.a@0x4666 | |
--- End Content --- | |
cmd = C:\Users\User\Downloads\arduino-1.8.19\hardware\tools\avr/bin/avr-gcc @C:\Users\User\AppData\Local\Temp\ccxdoFNZ | |
--- Content Of C:\Users\User\AppData\Local\Temp\ccxdoFNZ:--- | |
-xlto | |
-c | |
-fmath-errno | |
-fsigned-zeros | |
-ftrapping-math | |
-fno-trapv | |
-fno-openmp | |
-fno-openacc | |
-mn-flash=1 | |
-mmcu=avr5 | |
-Os | |
-mn-flash=1 | |
-mno-skip-bug | |
-fno-exceptions | |
-Os | |
-g | |
-fuse-linker-plugin | |
-L | |
C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_989838 | |
-specs=device-specs/specs-atmega328p | |
-mmcu=avr5 | |
-dumpdir | |
C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_989838/ | |
-dumpbase | |
test.ino.elf.ltrans0 | |
-fltrans | |
-o | |
C:\\Users\\User\\AppData\\Local\\Temp\\ccRA9cPp.ltrans0.ltrans.o | |
C:\\Users\\User\\AppData\\Local\\Temp\\ccRA9cPp.ltrans0.o | |
--- End Content --- | |
cmd = C:\Users\User\Downloads\arduino-1.8.19\hardware\tools\avr/bin/avr-gcc -Os | |
-g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o C:\Users\User\AppData\Local\Temp\arduino_build_989838/test.ino.elf | |
sketch\test.ino.cpp.o | |
C:\Users\User\AppData\Local\Temp\arduino_build_989838/core\core.a -LC:\Users\User\AppData\Local\Temp\arduino_build_989838 | |
-lm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <shlwapi.h> | |
#include <stdarg.h> | |
#include <stdio.h> | |
void dbgprintf(const char *fmt, ...) { | |
va_list aptr; | |
va_start(aptr, fmt); | |
vfprintf(stderr, fmt, aptr); | |
fprintf(stderr, "\r\n"); | |
va_end(aptr); | |
} | |
void wcswrap(wchar_t *dst, const wchar_t *src, int width) { | |
int w = 0; | |
while(*src) { | |
if(w >= width) { | |
switch (*src) { | |
case '\n': | |
case '\r': | |
case '\t': | |
case ' ': | |
*dst++ = '\n'; | |
*dst++ = ' '; | |
*dst++ = ' '; | |
w = 0; | |
} | |
} | |
*dst++ = *src++; | |
w++; | |
} | |
*dst = 0; | |
} | |
int wmain(int argc, wchar_t *argv[]) { | |
static WCHAR buf[4096]; | |
wcswrap(buf, GetCommandLineW(), 80); | |
dbgprintf("cmd = %S", buf); | |
GetCurrentDirectoryW(sizeof(buf) / sizeof(buf[0]), buf); | |
STARTUPINFOW si={0}; | |
si.cb = sizeof(si); | |
PROCESS_INFORMATION pi; | |
WCHAR cmdline[2048]; | |
wcscpy(cmdline, GetCommandLineW()); | |
WCHAR exe[1024]; | |
DWORD nr = GetModuleFileNameW(NULL, exe, sizeof(exe) / sizeof(exe[0])); | |
if(nr == 0) { | |
dbgprintf("GetModuleFileNameW failed, err: 0xA%x", GetLastError()); | |
return 1; | |
} | |
wcsrchr(exe, '\\')[1] = 0; | |
wcscat(exe, L"_"); | |
wcscat(exe, PathFindFileNameW(argv[0])); | |
if(!PathFileExistsW(exe)) { | |
wcscat(exe, L".exe"); | |
} | |
// dbgprintf("exe path: %S", exe); | |
for(int i = 0; i < argc; i++) { | |
if(argv[i][0] == '@') { | |
HANDLE hFile = CreateFileW(&argv[i][1], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | |
DWORD size = GetFileSize(hFile, NULL); | |
HANDLE hMapping = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, size, NULL); | |
LPVOID data = MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, size); | |
fprintf(stderr, "--- Content Of %S:---\r\n%s\r\n--- End Content ---\r\n", &argv[i][1], data); | |
UnmapViewOfFile(data); | |
CloseHandle(hMapping); | |
CloseHandle(hFile); | |
} | |
} | |
BOOL r = CreateProcessW(exe, cmdline, NULL, NULL, | |
TRUE, 0, NULL, buf, &si, &pi); | |
if(r == FALSE) { | |
dbgprintf("Can not start process, err: 0x%x", GetLastError()); | |
return 1; | |
} | |
CloseHandle(pi.hThread); | |
DWORD w = WaitForSingleObject(pi.hProcess, INFINITE); | |
if(w != WAIT_OBJECT_0) { | |
dbgprintf("WaitForSingleObject returned 0x%x", w); | |
return 1; | |
} | |
DWORD exitcode = 0; | |
GetExitCodeProcess(pi.hProcess, &exitcode); | |
CloseHandle(pi.hProcess); | |
ExitProcess(exitcode); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment