20#define C_ASSERT(expr) extern char (*c_assert(void)) [(expr) ? 1 : -1]
24#if !defined(_MSC_VER) && !defined(__cdecl)
40#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
43#define min(a,b) (((a) < (b)) ? (a) : (b))
47#define strcasecmp _stricmp
53#define SW_SHOWNORMAL 1
54#define SW_SHOWMINNOACTIVE 7
71#define DEFINE_GUID2(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) const GUID name = { l,w1,w2,{ b1,b2,b3,b4,b5,b6,b7,b8 } }
72DEFINE_GUID2(CLSID_ShellLink, 0x00021401,0,0,0xC0,0,0,0,0,0,0,0x46);
73DEFINE_GUID2(CLSID_MyComputer,0x20D04FE0,0x3AEA,0x1069,0xA2,0xD8,0x08,0x00,0x2B,0x30,0x30,0x9D);
75#define LOCATOR_LOCAL 0x1
76#define LOCATOR_NETWORK 0x2
88#define SLDF_DEFAULT 0x00000000
89#define SLDF_HAS_ID_LIST 0x00000001
90#define SLDF_HAS_LINK_INFO 0x00000002
91#define SLDF_HAS_NAME 0x00000004
92#define SLDF_HAS_RELPATH 0x00000008
93#define SLDF_HAS_WORKINGDIR 0x00000010
94#define SLDF_HAS_ARGS 0x00000020
95#define SLDF_HAS_ICONLOCATION 0x00000040
96#define SLDF_UNICODE 0x00000080
97#define SLDF_HAS_EXP_SZ 0x00000200
98#define SLDF_HAS_EXP_ICON_SZ 0x00004000
100#define LINK_ID_LIST SLDF_HAS_ID_LIST
101#define LINK_FILE SLDF_HAS_LINK_INFO
102#define LINK_DESCRIPTION SLDF_HAS_NAME
103#define LINK_RELATIVE_PATH SLDF_HAS_RELPATH
104#define LINK_WORKING_DIR SLDF_HAS_WORKINGDIR
105#define LINK_CMDLINE_ARGS SLDF_HAS_ARGS
106#define LINK_ICON SLDF_HAS_ICONLOCATION
107#define LINK_UNICODE SLDF_UNICODE
153#define PT_DRIVE1 0x2F
154#define PT_FOLDER 0x31
158#define REGITEMORDER_DEFAULT 0x80
159#define REGITEMORDER_LIBRARIES 0x42
160#define REGITEMORDER_USERSFILEFOLDER 0x44
161#define REGITEMORDER_MYCOMPUTER 0x50
196#define EXP_SPECIAL_FOLDER_SIG 0xA0000005
207#define EXP_SZ_LINK_SIG 0xA0000001
208#define EXP_SZ_ICON_SIG 0xA0000007
225#define CSIDL_WINDOWS 0x24
226#define CSIDL_SYSTEM 0x25
235 {
CSIDL_SYSTEM,
"system",
"X:\\reactos\\system32",
"%SystemRoot%\\system32" },
268 wcstr[
i] = (
wchar_t)mbstr[
i];
287 return (
c ==
'\\' ||
c ==
'/');
314 if ((
ptr >
str + 1) && (*
str ==
'"') && (*(
ptr-1) ==
'"'))
323 if (*
ptr ==
'^' && *(
ptr+1) ==
'%')
339 buf[
sizeof(
"shell:") - 1] =
'\0';
343 target +=
sizeof(
"shell:") - 1;
344 for (
unsigned long i = 0;; ++
i)
377 wchar_t tmpBufferU[1024];
379 fwrite(tmpBufferU, uhTmp *
sizeof(
wchar_t), 1,
pFile);
385 const char *pszOutputPath =
"shortcut.lnk";
386 const char *pszTarget =
NULL;
387 const char *pszDescription =
NULL;
388 const char *pszWorkingDir =
NULL;
389 const char *pszCmdLineArgs =
NULL;
390 const char *pszIcon =
NULL;
394 bool bHelp =
false, bUnicode =
false, bMinimized =
false;
407 if ((
argv[
i][0] ==
'-' ||
argv[
i][0] ==
'/') &&
430 pszOutputPath =
argv[
i];
438 pszDescription =
argv[
i];
444 pszWorkingDir =
argv[
i];
450 pszCmdLineArgs =
argv[
i];
462 unsigned Data4Tmp[8],
j;
466 sscanf(
argv[
i],
"{%8x-%4hx-%4hx-%2x%2x-%2x%2x%2x%2x%2x%2x}",
468 &Data4Tmp[0], &Data4Tmp[1], &Data4Tmp[2], &Data4Tmp[3],
469 &Data4Tmp[4], &Data4Tmp[5], &Data4Tmp[6], &Data4Tmp[7]);
470 for (
j = 0;
j < 8; ++
j)
482 if (!pszTarget || bHelp)
484 printf(
"Usage: %s [-h][-v][-o path][-u][-d descr][-w path][-c cmdline_args][-i [icon_path[,nr]]][-g guid] target\n"
485 "-h\tShows this help.\n"
486 "-v\tEnables verbose mode for diagnostics.\n"
487 "-o path\tSets the output path.\n"
488 "-u\tCreates a Unicode-aware shortcut.\n"
489 "-d descr\tSets the shortcut description.\n"
490 "-w path\tSets the working directory for the executable.\n"
491 "-c cmdline_args\tSets the command-line arguments passed to the program.\n"
492 "-i [icon_path[,nr]]\tSets the icon path and optionally its index. If only an index is given (but no path), the target file is used instead.\n"
493 "-m\tStart minimized.\n"
494 "-g guid\tSets the GUID to which the target path is relative. Default value is MyComputer GUID.\n"
495 "target\tAbsolute or relative to GUID specified with the -g option path.\n",
argv[0]);
513 dwTmp =
strtol(pszIcon, &endptr, 0);
514 if (endptr && endptr != pszIcon)
528 if (endptr && endptr != (
ptr+1))
539 trace(
"OutputPath = %s\n"
544 "Icon = %s (%d)\n\n",
545 pszOutputPath, pszTarget, pszDescription,
546 pszWorkingDir, pszCmdLineArgs,
547 (pszIcon == (
char*)1) ? pszTarget : pszIcon,
IconIndex);
552 printf(
"Failed to open %s\n", pszOutputPath);
559 Header.Guid = CLSID_ShellLink;
583 Header.Flags &= ~LINK_ID_LIST;
586 Header.Flags &= ~LINK_RELATIVE_PATH;
603 trace(
"Header.Flags = 0x%08x\n"
604 "Header.IconIndex = %d\n"
605 "Header.ShowCmd = %u\n",
615 unsigned int cbListSize =
sizeof(IdListGuid) +
sizeof(
uint16_t);
618 const char *pszOrgTarget = pszTarget;
619 size_t specialPathLen = 0;
626 CsidlBlock.
cbSize =
sizeof(CsidlBlock);
631 pszTarget = targetpath;
635 if (pszName[0] && pszName[0] !=
':' && pszName[1] ==
':')
637 cbListSize +=
sizeof(IdListDrive);
649 if (
cchName != 1 || pszName[0] !=
'.')
653 cbListSize +=
sizeof(IdListFile) + (
cchName + 1) + 1;
656 if (special && ((pszName+
cchName)-pszTarget == specialPathLen))
660 pCsidlBlock = &CsidlBlock;
672 IdListGuid.
Size =
sizeof(IdListGuid);
680 if (
isalpha(pszName[0]) && pszName[1] ==
':')
682 memset(&IdListDrive, 0,
sizeof(IdListDrive));
683 IdListDrive.
Size =
sizeof(IdListDrive);
686 fwrite(&IdListDrive,
sizeof(IdListDrive), 1,
pFile);
698 if (
cchName != 1 || pszName[0] !=
'.')
700 memset(&IdListFile, 0,
sizeof(IdListFile));
703 IdListFile.
Size =
sizeof(IdListFile) + (
cchName + 1) + 1;
729 pszTarget = targetpath;
734 if (pszIcon == (
char*)1)
739 memset(&SzLinkBlock, 0,
sizeof(SzLinkBlock));
740 SzLinkBlock.
cbSize =
sizeof(SzLinkBlock);
747 pSzLinkBlock = &SzLinkBlock;
752 memset(&SzIconBlock, 0,
sizeof(SzIconBlock));
753 SzIconBlock.
cbSize =
sizeof(SzIconBlock);
760 pSzIconBlock = &SzIconBlock;
785 fwrite(pCsidlBlock,
sizeof(*pCsidlBlock), 1,
pFile);
787 fwrite(pSzLinkBlock,
sizeof(*pSzLinkBlock), 1,
pFile);
789 fwrite(pSzIconBlock,
sizeof(*pSzIconBlock), 1,
pFile);
int CDECL vprintf(const char *format, va_list valist)
int CDECL fclose(FILE *file)
FILE *CDECL fopen(const char *path, const char *mode)
int CDECL fputc(int c, FILE *file)
size_t CDECL fwrite(const void *ptr, size_t size, size_t nmemb, FILE *file)
_ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl sscanf(const char *, const char *,...) __WINE_CRT_SCANF_ATTR(2
_ACRTIMP __msvcrt_long __cdecl strtol(const char *, char **, int)
_ACRTIMP char *__cdecl strchr(const char *, int)
_ACRTIMP size_t __cdecl strlen(const char *)
_ACRTIMP int __cdecl strcmp(const char *, const char *)
_ACRTIMP char *__cdecl strrchr(const char *, int)
static const WCHAR IconIndex[]
GLuint GLuint GLsizei count
GLenum GLuint GLenum GLsizei const GLchar * buf
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
size_t mbstowcs16(wchar_t *wcstr, const char *mbstr, size_t count)
static bool has_env_variables(const char *str)
static const struct SPECIALFOLDER * get_special_folder(const char *target)
struct _EXP_SZ_LINK EXP_SZ_LINK
struct _ID_LIST_GUID ID_LIST_GUID
struct _LNK_HEADER LNK_HEADER
struct _LNK_LOCATOR_INFO LNK_LOCATOR_INFO
#define LINK_RELATIVE_PATH
static const struct SPECIALFOLDER g_specialfolders[]
struct _EXP_SPECIAL_FOLDER EXP_SPECIAL_FOLDER
#define LINK_CMDLINE_ARGS
struct _FILETIME * PFILETIME
struct _FILETIME FILETIME
#define EXP_SPECIAL_FOLDER_SIG
static bool is_path_separator(char c)
struct _ID_LIST_FILE ID_LIST_FILE
static void write_string(FILE *pFile, bool bUnicode, const char *str)
static void strip_quotes_and_unescape_envvars(char **pstr)
#define REGITEMORDER_MYCOMPUTER
#define SLDF_HAS_EXP_ICON_SZ
struct _LNK_LOCAL_VOLUME_INFO LNK_LOCAL_VOLUME_INFO
#define SW_SHOWMINNOACTIVE
struct _ID_LIST_DRIVE ID_LIST_DRIVE
#define DEFINE_GUID2(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
WCHAR szwTarget[MAX_PATH]
wchar_t szwTarget[MAX_PATH]
uint32_t VolumeNameOffset
uint32_t LocalBasePathnameOffset
uint32_t LocalVolumeInfoOffset
uint32_t RemainingPathnameOffset
uint32_t NetworkVolumeInfoOffset
_Must_inspect_result_ _In_ WDFOBJECT _In_ CONST GUID * Guid
_In_ PSID _Out_writes_to_opt_ cchName LPSTR _Inout_ LPDWORD cchName