Created
November 7, 2017 21:36
-
-
Save osvein/317bae38afde36065e295f846f03b4e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* pas - papyrus assembler | |
| * Copyright (C) 2017 Oskar Sveinsen | |
| * | |
| * This program is free software: you can redistribute it and/or modify | |
| * it under the terms of the GNU General Public License as published by | |
| * the Free Software Foundation, either version 3 of the License, or | |
| * (at your option) any later version. | |
| * | |
| * This program is distributed in the hope that it will be useful, | |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| * GNU General Public License for more details. | |
| * | |
| * You should have received a copy of the GNU General Public License | |
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| */ | |
| #include <stdint.h> | |
| #include <stdio.h> | |
| #include "pas.h" | |
| char **strings; | |
| int | |
| disassemble(FILE *in, FILE *out) | |
| { | |
| int i; | |
| uint64_t buf8; | |
| uint32_t buf4; | |
| uint16_t buf2; | |
| /* header */ | |
| fread(&buf4, 4, 1, in); | |
| if (buf4 != PEX_SIGNATURE) | |
| return 0; | |
| fread(&buf2, 2, 1, in); | |
| if (!PEX_IS_VERSION_SUPPORTED(buf2)) | |
| return 0; | |
| getc(in); | |
| getc(in); | |
| /* info */ | |
| fputs(".info\n\t.compileTime ", out); | |
| fread(&buf8, 8, 1, in); | |
| fprintf(out, "%lu\n\t.source \"", buf8); | |
| fread(&buf2, 2, 1, in); | |
| for (i = 0; i < buf2; i++) | |
| fputc(out, getc(in)); | |
| fputs("\"\n\t.user \"", out); | |
| fread(&buf2, 2, 1, in); | |
| for (i = 0; i < buf2; i++) | |
| fputc(out, getc(in)); | |
| fputs("\"\n\t.computer \"", out); | |
| fread(&buf2, 2, 1, in); | |
| for (i = 0; i < buf2; i++) | |
| fputc(out, getc(in)); | |
| fputs("\"\n.endInfo\n", out); | |
| /* strings */ | |
| fread(&buf2, 2, 1, in); | |
| strings = malloc(buf2); | |
| for (i = 0; i < buf2; i++) { | |
| uint16_t len; | |
| fread(&len, 2, 1, in); | |
| strings[i] = malloc(len + 1); | |
| fread(strings[i], 1, len, in); | |
| strings[i][len + 1] = '\0'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment