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

Fix SETLIST without active table #80

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 40 additions & 12 deletions luadec/decompile.c
Expand Up @@ -929,34 +929,38 @@ void AddToTable(Function* F, DecTable* tbl, const char* value, const char* key)
AddToList(list, (ListItem*)item);
}

void SetList(Function* F, int a, int b, int c) {
int i;
int SetList(Function* F, int a, int b, int c) {
int i = 1, j;
DecTable* tbl = (DecTable*)FindFromListTail(&(F->tables), (ListItemCmpFn)MatchTable, &a);
if (tbl == NULL) {
sprintf(errortmp, "No list found for R%d , SetList fails", a);
SET_ERROR(F, errortmp);
return;
UnsetPending(F, a);
}
if (b == 0) {
const char* rstr;
i = 1;
while (1) {
rstr = GetR(F, a + i);
if (error)
return;
return tbl ? 0 : i;
if (strcmp(rstr,".end") == 0)
break;
AddToTable(F, tbl, rstr, NULL); // Lua5.1 specific TODO: it's not really this :(
if (tbl) {
AddToTable(F, tbl, rstr, NULL); // Lua5.1 specific TODO: it's not really this :(
}
i++;
};
} //should be {...} or func(func()) ,when b == 0, that will use all avaliable reg from R(a)

for (i = 1; i <= b; i++) {
const char* rstr = GetR(F, a + i);
for (j = 1; j <= b; j++) {
const char* rstr = GetR(F, a + j);
if (error)
return;
AddToTable(F, tbl, rstr, NULL); // Lua5.1 specific TODO: it's not really this :(
return tbl ? 0 : i + j - 2;
if (tbl) {
AddToTable(F, tbl, rstr, NULL); // Lua5.1 specific TODO: it's not really this :(
}
}

return tbl ? 0 : i + j - 2;
}

void UnsetPending(Function* F, int r) {
Expand Down Expand Up @@ -3026,7 +3030,31 @@ char* ProcessCode(Proto* f, int indent, int func_checking, char* funcnumstr) {
}
#endif
}
TRY(SetList(F, a, b, c));

const char *astr;
const char *cstr;
int setlist;
/*
* first try to add into a list
*/
TRY(setlist = SetList(F, a, b, c));
if (setlist) {
/*
* if failed, just output an assignment
*/
for (int i = setlist; i >= 1; i--) {
TRY(astr = GetR(F, a));
if (isIdentifier(astr)) {
StringBuffer_set(str, astr);
} else {
StringBuffer_printf(str, "(%s)", astr);
}
StringBuffer_addPrintf(str, "[%d]", (c-1)*50+i); // todo: s/50/LFS_SIZE or w/e
PENDING(a+i) = 1;
TRY(cstr = GetR(F, a+i));
TRY(AssignGlobalOrUpvalue(F, StringBuffer_getRef(str), cstr));
}
}
break;
}
#if LUA_VERSION_NUM == 501
Expand Down