⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 stbconvert103 with source
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus, lh5;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Openstbfile1: TMenuItem;
    Exit1: TMenuItem;
    OpenDialog1: TOpenDialog;
    Openbinfile1: TMenuItem;
    N1: TMenuItem;
    Memo1: TMemo;
    Help1: TMenuItem;
    About1: TMenuItem;
    Edit1: TMenuItem;
    ChangeNDFChannellist1: TMenuItem;
    procedure Exit1Click(Sender: TObject);
    procedure Openbinfile;
    procedure Openstbfile1Click(Sender: TObject);
    procedure Openbinfile1Click(Sender: TObject);
    procedure About1Click(Sender: TObject);
    procedure ChangeNDFChannellist1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  apsize: dword;
implementation

uses Unit2, Unit3;

{$R *.dfm}

procedure TForm1.Exit1Click(Sender: TObject);
begin
close;
end;

function HexToStr(HexValue:integer): string;
var
s: string;
i: integer;
begin
 s:='';
 while HexValue>0 do begin
   i:=HexValue mod 16;
   if i<10 then s:=Chr(i+48)+s else s:=Chr(i+55)+s;
   HexValue:=HexValue div 16;
 end;
 while Length(s)<2 do s:='0'+s;
 Result:=s;
end;

procedure TForm1.Openstbfile1Click(Sender: TObject);
var
p, p2: ^byte;
F, F2: File;
S: byte;
i, n: integer;
tmp, size, header: longword;
tmp2: word;
begin
opendialog1.FileName:='*.stb';
if opendialog1.Execute then
begin
memo1.lines.clear;
screen.cursor:=crhourglass;
AssignFile(F, opendialog1.filename);
reset(f,1);
blockread (f,tmp,4);
if tmp<>$425453 then begin showmessage('Error, wrong file!'); closefile(f); exit; end;
memo1.Lines.Add(hextostr(lo(tmp))+' '+hextostr(hi(tmp))+' '+hextostr(lo(tmp div $10000))+' '+hextostr(hi(tmp div $10000))+' : STB');

blockread (f,tmp,4);
header:=tmp;
if (header<$28) or (header>$40) then begin showmessage('Error, wrong file type!'); closefile(f); exit; end;
memo1.Lines.Add(hextostr(lo(tmp))+' '+hextostr(hi(tmp))+' '+hextostr(lo(tmp div $10000))+' '+hextostr(hi(tmp div $10000))+' : Header length '+inttostr(header)+' bytes');

blockread (f,tmp,4);
memo1.Lines.Add(hextostr(lo(tmp))+' '+hextostr(hi(tmp))+' '+hextostr(lo(tmp div $10000))+' '+hextostr(hi(tmp div $10000))+' : ?');

blockread (f,tmp,4);
memo1.Lines.Add(hextostr(lo(tmp))+' '+hextostr(hi(tmp))+' '+hextostr(lo(tmp div $10000))+' '+hextostr(hi(tmp div $10000))+' : ?');

blockread(f,tmp2,2);
memo1.Lines.Add(hextostr(lo(tmp2))+' '+hextostr(hi(tmp2))+' : HW type');

blockread(f,tmp2,2);
memo1.Lines.Add(hextostr(lo(tmp2))+' '+hextostr(hi(tmp2))+' : HW version');

blockread(f,tmp2,2);
memo1.Lines.Add(hextostr(lo(tmp2))+' '+hextostr(hi(tmp2))+' : Boot version');

blockread(f,tmp2,2);
memo1.Lines.Add(hextostr(lo(tmp2))+' '+hextostr(hi(tmp2))+' : Firmware version');

blockread (f,tmp,4);
memo1.Lines.Add(hextostr(lo(tmp))+' '+hextostr(hi(tmp))+' '+hextostr(lo(tmp div $10000))+' '+hextostr(hi(tmp div $10000))+' : First is number of parts. Others ?');

blockread (f,tmp,4);
memo1.Lines.Add(hextostr(lo(tmp))+' '+hextostr(hi(tmp))+' '+hextostr(lo(tmp div $10000))+' '+hextostr(hi(tmp div $10000))+' : Address where to write 1st part');

blockread (f,tmp,4);
memo1.Lines.Add(hextostr(lo(tmp))+' '+hextostr(hi(tmp))+' '+hextostr(lo(tmp div $10000))+' '+hextostr(hi(tmp div $10000))+' : Where to start');

blockread (f,tmp,4);
memo1.Lines.Add(hextostr(lo(tmp))+' '+hextostr(hi(tmp))+' '+hextostr(lo(tmp div $10000))+' '+hextostr(hi(tmp div $10000))+' : How many bytes');

if header>$28 then
begin
blockread (f,tmp,4);
memo1.Lines.Add(hextostr(lo(tmp))+' '+hextostr(hi(tmp))+' '+hextostr(lo(tmp div $10000))+' '+hextostr(hi(tmp div $10000))+' : Address where to write 2nd part');

