Sponsored Content
Top Forums UNIX for Advanced & Expert Users Another binary manipulation thread. Post 302854517 by DGPickett on Tuesday 17th of September 2013 03:23:35 PM
Old 09-17-2013
So, you can see shell is not a binary capable tool. Some bytes it can handle, but nulls, linefeeds, white space are problematic. But you can write trivial C to support it, like at tool that just does a tr of null to something else, trnull:
Code:
 
#include <stdio.h>
 
int main( int argc, char **argv ){
  int c ;
  if ( argc != 2 || strlen( argv[1] ) != 1 ){
    fputs(
"\n"
"Usage: trnull <byte_for_null>\n"
"\n"
"Translates null to <byte_for_null>, reading stdin and writing stdout.\n"
"\n", stderr );
    exit( 1 );
   }
  while ( EOF != ( c = getchar() )){
    if ( EOF == putchar( c ? c : argv[1][0] )){
      if ( ferror( stdout )){
        perror( "stdout" );
        exit( 2 );
       }
     }
   }
  if ( ferror( stdin )){
    perror( "stdin" );
    exit( 3 );
   }
 }
"mysrc/trnull.c" 31 lines, 541 characters 
$ mycc trnull
$ trnull
 
Usage: trnull <byte_for_null>
 
Translates null to <byte_for_null>, reading stdin and writing stdout.
 
$ all256|trnull '!'|od -bc
0000000   ! 001 002 003 004 005 006 007  \b  \t  \n 013  \f  \r 016 017
        041 001 002 003 004 005 006 007 010 011 012 013 014 015 016 017
0000020 020 021 022 023 024 025 026 027 030 031 032 033 034 035 036 037
        020 021 022 023 024 025 026 027 030 031 032 033 034 035 036 037
0000040       !   "   #   $   %   &   '   (   )   *   +   ,   -   .   /
        040 041 042 043 044 045 046 047 050 051 052 053 054 055 056 057
0000060   0   1   2   3   4   5   6   7   8   9   :   ;   <   =   >   ?
        060 061 062 063 064 065 066 067 070 071 072 073 074 075 076 077
0000100   @   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O
        100 101 102 103 104 105 106 107 110 111 112 113 114 115 116 117
0000120   P   Q   R   S   T   U   V   W   X   Y   Z   [   \   ]   ^   _
        120 121 122 123 124 125 126 127 130 131 132 133 134 135 136 137
