Skip to content

Commit

Permalink
Add const qualifiers in stub.c to enhance type safety
Browse files Browse the repository at this point in the history
  • Loading branch information
shinokaro committed Feb 14, 2024
1 parent 3f306c0 commit 4519c2b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions src/stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ char *JoinPath(const char *p1, const char *p2)
return ConcatStr(p1, p2, NULL);
}

SIZE_T ParentDirectoryPath(char *dest, SIZE_T dest_len, char *path)
SIZE_T ParentDirectoryPath(char *dest, SIZE_T dest_len, const char *path)
{
if (path == NULL) return 0;

Expand All @@ -170,7 +170,7 @@ SIZE_T ParentDirectoryPath(char *dest, SIZE_T dest_len, char *path)
return i;
}

char *ExpandInstDirPath(char *rel_path)
char *ExpandInstDirPath(const char *rel_path)
{
if (rel_path == NULL || *rel_path == '\0') {
DEBUG("rel_path is null or empty");
Expand All @@ -180,7 +180,7 @@ char *ExpandInstDirPath(char *rel_path)
return JoinPath(InstDir, rel_path);
}

BOOL CheckInstDirPathExists(char *rel_path)
BOOL CheckInstDirPathExists(const char *rel_path)
{
char *path = ExpandInstDirPath(rel_path);
BOOL result = (GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES);
Expand Down Expand Up @@ -307,7 +307,7 @@ BOOL WINAPI ConsoleHandleRoutine(DWORD dwCtrlType)
return TRUE;
}

BOOL DeleteRecursively(char *path)
BOOL DeleteRecursively(const char *path)
{
char *findPath = JoinPath(path, "*");

Expand Down Expand Up @@ -591,10 +591,10 @@ BOOL ProcessImage(LPVOID pSeg, DWORD data_len, BOOL compressed)

#define PLACEHOLDER '|'

char *ReplaceInstDirPlaceholder(char *str)
char *ReplaceInstDirPlaceholder(const char *str)
{
int InstDirLen = strlen(InstDir);
char *p;
const char *p;
int c = 0;

for (p = str; *p; p++) { if (*p == PLACEHOLDER) c++; }
Expand Down Expand Up @@ -644,7 +644,7 @@ char *SkipArg(char *str)
/**
Create a file (OP_CREATE_FILE opcode handler)
*/
BOOL MakeFile(char *file_name, DWORD file_size, LPVOID data)
BOOL MakeFile(const char *file_name, DWORD file_size, const void *data)
{
if (file_name == NULL || *file_name == '\0') {
FATAL("file_name is null or empty");
Expand Down Expand Up @@ -698,7 +698,7 @@ BOOL MakeFile(char *file_name, DWORD file_size, LPVOID data)
/**
Create a directory (OP_CREATE_DIRECTORY opcode handler)
*/
BOOL MakeDirectory(char *dir_name)
BOOL MakeDirectory(const char *dir_name)
{
DEBUG("MakeDirectory");

Expand Down Expand Up @@ -751,7 +751,7 @@ DWORD CreateAndWaitForProcess(const char *app_name, char *cmd_line)
* Sets up a process to be created after all other opcodes have been processed. This can be used to create processes
* after the temporary files have all been created and memory has been freed.
*/
BOOL SetScript(char *app_name, char *script_name, char *cmd_line)
BOOL SetScript(const char *app_name, const char *script_name, const char *cmd_line)
{
DEBUG("SetScript");

Expand Down Expand Up @@ -804,7 +804,7 @@ BOOL SetScript(char *app_name, char *script_name, char *cmd_line)
return TRUE;
}

BOOL SetEnv(char *name, char *value)
BOOL SetEnv(const char *name, const char *value)
{
char *replaced_value = ReplaceInstDirPlaceholder(value);

Expand Down
8 changes: 4 additions & 4 deletions src/unpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#define OP_SET_SCRIPT (BYTE)4
#define OP_MAX (BYTE)5

BOOL MakeDirectory(char *dir_name);
BOOL MakeFile(char *file_name, DWORD file_size, LPVOID data);
BOOL SetEnv(char *name, char *value);
BOOL SetScript(char *app_name, char *script_name, char *cmd_line);
BOOL MakeDirectory(const char *dir_name);
BOOL MakeFile(const char *file_name, DWORD file_size, const void *data);
BOOL SetEnv(const char *name, const char *value);
BOOL SetScript(const char *app_name, const char *script_name, const char *cmd_line);

BYTE ProcessOpcodes(LPVOID* p);

0 comments on commit 4519c2b

Please sign in to comment.