1
1
use crate :: cpio:: { cpio_commands, print_cpio_usage} ;
2
- use crate :: dtb:: { dtb_commands , print_dtb_usage , DtbAction } ;
2
+ use crate :: dtb:: { DtbAction , dtb_commands , print_dtb_usage } ;
3
3
use crate :: ffi:: {
4
- cleanup, compress, decompress_raw, formats, repack, sign, split_image_dtb, unpack, verify
4
+ cleanup, compress, decompress_raw, formats, repack, sign, split_image_dtb, unpack, verify,
5
5
} ;
6
6
use crate :: patch:: hexpatch;
7
7
use crate :: payload:: extract_boot_from_payload;
8
8
use crate :: sign:: sha1_hash;
9
9
use argh:: FromArgs ;
10
10
use base:: {
11
- cmdline_logging , libc :: umask , log_err , map_args , raw_cstr , EarlyExitExt , LoggedResult ,
12
- MappedFile , ResultExt , Utf8CStr ,
11
+ EarlyExitExt , LoggedResult , MappedFile , ResultExt , Utf8CStr , cmdline_logging , libc :: umask ,
12
+ log_err , map_args , raw_cstr ,
13
13
} ;
14
14
use std:: ffi:: c_char;
15
15
@@ -259,14 +259,10 @@ Supported actions:
259
259
) ;
260
260
}
261
261
262
- #[ no_mangle]
263
- pub unsafe extern "C" fn main (
264
- argc : i32 ,
265
- argv : * const * const c_char ,
266
- _envp : * const * const c_char ,
267
- ) -> i32 {
262
+ #[ unsafe( no_mangle) ]
263
+ pub extern "C" fn main ( argc : i32 , argv : * const * const c_char , _envp : * const * const c_char ) -> i32 {
268
264
cmdline_logging ( ) ;
269
- umask ( 0 ) ;
265
+ unsafe { umask ( 0 ) } ;
270
266
let res: LoggedResult < ( ) > = try {
271
267
let mut cmds = map_args ( argc, argv) ?;
272
268
if argc < 2 {
@@ -295,44 +291,61 @@ pub unsafe extern "C" fn main(
295
291
dump_header,
296
292
ref mut img,
297
293
} ) => {
298
- return unpack (
299
- Utf8CStr :: from_string ( img) . as_ptr ( ) ,
300
- no_decompress,
301
- dump_header,
302
- ) ;
294
+ return unsafe {
295
+ unpack (
296
+ Utf8CStr :: from_string ( img) . as_ptr ( ) ,
297
+ no_decompress,
298
+ dump_header,
299
+ )
300
+ } ;
303
301
}
304
302
Action :: Repack ( Repack {
305
303
no_compress,
306
304
ref mut img,
307
305
ref mut out,
308
306
} ) => {
309
- repack (
310
- Utf8CStr :: from_string ( img) . as_ptr ( ) ,
311
- Utf8CStr :: from_string ( out) . as_ptr ( ) ,
312
- no_compress,
313
- ) ;
307
+ unsafe {
308
+ repack (
309
+ Utf8CStr :: from_string ( img) . as_ptr ( ) ,
310
+ Utf8CStr :: from_string ( out) . as_ptr ( ) ,
311
+ no_compress,
312
+ )
313
+ } ;
314
314
}
315
315
Action :: Verify ( Verify {
316
316
ref mut img,
317
317
ref mut cert,
318
318
} ) => {
319
- return verify ( Utf8CStr :: from_string ( img) . as_ptr ( ) , cert. as_mut ( ) . map ( |x| Utf8CStr :: from_string ( x) . as_ptr ( ) ) . unwrap_or ( std:: ptr:: null ( ) ) ) ;
319
+ return unsafe {
320
+ verify (
321
+ Utf8CStr :: from_string ( img) . as_ptr ( ) ,
322
+ cert. as_mut ( )
323
+ . map ( |x| Utf8CStr :: from_string ( x) . as_ptr ( ) )
324
+ . unwrap_or ( std:: ptr:: null ( ) ) ,
325
+ )
326
+ } ;
320
327
}
321
328
Action :: Sign ( Sign {
322
329
ref mut img,
323
330
ref mut args,
324
331
} ) => {
325
332
let ( pem, pk8) = match args. get_mut ( 1 ..=2 ) {
326
- Some ( [ pem, pk8] ) => ( Utf8CStr :: from_string ( pem) . as_ptr ( ) , Utf8CStr :: from_string ( pk8) . as_ptr ( ) ) ,
333
+ Some ( [ pem, pk8] ) => (
334
+ Utf8CStr :: from_string ( pem) . as_ptr ( ) ,
335
+ Utf8CStr :: from_string ( pk8) . as_ptr ( ) ,
336
+ ) ,
327
337
_ => ( std:: ptr:: null ( ) , std:: ptr:: null ( ) ) ,
328
338
} ;
329
- return sign (
330
- Utf8CStr :: from_string ( img) . as_ptr ( ) ,
331
- args. first_mut ( )
332
- . map ( |x| Utf8CStr :: from_string ( x) . as_ptr ( ) )
333
- . unwrap_or ( raw_cstr ! ( "/boot" ) ) ,
334
- pem, pk8
335
- )
339
+ return unsafe {
340
+ sign (
341
+ Utf8CStr :: from_string ( img) . as_ptr ( ) ,
342
+ args. first_mut ( )
343
+ . map ( |x| Utf8CStr :: from_string ( x) . as_ptr ( ) )
344
+ . unwrap_or ( raw_cstr ! ( "/boot" ) ) ,
345
+ pem,
346
+ pk8,
347
+ )
348
+ } ;
336
349
}
337
350
Action :: Extract ( Extract {
338
351
ref payload,
@@ -353,7 +366,11 @@ pub unsafe extern "C" fn main(
353
366
ref mut src,
354
367
ref mut dest,
355
368
} ) => {
356
- if !hexpatch ( file, Utf8CStr :: from_string ( src) , Utf8CStr :: from_string ( dest) ) {
369
+ if !hexpatch (
370
+ file,
371
+ Utf8CStr :: from_string ( src) ,
372
+ Utf8CStr :: from_string ( dest) ,
373
+ ) {
357
374
Err ( log_err ! ( "Failed to patch" ) ) ?;
358
375
}
359
376
}
@@ -368,7 +385,7 @@ pub unsafe extern "C" fn main(
368
385
0
369
386
} else {
370
387
1
371
- }
388
+ } ;
372
389
}
373
390
Action :: Dtb ( Dtb {
374
391
ref mut file,
@@ -381,13 +398,15 @@ pub unsafe extern "C" fn main(
381
398
0
382
399
} else {
383
400
1
384
- }
401
+ } ;
385
402
}
386
403
Action :: Split ( Split {
387
404
no_decompress,
388
405
ref mut file,
389
406
} ) => {
390
- return split_image_dtb ( Utf8CStr :: from_string ( file) . as_ptr ( ) , no_decompress) ;
407
+ return unsafe {
408
+ split_image_dtb ( Utf8CStr :: from_string ( file) . as_ptr ( ) , no_decompress)
409
+ } ;
391
410
}
392
411
Action :: Sha1 ( Sha1 { ref mut file } ) => {
393
412
let file = MappedFile :: open ( Utf8CStr :: from_string ( file) ) ?;
@@ -406,31 +425,31 @@ pub unsafe extern "C" fn main(
406
425
ref mut file,
407
426
ref mut out,
408
427
} ) => {
409
- decompress_raw (
410
- Utf8CStr :: from_string ( file) . as_mut_ptr ( ) ,
411
- out. as_mut ( )
412
- . map ( |x| Utf8CStr :: from_string ( x) . as_ptr ( ) )
413
- . unwrap_or ( std:: ptr:: null ( ) ) ,
414
- ) ;
428
+ unsafe {
429
+ decompress_raw (
430
+ Utf8CStr :: from_string ( file) . as_mut_ptr ( ) ,
431
+ out. as_mut ( )
432
+ . map ( |x| Utf8CStr :: from_string ( x) . as_ptr ( ) )
433
+ . unwrap_or ( std:: ptr:: null ( ) ) ,
434
+ )
435
+ } ;
415
436
}
416
437
Action :: Compress ( Compress {
417
438
ref mut file,
418
439
ref mut format,
419
440
ref mut out,
420
441
} ) => {
421
- compress (
422
- Utf8CStr :: from_string ( format) . as_ptr ( ) ,
423
- Utf8CStr :: from_string ( file) . as_ptr ( ) ,
424
- out. as_mut ( )
425
- . map ( |x| Utf8CStr :: from_string ( x) . as_ptr ( ) )
426
- . unwrap_or ( std:: ptr:: null ( ) ) ,
427
- ) ;
442
+ unsafe {
443
+ compress (
444
+ Utf8CStr :: from_string ( format) . as_ptr ( ) ,
445
+ Utf8CStr :: from_string ( file) . as_ptr ( ) ,
446
+ out. as_mut ( )
447
+ . map ( |x| Utf8CStr :: from_string ( x) . as_ptr ( ) )
448
+ . unwrap_or ( std:: ptr:: null ( ) ) ,
449
+ )
450
+ } ;
428
451
}
429
452
}
430
453
} ;
431
- if res. is_ok ( ) {
432
- 0
433
- } else {
434
- 1
435
- }
454
+ if res. is_ok ( ) { 0 } else { 1 }
436
455
}
0 commit comments