BC/NW 2022 1 (39):8.1
( )
.., .., ..
. - , , , . . . , , .
, , , .
, , . . , , , , , . , , , - . .
, . , , , .
.
, , , .
, , . , , , . , .
.
- :
1. ( ).
2. () , , ( ).
3. .
4. C++.
5. .
6. , , .
7. .
, , Assembler MS-DOS. . , .
MS-DOS , x86 , , , MS-DOS.
(). , IDA PRO 7.5 SP3, :
IDA Pro , MS DOS EXE File [6],
IDA Pro [6]
[6]
, . :
, , .
, FAR manager [8].
FAR Manager Microsoft Windows Linux. , F3 F4[8].
1
1.1
assembler.
, , 20 ***.txt 20 ***.txt. , .
, i i mod key_length , .
, , , .
1
:
namefld_in =aaa.txt
namefld_out =abb.txt
aaa.txt
abc
abb.txt
2.3
1.1.1 ( , , )
, assembler 1.1
1.1. .
|
|
|
requst_in_file |
db |
. |
requst_out_file |
db |
. |
err_in_file_m |
db |
. |
err_out_file_m |
db |
. |
err_key_m |
db |
. |
mess_done |
db |
. |
new_str |
db |
. |
buff |
db |
. |
handle_in |
dw |
|
handle_out |
dw |
|
key_len |
dw |
|
count |
dw |
. |
, 1.2
1.2. , .
INITSRD |
DS ES. |
input_kbd |
. |
read |
. |
write |
. |
init |
. |
err_in_file |
. |
err_out_file |
. |
coding |
. |
exit |
. |
1.1.2 assembler
, 1.1.
( 1 .1.1) , .
(, 2 1.1), , , , , , , , , . 1.3.
. ( 5 1.1)
, , , , MS-DOS return 0 C++.
1.1:
.1.1 assembler
1.3.
|
|
|
1 |
20 |
error: cannot open sourse file |
2 |
20 |
error: cannot open out file |
3 |
|
|
1.1.3 DOS
:
09H INT 21H
AH = 09H
DS:DX = , '$' (ASCII 24H)
:
0ah 21h.
AH = 0aH
DS:DX = ( )
= , CR (ASCII 0dH)
:
3dH INT 21H
AH = 3dH
DS:DX = ASCIIZ
AL =
AX = CF .
DS:DX ASCIIZ : "d:\\",0. / , .
.
/ :
o AL = 0
o AL = 1
o AL = 2
:
3 INT 21
AH = 3cH
DS:DX = ASCIIZ
CX =
AX = CF
DS:DX ASCIIZ : "d:\\",0. / , .
( )
/
(handle)
:
,
:
3F INT 21
AH = 3fH
BX =
DS:DX =
CX =
AX = CF
CX , BX. / , DS:DX.
:
40 INT 21
AH = 40H
BX =
DS:DX = ,
CX =
AX = CF
AL = ( )
CX , BX. , DS:DX. , / .
:
3Eh INT 21h
AH = 3eH
BX =
AX = CF
BX (handle), . , , , , , .
1.1.4
, . , .
sourse file is :
,
error: cannot open sourse file
, . .
out file is :
, , .
error: cannot open out file
, .
done.
.
, ( 1.2)
.1.2
1.1.5
.exe .
DOSBox DOS, TASM
Turbo Assembler(TASM) DOS ( ).
DOSBox , .asm
//
, .
Tasm _
Tlink _
.exe DOSBox _.exe
1.2.
FAR ,
. 1.3 FAR
. 1.3 200 33C 37D 3E4.
, IDA, , .
Hex View-1, alt+3 windows , :
. 1.4 IDA Pro
1.4 , 5.1 200 410 1000:0000 1000:0145 , 1015:002E 1015:00A5
IDA view-A Hex View-1, , :
B4 09 mov ah,9 .
Mov dx,3Ch BA 3C 00 , .
.
mov ah, 3Ch mov ah,9
B4 3C B4 09
, , ah. , B4 - , .
, ,
mov dx, 38h mov dx, 16h
BA 38 00 BA 16 00
, BA dx
mov ah,9
Ÿ hex B4 09
1011 0100 0000 1001
, . mod r/m.[7] (. 5.3)
1.5
(. 1.5).
. 1.4 [7]
w=0 , 0 8 ( 1.4)
Reg = 100 w=0 AH ( 1.5 1.6)
.1.5 reg( w )[7]
. 1.6 reg( w )[7]
, :
10011 | 0 | 100 | 0000 1001
Ϡ | w | reg | (. 5.2)
-
A3 A4 01 B4 3C B9 00 00 BA 18 00 CD 21 73 03
:
mov word_102E4, ax
mov ah, 3Ch
mov cx, 0
mov dx, 18h
int 21h
jnb short loc_1007
1.7
. 1.7
|
|
mov word_102E4, ax |
A3 A4 01 |
mov ah, 3Ch |
B4 3C |
mov cx, 0 |
B9 00 00 |
mov dx, 18h |
BA 18 00 |
int 21h |
CD 21 |
jnb short loc_10073 |
73 03 |
2 , ++
2.1
IDA PRO
( 2.1), : , , .
. 2.1 IDA
new .exe . IDA 1( 2.2), start 2( 2.2), , . 1 .
.2.2 IDA PRO
, , , 3( 2.2), 2 , . , , .
2.3
, :
1.
2.
.2.3 IDA Pro
start , :
1. 2 .
2. jnb .
, 2 , (If else)
, 1010 (. 2.4), 10118 (. 2.5) ( call - ) start , , .
.2.4 1010
.2.5 10118
, DOS 21h ah 9, , dx ( 1.1.4).
, , 2
, : error: cannot open source file$ error: cannot open out file$, .
10118+3, $
10122
10122 , ( 2.6) , 2 , , 10118h 1010Eh, , , (dsegment) , dx, .
.2.6
2 - ( 2.7)
( if) - ,
.2.7
10090h ( 2.8)
.2.8
, - cx .
, di, 2Eh ( 2.8))
.2.9
( 2.9) key is flag , flag
, ( 2.10) ( 2.9) .
.2.10
, :
- ( )
-
-
-
.
2.2. ++
2.2.1
, , ***.txt ***.txt. , .
, i i mod key_length ,
2.2.2
2.
2.1
|
|
|
|
|
|
|
fin_name |
|
Char* |
|
|
fout_name |
|
Char* |
|
|
|
|
key_length |
|
int |
|
|
key |
|
Char* |
|
|
|
key_str |
|
string |
|
|
|
fout
|
|
ifstream |
|
|
|
fin
|
|
ofstream |
|
|
4 ,
2.2
|
|
|
void err_in_proc |
|
( ) |
void err_out_proc |
|
( ) |
void code_proc |
|
|
void end_proc |
|
|
2.2.3
, 2.10.
( 1 .2.10) , . , .
(, 2 2.10), , , , , , . 1.3.
. ( 5 2.10)
, , , , MS-DOS return 0 C++.
:
.2.10
2.2.4
, . , .
sourse file is :
,
error: cannot open sourse file
, . .
out file is :
, , .
error: cannot open out file
, .
done
.
, ( 2.10)
.2.11
2.3
2.3
|
|
Assembler |
C++ |
1 |
11111111111 1 1 1 1 |
bbbbbbbbbbb>;b>;b>;b>;b |
bbbbbbbbbbb>;b>;b>;b>;b>; |
2 |
abc |
|
-s |
3 |
11111111111 1 1 1 1 |
QQxo-s-pnq |
QQxo-s-pnqr |
4 |
i hate everything about you |
@@ |
@@ހ* |
11111111111 .
, assembler 10 Win1251( 2.12) 13.
.2.12 win-1251
, . \n 10 13 \r .
1 49 1- 49 49+49=98 b
++ , . , , .
a+k=̠ 97+107=204
b+e=Ǡ 98+101=199
c+y =ܠ 99+121=220
3 2.3 , key is flag
2.4
, , .
, . , .
. ++ , . 3.
2.4
|
|
|
++ |
1 |
bbbbbbbbbbb>;b>;b>;b>;b>; |
11111111111 1 1 1 1 |
11111111111 1 1 1 1 |
2 |
bbbbbbbbbbb>;b>;b>;b>;b |
11111111111 1 1 1 1 |
11111111111 1 1 1 1 |
3 |
ԅ@@߅ |
i hate everything about you |
i hate everything about you |
- , , .
, ++.
, . , . ++ .
. . , .
, , , .
1. . . : . : , 2013. 56 .
2. - : : URL: https://habr.com/ru/post/220245/ ( : 04.03.2022). : . : .
4. VisualStudio: URL: https://m-i-kuznetsov.livejournal.com/152857.html ( : 04.03.2022). : . : .
5. .., .., . O. . , 681.3.06
6. IDA PRO https://hex-rays.com/ida-pro/ ( : 21.05.2022) : . : .
7. . . Assembler. . 2- . .: , 2003. 637 .: . ISBN 5-94723-581-1
8. Far Manager https://www.farmanager.com/index.php?l=ru ( : 20.06.2022) : . : .