Skip to content

Commit b19cd40

Browse files
committed
[LibGen] Add file as input feature cause cmd line is too long sometimes
Mostly AI generated, of course
1 parent 81a8cc9 commit b19cd40

File tree

2 files changed

+59
-6
lines changed

2 files changed

+59
-6
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
@echo off
22
call "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
33
cl main.cpp /Felibgen.exe /Os /INCREMENTAL:NO /nologo
4+
echo done, check the libgen.exe

tools/libgen/main.cpp

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,32 +1526,84 @@ int main(int argc, char* argv[])
15261526
{
15271527
char *pName;
15281528
char *fileName;
1529+
char *fileNameWithFunctionNames;
15291530
SYMBOL_INFO *pSymbolList;
1531+
int argvOffset = 0;
1532+
bool useFile = false;
15301533

15311534
if (argc < 5) {
1532-
printf("Not enough arguments: 64/32 dllname filename.lib funcname1 funcname2 etc\n");
1535+
printf("Expected arguments: 64/32 dllname filename.lib funcname1 funcname2 etc\n");
1536+
printf("Alternatively: file 64/32 dllname filename.lib funcnames.txt\n");
15331537
fflush(0);
15341538
exit(123);
15351539
}
15361540

1541+
// `file`
1542+
if (argv[argvOffset + 1][0] == 'f') {
1543+
useFile = true;
1544+
argvOffset++;
1545+
}
1546+
15371547
g_InfoAll.bX64 = TRUE;
1538-
if (argv[1][0] == '3') {
1548+
// `32`
1549+
if (argv[argvOffset + 1][0] == '3') {
15391550
g_InfoAll.bX64 = FALSE;
15401551
}
15411552

1542-
pName = "long_dll_name_long_dll_name_long_dll_name";
1543-
pName = argv[2];
1544-
fileName = argv[3];
1553+
pName = argv[argvOffset + 2];
1554+
fileName = argv[argvOffset + 3];
15451555

15461556
pSymbolList = CreateSymbolList(pName);
15471557

1558+
if (useFile) {
1559+
fileNameWithFunctionNames = argv[argvOffset + 4];
1560+
1561+
FILE *file = fopen(fileNameWithFunctionNames, "r");
1562+
if (file == 0) {
1563+
printf("Failed to open file %s\n", fileNameWithFunctionNames);
1564+
fflush(0);
1565+
exit(2);
1566+
}
1567+
fseek(file, 0, SEEK_END);
1568+
int fileSize = ftell(file);
1569+
rewind(file);
1570+
1571+
char *pFileContents = new char[fileSize + 1];
1572+
fread(pFileContents, 1, fileSize, file);
1573+
fclose(file);
1574+
pFileContents[fileSize] = 0; // null-terminate
1575+
1576+
int i = 0;
1577+
while (pFileContents[i] != 0 && i < fileSize) {
1578+
char *pBegin = pFileContents + i;
1579+
// Both spaces and enters work
1580+
while (
1581+
pFileContents[i] != 0
1582+
&& pFileContents[i] != '\n'
1583+
&& pFileContents[i] != ' '
1584+
) {
1585+
i++;
1586+
}
1587+
int len = i - (pBegin - pFileContents);
1588+
if (len == 0) {
1589+
break;
1590+
}
1591+
char *pFuncName = new char[len + 1];
1592+
memcpy(pFuncName, pBegin, len);
1593+
pFuncName[len] = 0;
1594+
// printf("AddFunction from file: `%s`\n", pFuncName);
1595+
AddFunction(pSymbolList, pFuncName, 0, 0, CALLING_CONVENTION_UNDECORATED, IMPORT_BY_DECORATED_NAME);
1596+
i++;
1597+
}
1598+
} else {
15481599
int i = 4;
15491600
while (i < argc) {
1550-
AddFunction(pSymbolList, argv[i], 0, 0, CALLING_CONVENTION_UNDECORATED, IMPORT_BY_DECORATED_NAME);
1601+
AddFunction(pSymbolList, argv[argvOffset + i], 0, 0, CALLING_CONVENTION_UNDECORATED, IMPORT_BY_DECORATED_NAME);
15511602
// TODO add verbose mode
15521603
// printf("AddFunction %s\n", argv[i]);
15531604
i++;
15541605
}
1606+
}
15551607

15561608
fflush(0);
15571609
//AddFunction(pSymbolList, "function100", 0, 0, CALLING_CONVENTION_STDCALL, IMPORT_BY_DECORATED_NAME);

0 commit comments

Comments
 (0)