0000140   `   a   b   c   d   e   f   g   h   i   j   k   l   m   n   o
        140 141 142 143 144 145 146 147 150 151 152 153 154 155 156 157
0000160   p   q   r   s   t   u   v   w   x   y   z   {   |   }   ~ 177
        160 161 162 163 164 165 166 167 170 171 172 173 174 175 176 177
0000200 200 201 202 203 204 205 206 207 210 211 212 213 214 215 216 217
        200 201 202 203 204 205 206 207 210 211 212 213 214 215 216 217
0000220 220 221 222 223 224 225 226 227 230 231 232 233 234 235 236 237
        220 221 222 223 224 225 226 227 230 231 232 233 234 235 236 237
0000240 240 241 242 243 244 245 246 247 250 251 252 253 254 255 256 257
        240 241 242 243 244 245 246 247 250 251 252 253 254 255 256 257
0000260 260 261 262 263 264 265 266 267 270 271 272 273 274 275 276 277
        260 261 262 263 264 265 266 267 270 271 272 273 274 275 276 277
0000300 300 301 302 303 304 305 306 307 310 311 312 313 314 315 316 317
        300 301 302 303 304 305 306 307 310 311 312 313 314 315 316 317
0000320 320 321 322 323 324 325 326 327 330 331 332 333 334 335 336 337
        320 321 322 323 324 325 326 327 330 331 332 333 334 335 336 337
0000340 340 341 342 343 344 345 346 347 350 351 352 353 354 355 356 357
        340 341 342 343 344 345 346 347 350 351 352 353 354 355 356 357
0000360 360 361 362 363 364 365 366 367 370 371 372 373 374 375 376 377
        360 361 362 363 364 365 366 367 370 371 372 373 374 375 376 377
0000400
$


Last edited by DGPickett; 09-17-2013 at 04:34 PM..
 

4 More Discussions You Might Find Interesting

1. Programming

How to cancel a thread safely from the initial thread?

how about asynchronous canceling? or with signal? if with signal whether it effects the process? my english so badly :( :( (1 Reply)
Discussion started by: alan.zhao
1 Replies

2. Shell Programming and Scripting

Convert binary file to csv and then back to the binary format

Hello *nix specialists, Im working for a non profit organisation in Germany to transport DSL over WLAN to people in areas without no DSL. We are using Linksys WRT 54 router with DD-WRT firmware There are at the moment over 180 router running but we have to change some settings next time. So my... (7 Replies)
Discussion started by: digidax
7 Replies

3. Shell Programming and Scripting

Another Building Block, Binary File Manipulation...

Apologies for any typos, and IF this has been done before... This is yet another building block. The code generates a 256 byte binary file of _characters_ 0x00 to 0xFF for general usage and generates another binary file manipulated in a basic way. I need this facility for a kids project I am... (0 Replies)
Discussion started by: wisecracker
0 Replies

4. Forum Support Area for Unregistered Users & Account Problems

Not able to post thread/reply to thread

Dear Moderator I am not able to post any new thread or post reply to mine old thread. Kindly help as i am stuck on one problem and needed suggestion. Regards Jaydeep (1 Reply)
Discussion started by: jaydeep_sadaria
1 Replies
iconv_koi8-r(5)                                         Standards, Environments, and Macros                                        iconv_koi8-r(5)

NAME
iconv_koi8-r - code set conversion tables for KOI8-R DESCRIPTION
The following code set conversions are supported: +-------------------------------------------------------------------------+ | Code Set Conversions Supported | +--------------+--------+--------------+--------+-------------------------+ | Code |Symbol |Target Code |Symbol | Target Output | +--------------+--------+--------------+--------+-------------------------+ |KOI8-R |koi8 |ISO 8859-5 |iso5 | ISO 8859-5 Cyrillic | +--------------+--------+--------------+--------+-------------------------+ |KOI8-R |koi8 |PC Cyrillic |alt | Alternative PC Cyrillic | +--------------+--------+--------------+--------+-------------------------+ |KOI8-R |koi8 |MS 1251 |win5 | Windows Cyrillic | +--------------+--------+--------------+--------+-------------------------+ |KOI8-R |koi8 |Mac Cyrillic |mac | Macintosh Cyrillic | +--------------+--------+--------------+--------+-------------------------+ CONVERSIONS
The conversions are performed according to the following tables. All values in the tables are given in octal. KOI8-R to ISO 8859-5 For the conversion of KOI8-R to ISO 8859-5, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | KOI8-R | ISO 8859-5 | KOI8-R | ISO 8859-5 | |24 | 4 |320 |337 | |241 | 362 |321 |357 | |242 | 363 |322 |340 | |243 | 361 |323 |341 | |244 | 364 |324 |342 | |245 | 365 |325 |343 | |246 | 366 |327 |322 | |247 | 367 |330 |354 | |250 | 370 |331 |353 | |251 | 371 |332 |327 | |252 | 372 |333 |350 | |253 | 373 |334 |355 | |254 | 374 |335 |351 | |256 | 376 |336 |347 | |257 | 377 |337 |352 | |260 | 360 |340 |316 | |261 | 242 |341 |260 | |262 | 243 |342 |261 | |263 | 241 |343 |306 | |264 | 244 |344 |264 | |265 | 245 |345 |265 | |266 | 246 |346 |304 | |267 | 247 |347 |263 | |270 | 250 |350 |305 | |271 | 251 |351 |270 | |272 | 252 |352 |271 | |273 | 253 |353 |272 | |274 | 254 |354 |273 | |275 | 255 |355 |274 | |276 | 256 |356 |275 | |277 | 257 |357 |276 | |300 | 356 |360 |277 | |301 | 320 |361 |317 | |302 | 321 |362 |300 | |303 | 346 |363 |301 | |304 | 324 |364 |302 | |305 | 325 |365 |303 | |306 | 344 |366 |266 | |307 | 323 |367 |262 | |310 | 345 |370 |314 | |311 | 330 |371 |313 | |312 | 331 |372 |267 | |313 | 332 |373 |310 | |314 | 333 |374 |315 | |315 | 334 |375 |311 | |316 | 335 |376 |307 | |317 | 336 | | | +---------------+----------------+----------------+---------------+ KOI8-R to PC Cyrillic For the conversion of KOI8-R to PC Cyrillic, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | KOI8-R | PC Cyrillic | KOI8-R | PC Cyrillic | |24 | 4 |333 |350 | |200-242 | 40 |334 |355 | |243 | 361 |335 |351 | |244-254 | 40 |336 |347 | |255 | 260 |337 |352 | |256-262 | 40 |340 |236 | |263 | 360 |341 |200 | |264-274 | 40 |342 |201 | |275 | 260 |343 |226 | |276-277 | 40 |344 |204 | |300 | 356 |345 |205 | |301 | 240 |346 |224 | |302 | 241 |347 |203 | |303 | 346 |350 |225 | |304 | 244 |351 |210 | |305 | 245 |352 |211 | |306 | 344 |353 |212 | |307 | 243 |354 |213 | |310 | 345 |355 |214 | |311 | 250 |356 |215 | |312 | 251 |357 |216 | |313 | 252 |360 |217 | |314 | 253 |361 |237 | |315 | 254 |362 |220 | |316 | 255 |363 |221 | |317 | 256 |364 |222 | |320 | 257 |365 |223 | |321 | 357 |366 |206 | |322 | 340 |367 |202 | |323 | 341 |370 |234 | |324 | 342 |371 |233 | |325 | 343 |372 |207 | |326 | 246 |373 |230 | |327 | 242 |374 |235 | |330 | 354 |375 |231 | |331 | 353 |376 |227 | |332 | 247 | | | +---------------+----------------+----------------+---------------+ KOI8-R to MS 1251 For the conversion of KOI8-R to MS 1251, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | KOI8-R | MS 1251 | KOI8-R | MS 1251 | |24 | 4 |317 |356 | |200-237 | 40 |320 |357 | |241 | 220 |321 |377 | |242 | 203 |322 |360 | |243 | 270 |323 |361 | |244 | 272 |324 |362 | |245 | 276 |325 |363 | |246 | 263 |326 |346 | |247 | 277 |327 |342 | |250 | 274 |330 |374 | |251 | 232 |331 |373 | |252 | 234 |332 |347 | |253 | 236 |333 |370 | |254 | 235 |334 |375 | |255 | 210 |335 |371 | |256 | 242 |336 |367 | |257 | 237 |337 |372 | |260 | 271 |340 |336 | |261 | 200 |341 |300 | |262 | 201 |342 |301 | |263 | 250 |343 |326 | |264 | 252 |344 |304 | |265 | 275 |345 |305 | |266 | 262 |346 |324 | |267 | 257 |347 |303 | |270 | 243 |350 |325 | |271 | 212 |351 |310 | |272 | 214 |352 |311 | |273 | 216 |353 |312 | |274 | 215 |354 |313 | |275 | 210 |355 |314 | |276 | 241 |356 |315 | |277 | 217 |357 |316 | |300 | 376 |360 |317 | |301 | 340 |361 |337 | |302 | 341 |362 |320 | |303 | 366 |363 |321 | |304 | 344 |364 |322 | |305 | 345 |365 |323 | |306 | 364 |366 |306 | |307 | 343 |367 |302 | |310 | 365 |370 |334 | |311 | 350 |371 |333 | |312 | 351 |372 |307 | |313 | 352 |373 |330 | |314 | 353 |374 |335 | |315 | 354 |375 |331 | |316 | 355 |376 |327 | |376 | 227 | | | +---------------+----------------+----------------+---------------+ KOI8-R to Mac Cyrillic For the conversion of KOI8-R to Mac Cyrillic, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | KOI8-R | Mac Cyrillic | KOI8-R | Mac Cyrillic | |24 | 4 |317 |356 | |200-237 | 40 |320 |357 | |240 | 312 |321 |337 | |241 | 254 |322 |360 | |242 | 257 |323 |361 | |243 | 336 |324 |362 | |244 | 271 |325 |363 | |245 | 317 |326 |346 | |246 | 264 |327 |342 | |247 | 273 |330 |374 | |250 | 300 |331 |373 | |251 | 275 |332 |347 | |252 | 277 |333 |370 | |253 | 40 |334 |375 | |254 | 316 |335 |371 | |255 | 40 |336 |367 | |256 | 331 |337 |372 | |257 | 333 |340 |236 | |260 | 334 |341 |200 | |261 | 253 |342 |201 | |262 | 256 |343 |226 | |263 | 335 |344 |204 | |264 | 270 |345 |205 | |265 | 301 |346 |224 | |266 | 247 |347 |203 | |267 | 272 |350 |225 | |270 | 267 |351 |210 | |271 | 274 |352 |211 | |272 | 276 |353 |212 | |273 | 40 |354 |213 | |274 | 315 |355 |214 | |275 | 40 |356 |215 | |276 | 330 |357 |216 | |277 | 332 |360 |217 | |300 | 376 |361 |237 | |301 | 340 |362 |220 | |302 | 341 |363 |221 | |303 | 366 |364 |222 | |304 | 344 |365 |223 | |305 | 345 |366 |206 | |306 | 364 |367 |202 | |307 | 343 |370 |234 | |310 | 365 |371 |233 | |311 | 350 |372 |207 | |312 | 351 |373 |230 | |313 | 352 |374 |235 | |314 | 353 |375 |231 | |315 | 354 |376 |227 | |316 | 355 | | | +---------------+----------------+----------------+---------------+ FILES
/usr/lib/iconv/*.so conversion modules /usr/lib/iconv/*.t conversion tables /usr/lib/iconv/iconv_data list of conversions supported by conversion tables SEE ALSO
iconv(1), iconv(3C), iconv(5) SunOS 5.10 18 Apr 1997 iconv_koi8-r(5)
All times are GMT -4. The time now is 06:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy