Skip to content

Commit

Permalink
autoadd includes, kill entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
notaz committed Jan 31, 2014
1 parent 74cea04 commit 1402b79
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions plugin/saveasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static const char *reserved_names[] = {
"type",
"offset",
"aam",
"text",
};

static int is_name_reserved(const char *name)
Expand Down Expand Up @@ -375,6 +376,14 @@ static void idaapi run(int /*arg*/)
memcpy(p, ".xmm", 4);
fout_line++;
qfprintf(fout, "%s\n", buf);
continue;
}
p = strstr(buf, ".model");
if (p != NULL) {
qstrncpy(p, "include imports.inc", sizeof(buf) - (p - buf));
fout_line++;
qfprintf(fout, "\n%s\n", buf);
continue;
}
}
pl.lnnum = i;
Expand Down Expand Up @@ -452,20 +461,24 @@ static void idaapi run(int /*arg*/)
for (i = pl.lnnum; i < n; i++) {
do_def_line(buf, sizeof(buf), ln.down());

char *fw;
for (fw = buf; *fw != 0 && *fw == ' '; )
fw++;

// patches..
if (drop_large) {
p = strstr(buf, "large ");
p = strstr(fw, "large ");
if (p != NULL)
memmove(p, p + 6, strlen(p + 6) + 1);
}
while (drop_rva) {
p = strstr(buf, " rva ");
p = strstr(fw, " rva ");
if (p == NULL)
break;
memmove(p, p + 4, strlen(p + 4) + 1);
}
if (set_scale) {
p = strchr(buf, '[');
p = strchr(fw, '[');
if (p != NULL)
p = strchr(p, '+');
if (p != NULL && p[1] == 'e') {
Expand All @@ -477,7 +490,7 @@ static void idaapi run(int /*arg*/)
}
}
else if (jmp_near) {
p = strchr(buf, 'j');
p = strchr(fw, 'j');
while (p && *p != ' ')
p++;
while (p && *p == ' ')
Expand All @@ -488,32 +501,40 @@ static void idaapi run(int /*arg*/)
}
}
if (word_imm) {
p = strstr(buf, ", ");
p = strstr(fw, ", ");
if (p != NULL && '0' <= p[2] && p[2] <= '9') {
p += 2;
memmove(p + 9, p, strlen(p) + 1);
memcpy(p, "word ptr ", 9);
}
}
else if (dword_imm) {
p = strstr(buf, ", ");
p = strstr(fw, ", ");
if (p != NULL && '0' <= p[2] && p[2] <= '9') {
p += 2;
memmove(p + 10, p, strlen(p) + 1);
memcpy(p, "dword ptr ", 10);
}
}
else if (do_pushf) {
p = strstr(buf, "pushf");
p = strstr(fw, "pushf");
if (p == NULL)
p = strstr(buf, "popf");
p = strstr(fw, "popf");
if (p != NULL) {
p = strchr(p, 'f') + 1;
memmove(p + 1, p, strlen(p) + 1);
*p = 'd';
}
}

if (fw[0] == 'e' && IS_START(fw, "end") && fw[3] == ' ') {
fout_line++;
qfprintf(fout, "include public.inc\n\n");

// kill entry point
fw[3] = 0;
}

fout_line++;
qfprintf(fout, "%s\n", buf);
}
Expand Down

0 comments on commit 1402b79

Please sign in to comment.