-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.cpp
102 lines (86 loc) · 3.35 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Free Disassembler and Assembler -- Demo program
//
// Copyright (C) 2001 Oleh Yuschuk
//
// 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 2 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, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#define STRICT
#define MAINPROG // Place all unique variables here
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#pragma hdrstop
#include "disasm.h"
void main(void) { // Old form. So what?
int i,j,n;
ulong l;
char *pasm;
t_disasm da;
t_asmmodel am;
char s[TEXTLEN],errtext[TEXTLEN];
// Demonstration of Disassembler.
printf("Disassembler:\n");
// Quickly determine size of command.
l=Disasm("\x81\x05\xE0\x5A\x47\x00\x01\x00\x00\x00\x11\x22\x33\x44\x55\x66",
10,0x400000,&da,DISASM_SIZE);
printf("Size of command = %i bytes\n",l);
// ADD [475AE0],1 MASM mode, lowercase, don't show default segment
ideal=0; lowercase=1; putdefseg=1;
l=Disasm("\x33\x44\x55\x66",
6,0x400000,&da,DISASM_CODE);
printf("%3i %-24s %-24s (MASM)\n",l,da.dump,da.result);
// ADD [475AE0],1 IDEAL mode, uppercase, show default segment
ideal=1; lowercase=0; putdefseg=1;
l=Disasm("\x81\x05\xE0\x5A\x47\x00\x01\x00\x00\x00",
10,0x400000,&da,DISASM_CODE);
printf("%3i %-24s %-24s (IDEAL)\n",l,da.dump,da.result);
// CALL 45187C
l=Disasm("\xE8\x1F\x14\x00\x00",
5,0x450458,&da,DISASM_CODE);
printf("%3i %-24s %-24s jmpconst=%08X\n",l,da.dump,da.result,da.jmpconst);
// JNZ 450517
l=Disasm("\x75\x72",
2,0x4504A3,&da,DISASM_CODE);
printf("%3i %-24s %-24s jmpconst=%08X\n",l,da.dump,da.result,da.jmpconst);
// Demonstration of Assembler.
printf("\nAssembler:\n");
// Assemble one of the commands above. First try form with 32-bit immediate.
pasm="ADD [DWORD 475AE0],1";
printf("%s:\n",pasm);
j=Assemble(pasm,0x400000,&am,0,0,errtext);
n=sprintf_s(s,"%3i ",j);
for (i=0; i<j; i++) n+= sprintf(s+n, "%02X ",am.code[i]);
if (j<=0) sprintf(s+n, " error=\"%s\"",errtext);
printf("%s\n",s);
// Then variant with 8-bit immediate constant.
j=Assemble(pasm,0x400000,&am,0,2,errtext);
n= sprintf_s(s,"%3i ",j);
for (i=0; i<j; i++) n+= sprintf(s+n, "%02X ",am.code[i]);
if (j<=0) sprintf(s+n, " error=\"%s\"",errtext);
printf("%s\n",s);
// Error, unable to determine size of operands.
pasm="MOV [475AE0],1";
printf("%s:\n",pasm);
j=Assemble(pasm,0x400000,&am,0,4,errtext);
n= sprintf_s(s,"%3i ",j);
for (i=0; i<j; i++) n+= sprintf(s+n, "%02X ",am.code[i]);
if (j<=0) sprintf(s+n, " error=\"%s\"",errtext);
printf("%s\n",s);
// Show results.
//Sleep(10000);
system( "pause" );
};