blockread (f,tmp,4);
memo1.Lines.Add(hextostr(lo(tmp))+' '+hextostr(hi(tmp))+' '+hextostr(lo(tmp div $10000))+' '+hextostr(hi(tmp div $10000))+' : Where to start');

blockread (f,tmp,4);
memo1.Lines.Add(hextostr(lo(tmp))+' '+hextostr(hi(tmp))+' '+hextostr(lo(tmp div $10000))+' '+hextostr(hi(tmp div $10000))+' : How many bytes');
end;

if header>$34 then
begin
blockread (f,tmp,4);
memo1.Lines.Add(hextostr(lo(tmp))+' '+hextostr(hi(tmp))+' '+hextostr(lo(tmp div $10000))+' '+hextostr(hi(tmp div $10000))+' : Address where to write 3rd part');

blockread (f,tmp,4);
memo1.Lines.Add(hextostr(lo(tmp))+' '+hextostr(hi(tmp))+' '+hextostr(lo(tmp div $10000))+' '+hextostr(hi(tmp div $10000))+' : Where to start');

blockread (f,tmp,4);
memo1.Lines.Add(hextostr(lo(tmp))+' '+hextostr(hi(tmp))+' '+hextostr(lo(tmp div $10000))+' '+hextostr(hi(tmp div $10000))+' : How many bytes');
end;

{End of header, start of lha part}

memo1.lines.add('***************');

blockread(f,tmp2,2);
memo1.Lines.Add(hextostr(lo(tmp2))+' '+hextostr(hi(tmp2))+' : Lha header length and checksum');

blockread(f,tmp,4);
blockread(f,s,1);
memo1.Lines.Add(hextostr(lo(tmp))+' '+hextostr(hi(tmp))+' '+hextostr(lo(tmp div $10000))+' '+hextostr(hi(tmp div $10000))+' '+hextostr(s)+' : -lh5- Method ID');

blockread(f,tmp,4);
memo1.Lines.Add(hextostr(lo(tmp))+' '+hextostr(hi(tmp))+' '+hextostr(lo(tmp div $10000))+' '+hextostr(hi(tmp div $10000))+' : Byte count of compressed file');

blockread(f,tmp,4);
size:=tmp;
memo1.Lines.Add(hextostr(lo(tmp))+' '+hextostr(hi(tmp))+' '+hextostr(lo(tmp div $10000))+' '+hextostr(hi(tmp div $10000))+' : Byte count before compression');

blockread(f,tmp,4);
memo1.Lines.Add(hextostr(lo(tmp))+' '+hextostr(hi(tmp))+' '+hextostr(lo(tmp div $10000))+' '+hextostr(hi(tmp div $10000))+' : Last modified time / date');

blockread(f,tmp2,2);
memo1.Lines.Add(hextostr(lo(tmp2))+' '+hextostr(hi(tmp2))+' : Normal file msdos and header level 1');

blockread(f,s,1);
memo1.Lines.Add(hextostr(s)+' : Length of file name, (0 bytes)');

blockread(f,tmp2,2);
memo1.Lines.Add(hextostr(lo(tmp2))+' '+hextostr(hi(tmp2))+' : CRC16 before compression');

blockread(f,tmp2,2);
blockread(f,s,1);
memo1.Lines.Add(hextostr(lo(tmp2))+' '+hextostr(hi(tmp2))+' '+hextostr(s)+' : OS ID and next header size');

GetMem(p, 2000000); {value p, filesize(F) here sometimes causes access violation later, why???)}
GetMem(p2, size);
n:=0;
while not eof(f) do
begin
 n:=n+1;
 blockread(f,s,1);
 p^:=s;
 inc(p);
end;
closefile(f);
dec(p,n);
LH5Decompress(p, n, p2, size);
AssignFile(F2, copy(opendialog1.FileName,1, length(opendialog1.filename)-4)+'.bin');
rewrite(f2,1);
for i:=1 to size do
begin
 blockwrite(f2,p2^,1);
 inc(p2);
end;
closefile(f2);
freemem(p);
dec(p2,size);
freemem(p2);
showmessage('Done, '+ copy(opendialog1.FileName,1, length(opendialog1.filename)-4)+'.bin'+' created!');
screen.cursor:=crarrow;
end;
end;

procedure TForm1.Openbinfile1Click(Sender: TObject);
var f: file;
tmp: dword;
begin
opendialog1.FileName:='*.bin';
if opendialog1.Execute then
begin
form2.ComboBox1.ItemIndex:=-1;
form2.combobox1.Text:='SELECT MODEL';
form2.CheckBox1.Enabled:=false;
form2.CheckBox2.Enabled:=false;
form2.CheckBox1.Checked:=false;
form2.CheckBox2.Checked:=false;
AssignFile(F, opendialog1.filename);
reset(f,1);
if filesize(f)<16 then begin showmessage('Wrong file!'); exit; end;
seek(f,4);
blockread(f,apsize,4);
seek(f,12);
blockread(f,tmp,4);
closefile(f);
if tmp=$54584E43 then
begin
form2.Label1.Caption:='Chip: Conexant';
form2.CheckBox1.Enabled:=true;
form2.CheckBox2.Enabled:=true;
form2.CheckBox1.Checked:=true;
form2.CheckBox2.Checked:=true;
end
else form2.Label1.Caption:='Chip: STI5518';
form2.visible:=true;
end;
end;

