This shows you the differences between two versions of the page.
sample_code:hexview [2015/07/13 00:58] stevegarman created |
sample_code:hexview [2015/07/30 05:17] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== File Hex Viewer ====== | ||
- | ===== Sample code ===== | ||
- | <code JavaScript hexView.js> | ||
- | // | ||
- | function OnStart() | ||
- | { | ||
- | |||
- | var path="/ | ||
- | // | ||
- | var lay = app.CreateLayout( " | ||
- | var scroll = app.CreateScroller( 1.0, | ||
- | lay.AddChild( scroll ); | ||
- | |||
- | // | ||
- | var layScroll = app.CreateLayout( " | ||
- | scroll.AddChild( layScroll ); | ||
- | |||
- | var view=app.CreateWebView(1.5, | ||
- | layScroll.AddChild(view); | ||
- | |||
- | // | ||
- | app.AddLayout( lay ); | ||
- | hexView(path, | ||
- | } | ||
- | |||
- | |||
- | function hexView(fullPath, | ||
- | { | ||
- | var file = app.CreateFile( fullPath, | ||
- | var len = file.GetLength(); | ||
- | var bull="& | ||
- | var html="< | ||
- | var int, | ||
- | file.Seek( 0 ); | ||
- | app.ShowProgress(" | ||
- | var whole = file.ReadData( len," | ||
- | do | ||
- | { | ||
- | var data = whole.slice(0, | ||
- | whole=whole.slice(8); | ||
- | // | ||
- | if(data==undefined) break; | ||
- | len = data.length; | ||
- | hbuff=""; | ||
- | abuff="< | ||
- | var pos8="< | ||
- | (" | ||
- | pos.toString(16)).slice(-8).toUpperCase() + | ||
- | "</ | ||
- | for(var i=0; | ||
- | { | ||
- | int=data[i]; | ||
- | hex=(" | ||
- | asc=bull; | ||
- | if(int> | ||
- | asc=String.fromCharCode(int); | ||
- | hbuff+="< | ||
- | abuff+=asc; | ||
- | } | ||
- | abuff+="</ | ||
- | row="< | ||
- | html +=row+" | ||
- | pos+=len; | ||
- | } | ||
- | while(len > | ||
- | html+="</ | ||
- | app.HideProgress(); | ||
- | webView.LoadHtml(html); | ||
- | // | ||
- | file.Close(); | ||
- | } | ||
- | |||
- | |||
- | </ |