Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] lower upper search #29

Open
wants to merge 3 commits into
base: stable
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 93 additions & 26 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,37 +224,58 @@ int argmain(int argc, char **argv)

if (!strcmp(argv[0], "ssearch"))
{
if (argc != 3)
if (argc != 3 && argc != 4)
goto help;

u8 u8query = 0;
u16 u16query = 0;
u32 u32query = 0;
u64 u64query = 0;
u8 u8LowQuery = 0;
u16 u16LowQuery = 0;
u32 u32LowQuery = 0;
u64 u64LowQuery = 0;

u8 u8UppQuery = 0;
u16 u16UppQuery = 0;
u32 u32UppQuery = 0;
u64 u64UppQuery = 0;

if (!strcmp(argv[1], "u8"))
{
search = VAL_U8;
u8query = strtoul(argv[2], NULL, 10);
u8LowQuery = strtoul(argv[2], NULL, 10);
}
else if (!strcmp(argv[1], "u16"))
{
search = VAL_U16;
u16query = strtoul(argv[2], NULL, 10);
u16LowQuery = strtoul(argv[2], NULL, 10);
}
else if (!strcmp(argv[1], "u32"))
{
search = VAL_U32;
u32query = strtoul(argv[2], NULL, 10);
u32LowQuery = strtoul(argv[2], NULL, 10);
}
else if (!strcmp(argv[1], "u64"))
{
search = VAL_U64;
u64query = strtoull(argv[2], NULL, 10);
u64LowQuery = strtoull(argv[2], NULL, 10);
}
else
goto help;

if (argc == 4) {
if (search == VAL_U8)
{
u8UppQuery = strtoul(argv[3], NULL, 10);
} else if (search == VAL_U16)
{
u16UppQuery = strtoul(argv[3], NULL, 10);
} else if (search == VAL_U32)
{
u32UppQuery = strtoul(argv[3], NULL, 10);
} else if (search == VAL_U64)
{
u64UppQuery = strtoull(argv[3], NULL, 10);
}
}

MemoryInfo meminfo;
memset(&meminfo, 0, sizeof(MemoryInfo));

Expand Down Expand Up @@ -286,7 +307,12 @@ int argmain(int argc, char **argv)
u8 *u8buf = (u8 *)outbuf;
for (u64 i = 0; i < chunksize / sizeof(u8); i++)
{
if (u8buf[i] == u8query && searchSize < SEARCH_ARR_SIZE)
if (searchSize >= SEARCH_ARR_SIZE)
{
break;
}

if (u8buf[i] == u8LowQuery || (argc == 4 && (u8buf[i] >= u8LowQuery && u8buf[i] <= u8UppQuery)))
{
printf("Got a hit at %lx!\r\n", curaddr + i * sizeof(u8));
searchArr[searchSize++] = curaddr + i * sizeof(u8);
Expand All @@ -299,7 +325,12 @@ int argmain(int argc, char **argv)
u16 *u16buf = (u16 *)outbuf;
for (u64 i = 0; i < chunksize / sizeof(u16); i++)
{
if (u16buf[i] == u16query && searchSize < SEARCH_ARR_SIZE)
if (searchSize >= SEARCH_ARR_SIZE)
{
break;
}

if (u16buf[i] == u16LowQuery || (argc == 4 && (u16buf[i] >= u16LowQuery && u16buf[i] <= u16UppQuery)))
{
printf("Got a hit at %lx!\r\n", curaddr + i * sizeof(u16));
searchArr[searchSize++] = curaddr + i * sizeof(u16);
Expand All @@ -312,7 +343,12 @@ int argmain(int argc, char **argv)
u32 *u32buf = (u32 *)outbuf;
for (u64 i = 0; i < chunksize / sizeof(u32); i++)
{
if (u32buf[i] == u32query && searchSize < SEARCH_ARR_SIZE)
if (searchSize >= SEARCH_ARR_SIZE)
{
break;
}

if (u32buf[i] == u32LowQuery || (argc == 4 && (u32buf[i] >= u32LowQuery && u32buf[i] <= u32UppQuery)))
{
printf("Got a hit at %lx!\r\n", curaddr + i * sizeof(u32));
searchArr[searchSize++] = curaddr + i * sizeof(u32);
Expand All @@ -325,7 +361,12 @@ int argmain(int argc, char **argv)
u64 *u64buf = (u64 *)outbuf;
for (u64 i = 0; i < chunksize / sizeof(u64); i++)
{
if (u64buf[i] == u64query && searchSize < SEARCH_ARR_SIZE)
if (searchSize >= SEARCH_ARR_SIZE)
{
break;
}

if (u64buf[i] == u64LowQuery || (argc == 4 && (u64buf[i] >= u64LowQuery && u64buf[i] <= u64UppQuery)))
{
printf("Got a hit at %lx!\r\n", curaddr + i * sizeof(u64));
searchArr[searchSize++] = curaddr + i * sizeof(u32);
Expand All @@ -348,34 +389,60 @@ int argmain(int argc, char **argv)

if (!strcmp(argv[0], "csearch"))
{
if (argc != 2)
if (argc != 2 && argc != 3)
goto help;

if (search == VAL_NONE)
{
printf("You need to start a search first!");
return 0;
}

u8 u8NewVal = 0;
u16 u16NewVal = 0;
u32 u32NewVal = 0;
u64 u64NewVal = 0;
u8 u8NewLowVal = 0;
u16 u16NewLowVal = 0;
u32 u32NewLowVal = 0;
u64 u64NewLowVal = 0;

u8 u8NewUppVal = 0;
u16 u16NewUppVal = 0;
u32 u32NewUppVal = 0;
u64 u64NewUppVal = 0;

if (search == VAL_U8)
{
u8NewVal = strtoul(argv[1], NULL, 10);
u8NewLowVal = strtoul(argv[1], NULL, 10);
}
else if (search == VAL_U16)
{
u16NewVal = strtoul(argv[1], NULL, 10);
u16NewLowVal = strtoul(argv[1], NULL, 10);
}
else if (search == VAL_U32)
{
u32NewVal = strtoul(argv[1], NULL, 10);
u32NewLowVal = strtoul(argv[1], NULL, 10);
}
else if (search == VAL_U64)
{
u64NewVal = strtoull(argv[1], NULL, 10);
u64NewLowVal = strtoull(argv[1], NULL, 10);
}

if (argc == 3)
{
if (search == VAL_U8)
{
u8NewUppVal = strtoul(argv[2], NULL, 10);
}
else if (search == VAL_U16)
{
u16NewUppVal = strtoul(argv[2], NULL, 10);
}
else if (search == VAL_U32)
{
u32NewUppVal = strtoul(argv[2], NULL, 10);
}
else if (search == VAL_U64)
{
u64NewUppVal = strtoull(argv[2], NULL, 10);
}
}

u64 newSearchSize = 0;
Expand All @@ -385,7 +452,7 @@ int argmain(int argc, char **argv)
{
u8 val;
svcReadDebugProcessMemory(&val, debughandle, searchArr[i], sizeof(u8));
if (val == u8NewVal)
if (val == u8NewLowVal || (argc == 3 && (val >= u8NewLowVal && val <= u8NewUppVal)))
{
printf("Got a hit at %lx!\r\n", searchArr[i]);
searchArr[newSearchSize++] = searchArr[i];
Expand All @@ -395,7 +462,7 @@ int argmain(int argc, char **argv)
{
u16 val;
svcReadDebugProcessMemory(&val, debughandle, searchArr[i], sizeof(u16));
if (val == u16NewVal)
if (val == u16NewLowVal || (argc == 3 && (val >= u16NewLowVal && val <= u16NewUppVal)))
{
printf("Got a hit at %lx!\r\n", searchArr[i]);
searchArr[newSearchSize++] = searchArr[i];
Expand All @@ -405,7 +472,7 @@ int argmain(int argc, char **argv)
{
u32 val;
svcReadDebugProcessMemory(&val, debughandle, searchArr[i], sizeof(u32));
if (val == u32NewVal)
if (val == u32NewLowVal || (argc == 3 && (val >= u32NewLowVal && val <= u32NewUppVal)))
{
printf("Got a hit at %lx!\r\n", searchArr[i]);
searchArr[newSearchSize++] = searchArr[i];
Expand All @@ -415,7 +482,7 @@ int argmain(int argc, char **argv)
{
u64 val;
svcReadDebugProcessMemory(&val, debughandle, searchArr[i], sizeof(u64));
if (val == u64NewVal)
if (val == u64NewLowVal || (argc == 3 && (val >= u64NewLowVal && val <= u64NewUppVal)))
{
printf("Got a hit at %lx!\r\n", searchArr[i]);
searchArr[newSearchSize++] = searchArr[i];
Expand Down