procedure TForm1.Openbinfile;
CONST
  table: ARRAY[0..255] OF WORD =
 ($0000,$C0C1,$C181,$0140,$C301,$03C0,$0280,$C241,$C601,$06C0,$0780,
  $C741,$0500,$C5C1,$C481,$0440,$CC01,$0CC0,$0D80,$CD41,$0F00,$CFC1,
  $CE81,$0E40,$0A00,$CAC1,$CB81,$0B40,$C901,$09C0,$0880,$C841,$D801,
  $18C0,$1980,$D941,$1B00,$DBC1,$DA81,$1A40,$1E00,$DEC1,$DF81,$1F40,
  $DD01,$1DC0,$1C80,$DC41,$1400,$D4C1,$D581,$1540,$D701,$17C0,$1680,
  $D641,$D201,$12C0,$1380,$D341,$1100,$D1C1,$D081,$1040,$F001,$30C0,
  $3180,$F141,$3300,$F3C1,$F281,$3240,$3600,$F6C1,$F781,$3740,$F501,
  $35C0,$3480,$F441,$3C00,$FCC1,$FD81,$3D40,$FF01,$3FC0,$3E80,$FE41,
  $FA01,$3AC0,$3B80,$FB41,$3900,$F9C1,$F881,$3840,$2800,$E8C1,$E981,
  $2940,$EB01,$2BC0,$2A80,$EA41,$EE01,$2EC0,$2F80,$EF41,$2D00,$EDC1,
  $EC81,$2C40,$E401,$24C0,$2580,$E541,$2700,$E7C1,$E681,$2640,$2200,
  $E2C1,$E381,$2340,$E101,$21C0,$2080,$E041,$A001,$60C0,$6180,$A141,
  $6300,$A3C1,$A281,$6240,$6600,$A6C1,$A781,$6740,$A501,$65C0,$6480,
  $A441,$6C00,$ACC1,$AD81,$6D40,$AF01,$6FC0,$6E80,$AE41,$AA01,$6AC0,
  $6B80,$AB41,$6900,$A9C1,$A881,$6840,$7800,$B8C1,$B981,$7940,$BB01,
  $7BC0,$7A80,$BA41,$BE01,$7EC0,$7F80,$BF41,$7D00,$BDC1,$BC81,$7C40,
  $B401,$74C0,$7580,$B541,$7700,$B7C1,$B681,$7640,$7200,$B2C1,$B381,
  $7340,$B101,$71C0,$7080,$B041,$5000,$90C1,$9181,$5140,$9301,$53C0,
  $5280,$9241,$9601,$56C0,$5780,$9741,$5500,$95C1,$9481,$5440,$9C01,
  $5CC0,$5D80,$9D41,$5F00,$9FC1,$9E81,$5E40,$5A00,$9AC1,$9B81,$5B40,
  $9901,$59C0,$5880,$9841,$8801,$48C0,$4980,$8941,$4B00,$8BC1,$8A81,
  $4A40,$4E00,$8EC1,$8F81,$4F40,$8D01,$4DC0,$4C80,$8C41,$4400,$84C1,
  $8581,$4540,$8701,$47C0,$4680,$8641,$8201,$42C0,$4380,$8341,$4100,
  $81C1,$8081,$4040);

var
p, p2 : ^byte;
w1, w2, w3, w4: byte;
s: byte;
n, i, q, W, k: Integer;
F,F2: File;
calculate: dword;
chaddr, tmp, t: longword;
sw, hwtype, hwversion, bootversion, crcvalue: word;
headerlen, write1, write2, write3, Uncomp: longword;
 found: boolean;
begin
screen.cursor:=crhourglass;
if form2.combobox1.ItemIndex=0 then
begin
 {TM 1000D}
 hwtype:=$1108;
 hwversion:=$1201;
 bootversion:=$1002;
 write1:=$7F020000;
 write2:=$7F17FF90;
 write3:=$7F1E0000;
end;

if form2.combobox1.ItemIndex=1 then
begin
 {TM 1000CI}
 hwtype:=$1008;
 hwversion:=$1201;
 bootversion:=$1002;
 write1:=$7F020000;
 write2:=$7F17FF90;
 write3:=$7F1E0000;
end;

if form2.combobox1.ItemIndex=2 then
begin
 {TM 1600CI}
 hwtype:=$0408;
 hwversion:=$0001;
 bootversion:=$3001;
 write1:=$7FE00000;
 write2:=$7FF7FF90;
 write3:=$7FFC0000;
end;

if form2.combobox1.ItemIndex=3 then
begin
 {CT 1500}
 hwtype:=$1110;
 hwversion:=$1001;
 bootversion:=$1002;
 write1:=$7F020000;
 write2:=$7F17FF90;
 write3:=$7F1E0000;
end;

if form2.combobox1.ItemIndex=4 then
begin
 {CT 2000}
 hwtype:=$0410;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -